Add additional behaviour to existing Eclipse button? - eclipse-plugin

I would like to add additional behaviour to an existing button in the Eclipse ide with a plugin.
To have an example, I would like to print to standard out each time the "Remove Launch" button in the console view gets pressed (see image).
Should I find and override/extend the corresponding, existing Handler with my logic?
Should I work with the these extensions?
ConsoleView extension locationURI="toolbar:org.eclipse.ui.console.ConsoleView"
Commands extension: "org.eclipse.ui.commands"

There isn't a general way to hook in to existing actions.
For Remove Launch you can set up a listener to be notified of removed launches by using the ILaunchManager:
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
launchManager.addLaunchListener(listener);
The listener is an ILaunchesListener which has a launchesRemoved method that will be called when a launch is removed.

Related

Intellij plugin/action - how to add caret listener to editor automatically on load?

How to add a caret listener to the active editor during "on load", such as when the intellij application starts or when an editor is opened?
I know how to do so in actionPerformed but apparently it is not the right place to do so, and the constructor has no AnActionEvent being passed in so I couldn't get an Editor instance.
I'm not sure what you mean by 'active' editor here. Editor which is active when a particular action is invoked can be retrieved from DataContext passed to actionPerformed.
If you want to add a listener to any editor, when it's created, you can do it in EditorFactoryListener.editorCreated. It can be also simpler to register a listener which will get events from all editors (see EditorFactory.getEventMulticaster()).

How to add buttons linked to your external tool in IntelliJ IDEA

I created some batch work and integrated it as ExternalTool to the IntelliJ IDEA. as described here: Configure Intellij IDEA to run batch file
But how can I add buttons to my toolbar that will activate the batch that defined as external tool?
It is quite easy.
Assuming that you already have an External Tool configured just right click on the menu bar and choose Customize Menus and Toolbars...:
Next step is to mark the last item (whatever that is in your setup) in Main Toolbar and select Add After...:
Now you can select your external tool from the Choose Actions To Add window (here you can also select an icon to use):
Action has been added:
And your button has been added to the toolbar:

How to reopen ViewPart?

I am working to make an Eclipse Plugin. I used a plugin project template that generated a View class which extends ViewPart. I think that it is part of SWT.
My problem is that the View is like a window inside of the main Frame which has buttons for close, minimize. I clicked on the X button of the View by mistake. Now I cannot make it visible again even if I relaunch the Eclipse Application.
Now, my Eclipse application looks like this:
It had some panels and buttons before. But I cannot make the View visible again. How should I make to bring it back? I have tried to delete the plugin project from Eclipse and import it again. But it did not work.
I bet that there it is an easy way to make the View visible again but I do not know how. Is there any setting through MANIFEST file? Or other file?
Specify the -clearPersistedState argument when you run the RCP (this assumes you are using Eclipse 4.x).
1) quick solution
restart workbench with clear workspace option checked under run configuration ..
2) Full Solution
you should add a menu in menu bar to open your view so that you can open your view when ever you want
create a command say openMyMenu
create a handler for it and call below code from handler execute method.
add that command to main menu bar..
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(<view ID>);

Eclipse Kepler: detached window and toolbar

In my Eclipse plug-in I have a custom editor which has its own toolbar. If I detach such an editor I still can use this toolbar. But only if there is no other editor (without this toolbar) active on the workbench. In this case the toolbar of the detached window disappears while activating the workbench so I can't use it anymore for the detached window. Is this a bug or a feature?
Is it somehow possible to attach the toolbar to the detached editor window to prevent such errors?
If your editor's toolbar is actually showing in the main window (the usual case) then what is happening is that when you click on the main window to use the tool the main window activates, changing the currently active part. This is a known issue for which no viable solution has been proposed...
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323706 and related defects for the gory details.
The usual workaround is to use key-bindings for commands you want to execute in DW's.

How to add a button to the main toolbar in Eclipse programmatically

I've a question. I cannot find the way, how to add buttons to main toolbar programmatically. My problem is, that I've the task to dynamically (based on XML configuration file) build menus and toolbar. I found how to add a menu item programmatically, but not toolbar button.
Tutorials mostly show how to create buttons and menus using plugin descriptor (plugin.xml), but not how to do it programatically. It seems, that it is out of bounds of Eclipse plugin philosophy.
I've just found this:
There might be layout problems with this approach. I also don't
believe the framework will try and re-create your dynamic item except
at random toolbarmanager updates. With Menus they can be updated on an
SWT.Show event, which is why CompoundContributionItem only applies to
Menus.
What shall I do? Can I say Sorry, there is no way to build toolbar dynamically. I can do it just for menus? Collegue says, that it must be possible, but he does neither know how.
The only way to be able to create main toolbar entries programmatically is in an RCP app, where you supply the ActionBarAdvisor for the workbench window. This isn't dynamic, however, just called on window creation.
Another way to do it would be to use org.eclipse.ui.menus and contribute org.eclipse.ui.menus.ExtensionContributionFactory. It also works only on workbench window creation (not really dynamic), but you could read your own XML and provide IContributionItems for the main menu or toolbar.
How dynamic are you trying to be? Most solutions work well on startup/window creation.
PW
Whenever you try to do something programmatically in Eclipse that is normally done through plugin definitions you are walking on thin ice. I've tried it on a few occasions and it rarely ended up being easy or good.
Instead, think of what it is that you only know at runtime and need to be able to change on the fly. Is it the name or icon of the button? That can be changed at runtime.
Take a look at runtime commands, they can be confusing to define properly, but with them you can for example create buttons that are only visible if a condition is active. That condition could be set at runtime.