fix menu checkboxes and radio buttons

This commit is contained in:
Vadim Lopatin 2016-05-18 14:02:38 +03:00
parent 9d983dcf52
commit 8a7fec4674
3 changed files with 22 additions and 7 deletions

View File

@ -319,6 +319,10 @@ class Action {
} }
return this; return this;
} }
@property const(Action) checked(bool newValue) const {
state = ActionState(_state.enabled, _state.visible, newValue);
return this;
}
/// returns optional string parameter /// returns optional string parameter
@property string stringParam() const { @property string stringParam() const {

View File

@ -114,6 +114,10 @@ class MenuItem {
/// get check for checkbox or radio button item /// get check for checkbox or radio button item
@property bool checked() { @property bool checked() {
//if (_checked) {
// Log.d("Menu item is checked");
// return true;
//}
return _checked; return _checked;
} }
/// check radio button with specified index, uncheck other radio buttons in group (group consists of sequence of radio button items; other item type - end of group) /// check radio button with specified index, uncheck other radio buttons in group (group consists of sequence of radio button items; other item type - end of group)
@ -135,6 +139,8 @@ class MenuItem {
@property MenuItem checked(bool flg) { @property MenuItem checked(bool flg) {
if (_checked == flg) if (_checked == flg)
return this; return this;
if (_action)
_action.checked = flg;
_checked = flg; _checked = flg;
if (flg && _parent && type == MenuItemType.Radio) { if (flg && _parent && type == MenuItemType.Radio) {
int index = _parent.subitemIndex(this); int index = _parent.subitemIndex(this);
@ -238,9 +244,10 @@ class MenuItem {
//if (_action.id == EditorActions.Copy) { //if (_action.id == EditorActions.Copy) {
// Log.d("Requesting Copy action. Old state: ", _action.state); // Log.d("Requesting Copy action. Old state: ", _action.state);
//} //}
w.updateActionState(_action, true); bool actionStateProcessed = w.updateActionState(_action, true, false);
_enabled = _action.state.enabled; _enabled = _action.state.enabled;
_checked = _action.state.checked; if (actionStateProcessed)
_checked = _action.state.checked;
} }
for (int i = 0; i < _subitems.length; i++) { for (int i = 0; i < _subitems.length; i++) {
_subitems[i].updateActionState(w); _subitems[i].updateActionState(w);
@ -620,7 +627,7 @@ class MenuWidgetBase : ListWidget {
_parentMenu.onMenuItem(item); _parentMenu.onMenuItem(item);
else { else {
// top level handling // top level handling
Log.d("onMenuItem ", item.id); debug(DebugMenus) Log.d("onMenuItem ", item.id);
selectItem(-1); selectItem(-1);
setHoverItem(-1); setHoverItem(-1);
selectOnHover = false; selectOnHover = false;
@ -691,9 +698,9 @@ class MenuWidgetBase : ListWidget {
/// 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)
override bool handleActionStateRequest(const Action a) { override bool handleActionStateRequest(const Action a) {
if (_menuTogglePreviousFocus) { if (_menuTogglePreviousFocus) {
Log.d("Menu.handleActionStateRequest forwarding to ", _menuTogglePreviousFocus); debug(DebugMenus) Log.d("Menu.handleActionStateRequest forwarding to ", _menuTogglePreviousFocus);
bool res = _menuTogglePreviousFocus.handleActionStateRequest(a); bool res = _menuTogglePreviousFocus.handleActionStateRequest(a);
Log.d("Menu.handleActionStateRequest forwarding handled successful: ", a.state.toString); debug(DebugMenus) Log.d("Menu.handleActionStateRequest forwarding handled successful: ", a.state.toString);
return res; return res;
} }
return false; return false;
@ -916,7 +923,7 @@ class MainMenu : MenuWidgetBase {
// activating! // activating!
_menuTogglePreviousFocus = window.focusedWidget; _menuTogglePreviousFocus = window.focusedWidget;
//updateActionState(true); //updateActionState(true);
Log.d("MainMenu: updateActionState"); debug(DebugMenus) Log.d("MainMenu: updateActionState");
_item.updateActionState(this); _item.updateActionState(this);
} }
super.handleFocusChange(focused); super.handleFocusChange(focused);

View File

@ -691,7 +691,7 @@ public:
/// action to emit on click /// action to emit on click
@property void action(Action action) { _action = action; handleActionStateChanged(); } @property void action(Action action) { _action = action; handleActionStateChanged(); }
/// ask for update state of some action (unles force=true, checks window flag actionsUpdateRequested), returns true if action state is changed /// ask for update state of some action (unles force=true, checks window flag actionsUpdateRequested), returns true if action state is changed
bool updateActionState(Action a, bool force = false) { bool updateActionState(Action a, bool force = false, bool allowDefault = true) {
if (Window w = window) { if (Window w = window) {
if (!force && !w.actionsUpdateRequested()) if (!force && !w.actionsUpdateRequested())
return false; return false;
@ -703,7 +703,11 @@ public:
if (w.dispatchActionStateRequest(a, this)) { if (w.dispatchActionStateRequest(a, this)) {
// state is updated // state is updated
//Log.d("updateActionState ", a.label, " found state: ", a.state.toString); //Log.d("updateActionState ", a.label, " found state: ", a.state.toString);
if (allowDefault)
return true; // return 'request dispatched' flag instead of 'changed'
} else { } else {
if (!allowDefault)
return false;
a.state = a.defaultState; a.state = a.defaultState;
//Log.d("updateActionState ", a.label, " using default state: ", a.state.toString); //Log.d("updateActionState ", a.label, " using default state: ", a.state.toString);
} }