From 89bd705477f1d982e227faf0c5ca94075b1be06b Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 16 Jan 2015 16:40:03 +0300 Subject: [PATCH] fix action handling --- src/dlangui/widgets/appframe.d | 11 +++++++++-- src/dlangui/widgets/toolbars.d | 5 +++++ src/dlangui/widgets/widget.d | 1 - 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dlangui/widgets/appframe.d b/src/dlangui/widgets/appframe.d index 2c15e1a2..d2cf83d8 100644 --- a/src/dlangui/widgets/appframe.d +++ b/src/dlangui/widgets/appframe.d @@ -24,7 +24,7 @@ import dlangui.widgets.layouts; import dlangui.widgets.statusline; import dlangui.widgets.toolbars; -class AppFrame : VerticalLayout, MenuItemClickHandler { +class AppFrame : VerticalLayout, MenuItemClickHandler, MenuItemActionHandler { protected MainMenu _mainMenu; protected StatusLine _statusLine; protected ToolBarHost _toolbarHost; @@ -64,7 +64,14 @@ class AppFrame : VerticalLayout, MenuItemClickHandler { /// override to handle main menu commands override bool onMenuItemClick(MenuItem item) { - return false; + // default handling: call Action handler + return onMenuItemAction(item.action); + } + + /// override to handle main menu actions + bool onMenuItemAction(const Action action) { + // default handling: dispatch action using window (first offered to focused control, then to main widget) + return window.dispatchAction(action); } /// create main menu diff --git a/src/dlangui/widgets/toolbars.d b/src/dlangui/widgets/toolbars.d index bb943bdf..b9d6b9e3 100644 --- a/src/dlangui/widgets/toolbars.d +++ b/src/dlangui/widgets/toolbars.d @@ -52,6 +52,11 @@ class ToolBarHost : HorizontalLayout { } return null; } + /// override to handle specific actions + override bool handleAction(const Action a) { + // route to focused control first, then to main widget + return window.dispatchAction(a); + } } /// image button for toolbar diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index e8d3f78b..545e40df 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -906,7 +906,6 @@ class Widget { return false; } - // called to process click and notify listeners protected bool handleClick() { bool res = false;