How to customize the "Save Resource" dialog of an ISaveablePart in Eclipse? - 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.

Related

Clickable link in active editor

If I add a link to the active editor either by using the menu/context menu or by simply typing a URL (e.g., http://www.google.com), the link is added but it is not immediately clickable. The only way a user can use the link to navigate to a page is by ctrl-clicking and choosing to open in a new tab. If the editor is in read-only mode then it works as intended but not when the editor is active.
Is there a way to make links clickable in an active editor?
thnx,
Christoph
TinyMCE will not (by default) make the link clickable. You can right click on the link and a context menu appears. In that menu is an option to open the link. To modify a link one needs to click on it (select it) in TinyMCE. If that act (clicking) opened the link you would not be able to easily select the link to act upon it in the editor.

Eclipse Plugin - How to get the last worked on editor

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.

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.