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

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.

Related

Rename resource file does not change editor part title

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.

Eclipse - Change problems view action

I am currently working on eclipse plugin development. I am working with the builders and markers and I have implemented a rename participant where it checks for a valid file name (does not contain any special characters, lets assume a valid file name to be a alpha numeric regular expression). Its working fine when the user is working within the workbench. Say, when a user directly goes into the file system and changes the file name. I have implemented the markers for this case too. It will show problem marker for the respective file in the project stating, "Invalid file entered - {filename}"
Is there any possibility to change the action on clicking the respective problem marker in the problems view. Say, if such a rename problem marker comes I want to open the rename resource dialog instead of opening the respective file on clicking the problem in the view. Any help upon that.
Although this does not change the double-click behaviour of the marker, you could provide a Quick Fix for the user as described in the Eclipse marker resolution help, and display the rename resource dialog from within the IMarkerResolutionGenerator you provide.

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

Eclipse RCP - Launch editor from file menu

What would be the best approach to launch an editor from the file menu(File>New). Should I encase the editor inside a view and launch the view from a command?
If you want an editor without a file, the best approach would be to go through the normal wizard creation stuff, but instead of creating a real file, use a virtual input instead. These might both be relevant to your interests: http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_a_file_in_the_workspace%3F and http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F and http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F. I did see something ages ago which was about creating totally virtual inputs. If I see it, I'll edit the post. Otherwise, it should be as simple as creating a subclass of org.eclipse.ui.IEditorInput and then not pointing it at any resource, but using it to create the editor.