Rename resource file does not change editor part title - eclipse

In my plugin project, I have a project explorer view where I can rename a config file which in shown in another editor part. The file can be renamed in the explorer with the rename resource dialog but the corresponding the editor tab title does not change. The same problem is described here and also here. Is there a standard way to get the rename functionality working without the creating a custom listener?

Editors based on AbstractTextEditor (or one of its subclasses such as TextEditor) should handle renames through the FileDocumentProvider which listens for resource changes.
Other editors need to use an IResourceChangeListener to deal with this.

Related

How to change open with options in navigator depending upon name of the resource?

I am working on eclipse RCP application which implements CommonNavigator view to display navigator. I have few LinkedResources in navigator that link to files on the file system with custom extension. These custom extension files are opened in custom editor as well as in TextEditor.
One of the file named default.ext will be common to all the projects and I want to keep it read only. Is it possible to open file in custom editor only? For ex. Default.ext should be opened in only custom editor, however Test.ext should be opened in custom editor as well as text editor.
This way I could handle save action in my editor depending upon file name and keep the file read only.
Is there any other way to keep files read only?
Short answer: not possible in the way you describe.
Long answer: if somebody really wants to modify a file then there's no way or need to stop this. What you can do is either (1) hide the file from user or (2) set Read-only flag to discourage users from modifying the file.

it is possible to intercept the Open File menu in eclipse?

My project require to open a file with specified extension in eclipse, but not in a editor. the file should be open in a embedded QT application in a view of eclipse.
my thinking is trying to intercept the open file action in eclipse, and if the file extension is the one i am interesting, then I get the view embedded, and ask it to open the file.
the question is I does NOT find any extension to allow me to hook the Open File ... menu. I debug the eclipse editor, I find there is a IOpenListener which seems to be responsible for open file, I didnot try it.
is there a good way to do this.
I don't think you can associate a view with a file type. You'll have to use an editor, as editors are associated with a file; views are not.
In your plugin.xml, add the org.eclipse.ui.editors extension, and then add an editor to it. Specify the file extension(s) it should handle in the 'extensions' element, along with the name, id, class, etc. of the editor you want to open it with.
If you absolutely must use a view, you could provide a way to open a file from within the view itself. Depending on what you're doing, this will probably be deviating from Eclipse UI guidelines.

Eclipse file associations for extensions with multiple periods

I have several Mako templates in my project that are named things like header.html.tmpl and settings.py.tmpl. I would like to add file associations to Eclipse to open these with the appropriate editors. For example, I would like header.html.tmpl to be opened in the HTML editor, settings.py.tmpl to be opened in the Python editor, etc. I go to Preferences->File Associations and I try adding *.py.tmpl to the list but after I click "Ok" nothing happens and the desired extension does not appear in the list. If I try instead using .py.tmpl I can add it to the list and add the Python editor to its associated editors but when I double-click a .py.tmpl file it doesn't use the correct editor.
Obviously it would probably work to just use -tmpl instead of .tmpl, but I'm wondering if anyone knows a way around this or can confirm that it's a bug/missing feature.
Its a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=168573

How to programmatically reload a text editor in Eclipse?

In Eclipse, if I change a file programmatically, and it is open in a text editor, it doesn't always reload, not even when refreshing the resource programmatically. How can I forcibly reload the text editor from code so that it show the changed file contents?
In your project explorer or navigator, you can right-click on the file that's currently open and select refresh. This has always worked for me, even when editing files with several programs. Make sure to click the file itself, not parent objects like packages or folders or projects.
Edit
Refreshing programmatically? I would look into an Eclipse scripting tool:
http://eclipse-shell.sourceforge.net/
I guess there was another one called Monkey, but it doesn't appear to be maintained.
I don't know of any possibility to programmatically reload the file.
Some editors (e.g. GMF editors) look for changes in the underlying files, and refresh themselves, but this is not required at all.
I don't think that a forced reload is an option implemented globally, as in some cases there could be some merging steps involved that can be quite erroneous.
My ideas to solve this:
Have a specific editor that refreshes its content when the used resource changes (this can be timeconsuming);
Or close the editors of the file and reopen them (this is ugly in the eye of the user).
Since the Luna release of eclipse there's no need to reload files with F5/manual Refresh.
Really nice, especially as there was a bug with the F5 key binding.

How do I open my editor while I am selecting a file in project explorer?

When i am selecting a file in the project explorer, it should allow me to open my editor instead it shows text editor.How can we handle this programmatically in eclipse plugin development ?
regards
Mathan
Window - Preferences - General - Editors - File Associations
Their you can select which editor is open, for the different file endings.
When you want to do this with a self implemented editor you have to implement the extension poin for editors
org.eclipse.ui.editors
The field "extensions" defines which file ending is associated to the editor
There is also possibility to register your own content type of file. It can be registered as a sub-type of existing content type i.e. XML. To do that you should add an extension point of org.eclipse.core.contenttype.contentTypes
Sample extension point:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
default-charset="UTF-8"
describer="com.example.MyContentDescriber"
file-extensions="xml"
id="org.eclipse.core.runtime.xml.exampleContentType"
name="exampleContentType"
priority="normal">
</content-type>
As you can see new content type is extending an xml content type. The next step is to implement content describer, which looks into the file and determines if it is of your type. There are two interfaces you can implement to do the job: IContentDescriber or ITextContentDescriber. Path to your implementation of describer must be specified in content type as it is shown in the snippet.
Then your editor can be declared as the one, who will be handling your kind of content types.
<editor class="com.example.MyEditor"
default="true"
icon="res/icons/dialog.png"
id="[some_id]"
name="Dialog editor">
<contentTypeBinding
contentTypeId="org.eclipse.core.runtime.xml.exampleContentType">
</contentTypeBinding>
</editor>
Important things:
files that have been already opened in eclipse might 'remember' in which editor they were last opened and this one will be chosen,
your describer might be used a lot so you should consider performance issues while implementing it
More in the topic:
ECLIPSE: Contributing content types
Any plugin that contributes an editor to the workbench can associate an extension the editor understands in their plugin.xml.
The extensions attribute describes the file types that the editor understands. (You could also specify filenames if you need to be more specific.)
I believe this is enough to make your editor open when you click a file of your extension. (at least be preferred the first time you open the file. i.e. eclipse will prefer the last used editor for that file that session).
More info.
Using the file extension method is preferred because that's easy. However if you can't do that, then the only alternative I know of is to provide an action provider in the Common Navigator configuration.
You will need to subclass CommonActionProvider and in the fillContextMenu() method you can look at the resource and then decide to have your own Open action (for your editor) or add the standard Open action.