I'm writing a plugin for Eclipse and I'm wondering how I can listen on editor text changed events for any of the active editors.
Basically I want listener events to fire when any text is modified in any of the open editors.
You want to get to the JFace Document object associated with the editor and add an IDocumentListener, that should get you started.
Sounds really untypical. Also very intrusive and dangerous. Why would you want to listen to any typing in any of the editors? It is strongly recommended not to do it. Shouldn't that be limited to a bunch of editors for a same model (IEditorInput)?
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorReferences = page.getEditorReferences();
From editorReferences try and find out a way to add a listener. IEditorReference is a handle, it doesn't mean the editor is activated. When you open eclipse, editors are activated lazily (when they are clicked for opening). So activating all open editors can also cause performance issues.
Related
is there a possible way to extend a perspective with the extension point org.eclipse.ui.perspectiveExtensions in such a way that its assosioated perspective editor can be added to my MutliPageEditor?
Is there a way to listen for the editor to open and then creating a MutliPageEditor where the opended editor will be added to it?
No, this is not possible.
The perspective extensions don't have any support for merging editors like this.
You can listen for editors (and views) opening but there is no way change the structure of the editor that has opened.
I've recently developed a new RCP application with eclipse e4 and now I have run into a problem that whenever I want to open another editor which has the same label, that I cannot open it because I always check if there is already an open editor with the same label and then grant this editor focus in order to bring it on top of the part stack.
I use a part descriptor to dynamically open an editor whenever the user double-clicks on a tree element and then uses the tree elements name as label. Now it can happen that some tree elements have the same label ...
Is there any other way in eclipse e4 I can check if an editor is already open, besides comparing the label of all open editors with the label of the editor I want to open?
Any help or pointers would be appreciated.
The default way is assigning an input uri while creating an editor (InputPart in e4)
MInputPart inputPart = MBasicFactory.INSTANCE.createInputPart();
inputPart.setInputURI("someInputUri");
And then you can call:
Collection<MInputPart> inputParts = partService.getInputParts("someInputUri");
Where partService is an instance of EPartService. You can manage a group of input parts using this approach.
I have this habit of looking into other source codes from different projects for a reference. However, this leads to cumulative issue of forgetting to close the tab. I may have around 100 source tabs opened up (which is related to current and unrelated projects).
Is there a preference or plugin to auto close unused tabs after certain idle period? Like say after 10 minutes of inactivity.
The issue I face is when I'm in a hurry the tabs pile up and consume lots of memory, and not to mention if you have opened up Chrome for reading documentation and StackOverflow digging. Finally slows down my system due to swap usage.
[ Update ]
Found some interesting tips from this link
So how to quickly close unnecessary tabs in Eclipse?
Closing tabs one by one by clicking on the tab with a wheel/MMB. It’s faster than clicking LMB on a small cross icon, because it’s enough to click anywhere on a surface of a tab. I do it when there is few tabs to close (like one or two) and tabs that I want to closearen’t hidden.
Closing current tab using Ctrl+W keystroke. I do when tab to be closed happens to be an active tab. And when I just visited some class to check something and I won’t need to revisit it anymore soon.
Using Ctrl+Shift+W keystroke to close all tabs. I do it when I’m starting completely new tasks or at the moment I’m too lazy for 4 or 5. :-) .
Right-clicking on the tab that should stay open and selecting “Close all others” option. It’s handy in cases where only one editor is significant and others are a result of code exploration.
This is my favourite one: Using ctrl+shift+e keystroke to display “Open editors” dialog, selecting editors that should stay open (with ctrl pressed), “invert selection”, “close all selected” and finally hitting esc to close the dialog. It may seem complex but trust me it isn’t. It took me only a few attempts to learn how to use this trick effectively. I often do it when I forgot to close tabs for a while and I have a lot of tabs open and what’s worse, some of tabs aren’t visible on tabs bar (arrow icon needs to be clicked to see the hidden tabs).
There is a feature General > Editors > Close editors automatically which closes unused editors automatically.
There is no auto-close feature/plug-in in eclipse. Because user opened all the editors manually and he/she has to close these on their wishes but not automatically.
For your problem I suggest you to use Mylyn plug-in so that you can stick to only those editors(context) you frequent used, hiding all other editors, packages, classes etc.
Also there is an eclipse plug-in for pinning editors refer my answer for the post Eclipse - How to pin editor tabs?
I am developing RCP plug-in with GEF framework.
I've created basic graphical editor (GraphicalEditor and IEditorInput)
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(new TEditorInput("T"), TGraphicalEditor.ID,false);
When I run the application I get editor with a header that contains the tab with the name of the editor and control buttons to maximize and minimize the editor.
What I need is to display just the editor, without the header.
Can it be done?
To my knowledge, it is not possible to just hide an editor's tab.
However, you can try two workarounds:
Have your GEF editor be displayed in an Eclipse view instead of an editor and open such a view as a standalone view. An example of how to open a GEF diagram in a view can be found in GEF's Directed Graph Example. An example of how to open a view as standalone can be found in one the Eclipse RCP official tutorials.
Extend the presentation factories extension point to control how workbench parts are displayed (which includes control over the part stack tab).
I suggest you try the first approach, as to me it seems easier to implement.
The idea with editors is that you can instantiate them multiply for different editor inputs. I am not aware of any way to restrict the number of open editors to just one (well, it appears you can in Eclipse 4.2 if that helps you)
For views, what you want can be done by setting the perspective to fixed and set showTitle of the org.eclipse.ui.perspectiveExtensions extension to false on the view. Maybe you can use a view instead of an editor and control the editor input yourself?
(For example, using an editor, the default Open action would instantiate a new editor, while you probably want to replace the contents in your only editor, right?)
I was wondering if there is a manner to make it impossible to open more than 1 editor at a time? what I have now is a button that each time it is pressed gives a new editor.
I am using eclipse RCP
thanks
You could add an IPartListener on the IPartService of the IWorkbenchWindow that close all other editors when a new editor is opened. You find the current set of editors via IWorkbenchPage.getEditorReferences().