diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index e8aeaa7a..68629f95 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -85,6 +85,17 @@ extern (C) int UIAppMain(string[] args) { mainMenuItems.add(windowItem); mainMenuItems.add(helpItem); MainMenu mainMenu = new MainMenu(mainMenuItems); + mainMenu.onMenuItemListener = delegate(MenuItem item) { + Log.d("mainMenu.onMenuItemListener", item.label); + const Action a = item.action; + if (a) { + if (window.focusedWidget) + return window.focusedWidget.handleAction(a); + else + return contentLayout.handleAction(a); + } + return false; + }; contentLayout.addChild(mainMenu); TabWidget tabs = new TabWidget("TABS"); diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index ba2f62aa..0c1ce5d9 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1199,7 +1199,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener { return true; } - override protected bool handleAction(Action a) { + override protected bool handleAction(const Action a) { TextPosition oldCaretPos = _caretPos; dstring currentLine = _content[_caretPos.line]; switch (a.id) { @@ -1571,7 +1571,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener { /// handle keys override bool onKeyEvent(KeyEvent event) { - if (event.action == KeyAction.Text && event.text.length) { + if (event.action == KeyAction.Text && event.text.length && !(event.flags & (KeyFlag.Control | KeyFlag.Alt))) { Log.d("text entered: ", event.text); if (readOnly) return true; @@ -1718,7 +1718,7 @@ class EditLine : EditWidgetBase { measuredContent(parentWidth, parentHeight, _measuredTextSize.x, _measuredTextSize.y); } - override protected bool handleAction(Action a) { + override protected bool handleAction(const Action a) { switch (a.id) { case EditorActions.Up: break; @@ -2016,7 +2016,7 @@ class EditBox : EditWidgetBase, OnScrollHandler { return res; } - override protected bool handleAction(Action a) { + override protected bool handleAction(const Action a) { TextPosition oldCaretPos = _caretPos; dstring currentLine = _content[_caretPos.line]; switch (a.id) { diff --git a/src/dlangui/widgets/menu.d b/src/dlangui/widgets/menu.d index fc729bf3..78c994af 100644 --- a/src/dlangui/widgets/menu.d +++ b/src/dlangui/widgets/menu.d @@ -460,11 +460,21 @@ class MenuWidgetBase : ListWidget { if (event.keyCode == KeyCode.LEFT || event.keyCode == KeyCode.RIGHT) { return true; } - } + } else if (event.action == KeyAction.Text && event.flags == 0) { + dchar ch = event.text[0]; + int index = _item.findSubitemByHotkey(ch); + if (index >= 0) { + itemClicked(index); + return true; + } + } } + if (_selectedItemIndex >= 0 && event.action == KeyAction.KeyDown && event.flags == 0 && (event.keyCode == KeyCode.RETURN || event.keyCode == KeyCode.SPACE)) { + itemClicked(_selectedItemIndex); + return true; + } return super.onKeyEvent(event); } - } /// main menu (horizontal) @@ -494,6 +504,13 @@ class MainMenu : MenuWidgetBase { protected int _menuToggleState; protected Widget _menuTogglePreviousFocus; + override protected void onMenuItem(MenuItem item) { + debug Log.d("MainMenu.onMenuItem ", item.action.label); + bool delegate(MenuItem item) listener = _onMenuItemClickListener; + deactivate(); + if (listener !is null) + listener(item); + } /// return true if main menu is activated (focused or has open submenu) @property bool activated() { @@ -559,6 +576,18 @@ class MainMenu : MenuWidgetBase { deactivate(); return true; } + if (event.action == KeyAction.Text && (event.flags & KeyFlag.Alt) && !(event.flags & KeyFlag.Shift) && !(event.flags & KeyFlag.Shift)) { + dchar ch = event.text[0]; + int index = _item.findSubitemByHotkey(ch); + if (index >= 0) { + activate(); + //selectItem(index); + itemClicked(index); + return true; + } else { + return false; + } + } if (event.action == KeyAction.KeyDown && isAlt && noOtherModifiers) { _menuToggleState = 1; diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 8d51cada..84dfedcd 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -791,7 +791,7 @@ class Widget { @property ref ActionMap acceleratorMap() { return _acceleratorMap; } /// override to handle specific actions - protected bool handleAction(Action a) { + bool handleAction(const Action a) { if (parent) // by default, pass to parent widget return parent.handleAction(a); return false;