Code::Blocks - a quicker way to add new files - codeblocks

I'm using Code::Blocks 16.0.1. Now, when I'd like to add a new C source file I have to navigate using my mouse a lot: go to the file submenu, select File, select C/C++ source, select the directory to create it in - too much mouse usage!!
Is there any way to do it more quickly? I'd rather right click on the destination directory, to add the file there, for example.\
Still, I'd like to get a template with the include guards.

Drag & drop directly into the left-tree, under Sources or project icon.

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.

Code Blocks(New project/Rename main file)

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.

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 :)

How is "Add Existing Item..." in Visual Studio meant to work?

I never use "Add existing item..." feature in Visual Studio's Solution Explorer because it is confusing:
it seems to me the way it should work is that if you have a Customer.cs file in Models directory, that you could choose "Add existing item", it would then show you which items exist in that directory an allow you to choose one. Instead, it opens a file dialogue to some seemingly random directory on your hard drive, and I'm not sure if it is going to make a copy of that file, or use it outside the solution, etc.
instead, if I want to "add an existimg item", I go into windows explorer, click file, CTRL-C, click folder in solution explorer, ctrl-v, and it is clear
Do others do it differently? Am I missing something about how "add existing item" in solution explorer is supposed to work?
The folder opens where-ever you last left it...
As for using this feature; by default (Add) it does IMO the least useful thing; copy the file. But if you notice, the add button is actually a drop-down; hit the down arrow and you can add a link to the file - i.e. leave it where it is and reference it by location (Add As Link).
The quick and easy way to do what you are trying to do (add an existing file that already exists within the folder in your project) is:
At the top of the Solution Explorer window is an icon/button for "Show All Files", enable it (if it is already enabled and the file you are looking for is not shown, click "Refresh"). Note that this setting is enabled on a per project basis.
Right click on the file that you want to include and select "Include in Project".
Add Existing file adds the file to the project. Keeping it in the project directory is something different and making it a part of the project is something different. By making it a part of the project, its entry is made in .csproj/.vcproj/etc and then further properties can be set of this file such as specifying a custom build step etc.
And No, it doesn't create a copy of the file in your current project's directory in case of a Visual C++ project. In case of a CSharp Project, it does create a copy.
e.g., I use this when I need to add a bitmap/png file in my project which I have gotten from an external source. I just copy the file to my project directory and then use Add Existing File to add this to the project.
I'm using it. I even didn't know it's possible to ctrl+c ctrl+v in solution explorer.
It's particulary handy, if you want to add something 'as link'.
I do use it but often I just add file as a link. That make it easier to maintain some common classes if you do not want to make full assembly out of them.
As far as my experience goes using this function, it does the same copy and paste that you are describing.

Moving files from one Visual Studio solution to another

What I usually do is create a new file in the solution where I want to use it (same name), copy & paste the contents of a class from the source solution to the target, fix the namespace & imports as needed.
The only other way I know to do it is open the source file in the target solution and then just save a copy into that folder, which can get confusing with two files open with the same name in one solution.
Does anyone have an easier way to do this?
You can just copy and paste the files themselves.
When you have your solution open, look at the top of the solution explorer and you'll see an icon that looks like a page with a page outline behind it and a yellow page (not a very intuitive icon). This is the "show all files" button. Click that and you'll see all the files in your currently selected project (it is project-specific). Highlight any files that you want to include, right-click, and select "Include in Project."
You could just copy the file with Explorer. Or better yet, start refactoring your projects so that you'll create assemblies that are usable by multiple client projects.

Resources