A better NetBeans menu bar

Quick Search in menu bar

If you only use a couple of toolbar buttons but do not want to waste the vertical space required to show a regular toolbar - say because you use a smaller laptop screen - you can get NetBeans to insert the buttons into the menu bar.

Just shut down the IDE, then go into the config subdirectory of your NetBeans user directory (location varies; see Help > About). Create a subdirectory Menu, and in it create three files:

  1. org-openide-actions-GarbageCollectAction.instance (empty)
  2. org-netbeans-modules-quicksearch-QuickSearchAction.instance (empty)
  3. .nbattrs containing the text:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE attributes PUBLIC "-//NetBeans//DTD DefaultAttributes 1.0//EN"
                 "http://www.netbeans.org/dtds/attributes-1_0.dtd">
    <attributes version="1.0">
        <fileobject name="org-openide-actions-GarbageCollectAction.instance">
            <attr name="position" intvalue="9000"/>
        </fileobject>
        <fileobject name="org-netbeans-modules-quicksearch-QuickSearchAction.instance">
            <attr name="position" intvalue="9010"/>
        </fileobject>
    </attributes>
    

After restarting the IDE you should see two new buttons in the menu bar.

Comments:

This is cool! I never thought about something like this, but, have never used anything but the GarbageCollection button and the QuickSearch on the tool bars, so this is a perfect fit.

Posted by adam on March 11, 2010 at 06:30 AM EST #

Hi, very nice. Anyone an idea how to do that on Mac OSx? I can't create a file starting with a . (dot).

Thanks

Posted by MasterB on March 11, 2010 at 09:34 AM EST #

MasterB -- you should be able to create '.nbattrs' from a Terminal window.

Posted by Ben Sandberg on March 11, 2010 at 09:42 AM EST #

If possible , NetBeans should provide a DND operation for this like the Toolbar item...

Posted by hatnsy on March 11, 2010 at 12:13 PM EST #

This is worst idea I have ever seen. Please bear in mind that this doesn't work with Mac OS X's menubar. Menu bar should contain only menus, nothing more. Everything else will be ignored. Interesting experiment, but not good for production use...

Posted by Marian Boucek on March 12, 2010 at 01:24 AM EST #

Right, this will not work on a Mac because it uses a native screen menu, and tries to translate JMenu's and JMenuItem's to native components. Should work on other platforms, where Swing is rendering the menu bar inside the main frame and can render any Component inside it.

By the way it should be possible to create a ZIP file from these customizations that could be imported using Tools > Options > Import if there is interest. There is currently no GUI for managing this kind of customization once imported, though. Older versions of NetBeans did use to have a GUI for customizing menus, which could be resurrected as a plugin.

Posted by Jesse Glick on March 12, 2010 at 02:30 AM EST #

I used this for a few days now and I much prefer these buttons being in the menu bar. Whilst I accept that the mac doesn't support it, I don't see why this makes it bad for other OSs. I think it is worse to have screen-space wasted with things I never use!

I have filed issue 182091 as an enhancement request. Anyone who thinks this is great can vote for it to be made a feature.

Posted by Daniel Sheppard on March 15, 2010 at 10:55 PM EDT #

This is a great tip, very useful. I want to add the Projects button to the Menu Bar. How do I determine the file name needed to create this file? I tried org-openide-actions-ProjectsAction.instance but it didn't work. Thanx.

Posted by Mavis Donkor on March 24, 2010 at 03:20 AM EDT #

So long as there is no GUI support such as drag-and-drop for this customization (\*), you need to look up the action name manually. In general, you cannot create a \*.instance file in the menu bar (it happens to work for Memory and Quick Search); you will need to create a \*.shadow file (basename arbitrary), and in .nbattrs specify the path to the definition. (Abbreviated) paths can be found in e.g.

http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/build/generated/layers.txt

in the Actions/ subfolders. In this case, Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance is the location of the action for "Open Project", so if you had created $userdir/config/Menu/open-project.shadow then you would add to $userdir/config/Menu/.nbattrs:

<fileobject name="open-project.shadow">
<attr name="position" intvalue="9020"/>
<attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance"/>
</fileobject>

(Note that you can make customizations like these using Notepad or whatever you like while the IDE is running; they should take effect when you next give focus to the IDE's main window.)

(\*) https://netbeans.org/bugzilla/show_bug.cgi?id=182091

Posted by Jesse Glick on March 24, 2010 at 03:43 AM EDT #

It worked. Thanx so much.

Posted by Mavis Donkor on March 24, 2010 at 05:10 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

jglick

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today