Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Managing Menu Item Enable State(Need to update enable state when cmd shortcut is typed.)
Managing Menu Item Enable State [message #663138] Mon, 04 April 2011 02:09 Go to next message
Doug M is currently offline Doug MFriend
Messages: 18
Registered: December 2009
Junior Member
Hi all. I want to enable/disable the File->Save menu item, depending on whether the document is dirty. MenuShown() in a MenuListener on the File menu seemed the perfect way to do this. It is called before the menu drops down, checks the front document state, and enables or disables the Save item as appropriate.

All would be well except that Save also must have the standard cmd-S shortcut. The MenuListener is *not* called when cmd-S is typed, therefore the Save menu item is selected when not appropriate (with menu blinking), and vice versa.

Is there some listener or method I am not aware of that can nicely work around this functional inconsistency?

I know I could have every place that dirties the document set the menu item's state. However, setting the state in the UI menu handler seems like the clear and clean way to handle this behavior. Besides when (someday) SWT allows a single menubar on OS X, you would have to start messing with the menus whenever a different document is brought to front.

FWIW, OS 9, OS 10, and Windows all have ways of notifying the application that a command key is about to be searched for in the menus, exactly so that the app can set the correct menu state.

Thanks in advance for ideas.

Doug
Re: Managing Menu Item Enable State [message #663248 is a reply to message #663138] Mon, 04 April 2011 12:36 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/03/2011 10:09 PM, DougM wrote:
> Hi all. I want to enable/disable the File->Save menu item, depending on
> whether the document is dirty. MenuShown() in a MenuListener on the File
> menu seemed the perfect way to do this. It is called before the menu
> drops down, checks the front document state, and enables or disables the
> Save item as appropriate.
>
> All would be well except that Save also must have the standard cmd-S
> shortcut. The MenuListener is *not* called when cmd-S is typed,
> therefore the Save menu item is selected when not appropriate (with menu
> blinking), and vice versa.

Currently in SWT, once disabled CTRL+S will never allow it to be
re-enabled, as the OS gives up when finding a disabled menu item.
Eclipse uses a KeyDown filter instead of standard MenuItem accelerators
as a workaround for its command framework.

You might have to open an enhancement request for the accelerator-key
search event.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Managing Menu Item Enable State [message #663445 is a reply to message #663138] Tue, 05 April 2011 06:58 Go to previous message
Lakshmi P ShanmugamFriend
Messages: 277
Registered: July 2009
Location: India
Senior Member
DougM wrote on Mon, 04 April 2011 07:39

Besides when (someday) SWT allows a single menubar on OS X,
Doug


As a side note, SWT will support the application menu bar in 3.7. The milestone builds already have the support. Please see Display.getMenuBar() and Snippet348 and Snippet354


Lakshmi P Shanmugam
Previous Topic:SWT.EMBEDDED problem on OSX
Next Topic:Drag and Drop between two Trees
Goto Forum:
  


Current Time: Mon Jan 25 02:18:33 GMT 2021

Powered by FUDForum. Page generated in 0.01919 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top