Update Eclipse menu item enabled state - eclipse-rcp

I created the menu item in the "File" menu as a command. For this command there is a handler implementing the IHandler interface. This handler contains the isEnabled method. I am trying to use this method to enable/disable my menu item, but that method is called only once when I click on the "File" menu. When clicked for the second, third etc. times, the isEnabled method is not called again even if I changed the state of page (open/close editors) before.
What should I do? Maybe this method is not intended for control menu items?

Are you subclassing org.eclipse.core.commands.AbstractHandler? You should use setBaseEnabled(boolean) to update the state of your handler (which would update your command).
It's only valid to change enabled state in your handler as long as you also fire the HandlerEvent. It's usually easier to call setBaseEnabled(boolean) which will fire the event for you.

If you're trying to enable/disable the menu, than you should use core expressions.
I've already explained how to do that in this answer:
Eclipse RCP menus & actions: Configure or code?
The part that you're interested in starts with:
For activating/deactivating a menu[...]
I hope this is what you're looking for.

Related

selectionChanged on specific items

I have an eclipse plugin which has multiple classes which make some UI contributions.
The contribution is done through the deprecated org.eclipse.ui.actionSets and the classes implement the IWorkbenchWindowActionDelegate which require an implementation of the selectionChanged(IAction action, ISelection selection).
The selectionChanged method is triggered on any selection change (another file opened, another item selected in Project Explorer, some text is selected in the editor(this one triggers several calls of the method)).
Is there a filtering or something which I can do to limit the selectionChanged observed objects. For example, for class A, trigger the selectionChanged only if the opened file in editor changes)?
No, there is no way to filter that.
Selections coming from text editors with be instances of ITextSelection, other selections will usually be instances of IStructuredSelection so you can check for those instances to do simple filtering in your code.

Get notified when user jumps to a marker (annotation) in Eclipse

I'm currently writing a plugin for the Eclipse IDE. In this plugin, I defined my own type of resource marker (IMarker). Using the standard Eclipse means like the "Next annotation"/"Previous annotation" buttons, the user has the possibility to navigate between these markers. I also wrote a view which shows some detail information for a single marker. This view shall be updated when the user navigates to a marker. Can I register some kind of listener/observer that will be notified when the user selects/jumps to a marker? If so, how? If not, what are my alternatives?
The Next Annotation action ends up calling the ITextEditorExtension4.gotAnnotation method. The usually implementation for this is in AbstractTextEditor. This just calls finds the annotation and calls the selectAndReveal method.
So there does not seem to be any special listener you can use for this. Normal selection events should be generated so you could use the ISelectionService selection listener but you will have to work out if the selection is for your marker.

Does Command work only for Button in Silverlight?

I have a confusion that only button element shows option for command and most of the other elements do not support this option.
Is it valid only for Button?
And is only Click Event handled by Command?? Because most of the samples i have seen, On clicking button command gets fired.
In case i want command to be fired on other events, then what to do?
Yes, there are some limitations like above. A command cannot be bound with the controls that doesn't implement ICommandSource interface. But you can use Dependency Property to write custom commands.
You can see this and this or googling for more examples.

How to block GtkEntry context menu

I find GtkEntry has a default context menu
But I really do not want it, how can I disable it
I googled but no effective way found
Did you try to just hide/unref/destroy the wigdet passed (the GtkMenu being spawned) within a signal handler hooked to populate-popup?
Another option would be to filter out all right click events by hooking up to GtkWidget's (actually yout GtkEntry which is a subclass of GtkWidget) clicked signal and returning TRUE (for being handled)

How to enable save action in Eclipse toolbar?

I am working under Eclipse plug-in development. I have implemented two view parts to view and change some objects. Each view part implements ISaveablePart to save modified objects and enable save button on toolbar.
The problem is: when I select my objects in Project Explorer, Save button isn't enabled, only Save All is enabled.
So I'd like to know is there any ability to enable Save button in this case?
You must first implement ISaveablePart, as you have mentioned above.
You have to fire an event (see IWorkbenchPartConstants.PROP_DIRTY), which will in turn ask your editor whether it's dirty (ISaveablePart#isDirty()). If the answer is true, then the save button will be enabled.
See FormEditor#editorDirtyStateChanged() for an example.