blob: af1fdcf5ab82749fb4afc1cc50a69af4993facbf [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
===How can I change the contents of a menu according to the selected file in the editor?===
* Create your action and let it implement [http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/actions/Presenter.Menu.html Presenter.Menu]
* Return a special <tt>JMenuItem</tt> subclass that implements [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] from <tt>getMenuPresenter()</tt>
* Implement [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] methods to return the desired menu content, using [http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.Registry.html TopComponent.Registry] for finding the selected file in the editor.
https://bitbucket.org/jglick/dynamicmenudemo/ also does something similar.
===Can I hide or show a whole menu or toolbar?===
To hide a menu or toolbar you have to edit your <tt>layer.xml</tt> and append <tt>_hidden</tt> to the name of the desired menu or toolbar. You may also hide <tt>*.instance</tt> files.
<syntaxhighlight lang="xml" enclose="div" highlight="6">
<folder name="Menu">
<!-- Hide View menu -->
<folder name="View_hidden"/>
<folder name="SomeMenu">
<!-- Hide a single menu item -->
<file name="SomeAction.instance_hidden"/>
</folder>
</folder>
<folder name="Toolbars">
<!-- Hide Edit toolbar -->
<folder name="Edit_hidden"/>
</folder>
</syntaxhighlight >
It's generally much easier to do this from the NetBeans IDE, [http://forums.netbeans.org/post-77476.html as described here].
Note that to hide the Navigate menu one has to declare GoTo_hidden instead of Navigate_hidden (the menu was originally named GoTo, but was later renamed to Navigate by the means of Bundle.properties).
===Apache Migration Information===
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqSwitchingMenusByContext ,
that was last modified by NetBeans user Jglick
on 2011-12-14T00:20:23Z.