main menu fixes

This commit is contained in:
Vadim Lopatin 2014-05-08 11:13:37 +04:00
parent dd0527a698
commit 8c9964e596
1 changed files with 21 additions and 7 deletions

View File

@ -267,6 +267,10 @@ class MenuWidgetBase : ListWidget {
ownAdapter = adapter; ownAdapter = adapter;
} }
@property protected bool isMainMenu() {
return _orientation == Orientation.Horizontal;
}
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout). /// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
override void measure(int parentWidth, int parentHeight) { override void measure(int parentWidth, int parentHeight) {
if (_orientation == Orientation.Horizontal) { if (_orientation == Orientation.Horizontal) {
@ -298,6 +302,11 @@ class MenuWidgetBase : ListWidget {
super.measure(parentWidth, parentHeight); super.measure(parentWidth, parentHeight);
} }
protected void performUndoSelection() {
selectItem(-1);
setHoverItem(-1);
}
protected void onPopupClosed(PopupWidget p) { protected void onPopupClosed(PopupWidget p) {
if (_openedPopup) { if (_openedPopup) {
if (_openedPopup is p) { if (_openedPopup is p) {
@ -306,10 +315,10 @@ class MenuWidgetBase : ListWidget {
_openedPopup = null; _openedPopup = null;
_openedMenu = null; _openedMenu = null;
if (undoSelection) { if (undoSelection) {
selectItem(-1); performUndoSelection();
setHoverItem(-1);
} }
window.setFocus(this); if (!isMainMenu)
window.setFocus(this);
} else if (thisPopup is p) { } else if (thisPopup is p) {
_openedPopup.close(); _openedPopup.close();
} }
@ -476,7 +485,7 @@ class MainMenu : MenuWidgetBase {
/// get text flags (bit set of TextFlag enum values) /// get text flags (bit set of TextFlag enum values)
@property override uint textFlags() { @property override uint textFlags() {
// override text flags for main menu // override text flags for main menu
if (activated) if (_selectedItemIndex >= 0)
return TextFlag.UnderlineHotKeys | TextFlag.HotKeys; return TextFlag.UnderlineHotKeys | TextFlag.HotKeys;
else else
return TextFlag.UnderlineHotKeysWhenAltPressed | TextFlag.HotKeys; return TextFlag.UnderlineHotKeysWhenAltPressed | TextFlag.HotKeys;
@ -488,9 +497,13 @@ class MainMenu : MenuWidgetBase {
/// return true if main menu is activated (focused or has open submenu) /// return true if main menu is activated (focused or has open submenu)
@property bool activated() { @property bool activated() {
return focused || _openedPopup !is null; return focused || _selectedItemIndex >= 0 || _openedPopup !is null;
} }
override protected void performUndoSelection() {
deactivate();
}
/// bring focus to main menu, if not yet activated /// bring focus to main menu, if not yet activated
void activate() { void activate() {
debug Log.d("activating main menu"); debug Log.d("activating main menu");
@ -501,14 +514,15 @@ class MainMenu : MenuWidgetBase {
} }
/// close and remove focus, if activated /// close and remove focus, if activated
void deactivate() { void deactivate(bool force = false) {
debug Log.d("deactivating main menu"); debug Log.d("deactivating main menu");
if (!activated) if (!activated && !force)
return; return;
if (_openedPopup !is null) if (_openedPopup !is null)
_openedPopup.close(); _openedPopup.close();
selectItem(-1); selectItem(-1);
setHoverItem(-1); setHoverItem(-1);
selectOnHover = false;
window.setFocus(_menuTogglePreviousFocus); window.setFocus(_menuTogglePreviousFocus);
} }