How to gray out an AnAction in the context/editor menu?


problem: the actions I "installed" in context and editor menus are never
grayed out.

They are AnAction subclasses, and I noticed their isAvailable() method
is only polled when I click on the entry, not when its containing menu
is expanded.

Alain

plugin.xml extract:


]]>

2 comments
Comment actions Permalink

Hi,

You can call setEnabled on presentation object in update method of AnAction.

Alain Ravet wrote:


problem: the actions I "installed" in context and editor menus are never
grayed out.

They are AnAction subclasses, and I noticed their isAvailable() method
is only polled when I click on the entry, not when its containing menu
is expanded.

Alain

plugin.xml extract:


<action id="MiniWiki.setBugsFile"


text="set miniWiki bugs file"
description="set the miniWiki bugsfile"
icon="/general/debug.png">
</action>


<group id="miniWikiEditor" text="miniWiki" popup="true">
<reference id="MiniWiki.setHomeFile"/>
<reference id="MiniWiki.setBugsFile"/>
<reference id="MiniWiki.setTodoFile"/>
<reference id="MiniWiki.setDoneFile"/>
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
<add-to-group group-id="StructureViewPopupMenu" anchor="last"/>

</group>



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

I created a simple helper class for this:

public abstract class MyAction extends AnAction {

protected MyAction(String text, Icon icon) {
super(text, text, icon);
}

public void update(AnActionEvent event) {
event.getPresentation().setEnabled(isEnabled());
}

protected abstract boolean isEnabled();
}

Now you just have to implement the isEnabled() method.


Maxim Mossienko wrote:

Hi,

You can call setEnabled on presentation object in update method of
AnAction.

Alain Ravet wrote:

>>
>> problem: the actions I "installed" in context and editor menus are
>> never grayed out.
>>
>> They are AnAction subclasses, and I noticed their isAvailable() method
>> is only polled when I click on the entry, not when its containing menu
>> is expanded.
>>
>> Alain
>>
>> plugin.xml extract:
>>
>>
>> > >> >> text="set miniWiki bugs file" >> description="set the miniWiki bugsfile" >> icon="/general/debug.png"> >> >> >> >> >> >> >> >> >> >> >> > anchor="last"/> >> >> >>]]>



--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0

Please sign in to leave a comment.