Eclipse: tried to use Text editor for .xml and .properties by changing the file associations
Windows -> Preferences -> General -> Editor -> File assocations
Can not remove or change order of the associated apps.
The fact that *.xml files are opened with the XML Editor is due to the content types settings: Window > Preferences: General > Content Types (Text > XML). Also for *.properties files there is an associated editor in Content Types (Text > Java Properties File).
If you want to open by default *.xml and *.properties files with the text editor, do the following in Window > Preferences: General > Content Types:
Click Add Root... and enter a name, e. g. XML
Kepp the new content type selected and in the section File associations click Add... and enter *.xml
Kepp the new file association selected and in the section Associated editors click Add... and choose the Text Editor
Repeat the steps with for *.properties files.
Under file types remove .xml and .properties, add them again, the click on each one and in the view below select the editor you want to be associated with the file type selected. if multiple you can select one as the default. Should be pretty straight forward.
I am implementing refactor action for my custom eclipse editor. When the file is renamed, I reset the editor input based on the renamed file and also update the part name.
However the editor references still hold the previous input and file names. Thus eclipse does not know changes to the editor window and cause problems later on like "empty editor tab" exceptions.
How to update the editor references for refactor actions on eclipse editor?
In your class derived from EditorPart do something like:
IEditorInput input = ... new editor input
setInputWithNotify(input);
setPartName(input.getName());
firePropertyChange(PROP_DIRTY);
We are currently using Apache Velocity and some of the files are just standard HTML files but have the extension .vm which means that they aren't recognized as HTML files and hence don't have syntax highlighting etc.
Is there a way to force a certain file type extension to be treated as another file type within Eclipse? For example our .vm files to be treated like .html files so correct syntax highlighting and code formatting is used by Eclipse.
Is there a built in way to do this or would I need to get a plugin to add this type of functionality?
Add *.vm to the HTML content type in Window -> Preferences -> General -> Content Types.
Then associate the file type with an editor in Window -> Preferences -> Editors -> File Associations. The default editors for HTML files are associated automatically by the content type.
I have in my source code:
// foo.cpp
struct foo
{
foo() {}
#ifdef I_WANT_THIS_FEATURE
void bar() {}
#endif
};
In my Makefile I have
foo.o: foo.cpp
g++ -c -DI_WANT_THIS_FEATURE foo.cpp -o foo.o
This compiles fine from the command line as well as with the external builder that I have created in Eclipse (which basically defines a few environment variables and calls make) and I can call foo::bar().
However, in the Eclipse CDT source code editor, the part where I define foo::bar() has a grey background (suggesting that foo::bar() would not be included in the build) and code completion on objects of type foo does not suggest bar() as a method that can be called.
How can I define the I_WANT_THIS_FEATURE macro in an Eclipse CDT makefile project with custom makefile so that it is known to the source code editor and the code completion?
In addition to Oswald's answer:
If you have several build configurations, the default behavior of the Eclipse Indexer seem to be that it always uses the first build configuration.
In my case the define was only defined in the 3rd build configuration, so the solution provided by Oswald did not help.
To change this globally, select Window -> Preferences -> C/C++ -> Indexer.
Choose Use active build configuration
You could also choose to override the global settings in the project settings under Project -> Properties -> C/C++ General -> Indexer and select Enable project specific settings followed by selecting Use active build configuration.
After this, the solution provided by Oswald should work:
Project -> Properties -> C/C++ General -> Paths and Symbols
Choose the Symbols tab and Add... a new Symbol with Name I_WANT_THIS_FEATURE and a Value of 1.
Found it: Project -> Properties -> C/C++ General -> Paths and Symbols
Choose the Symbols tab and Add... a new Symbol with Name I_WANT_THIS_FEATURE and a Value of 1.
Using -D with almost every compiler and just supplying a name like -DI_WANT_THIS_FEATURE defines the symbol I_WANT_THIS_FEATURE with a value of 1.
The eclipse indexer/editor apparently does not know that, so:
#if I_WANT_THIS_FEATURE
this code is marked inactive in editor,
but will be seen by compiler and cause error
#endif
where:
#ifdef I_WANT_THIS_FEATURE
this code is marked active in editor
#endif
So, this is really a problem with eclipse not knowing that default value for a symbol defined through -D is 1.
Eclipse makes this rather confusing, since there are multiple places to set this, and the settings are coupled, but here's how it works:
To set custom macros for a given project (affects both building and indexing in Eclipse)
Here's my preferred way to do it.
In this example we will set the following defines at the Eclipse project level (for its indexer and builder) rather than in your source code.
#define ARDUINO 1000
#define AVR
#define __AVR_ATmega328__
If you were defining them at the command-line when manually building a gcc or g++ project, the above #defines would look like this (search for -Dmacro in the man gcc pages for details):
-DARDUINO=1000 -DAVR -D__AVR_ATmega328__
So, do the following in your Eclipse project. My project here is called "Arduino 1.8.13" (see full screenshot of this a couple images below):
Right-click on your project in the "Project Explorer" pane on the left --> Properties --> C/C++ General --> Paths and Symbols --> Symbols tab --> select either GNU C or GNU C++ --> click the Add button at the top-right --> type ARDUINO for name and 1000 for value --> BE SURE TO CHECK THE 2 BOXES FOR Add to all configurations and Add to all languages (unless you don't want those behaviors) --> click OK.
Repeat this step for all defines, as follows. Be sure to check the boxes for Add to all configurations and Add to all languages (unless you don't want those behaviors) for each one:
Name: ARDUINO, Value: 1000
Name: AVR, Value: (leave empty)
Name: __AVR_ATmega328__, Value: (leave empty)
Here's a screenshot showing the first one. Notice all the highlighted sections to click or pay attention to:
Once you've done this for all macros you wish to define (ex: the 3 above), you will see the following:
If you checked the box for Add to all languages for each one, then these macros will have been applied to BOTH the GNU C and GNU C++ languages. So, click on one and then the other and you should see the macros in both places, like this:
If you checked the box for Add to all configurations for each one, then these macros will have also been applied to all build "Configurations", such as Debug and Release, as shown here:
Keep in mind all of the various combinations of "Languages" and "Configuration" are unique. You can set macros for one or both languages for each configuration individually if you don't check the 2 boxes for Add to all configurations and Add to all languages when adding the macros.
If you navigate to Project Properties --> C/C++ Build --> Settings --> Tool Settings tab --> Cross GCC Compiler --> Preprocessor you will also see these macros now defined for all "GCC" C files, when building or indexing!:
Note that you can also edit, add, or delete macros specific to a given "Configuration" or "Language" (this particular place is for the GNU C language) right here, rather than as previously done above, if you like. BUT, the only way to apply a given macro to ALL languages and ALL build configurations at once is doing it how I showed you above.
You can also see these macros are applied to the GNU C++ build and index settings if you navigate to Project Properties --> C/C++ Build --> Settings --> Tool Settings tab --> Cross G++ Compiler --> Preprocessor:
Again, to customize macros just for C++ and just for this selected "Configuration" you could edit them right here.
When done adding all macros, click Apply or Apply and Close. When asked, choose YES to re-index the entire project:
If you didn't click YES, you may manually trigger the project to be reindexed by right-clicking on it in the Project Explorer and going to --> Index --> Rebuild.
Troubleshooting
If your settings/macros don't seem to be getting applied, and your code still shows sections blacked-out, indicating the macros for those sections are false or undefined, you may need to do or check the following:
Try reindexing your project by right-clicking on it in the Project Explorer and going to --> Index --> Rebuild.
You may not have set the macros for the right build configuration or language. You will need to check all of the various build configurations and languages as I showed in the various screenshots above.
Follow the instructions above and re-add the macros, this time BEING SURE TO CHECK THE 2 BOXES FOR Add to all configurations and Add to all languages.
OR, manually navigate to the Project Properties --> C/C++ Build --> Settings --> Tool Settings tab -->
--> Cross GCC Compiler --> Preprocessor OR
--> Cross G++ Compiler --> Preprocessor...
...sections to manually configure the macros just for one language and/or configuration, or another. ALL of these settings must be either in-sync or set individually.
The easiest place to set these settings, as already stated above, is here: Right-click on your project in the "Project Explorer" pane on the left --> Properties --> C/C++ General --> Paths and Symbols --> Symbols tab. BUT, if you forgot to check the boxes for Add to all configurations and Add to all languages, I recommend just deleting the macros and then adding them again, this time checking those boxes.
If you don't want to worry about which build Configuration you have selected, and you didn't check the Add to all configurations box when you added the macros, you can also change this global workspace setting, but I don't really recommend it:
Window --> Preferences --> C/C++ --> Indexer --> select Use active build configuration. Again, however, I do NOT use this option myself and do not necessarily recommend you use it either. It's just something to be aware of is all.
See also
This answer is also posted on my website here: https://gabrielstaples.com/eclipse-defining-custom-macros-for-indexer/
My full Eclipse setup document here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/eclipse
IN Eclipse i want to chnage the default editor of some .htm files.
If i try to go to FIle Association and assiciate the default editor then file gets opened in that new editor but i don't get the syntax highlighting.
The solution is that the file association is locked ny some plugin editor
Preferences -- Context type----text ----Your editor -- reomve the extension
But i get the .htm(locked) so i cant remove it.
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-content-type.htm
Note: Certain items will be marked as "locked". An item is locked if
it is one of the associations provided by the plug-in that declares
the content type. In other words, you can remove only user-contributed
associations.
Is there any way to remove those locks even thought it can be hackish way but i want to do it
You don't need to "unlock" an existing association to add a new association and make it the default.
Add a new association via the "Add" button
Select the new entry
Hit the "Default" button to make your new entry the default editor
Could it be, that you want to change the "File Association"? This can be done in General / Editors / File Associations. BUT Eclipse uses at least one default-editor and this is the reason for the "locked"-message in the "Content Types". You could set the "Text Editor" to all unwanted types. Looks like a workaround, but makes sense, because it is the same as the file associations of your operating system, that asks you for the program to display the file.
Another question is, why do you want to unlock or remove the "Content Type"? Does it change anything in the Eclipse logic?
Go see this answer from "Greg Desmarais" (assign the desired editor to "default")
https://stackoverflow.com/a/15642583/162094