Eclipse Plugin - How to get the last worked on editor - eclipse

I am writing an eclipse plugin which exposes a view to the user with several buttons. On the click of any button, I would like to paste a certain comment into the editor window where the user is currently working and at the cursor location he is pointing to.
Once the user clicks the button, the editor window no longer has focus and the following code does not work.
workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor()
How can I detect the editor window where the user was working and the cursor location before the user clicked the button?

Use an IPartListener to listen to part activation events.
Set the listener up in your view initialization:
getSite().getPage().addPartListener(partListener);
(and don't forget to remove the listener in the view dispose).
Among other things this will give you part activation events:
public void partActivated(IWorkbenchPart part)
If part is an instance of IEditorPart then it is an editor being activated. So you just need to keep track of this activated editor.

Related

Detecting a click on Grid while row editor is opened in buffered mode

I want to show the dialog box by clicking on a different row (with options to save changes or cancel).
When Editor is open, it will catch the click and is stoping the event propagation, thus underlying Grid does not get the click event and ItemClickEvent is not being fired.
Is it possible to detect a click on the grid row through extensions or another way?
Is it possible to detect a click on the grid row through extensions or another way?
Technically speaking yes. E.g. GridFastNavigation add-on does this trick in order to make possible single click editor opening.
But you could also listen to Editor opening, see (https://vaadin.com/download/release/8.3/8.3.1/docs/api/com/vaadin/ui/components/grid/Editor.html#addOpenListener-com.vaadin.ui.components.grid.EditorOpenListener- ) when you are in unbuffered mode Editor already open, editor will re-open on the row you click. This catching this event could help you find a way.

How to customize the "Save Resource" dialog of an ISaveablePart in Eclipse?

I have an Eclipse application that uses a ViewPart as a floating window with buttons/options for what is happening in the editor.
It looks similar to the floating tool windows in GIMP.
Implementing ISaveablePart in the ViewPart provides a default dialog upon closing the ViewPart with everything I want: a Yes button for saving, a No button and a Cancel button.
However, I would like to customize that default dialog.
Is that possible? If so how?
I looked into ISaveablePart2, but I just end up with my own custom dialog PLUS the default. Is there a way to suppress the default dialog in ISaveablePart2? If so, that would also be a solution.
For clarity: I'm not married to either of these ideas. What I ultimately want is a custom dialog box to come up when someone closes the ViewPart to ask the user if they want to save the contents of the editor ---> with an option to cancel the closing of the ViewPart.
If you use ISaveablePart2 you should only get your own dialog as long as your promptToSaveOnClose method does not return ISaveablePart2.DEFAULT. So there should be no other dialog if you return ISaveablePart2.YES, ISaveablePart2.NO or ISaveablePart2.CANCEL.
The standard Save Prompt dialog is not customizable.
The code for this is org.eclipse.ui.internal.SaveableHelper.

How to make GraphicalEditorWithFlyoutPalette's PaletteView visible on first start

My GEF editor (extending GraphicalEditorWithFlyoutPalette) always opens the editor with the palette hidden on first start of the application / first opening of the editor (after a build for example).
As this will potentially bewilder users who'll need to go in search of the flyout icon first, I'd like to have the palette view shown whenever the editor is opened. The user can then choose to close it on his/her preferences.
How can I achieve this? The API doesn't seem to give any clues, or I'm unable to find them...
The state of the palette defines if it is open or closed. This state is accessible using the getPalettePreferences().setPaletteState() method that is accessible in the GraphicalEditorWithFlyoutPalette. To open the palette, you must set it to the FlyoutPaletteComposite.STATE_PINNED_OPEN, like this:
getPalettePreferences().setPaletteState(FlyoutPaletteComposite.STATE_PINNED_OPEN);
If you want to ALWAYS override the state so that the palette is always opened with the editor, you have to add the line to the constructor of your editor. If you only want to do this once, and then leave the state as it was last selected by the user... No idea how to do this :-(

Adding menu listener for Paste option in SWT Browser

I have a org.eclipse.swt.browser.Browser instance created in a composite. I would like to know when some content is pasted in the browser using the (platform specific) right click context menu and selecting the paste option.
In the menuDetected() of MenuDetectListener, I get a notification when the context menu is detected in the browser.
How can I know if the Paste option is selected from the context menu?
Regards,
Noopur
No you can't access the selected context menu item. There is no direct provision for that. At least not in eclipse 3.7. Although, you could try different combinations of events for determining the menu item. For example, in windows the internet explorer populates the status bar with 'inserts the clipboard...' when your mouse pointer hovers over the Paste menu item, you can capture this using StatusTextListener event.
Note: The hack is not an elegant solution, even if you get it working, there is still some possibility that it may break with new or older releases of SWT or in fact its behavior may vary with operating systems !!

How can I create a YUI menu where you can click to open the submenus?

We have a multi-tiered/hierarchical YUI menu activated via a YUI menu button. Everything in this menu works pretty well. If you mouseover a menu item with a submenu, the submenu appears as expected. You can select an item from this submenu just fine.
The problem, however, is that you can also click on the parent items of this menu which closes the entire menu. In fact, I want the opposite. I'd like a click of a parent menu item leave the top level menu open and open the submenu (i.e. I want a click to be identical to a mouseover event in terms of functionality).
Side note: This isn't an issue on a typical web browser (e.g. Firefox) where the click event doesn't matter because you can't have a click without a mouseover. This is an issue on the iPhone which doesn't have a mouseover event.
I've been playing with the autosubmenudisplay properties and keepopen properties, hoping I can just handle the parent item click events to do what I want but, so far, I've been unsuccessful. If I set autosubmenudisplay to false, I can't figure out how to get the submenus to display manually. The keepopen property doesn't seem to work rather I set it on the menu or submenus.
Is there a way to get the behavior I want so our iPhone users are happy?
Todd Kloots, author of the YUI Button and Menu widgets here. Took at look at your request. Unfortunately the current version YUI Button and Menu aren't designed to support the type of interaction you are looking to create. Feel free to file a feature request via SourceForge and I'll try to work on this for a future version of YUI.
Todd
It's not exactly what you asked for, but have you looked at iUI? You may be able to pick up some tricks from the implementation.