diff --git a/src/dlangui/core/events.d b/src/dlangui/core/events.d index c4bf586d..3caa30de 100644 --- a/src/dlangui/core/events.d +++ b/src/dlangui/core/events.d @@ -364,9 +364,7 @@ class Action { _iconId = a._iconId; _state = a._state; _defaultState = a._defaultState; - _accelerators.length = a._accelerators.length; - foreach(i; 0 .. _accelerators.length) - _accelerators[i] = a._accelerators[i]; + _accelerators = a._accelerators.dup; _stringParam = a._stringParam; _longParam = a._longParam; if (a._objectParam) @@ -484,7 +482,7 @@ class Action { return this; } /// returns true if accelerator matches provided key code and flags - bool checkAccelerator(uint keyCode, uint keyFlags) { + bool checkAccelerator(uint keyCode, uint keyFlags) const { foreach(a; _accelerators) { if (a.keyCode == keyCode && matchKeyFlags(keyFlags, a.keyFlags)) return true; diff --git a/src/dlangui/core/stdaction.d b/src/dlangui/core/stdaction.d index eee32bec..3b613aa5 100644 --- a/src/dlangui/core/stdaction.d +++ b/src/dlangui/core/stdaction.d @@ -40,7 +40,7 @@ enum StandardAction : int { } const Action ACTION_OK = new Action(StandardAction.Ok, "ACTION_OK"c, "dialog-ok"); -const Action ACTION_CANCEL = new Action(StandardAction.Cancel, "ACTION_CANCEL"c, "dialog-cancel"); +const Action ACTION_CANCEL = new Action(StandardAction.Cancel, "ACTION_CANCEL"c, "dialog-cancel").addAccelerator(KeyCode.ESCAPE); const Action ACTION_APPLY = new Action(StandardAction.Apply, "ACTION_APPLY"c, null); const Action ACTION_YES = new Action(StandardAction.Yes, "ACTION_YES"c, "dialog-ok"); const Action ACTION_NO = new Action(StandardAction.No, "ACTION_NO"c, "dialog-cancel"); diff --git a/src/dlangui/dialogs/dialog.d b/src/dlangui/dialogs/dialog.d index 901fd6c7..029eee5b 100644 --- a/src/dlangui/dialogs/dialog.d +++ b/src/dlangui/dialogs/dialog.d @@ -142,6 +142,15 @@ class Dialog : VerticalLayout { return res; } + /// map key to action + override Action findKeyAction(uint keyCode, uint flags) { + foreach(a; _buttonActions) { + if (a.checkAccelerator(keyCode, flags)) + return a.clone; + } + return super.findKeyAction(keyCode, flags); + } + /// Custom handling of actions override bool handleAction(const Action action) { foreach(const Action a; _buttonActions) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index a634222c..555ae831 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -273,7 +273,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { return true; } } - return false; + return super.onKeyEvent(event); } /// return true for custom drawn cell