mirror of https://github.com/buggins/dlangui.git
action state update - working
This commit is contained in:
parent
9e0d20c814
commit
172defcc07
|
@ -66,6 +66,9 @@ class ActionState {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
override string toString() const {
|
||||
return (enabled ? "enabled" : "disabled") ~ (visible ? "_visible" : "_invisible") ~ (checked ? "_checked" : "");
|
||||
}
|
||||
}
|
||||
|
||||
/// action is
|
||||
|
|
|
@ -231,7 +231,11 @@ class MenuItem {
|
|||
|
||||
/// call to update state for action (if action is assigned for widget)
|
||||
void updateActionState(Widget w) {
|
||||
//import dlangui.widgets.editors;
|
||||
if (_action) {
|
||||
//if (_action.id == EditorActions.Copy) {
|
||||
// Log.d("Requesting Copy action. Old state: ", _action.state);
|
||||
//}
|
||||
w.updateActionState(_action, true);
|
||||
_enabled = _action.state.enabled;
|
||||
_checked = _action.state.checked;
|
||||
|
@ -663,6 +667,17 @@ class MenuWidgetBase : ListWidget {
|
|||
protected int _menuToggleState;
|
||||
protected Widget _menuTogglePreviousFocus;
|
||||
|
||||
/// override to handle specific actions state (e.g. change enabled state for supported actions)
|
||||
override bool handleActionStateRequest(const Action a) {
|
||||
if (_menuTogglePreviousFocus) {
|
||||
Log.d("Menu.handleActionStateRequest forwarding to ", _menuTogglePreviousFocus);
|
||||
bool res = _menuTogglePreviousFocus.handleActionStateRequest(a);
|
||||
Log.d("Menu.handleActionStateRequest forwarding handled successful: ", a.state.toString);
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// list navigation using keys
|
||||
override bool onKeyEvent(KeyEvent event) {
|
||||
if (orientation == Orientation.Horizontal) {
|
||||
|
@ -723,7 +738,7 @@ class MenuWidgetBase : ListWidget {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (_selectedItemIndex >= 0 && event.action == KeyAction.KeyDown && event.flags == 0 && (event.keyCode == KeyCode.RETURN || event.keyCode == KeyCode.SPACE)) {
|
||||
if (_selectedItemIndex >= 0 && event.action == KeyAction.KeyDown && /*event.flags == 0 &&*/ (event.keyCode == KeyCode.RETURN || event.keyCode == KeyCode.SPACE)) {
|
||||
itemClicked(_selectedItemIndex);
|
||||
return true;
|
||||
}
|
||||
|
@ -757,8 +772,8 @@ class MainMenu : MenuWidgetBase {
|
|||
|
||||
/// call to update state for action (if action is assigned for widget)
|
||||
override void updateActionState(bool force) {
|
||||
Log.d("MainMenu: updateActionState");
|
||||
_item.updateActionState(this);
|
||||
//Log.d("MainMenu: updateActionState");
|
||||
//_item.updateActionState(this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -869,6 +884,9 @@ class MainMenu : MenuWidgetBase {
|
|||
if (focused && _openedPopup is null) {
|
||||
// activating!
|
||||
_menuTogglePreviousFocus = window.focusedWidget;
|
||||
//updateActionState(true);
|
||||
Log.d("MainMenu: updateActionState");
|
||||
_item.updateActionState(this);
|
||||
}
|
||||
super.handleFocusChange(focused);
|
||||
}
|
||||
|
|
|
@ -623,19 +623,25 @@ class Widget {
|
|||
/// action to emit on click
|
||||
@property const(Action) action() { return _action; }
|
||||
/// action to emit on click
|
||||
@property void action(const Action action) { _action = action.clone; }
|
||||
@property void action(const Action action) { _action = action.clone; handleActionStateChanged(); }
|
||||
/// action to emit on click
|
||||
@property void action(Action action) { _action = action; }
|
||||
@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
|
||||
bool updateActionState(Action a, bool force = false) {
|
||||
if (Window w = window) {
|
||||
if (!force && !w.actionsUpdateRequested())
|
||||
return false;
|
||||
const ActionState oldState = a.state;
|
||||
//import dlangui.widgets.editors;
|
||||
//if (a.id == EditorActions.Undo) {
|
||||
// Log.d("Requesting Undo action. Old state: ", a.state);
|
||||
//}
|
||||
if (w.dispatchActionStateRequest(a, this)) {
|
||||
// state is updated
|
||||
//Log.d("updateActionState ", a.label, " found state: ", a.state.toString);
|
||||
} else {
|
||||
a.state = a.defaultState;
|
||||
//Log.d("updateActionState ", a.label, " using default state: ", a.state.toString);
|
||||
}
|
||||
if (a.state != oldState)
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue