[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[ide4edu-dev] How to hide UI elements like menu or toolbar items using the Activities extension
|
As a resource for future IDE4Edu programmers in the hopes that it might save
someone some time, I wanted to post the lessons I've learned about how to
hide UI elements in Eclipse using the Activities extension.
=========================================================================
How to hide UI elements like menu or toolbar items using the Activities
extension
=========================================================================
The first steps are pretty standard for using extensions in Eclipse. Open
the plugin.xml file and add the org.eclipse.ui.activities extension. Then
create an activity node and give it a unique ID. Then create an
activityPatternBinding node and use the unique ID for the activity to find
the pattern node to the activity node.
The activityPatternBinding node requires that you supply a regular
expression for the ID string of the UI element that you wish to hide. This
sounds easy but in practice but finding these ID strings for some UI
elements can be quite difficult.
The problem is that there appears to be at least 3 ways that menu items and
toolbar buttons are added to the UI. The first way is through the newer
Command/Menu Extensions. The second way is through the older ActionSets
Extension. Then there are other UI elements that appear to be hard coded
into the Workbench and do not have ID strings and cannot be hidden using the
Activities Extension. Luckily there are few of this third type of UI
element.
I found that there was a cascade of 3 effective ways to find the ID's for a
UI item.
------------------------------------------------------------------------
3 ways to find the ID string for a UI element
------------------------------------------------------------------------
1. Use the Plug-In Spy
----------------------
The first way is to use the Plug-In Spy. Press alt-shift-F2 and click on a
menu item or toolbar button that you want to be hidden. If there is an ID
string under the heading "active action definition identifier" then you are
in luck. This item has been added using the Command Extension and you can
use this ID as the pattern argument for the Activities Extension. But not
all items that have been added using the Command Extension present their ID
string to the plug-in spy.
As a side note, the ID strings are period separated. For instance the ID for
a button might be "org.eclipse.ui.navigate.backwardHistory". Regular
expressions use the period to stand for any character. Luckily the period
used as a wild card matches with actual period characters so you don't need
to escape them if you don't want to. I find it makes it a bit easier to read
if they are not escaped and it is highly unlikely it will cause any
ambiguous matches.
2. Use the Plug-In Registry and plugin.xml files
------------------------------------------------
The second way is to use the Plug-In Registry. You can open this view by
going to:
Window/Show View.../Other/Plug-in Development/Plug-In Registry
What you would like to do is to try to get a couple pieces of information:
a) the plugin that is contributing the UI element
b) information about what kind of extension the plugin is using to create
the UI element
If there is a very unique word associated with the UI element or its tool
tip then you can use this in the Plug-In Registry's filter field to try to
nail down which plug-in is contributing the UI element. The filter field is
not a very powerful tool so it can be a bit frustrating to use. It does not
allow wildcards and does not match space characters.
When you track down which plug-in is contributing the UI element then you
open the the plug-in in question from the Plug-Ins view which is found
grouped with the Package Explorer in the Plug-in Development perspective.
Then go to the Extensions tab and search for the ID string which can usually
be found in either a usage of the Command or ActionSet extension. If the UI
element is added using an ActionSet then you prefix the plug-in ID to UI ID
in the pattern argument given to the Activities Extension. For example
org.eclipse.ui.actionsets.foo becomes the pattern
org.eclipse.ui/org.eclipse.ui.actionsets.foo.
3. Use regex wildcards to track down the ID
-------------------------------------------
The above 2 methods work for finding most ID's but still do not allow you to
find every ID string one would like. For instance, if the UI element is a
sub-menu then it can be tricky to track down the ID string for it.
So finally there is a slightly tedious but relatively sure-fire way to find
more clues about the ID string for the UI element to be hidden. I utilized
the fact that the regular expression pattern can be written so that is
matches multiple ID strings. So try a few common patterns as fields for the
activityPatternBinding and run IDE4Edu. Some patterns to try. There are
others.
- org.eclipse.ui.* : The standard eclipse tools
- org.eclipse.jdt.ui.* : The java tooling
- org.eclipse.debug.ui.* : Most of the running and debugging tools
- org.eclipse.jdt.debug.ui : Java specific running and debugging tools
- org.eclipse.search.* : The search tools
If the UI element is hidden when you run IDE4Edu with one of these patterns
used then we know what plug-in is contributing the element. Of course these
patterns hide a lot of UI elements so we have to narrow the pattern down
further.
So we use a manual binary search by eliminating half the letters at a time
from the pattern [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ].*.
For example if we use the pattern
org.eclipse.jdt.ui.[ABCDEFGHIJKLMNOPQRSTUVWXYZ].* and run IDE4Edu and
discover that the UI element in question has been hidden then we know the
first letter in the ID string for said element is a capital letter. You can
track down a single letter in a minute or two so it is not as bad as it
sounds and it can be quicker at times than digging through the plugin.xml
file for a plugin.
Once you have a letter or two you can usually narrow down the rest of the ID
string by typing what you know into the Plug-In Registry's filter field for
a list ID's that match that string. For instance if you find that the
pattern org.eclipse.ui.e.* hides the UI element you are looking for you type
org.eclipse.ui.e into the filter field and discover that there are only a
few ID's in Eclipse that start with org.eclipse.ui.e so this gives you some
clues about where to look.
- org.eclipse.ui.edit.*
- org.eclipse.ui.externaltools.*
- org.eclipse.ui.editors.*
- org.eclipse.ui.editorActions.*
Happy hunting!
Miles