How to obtain JMenuItems from JMenuBar of Intellij's Frame ?

Hi, Intellij
I trying to write a plugin to printout all the JMenuItems display in JMenuBar of Intellij's frame.

For example,
under there are items under File menu, like New Project, Open Project, New Module etc, I want to obtain all these subMenu and MenuItem from the the menubar for manipulation.

However after using

JFrame _win = (JFrame)WindowManager.getInstance().suggestParentWindow(null); // Obtain the frame reference

and getting the Jmenubar, I have found that only the top level menus (File, Edit , Search, View, Goto, Code, Analyze, Refactor etc) can be obtained but not their menuitems and submenu.

So what is the API and steps to obtain those JMenu and JMenuItem references ?

thx

4 comments
Comment actions Permalink

Hello geekycoder,

There is no API for that because the menus are built dynamically. What are
you trying to accomplish?

You may want to look at the ActionManager class instead - that's what the
menus are built from.

Hi, Intellij
I trying to write a plugin to printout all the JMenuItems display in
JMenuBar of Intellij's frame.
For example,
under there are items under File menu, like New Project, Open Project,
New Module etc, I want to obtain all these subMenu and MenuItem from
the the menubar for manipulation.
However after using

JFrame _win =
(JFrame)WindowManager.getInstance().suggestParentWindow(null); //
Obtain the frame reference

and getting the Jmenubar, I have found that only the top level menus
(File, Edit , Search, View, Goto, Code, Analyze, Refactor etc) can be
obtained but not their menuitems and submenu.

So what is the API and steps to obtain those JMenu and JMenuItem
references ?

thx

---
Original message URL:
http://www.jetbrains.net/devnet/message/5240455#5240455

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

hi, Dmitry Jemerov,
I like to create plug-in that allows a user to enter menu command textually rather than using a mouse since IDE now has too much option to browse through and then perhaps a few menu item will ever be useful, so these task will be quicker to enter through a textfield. It is akin to instant search for MenuItem just like the instant search implements in the Settings screen of Intellij. . Some similar to this http://geekyware.files.wordpress.com/2008/05/image12.png?w=202&h=223

It works something like Intellij's Enter Class Name: (ctrl-N) but instead of class, it shows "Enter Menu Choice:"
It will be a useful addition for Intellij and perhaps for Netbeans, eclipse since they too suffer from "menu item bloats"

Basically, whenever user call up the "Enter Menu Choice" window, the plug-in will iterate all MenuItems show in MenuBar of Intellij and only accept those that is displayed or enabled. Once user type a partial search, a list of those menuItem will show in a popup.

I hav checked through  ActionManager doc, unfortunately it seems it doesn't have a method to return all the actions associate with menu

http://www.jetbrains.com/idea/openapi/5.0/com/intellij/openapi/actionSystem/ActionManager.html
bstract  ActionPopupMenu    createActionPopupMenu(java.lang.String place, ActionGroup group)
          Factory method that creates an ActionPopupMenu from the specified group.
abstract  ActionToolbar    createActionToolbar(java.lang.String place, ActionGroup group, boolean horizontal)
          Factory method that creates an ActionToolbar from the specified group.
abstract  AnAction    getAction(java.lang.String actionId)
          Returns action associated with the specified actionId.
abstract  java.lang.String    getId(AnAction action)
          Returns actionId associated with the specified action.
static ActionManager    getInstance()
          Fetches the instance of ActionManager implementation.
abstract  void    registerAction(java.lang.String actionId, AnAction action)
          Registers the specified action with the specified id.
abstract  void    registerAction(java.lang.String actionId, AnAction action, PluginId pluginId)
          Registers the specified action with the specified id.
abstract  void    unregisterAction(java.lang.String actionId)
          Unregisters the action with the specified actionId.


Is there any other way it to gain access of Menu item ? Or is  it possible to create a API for it as it will be useful to create more useful plugin.

thx

0
Comment actions Permalink

Hello geekycoder,

This feature is already available in IntelliJ IDEA: Search | Find Action...
(Ctrl-Shift-A)

hi, /people/yole,
I like to create plug-in that allows a user to enter menu command
textually rather than using a mouse since IDE now has too much option
to browse through and then perhaps a few menu item will ever be
useful, so these task will be quicker to enter through a textfield. It
is akin to instant search for
MenuItem just like the instant search implements in the Settings
screen of Intellij. . Some similar to this
http://geekyware.files.wordpress.com/2008/05/image12.png?w=202&h=223
It works something like Intellij's Enter Class Name: (ctrl-N) but
instead of class, it shows "Enter Menu Choice:"

It will be a useful addition for Intellij and perhaps for Netbeans,
eclipse since they too suffer from "menu item bloats"

Basically, whenever user call up the "Enter Menu Choice" window, the
plug-in will iterate all MenuItems show in MenuBar of Intellij and
only accept those that is displayed or enabled. Once user type a
partial search, a list of those menuItem will show in a popup.

I hav checked through ActionManager doc, unfortunately it seems it
doesn't have a method to return all the actions associate with menu

http://www.jetbrains.com/idea/openapi/5.0/com/intellij/openapi/actionS
ystem/ActionManager.html
bstract ActionPopupMenu createActionPopupMenu(java.lang.String
place, ActionGroup group)
Factory method that creates an ActionPopupMenu from the
specified group.
abstract ActionToolbar createActionToolbar(java.lang.String place,
ActionGroup group, boolean horizontal)
Factory method that creates an ActionToolbar from the
specified group.
abstract AnAction getAction(java.lang.String actionId)
Returns action associated with the specified actionId.
abstract java.lang.String getId(AnAction action)
Returns actionId associated with the specified action.
static ActionManager getInstance()
Fetches the instance of ActionManager implementation.
abstract void registerAction(java.lang.String actionId, AnAction
action)
Registers the specified action with the specified id.
abstract void registerAction(java.lang.String actionId, AnAction
action, PluginId pluginId)
Registers the specified action with the specified id.
abstract void unregisterAction(java.lang.String actionId)
Unregisters the action with the specified actionId.
Is there any other way it to gain access of Menu item ? Or is it
possible to create a API for it as it will be useful to create more
useful plugin.

thx

---
Original message URL:
http://www.jetbrains.net/devnet/message/5240495#5240495

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi, Dmitry Jemerov,
that's great. I never thought that this feature already exists in Intellij, look like there's more to discover about Intellij <:^}

After using this feature, I wonder if the feature can be improved to be more usable.
1)  Hide disable Menu Item Choice. Currently, those disable Menu Item Choice is shown too which  is unnecessary since it can't be executed anyway (basically no effect on disable item when click).

2) Real text search on Menu Item label. Currently if a text is search, "irrelevant items" are included.
For example, type "version" shows some "noise". Should search on Menu Item Label and not other else.
- Convert Project
- What's new in Intellij

3) Support space as part of text search rather than as "AND" operator. Numerous menu item labels are made up of two words. or more For instance, to run the item Start Macro Recording. User should be able to type "o r" and the choice appear as the first choice.

4) Ability to customize to exclude menu for searching. For instance , the Help and Tools menu can be excluded for searching by options. No need to select from checkbox but user can type the  those excluded menu themselves (eg Help, Tools, or whatever menu to exclude)

Hope the suggestion helps...

thank for this great feature.



Attachment(s):
remove irrelevant items.jpg
provide space search.jpg
0

Please sign in to leave a comment.