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(windowItem);
|
||||||
mainMenuItems.add(helpItem);
|
mainMenuItems.add(helpItem);
|
||||||
MainMenu mainMenu = new MainMenu(mainMenuItems);
|
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);
|
contentLayout.addChild(mainMenu);
|
||||||
|
|
||||||
TabWidget tabs = new TabWidget("TABS");
|
TabWidget tabs = new TabWidget("TABS");
|
||||||
|
|
|
@ -1199,7 +1199,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected bool handleAction(Action a) {
|
override protected bool handleAction(const Action a) {
|
||||||
TextPosition oldCaretPos = _caretPos;
|
TextPosition oldCaretPos = _caretPos;
|
||||||
dstring currentLine = _content[_caretPos.line];
|
dstring currentLine = _content[_caretPos.line];
|
||||||
switch (a.id) {
|
switch (a.id) {
|
||||||
|
@ -1571,7 +1571,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
|
|
||||||
/// handle keys
|
/// handle keys
|
||||||
override bool onKeyEvent(KeyEvent event) {
|
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);
|
Log.d("text entered: ", event.text);
|
||||||
if (readOnly)
|
if (readOnly)
|
||||||
return true;
|
return true;
|
||||||
|
@ -1718,7 +1718,7 @@ class EditLine : EditWidgetBase {
|
||||||
measuredContent(parentWidth, parentHeight, _measuredTextSize.x, _measuredTextSize.y);
|
measuredContent(parentWidth, parentHeight, _measuredTextSize.x, _measuredTextSize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected bool handleAction(Action a) {
|
override protected bool handleAction(const Action a) {
|
||||||
switch (a.id) {
|
switch (a.id) {
|
||||||
case EditorActions.Up:
|
case EditorActions.Up:
|
||||||
break;
|
break;
|
||||||
|
@ -2016,7 +2016,7 @@ class EditBox : EditWidgetBase, OnScrollHandler {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected bool handleAction(Action a) {
|
override protected bool handleAction(const Action a) {
|
||||||
TextPosition oldCaretPos = _caretPos;
|
TextPosition oldCaretPos = _caretPos;
|
||||||
dstring currentLine = _content[_caretPos.line];
|
dstring currentLine = _content[_caretPos.line];
|
||||||
switch (a.id) {
|
switch (a.id) {
|
||||||
|
|
|
@ -460,11 +460,21 @@ class MenuWidgetBase : ListWidget {
|
||||||
if (event.keyCode == KeyCode.LEFT || event.keyCode == KeyCode.RIGHT) {
|
if (event.keyCode == KeyCode.LEFT || event.keyCode == KeyCode.RIGHT) {
|
||||||
return true;
|
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);
|
return super.onKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// main menu (horizontal)
|
/// main menu (horizontal)
|
||||||
|
@ -494,6 +504,13 @@ class MainMenu : MenuWidgetBase {
|
||||||
protected int _menuToggleState;
|
protected int _menuToggleState;
|
||||||
protected Widget _menuTogglePreviousFocus;
|
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)
|
/// return true if main menu is activated (focused or has open submenu)
|
||||||
@property bool activated() {
|
@property bool activated() {
|
||||||
|
@ -559,6 +576,18 @@ class MainMenu : MenuWidgetBase {
|
||||||
deactivate();
|
deactivate();
|
||||||
return true;
|
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) {
|
if (event.action == KeyAction.KeyDown && isAlt && noOtherModifiers) {
|
||||||
_menuToggleState = 1;
|
_menuToggleState = 1;
|
||||||
|
|
|
@ -791,7 +791,7 @@ class Widget {
|
||||||
@property ref ActionMap acceleratorMap() { return _acceleratorMap; }
|
@property ref ActionMap acceleratorMap() { return _acceleratorMap; }
|
||||||
|
|
||||||
/// override to handle specific actions
|
/// override to handle specific actions
|
||||||
protected bool handleAction(Action a) {
|
bool handleAction(const Action a) {
|
||||||
if (parent) // by default, pass to parent widget
|
if (parent) // by default, pass to parent widget
|
||||||
return parent.handleAction(a);
|
return parent.handleAction(a);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue