mirror of https://github.com/buggins/dlangui.git
shortcuts and actions handling signals in widgets; close #189
This commit is contained in:
parent
f68cce12b1
commit
9880447987
|
@ -341,10 +341,12 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
mainMenuItems.add(windowItem);
|
mainMenuItems.add(windowItem);
|
||||||
mainMenuItems.add(helpItem);
|
mainMenuItems.add(helpItem);
|
||||||
MainMenu mainMenu = new MainMenu(mainMenuItems);
|
MainMenu mainMenu = new MainMenu(mainMenuItems);
|
||||||
mainMenu.menuItemClick = delegate(MenuItem item) {
|
contentLayout.addChild(mainMenu);
|
||||||
Log.d("mainMenu.onMenuItemListener", item.label);
|
// to let main menu handle keyboard shortcuts
|
||||||
const Action a = item.action;
|
contentLayout.keyToAction = delegate(Widget source, uint keyCode, uint flags) {
|
||||||
if (a) {
|
return mainMenu.findKeyAction(keyCode, flags);
|
||||||
|
};
|
||||||
|
contentLayout.onAction = delegate(Widget source, const Action a) {
|
||||||
if (a.id == ACTION_FILE_EXIT) {
|
if (a.id == ACTION_FILE_EXIT) {
|
||||||
window.close();
|
window.close();
|
||||||
return true;
|
return true;
|
||||||
|
@ -392,10 +394,15 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return contentLayout.dispatchAction(a);
|
return contentLayout.dispatchAction(a);
|
||||||
|
};
|
||||||
|
mainMenu.menuItemClick = delegate(MenuItem item) {
|
||||||
|
Log.d("mainMenu.onMenuItemListener", item.label);
|
||||||
|
const Action a = item.action;
|
||||||
|
if (a) {
|
||||||
|
return contentLayout.dispatchAction(a);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
contentLayout.addChild(mainMenu);
|
|
||||||
|
|
||||||
// ========= create tabs ===================
|
// ========= create tabs ===================
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,16 @@ interface OnKeyHandler {
|
||||||
bool onKey(Widget source, KeyEvent event);
|
bool onKey(Widget source, KeyEvent event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// interface - slot for keyToAction
|
||||||
|
interface OnKeyActionHandler {
|
||||||
|
Action findKeyAction(Widget source, uint keyCode, uint keyFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// interface - slot for onAction
|
||||||
|
interface OnActionHandler {
|
||||||
|
bool onAction(Widget source, const Action action);
|
||||||
|
}
|
||||||
|
|
||||||
/// interface - slot for onMouse
|
/// interface - slot for onMouse
|
||||||
interface OnMouseHandler {
|
interface OnMouseHandler {
|
||||||
bool onMouse(Widget source, MouseEvent event);
|
bool onMouse(Widget source, MouseEvent event);
|
||||||
|
@ -1093,6 +1103,9 @@ public:
|
||||||
|
|
||||||
/// override to handle specific actions
|
/// override to handle specific actions
|
||||||
bool handleAction(const Action a) {
|
bool handleAction(const Action a) {
|
||||||
|
if (onAction.assigned)
|
||||||
|
if (onAction(this, a))
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/// override to handle specific actions state (e.g. change enabled state for supported actions)
|
/// override to handle specific actions state (e.g. change enabled state for supported actions)
|
||||||
|
@ -1144,6 +1157,10 @@ public:
|
||||||
/// map key to action
|
/// map key to action
|
||||||
Action findKeyAction(uint keyCode, uint flags) {
|
Action findKeyAction(uint keyCode, uint flags) {
|
||||||
Action action = _acceleratorMap.findByKey(keyCode, flags);
|
Action action = _acceleratorMap.findByKey(keyCode, flags);
|
||||||
|
if (action)
|
||||||
|
return action;
|
||||||
|
if (keyToAction.assigned)
|
||||||
|
action = keyToAction(this, keyCode, flags);
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1282,6 +1299,12 @@ public:
|
||||||
/// key event listener (bool delegate(Widget, KeyEvent)) - return true if event is processed by handler
|
/// key event listener (bool delegate(Widget, KeyEvent)) - return true if event is processed by handler
|
||||||
Signal!OnKeyHandler keyEvent;
|
Signal!OnKeyHandler keyEvent;
|
||||||
|
|
||||||
|
/// action by key lookup handler
|
||||||
|
Listener!OnKeyActionHandler keyToAction;
|
||||||
|
|
||||||
|
/// action handlers
|
||||||
|
Signal!OnActionHandler onAction;
|
||||||
|
|
||||||
/// mouse event listener (bool delegate(Widget, MouseEvent)) - return true if event is processed by handler
|
/// mouse event listener (bool delegate(Widget, MouseEvent)) - return true if event is processed by handler
|
||||||
Signal!OnMouseHandler mouseEvent;
|
Signal!OnMouseHandler mouseEvent;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue