Code Blocks(New project/Rename main file) - codeblocks

When I create a new project in code blocks File->New->project->console application->Go->C++-><project title>->GNU compiler->finish (both debug and release box are checked), Then a project is created having .cpp file with name of main.
My question is how to rename this main file.
Before asking this question I have tried to solve it, but it includes many steps.
I have tried two ways (one way gives me a solution, and the other way indicates that file has been corrupted).
Actually I want to find a quick way to rename this main file?
If there is any method please tell me.
Two methods which I used(mentioning below)
File->New->project->console application->Go->C++-><project title>->GNU compiler->finish
then go to local disc (where project is saved) rename main file. Open project again in code blocks. Open main file it says file does not exist.
This method was quick but failed to rename main.
File->New->project->console application->Go->C++-><project title>->GNU compiler->finish.
then in code blocks at left side bar Sources/main/right click on main/remove file from project (then code blocks indicate you have deleted this main file but actually its not when I checked in local disk, main file was there). Then I create a new.cpp` file as File/New/File and next simple steps.
So finally I got what I want. A new project with .cpp file (name of .cpp file that I want). But I'm not satisfied, I want a quick method.

As of Code::Blocks 13.12 you can rename a file within a project
like this: Say the file to be renamed is main.cpp in project
MyApp.
In the C::B Management pane navigate in the Projects tree-view to
Projects -> MyApp -> Sources -> main.cpp.
Right-click on the file-icon of main.cpp. A pop-up menu appears.
The third item on the menu is Rename file. You can take it from there

Capture your code in a text file.
Close code::blocks
In the folder containing the files, rename all *.cpp and *.h or whatever your using including the cbp file. Don't need to change the depend or layout. Delete the bin and debug folders.
Double click the cbp (project file).
Remove the old files (right mouse click remove).
Then right mouse click on the project and select "add files".
Choose your newly named files, build and run.

In Code::Blocks 16.01, assuming your project and files are open:
If you want to rename main.cpp then, in the Management window, Projects tab, navigate to the Sources folder of your project and right-click on main.cpp. In the context menu that appears, if you find Close main.cpp menu item — click it! otherwise click Rename file...
If you want to rename the title of your project, in the Management window, Projects tab, right-click on the title of your project. In the context menu that appears click Properties... to open the Project/targets options window, and type the new title of your project in the Title field. NOTE that this will not change the name of the project folder or the name of your project's .cbp file, because the title of your project is stored inside the .cbp file.
If you want to rename any file or folder in your project, first close the project using the File menu, then, in the Management window, Files tab, navigate to the desired file or folder, right-click on it and choose Rename.... Proceed with care. You might want to delete old .dependand .layout files that are no longer associated with your project.

In newer versions of CodeBlocks, simply close the file editor and right click on the file (at left tree) -> Rename File.

Related

How to move GlobalSuppressions.cs (Suppress Code Analysis) from project root in special folder?

I would like to move GlobalSuppressions.cs (Suppress Code Analysis) from project root in special folder.
Example
I would like to use one GlobalSuppressions.cs file in several projects of one solutions.
I don't think it is possible to move it. If you do, it simple recreates the file in the root folder. If you wanted to share the file, then you could:
Right-click on the other project
Click Add Existing Item
Locate the GlobalSuppressions.cs file and select it (single-click only)
Click the down-arrow just to the right of the Add button
Select Add As Link
This will basically add a shortcut to the file in your other project. You can tell if it has worked because the file icon in Solution Explorer will have a little blue arrow and square.

How can I change the location of files in xcode project?

I put some files on the same level of *.xcodeproj file carelessly. When I move these files into the right location in Finder, Xcode tells me that these files are missing. So I delete the group which contains these files whose names have been read (I realize it is a mistake). And I drag these files from Finder into the xcode to build a new group. But when I try to run the project, Xcode still can't find these code. How can I solve the problem?
When you see a file that is red (or in the wrong place), you can easily correct the location of these files by using the file inspector (which appears along the right side panel of your Xcode window).
It looks like this:
Clicking on the Folder icon next to the name will bring up an open panel from which you can choose the correct location of the file.
There is an easier way to re-organize files through the Xcode project. You can use Synx, it automatically fixes file paths, through the Xcode project groups.
You can check Github page for Synx
Synx
After intalling Synx just run the command below
synx path/to/my/project.xcodeproj
I found the answer.
3 things
1
removed the reference to the red files
then dragged them back into the project
relinked all my .m and .h files just incase
2
then removed the .app reference and dragged it back in to the project.
3
removed any duplicates or red files in the build phases
Fixed
Thanks everyone for your suggestions and help
From my point of view i would definitely avoid the virtual folders in the Xcode.The disadventage of this approach is whe nthe project gets bigger and bigger you can not find corresponding files in your filesystem easy.Even you click on "Show in finder" you need to look for the file among tens of files.
My approach is creating the folder in the finder and then dragging it to project.when i need to create a new file in this subfolder is will be added there anyhow.
Drag the new files from the finder to the Xcode project file structure.
Remove the old files.
I had a lot of class and find a good solution for solve this problem :)
1- Select a file that you want to change the location (Red)
2- Select "show the file inspector" from right side in Xcode
3- Select wrong path or unexpected path and copy like this screenshot
4- Close your project
5- Go to your root project and right click on "project *.xcodeproj" and select "Show package contents"
6- Right click on "project.pbxproj" and open with TextEdit
7- In the file select "Find and replace" or click on " Option+Command+F " and find location that you copied and replace with "" empty
8- Save and open the Xcode :)

Standard way to rename xcode project

After I create a project name for example Proj11, I'd like to change the name to Proj12.
So I use Project->Rename, then the name of the project to Proj12
But the project still contains several folders name Prlj11, and after I change the folders' name, the project can't been loaded.
So what is the standard way to rename my project as well as folder name.
Click on the project folder (blue folder with your app name on the top of the project navigator). Pull up the utilities (right pane), then file inspector. Your project name is there, change it to whatever you want. Then it will ask to save, keep all the files it selected for you selected, then press rename
The best answer I found was on the apple developer site. Imagine that? You can follow the link below, but essentially it is:
1) click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
2)a window will appear confirming the change and what it will change. Once you confirm it will make the changes.
https://developer.apple.com/library/ios/qa/qa1625/_index.html
OR ANOTHER WAY AND EVEN EASIER:
left-click on the name project and rename. As soon as you rename it will ask you if you want to rename:
The folders you see in XCode navigators are not an actual folder/directories, these are virtual folders only to group your files.
And the folders you see in Finder, the path you manually set for the project, you need to rename them manually.

Renaming xcode 4 project and the actual folder

I know how to rename the project in Xcode 4, but how do you rename the source folder? The thing is that renaming the project in Xcode, does only rename within Xcode (Though it is progress compared to previous) - but why Xcode is not renaming the folder in the filesystem I don't know.
You can do this from within Xcode without resorting to hand editing the pbxproj file in a text editor!
Here's how:
Rename your source folder in the Finder. This will break the project initially because Xcode doesn't automatically detect when the real folders that the virtual (yellow) project folders point to are changed, so all the files inside that folder will turn red in Xcode. Don't worry about that, we'll fix it in step 3.
In Xcode, click on the (now broken) virtual folder in the left-hand sidebar and rename it to match the name in the Finder (you can actually call it anything you want, or not rename it at all, but that would be insane). That won't fix the red files inside the folder, but that's OK.
In the right-hand sidebar in Xcode, click the icon shown in the screenshot below to bring up a file dialog. Select the folder that you previously renamed. This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.
In your build settings, search for the old folder name and manually rename any occurrences you find. There will typically be two of them, oldfolder/prefix.pch and oldfolder/info.plist, but there may be others.
All done!
EDIT: this option is still there in Xcode 5, but is helpfully hidden by default. To show it, click the thin "Identity and Type" header in the inspector above the "Text Settings" panel to expand it.
I've done it dozens of times:
Rename the Project by clicking then editing the Title in your Xcode Project Navigator.
Close Xcode.
Rename the source folder.
From the Finder, open the .pbxproj file inside project bundle (context menu "Show Package Contents") with any text editor.
Search and replace any occurrence of the original folder name with the new folder name.
Save the file.
Open Xcode project.
Task:
Rename "Play" to "Play2" both in Xcode and in Finder
Change this:
To this:
STEPS:
// Before anything, please backup the project in Finder!
Rename project in Xcode Project navigator // Click project name then hit enter
Rename group in Xcode Project navigator // not affecting folder name in Finder
Close Xcode
Rename outer folder (left column in image) in Finder
// All above steps are straight-forward and without side effects
//
// Now comes the tricky part: rename the inner folder (middle column in image) in Finder (the one at the same level with .xcodeproj)
Rename the inner folder in Finder while keeping Xcode closed
Right click .xcodeproj, select "Show Package Contents"
Open .pbxproj file with Mac TextEdit
Search and replace all "Play" with "Play2". To guarantee everything goes right, click the arrow on the left end of the search bar and modify the search attribute. Change "Contains" to "Full word", and uncheck "Ignore case"
Save .pbxproj file
Open Xcode project and Run
Here is how to rename a project effectively in XCode4 (INCLUDING THE FILES FOLDER):
Close all open projects completely in XCode to prevent any issues
Copy the Project in question to a new Folder (IMPORTANT: KEEP A BACKUP OF YOUR OLD PROJECT)
Open the Project
Rename the Project itself in XCode4 (double click on the project name), change the name and follow the steps (yes to everything)
Go to product, manage schemes and rename the scheme (double click on the scheme name)
Close your project (make sure is completely closed otherwise the next steps will not work)
In Finder go to the Project folder and right click on the .xcodeproj file, then select the option "Show Package Contents"
Then right click on the .pbxproj file and open it with TextEdit
Replace all occurrences of the Folder Name where the projects used to live (The old project name for the new project name)
Save the file
Open the Project again and Build it!
First of - dont rename an Xcode project!!!
If you have to, the beneath could be it - I never got it to work, ended up creating a new project and started all over copying in the existing files. Xcode is so ahh.... It has so many non productive things, like also try renaming a file from "Name" to "name". Well, well have fun.
I found the answer or how to work around this: Open the pbxproj file by right clicking "Show Package Content" and in there you edit a project.pbxproj file - you have to rename a reference called path and some other stuff - just search for the folder name added "/".
That is it.
Hope it helps some one.
Here is another issue that you should be aware of while replacing values in your *.pbxproj file. If your old folder name was FooBar you will have an entry in your *.pbxproj file that looks like this:
path = FooBar
Suppose your new folder name is Foo Bar. That is, you are introducing a space. Then, this line should become
path = "Foo Bar"
If you just do a simple find and replace, the result will be a *.pbxproj file that Xcode can't parse. If your new folder name has a space and the old name didn't have a space, be sure to include the double quotes.
I am summing up for myself, after examining various answers above and trying myself.
Let's assume the current project name is ProjAbc and you want to rename it to ProjDef:
Exit Xcode of that project.
In Finder, Duplicate the folder ABOVE ProjAbc.xcodeproj for backup.
In Finder, Rename freely the folder ABOVE ProjAbc.xcodeproj if you feel you need it to suit new project name.
In Finder, Rename the source files folder parallel to ProjAbc.xcodeproj from ProjAbc to ProjDef
Open Xcode for ProjAbc.xcodeproj (in Project Navigator, all files in virtual source folder ProjAbc will be in Red color).
In Xcode, click on the (now broken) virtual folder in the Project Navigator in the left-hand sidebar and rename it to match the name in Finder - ProjDef. That won't yet fix the red files inside the folder, but that's OK.
In Xcode, (still selecting the virtual folder in the left-hand sidebar) in the right-hand sidebar, in the File inspector, click the icon shown in the screenshot below to bring up a file dialog. In the file dialog, select the folder that you previously renamed (ProjDef). This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.
In Xcode, in Project Navigator, click on the ProjAbc project name, and rename it to ProjDef.
You will be prompted: "Rename project content items?". Click "Rename" button.
You will be prompted: "Would you like Xcode to take automatic snapshots before Project Rename and similar operations?". Click either "Disable" or "Enable". It does not matter.
In Xcode, now open "Build Settings" inside ProjDef target (inside project ProjDef in Project Navigator). Rename both foldername and filename of both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc.
In Xcode, in Project Navigator, in ProjDef virtual sources folder, in "Supporting Files", also rename again both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc
In Xcode Menu, press Product/Scheme/Manage Schemes... (or click "ProjAbc"> Scheme name in Scheme Bar at left top of Xcode, and press "Manage Schemes...") and in the dialog box rename Scheme from ProjAbc to ProjDef, then press "OK" button. If Project name is composed of single word, you may run it just now!
In Xcode, edit the top comment line in Supporting Files/*-Prefix.pch file, and replace ProjAbc by ProjDef (2 times). Of course correcting this comment is optional.
Exit Xcode.
In Finder, point to ProjDef.xcodeproj and open it in text editor. (Either open it in TextWrangler.app , or, mouse right-click and in the pop-up menu press "Show Package Contents" then edit file project.pbxproj in TextEdit.app)
In the Text Editor, search "ProjAbc" (Entire Word, Match Case) which should appear once (in paragraph: /* Begin PBXNativeTarget section */ in line: productName = ProjAbc;) and replace it by "ProjDef". Indeed, project could run anyway!, so this step is optional.
if project name is composed of 2 or more separate words, like "ProjDef Geh", then you MUST do next steps: Search for the reference to the Finder folder of the virtual source files folder -
Search for the line: path = ProjDef Geh;
It will appear once, in paragraph /* ProjDef Geh */
Replace it by the line: path = "ProjDef Geh";
Save from text editor, and exit the Text Editor.
That's it. As written above, if project name is composed of single word, you can run right at end of step 11.
I found the above answers really useful, especially Nick Lockwood's answer.
I just renamed a couple of folders in Xcode 8 and encountered two more issues:
A) "missing from working copy errors"
B) Core Data crashes.
How to resolve these two issues:
A) "missing from working copy errors"
I found the below answer very useful: Swift 3 / Xcode 8 Upgrade - 100's of DerivedData files missing from working copy errors
Basically Xcode 8 has rigorous source control, which can lead to the above errors. You have to:
Clean Xcode derived data.
Go to Source Control and click Refresh Status.
Go to Source Control and click Commit; select all the files on the left sidebar of the commit menu when committing (right click -> Select All).
You'll probably get an error.
Close the Commit menu.
Refresh Status.
Close your project by quitting Xcode.
Reopen your project, refresh status, commit again.
This time the commit should work.
Click Project -> Clean.
I'm assuming that you have already enabled Source Control. If you haven't, or if you get stuck following my instructions, just follow the more detailed instructions in the link provided.
B) Core Data crashes
Renaming folders will sometimes screw up Core Data. There are several possible reasons why this is so, and below are some fixes I can suggest:
Incorrect AppDelegate model name. This was the case in my situation. Go to your AppDelegate and find let container = NSPersistentContainer(name: "YOUR CORE DATA MODEL NAME"). Make sure that the name is correct.
In the future (several years after this post, when Apple changes Core Data again) or if you're using an older version of Core Data, take a careful look at AppDelegate. There's probably something funky there that's messing with your Core Data.
Incorrect model name in xcdatamodeld. Go to Finder and open your .xcdatamodeld in a text editor.
Check the following:
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>YOUR CORE DATA MODEL NAME.xcdatamodel</string> <-- Make sure this is correct.
</dict>
</plist>
More detail here: Core Data model files does not load on rename
If the two things above don't work, try to 1) delete your entity and then add another entity that's identical or 2) delete your xcdatamodeld and then add another data model that's identical (and make sure that the name of the new xcdatamodeld matches what is in your AppDelegate and the rest of your code). Never do this with a live App - or if you do this, make sure to properly migrate your Core Data whilst doing so.
If you are have old reference of source project into your project, When dublicate the project (every change made affect to both proejct)
here the solution
Dublicate Project from source project
Rename source folder of source project that break reference issue.
In dublicate proejct everything goes red choose your current folder of project. (screenshot is shows in green tick answer of stackoverflow)
========================================================================

Cannot add an icon to Resources

Have been inputting and testing some sample code and everything seems to be ok. Just that suddenly I am running into this very frustrating problem of trying to add an icon to the project. Have downloaded an icon file (extension : icns) to my desktop and dragged it to the "Resources" group in xCode. Then a dialogue comes up from xCode where I checked the 2 options : "Copy items into destination group's folder (if needed)" and "Recursively create groups for any added folders". But when I press the "Add" button, an "Alert" message box would come up. It says "Could not copy the icon to ...". Hope that someone knowledgable in this area would give me some hints...
This failure message usually results from attempting to add a file (that is outside the project folder), when a file with that name already exists in the target location within the project folder.
For example, let's say your project folder is ~/Developer/CoolProject/, and the Xcode project is at ~/Developer/CoolProject/CoolProject.xcodeproj. If you drag an image, coolImage.png, from your Desktop to Xcode with the options set as you described, Xcode will copy the image file to ~/Developer/CoolProject/coolImage.png. If you then repeat this same procedure, it will fail the second time with that error message.
What I would do is, in the Finder, check inside your project folder to see if the icns file has already been copied into the project folder. If there's a copy of the icns file already in the project folder, and that icns file isn't listed in the Groups & Files list in Xcode, you can resolve the problem by dragging the existing copy (that's inside the project folder) into the Xcode project window to bring up the Add File dialog. You can keep the same options as before, and this time, Xcode won't need to copy the image and so you'll avoid the error.
[UPDATED] OK, so what you'll want to do, based on the comment above, is go in the Finder and remove the existing .icns file from your project (in other words, move it to the Trash). Then you can re-add an icon with the same name (from a location outside your project folder) without getting the error. Also, in the future, remember that you might want to consider using the Also Move to Trash option when deleting files from within Xcode, if you no longer want the unused items inside your project folder.
Also, you may want to double-check to make sure the file in question is included as part of the Active Target. For example, if you add a file to your project, but the "include in active target" checkbox for the file is unchecked (like the ReadMe.rtfd file in the image below), then the file won't be copied into your application bundle at build time or be available at runtime.
(To add that Active Target checkbox column to the Groups & Files list, Control-click on the table column header view and choose Target Membership from the menu).

Resources