mirror of https://github.com/buggins/dlangui.git
menu item action handling
This commit is contained in:
parent
8c9964e596
commit
374b5bb058
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue