mirror of https://github.com/buggins/dlangui.git
fix crash on action handling
This commit is contained in:
parent
0b3440500a
commit
173388fdff
|
@ -341,10 +341,8 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
};
|
};
|
||||||
dlg.show();
|
dlg.show();
|
||||||
return true;
|
return true;
|
||||||
} else if (window.focusedWidget)
|
} else
|
||||||
return window.focusedWidget.handleAction(a);
|
return contentLayout.dispatchAction(a);
|
||||||
else
|
|
||||||
return contentLayout.handleAction(a);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -489,14 +489,32 @@ class Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// dispatch action to main widget
|
/// dispatch action to main widget
|
||||||
bool dispatchAction(const Action action) {
|
bool dispatchAction(const Action action, Widget sourceWidget = null) {
|
||||||
Widget focus = focusedWidget;
|
// try to handle by source widget
|
||||||
// first, offer action to focused widget
|
if(sourceWidget && isChild(sourceWidget)) {
|
||||||
if (focus && focus.handleAction(action))
|
if (sourceWidget.handleAction(action))
|
||||||
return true;
|
return true;
|
||||||
// if not processed by focused widget, pass to main widget
|
sourceWidget = sourceWidget.parent;
|
||||||
if (_mainWidget !is null)
|
}
|
||||||
return _mainWidget.handleAction(action);
|
Widget focus = focusedWidget;
|
||||||
|
// then offer action to focused widget
|
||||||
|
if (focus && isChild(focus)) {
|
||||||
|
if (focus.handleAction(action))
|
||||||
|
return true;
|
||||||
|
focus = focus.parent;
|
||||||
|
}
|
||||||
|
// then offer to parent chain of source widget
|
||||||
|
while (sourceWidget && isChild(sourceWidget)) {
|
||||||
|
if (sourceWidget.handleAction(action))
|
||||||
|
return true;
|
||||||
|
sourceWidget = sourceWidget.parent;
|
||||||
|
}
|
||||||
|
// then offer to parent chain of focused widget
|
||||||
|
while (focus && isChild(focus)) {
|
||||||
|
if (focus.handleAction(action))
|
||||||
|
return true;
|
||||||
|
focus = focus.parent;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,4 +98,10 @@ class AppFrame : VerticalLayout, MenuItemClickHandler, MenuItemActionHandler {
|
||||||
res.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
res.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// override to handle specific actions
|
||||||
|
override bool handleAction(const Action a) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1275,7 +1275,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
||||||
|
|
||||||
///
|
///
|
||||||
override bool onMenuItemAction(const Action action) {
|
override bool onMenuItemAction(const Action action) {
|
||||||
return handleAction(action);
|
return dispatchAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns true if widget can show popup (e.g. by mouse right click at point x,y)
|
/// returns true if widget can show popup (e.g. by mouse right click at point x,y)
|
||||||
|
@ -2084,16 +2084,16 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
||||||
uint keyFlags = event.flags & (MouseFlag.Shift | MouseFlag.Control | MouseFlag.Alt);
|
uint keyFlags = event.flags & (MouseFlag.Shift | MouseFlag.Control | MouseFlag.Alt);
|
||||||
if (event.wheelDelta < 0) {
|
if (event.wheelDelta < 0) {
|
||||||
if (keyFlags == MouseFlag.Shift)
|
if (keyFlags == MouseFlag.Shift)
|
||||||
return handleAction(new Action(EditorActions.ScrollRight));
|
return dispatchAction(new Action(EditorActions.ScrollRight));
|
||||||
if (keyFlags == MouseFlag.Control)
|
if (keyFlags == MouseFlag.Control)
|
||||||
return handleAction(new Action(EditorActions.ZoomOut));
|
return dispatchAction(new Action(EditorActions.ZoomOut));
|
||||||
return handleAction(new Action(EditorActions.ScrollLineDown));
|
return dispatchAction(new Action(EditorActions.ScrollLineDown));
|
||||||
} else if (event.wheelDelta > 0) {
|
} else if (event.wheelDelta > 0) {
|
||||||
if (keyFlags == MouseFlag.Shift)
|
if (keyFlags == MouseFlag.Shift)
|
||||||
return handleAction(new Action(EditorActions.ScrollLeft));
|
return dispatchAction(new Action(EditorActions.ScrollLeft));
|
||||||
if (keyFlags == MouseFlag.Control)
|
if (keyFlags == MouseFlag.Control)
|
||||||
return handleAction(new Action(EditorActions.ZoomIn));
|
return dispatchAction(new Action(EditorActions.ZoomIn));
|
||||||
return handleAction(new Action(EditorActions.ScrollLineUp));
|
return dispatchAction(new Action(EditorActions.ScrollLineUp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onMouseEvent(event);
|
return super.onMouseEvent(event);
|
||||||
|
@ -2402,13 +2402,13 @@ class EditBox : EditWidgetBase {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
} else if (event.action == ScrollAction.PageUp) {
|
} else if (event.action == ScrollAction.PageUp) {
|
||||||
handleAction(new Action(EditorActions.ScrollLeft));
|
dispatchAction(new Action(EditorActions.ScrollLeft));
|
||||||
} else if (event.action == ScrollAction.PageDown) {
|
} else if (event.action == ScrollAction.PageDown) {
|
||||||
handleAction(new Action(EditorActions.ScrollRight));
|
dispatchAction(new Action(EditorActions.ScrollRight));
|
||||||
} else if (event.action == ScrollAction.LineUp) {
|
} else if (event.action == ScrollAction.LineUp) {
|
||||||
handleAction(new Action(EditorActions.ScrollLeft));
|
dispatchAction(new Action(EditorActions.ScrollLeft));
|
||||||
} else if (event.action == ScrollAction.LineDown) {
|
} else if (event.action == ScrollAction.LineDown) {
|
||||||
handleAction(new Action(EditorActions.ScrollRight));
|
dispatchAction(new Action(EditorActions.ScrollRight));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2422,13 +2422,13 @@ class EditBox : EditWidgetBase {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
} else if (event.action == ScrollAction.PageUp) {
|
} else if (event.action == ScrollAction.PageUp) {
|
||||||
handleAction(new Action(EditorActions.ScrollPageUp));
|
dispatchAction(new Action(EditorActions.ScrollPageUp));
|
||||||
} else if (event.action == ScrollAction.PageDown) {
|
} else if (event.action == ScrollAction.PageDown) {
|
||||||
handleAction(new Action(EditorActions.ScrollPageDown));
|
dispatchAction(new Action(EditorActions.ScrollPageDown));
|
||||||
} else if (event.action == ScrollAction.LineUp) {
|
} else if (event.action == ScrollAction.LineUp) {
|
||||||
handleAction(new Action(EditorActions.ScrollLineUp));
|
dispatchAction(new Action(EditorActions.ScrollLineUp));
|
||||||
} else if (event.action == ScrollAction.LineDown) {
|
} else if (event.action == ScrollAction.LineDown) {
|
||||||
handleAction(new Action(EditorActions.ScrollLineDown));
|
dispatchAction(new Action(EditorActions.ScrollLineDown));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,13 +535,13 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
int col = colByAbsoluteX(event.position + _fullScrollableArea.left);
|
int col = colByAbsoluteX(event.position + _fullScrollableArea.left);
|
||||||
scrollTo(col, _scrollRow + _headerRows + _fixedRows);
|
scrollTo(col, _scrollRow + _headerRows + _fixedRows);
|
||||||
} else if (event.action == ScrollAction.PageUp) {
|
} else if (event.action == ScrollAction.PageUp) {
|
||||||
handleAction(new Action(GridActions.ScrollPageLeft));
|
dispatchAction(new Action(GridActions.ScrollPageLeft));
|
||||||
} else if (event.action == ScrollAction.PageDown) {
|
} else if (event.action == ScrollAction.PageDown) {
|
||||||
handleAction(new Action(GridActions.ScrollPageRight));
|
dispatchAction(new Action(GridActions.ScrollPageRight));
|
||||||
} else if (event.action == ScrollAction.LineUp) {
|
} else if (event.action == ScrollAction.LineUp) {
|
||||||
handleAction(new Action(GridActions.ScrollLeft));
|
dispatchAction(new Action(GridActions.ScrollLeft));
|
||||||
} else if (event.action == ScrollAction.LineDown) {
|
} else if (event.action == ScrollAction.LineDown) {
|
||||||
handleAction(new Action(GridActions.ScrollRight));
|
dispatchAction(new Action(GridActions.ScrollRight));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -552,13 +552,13 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
int row = rowByAbsoluteY(event.position + _fullScrollableArea.top);
|
int row = rowByAbsoluteY(event.position + _fullScrollableArea.top);
|
||||||
scrollTo(_scrollCol + _headerCols + _fixedCols, row);
|
scrollTo(_scrollCol + _headerCols + _fixedCols, row);
|
||||||
} else if (event.action == ScrollAction.PageUp) {
|
} else if (event.action == ScrollAction.PageUp) {
|
||||||
handleAction(new Action(GridActions.ScrollPageUp));
|
dispatchAction(new Action(GridActions.ScrollPageUp));
|
||||||
} else if (event.action == ScrollAction.PageDown) {
|
} else if (event.action == ScrollAction.PageDown) {
|
||||||
handleAction(new Action(GridActions.ScrollPageDown));
|
dispatchAction(new Action(GridActions.ScrollPageDown));
|
||||||
} else if (event.action == ScrollAction.LineUp) {
|
} else if (event.action == ScrollAction.LineUp) {
|
||||||
handleAction(new Action(GridActions.ScrollUp));
|
dispatchAction(new Action(GridActions.ScrollUp));
|
||||||
} else if (event.action == ScrollAction.LineDown) {
|
} else if (event.action == ScrollAction.LineDown) {
|
||||||
handleAction(new Action(GridActions.ScrollDown));
|
dispatchAction(new Action(GridActions.ScrollDown));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -901,18 +901,25 @@ class Widget {
|
||||||
|
|
||||||
/// override to handle specific actions
|
/// override to handle specific actions
|
||||||
bool handleAction(const Action a) {
|
bool handleAction(const Action a) {
|
||||||
if (parent) // by default, pass to parent widget
|
|
||||||
return parent.handleAction(a);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// call to dispatch action
|
||||||
|
bool dispatchAction(const Action a) {
|
||||||
|
if (window)
|
||||||
|
return window.dispatchAction(a, this);
|
||||||
|
else
|
||||||
|
return handleAction(a);
|
||||||
|
}
|
||||||
|
|
||||||
// called to process click and notify listeners
|
// called to process click and notify listeners
|
||||||
protected bool handleClick() {
|
protected bool handleClick() {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
if (onClickListener.assigned)
|
if (onClickListener.assigned)
|
||||||
res = onClickListener(this);
|
res = onClickListener(this);
|
||||||
else if (_action)
|
else if (_action) {
|
||||||
res = handleAction(_action);
|
return dispatchAction(_action);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -929,7 +936,7 @@ class Widget {
|
||||||
if (event.action == KeyAction.KeyDown) {
|
if (event.action == KeyAction.KeyDown) {
|
||||||
Action action = findKeyAction(event.keyCode, event.flags & (KeyFlag.Shift | KeyFlag.Alt | KeyFlag.Control));
|
Action action = findKeyAction(event.keyCode, event.flags & (KeyFlag.Shift | KeyFlag.Alt | KeyFlag.Control));
|
||||||
if (action !is null) {
|
if (action !is null) {
|
||||||
return handleAction(action);
|
return dispatchAction(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// handle focus navigation using keys
|
// handle focus navigation using keys
|
||||||
|
|
Loading…
Reference in New Issue