close dialog on ESC key - fix #313

This commit is contained in:
Vadim Lopatin 2016-10-20 15:15:11 +03:00
parent f1c2f4d530
commit a112994a4f
4 changed files with 13 additions and 6 deletions

View File

@ -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;

View File

@ -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");

View File

@ -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)

View File

@ -273,7 +273,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
return true;
}
}
return false;
return super.onKeyEvent(event);
}
/// return true for custom drawn cell