mirror of https://github.com/adamdruppe/arsd.git
ketmar changes
This commit is contained in:
parent
1db72d6b18
commit
0f8df3f6cd
24
minigui.d
24
minigui.d
|
@ -570,6 +570,8 @@ class Action {
|
||||||
private static Action[int] mapping;
|
private static Action[int] mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyEvent accelerator;
|
||||||
|
|
||||||
///
|
///
|
||||||
this(string label, ushort icon = 0, void delegate() triggered = null) {
|
this(string label, ushort icon = 0, void delegate() triggered = null) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
|
@ -3316,6 +3318,7 @@ class Window : Widget {
|
||||||
bool dispatchKeyEvent(KeyEvent ev) {
|
bool dispatchKeyEvent(KeyEvent ev) {
|
||||||
if(focusedWidget) {
|
if(focusedWidget) {
|
||||||
auto event = new Event(ev.pressed ? "keydown" : "keyup", focusedWidget);
|
auto event = new Event(ev.pressed ? "keydown" : "keyup", focusedWidget);
|
||||||
|
event.originalKeyEvent = ev;
|
||||||
event.character = ev.character;
|
event.character = ev.character;
|
||||||
event.key = ev.key;
|
event.key = ev.key;
|
||||||
event.state = ev.modifierState;
|
event.state = ev.modifierState;
|
||||||
|
@ -3670,6 +3673,10 @@ class MainWindow : Window {
|
||||||
ushort correctIcon = 0; // FIXME
|
ushort correctIcon = 0; // FIXME
|
||||||
auto action = new Action(memberName, correctIcon, &__traits(getMember, t, memberName));
|
auto action = new Action(memberName, correctIcon, &__traits(getMember, t, memberName));
|
||||||
|
|
||||||
|
if(accelerator.keyString.length) {
|
||||||
|
action.accelerator = KeyEvent.parse(accelerator.keyString);
|
||||||
|
}
|
||||||
|
|
||||||
if(toolbar !is .toolbar.init)
|
if(toolbar !is .toolbar.init)
|
||||||
toolbarActions ~= action;
|
toolbarActions ~= action;
|
||||||
if(menu !is .menu.init) {
|
if(menu !is .menu.init) {
|
||||||
|
@ -3696,6 +3703,15 @@ class MainWindow : Window {
|
||||||
auto tb = new ToolBar(toolbarActions, this);
|
auto tb = new ToolBar(toolbarActions, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delegate()[string] accelerators;
|
||||||
|
|
||||||
|
override void defaultEventHandler_keydown(Event event) {
|
||||||
|
auto str = event.originalKeyEvent.toStr;
|
||||||
|
if(auto acl = str in accelerators)
|
||||||
|
(*acl)();
|
||||||
|
super.defaultEventHandler_keydown(event);
|
||||||
|
}
|
||||||
|
|
||||||
override void defaultEventHandler_mouseover(Event event) {
|
override void defaultEventHandler_mouseover(Event event) {
|
||||||
super.defaultEventHandler_mouseover(event);
|
super.defaultEventHandler_mouseover(event);
|
||||||
if(this.statusBar !is null && event.target.statusTip.length)
|
if(this.statusBar !is null && event.target.statusTip.length)
|
||||||
|
@ -4523,6 +4539,10 @@ class MenuItem : MouseActivatedWidget {
|
||||||
painter.outlineColor = Color.black;
|
painter.outlineColor = Color.black;
|
||||||
painter.fillColor = Color.transparent;
|
painter.fillColor = Color.transparent;
|
||||||
painter.drawText(Point(cast(MenuBar) this.parent ? 4 : 20, 2), label, Point(width, height), TextAlignment.Left);
|
painter.drawText(Point(cast(MenuBar) this.parent ? 4 : 20, 2), label, Point(width, height), TextAlignment.Left);
|
||||||
|
if(action && action.accelerator !is KeyEvent.init) {
|
||||||
|
painter.drawText(Point(cast(MenuBar) this.parent ? 4 : 20, 2), action.accelerator.toStr(), Point(width, height), TextAlignment.Right);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5458,6 +5478,8 @@ class Event {
|
||||||
// for key events
|
// for key events
|
||||||
Key key; ///
|
Key key; ///
|
||||||
|
|
||||||
|
KeyEvent originalKeyEvent;
|
||||||
|
|
||||||
// char character events
|
// char character events
|
||||||
dchar character; ///
|
dchar character; ///
|
||||||
|
|
||||||
|
@ -6119,7 +6141,7 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/bb760476%28v=vs.85%29.as
|
||||||
/// This item in the menu will be preceded by a separator line
|
/// This item in the menu will be preceded by a separator line
|
||||||
struct seperator {}
|
struct seperator {}
|
||||||
/// Program-wide keyboard shortcut to trigger the action
|
/// Program-wide keyboard shortcut to trigger the action
|
||||||
struct accelerator { string acl; }
|
struct accelerator { string keyString; }
|
||||||
/// tells which menu the action will be on
|
/// tells which menu the action will be on
|
||||||
struct menu { string name; }
|
struct menu { string name; }
|
||||||
/// Describes which toolbar section the action appears on
|
/// Describes which toolbar section the action appears on
|
||||||
|
|
|
@ -3650,7 +3650,7 @@ struct KeyEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.key) return null;
|
if (!this.key && !(this.modifierState&(ModifierState.ctrl|ModifierState.alt|ModifierState.shift|ModifierState.windows))) return null;
|
||||||
|
|
||||||
// put modifiers
|
// put modifiers
|
||||||
if (this.modifierState&ModifierState.ctrl) put("Ctrl+");
|
if (this.modifierState&ModifierState.ctrl) put("Ctrl+");
|
||||||
|
@ -3658,25 +3658,28 @@ struct KeyEvent {
|
||||||
if (this.modifierState&ModifierState.windows) put("Win+");
|
if (this.modifierState&ModifierState.windows) put("Win+");
|
||||||
if (this.modifierState&ModifierState.shift) put("Shift+");
|
if (this.modifierState&ModifierState.shift) put("Shift+");
|
||||||
|
|
||||||
foreach (string kn; __traits(allMembers, Key)) {
|
if (this.key) {
|
||||||
if (this.key == __traits(getMember, Key, kn)) {
|
foreach (string kn; __traits(allMembers, Key)) {
|
||||||
// HACK!
|
if (this.key == __traits(getMember, Key, kn)) {
|
||||||
static if (kn == "N0") put("0");
|
// HACK!
|
||||||
else static if (kn == "N1") put("1");
|
static if (kn == "N0") put("0");
|
||||||
else static if (kn == "N2") put("2");
|
else static if (kn == "N1") put("1");
|
||||||
else static if (kn == "N3") put("3");
|
else static if (kn == "N2") put("2");
|
||||||
else static if (kn == "N4") put("4");
|
else static if (kn == "N3") put("3");
|
||||||
else static if (kn == "N5") put("5");
|
else static if (kn == "N4") put("4");
|
||||||
else static if (kn == "N6") put("6");
|
else static if (kn == "N5") put("5");
|
||||||
else static if (kn == "N7") put("7");
|
else static if (kn == "N6") put("6");
|
||||||
else static if (kn == "N8") put("8");
|
else static if (kn == "N7") put("7");
|
||||||
else static if (kn == "N9") put("9");
|
else static if (kn == "N8") put("8");
|
||||||
else put(kn);
|
else static if (kn == "N9") put("9");
|
||||||
return dest[0..dpos];
|
else put(kn);
|
||||||
|
return dest[0..dpos];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
put("Unknown");
|
||||||
|
} else {
|
||||||
|
if (dpos && dest[dpos-1] == '+') --dpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
put("Unknown");
|
|
||||||
return dest[0..dpos];
|
return dest[0..dpos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3728,13 +3731,29 @@ struct KeyEvent {
|
||||||
|
|
||||||
KeyEvent res;
|
KeyEvent res;
|
||||||
res.key = cast(Key)0; // just in case
|
res.key = cast(Key)0; // just in case
|
||||||
|
const(char)[] tk, tkn; // last token
|
||||||
|
bool allowEmascStyle = true;
|
||||||
tokenloop: for (;;) {
|
tokenloop: for (;;) {
|
||||||
auto tk = getToken();
|
tk = tkn;
|
||||||
if (tk is null) break;
|
tkn = getToken();
|
||||||
if (strEquCI(tk, "C") || strEquCI(tk, "Ctrl")) { res.modifierState |= ModifierState.ctrl; continue tokenloop; }
|
//k8: yay, i took "Bloody Mess" trait from Fallout!
|
||||||
if (strEquCI(tk, "M") || strEquCI(tk, "Alt")) { res.modifierState |= ModifierState.alt; continue tokenloop; }
|
if (tkn.length != 0 && tk.length == 0) { tk = tkn; continue tokenloop; }
|
||||||
if (strEquCI(tk, "H") || strEquCI(tk, "Win") || strEquCI(tk, "Windows")) { res.modifierState |= ModifierState.windows; continue tokenloop; }
|
if (tkn.length == 0 && tk.length == 0) break; // no more tokens
|
||||||
if (strEquCI(tk, "S") || strEquCI(tk, "Shift")) { res.modifierState |= ModifierState.shift; continue tokenloop; }
|
if (allowEmascStyle && tkn.length != 0) {
|
||||||
|
if (tkn.length == 1) {
|
||||||
|
if (strEquCI(tk, "C")) { res.modifierState |= ModifierState.ctrl; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "M")) { res.modifierState |= ModifierState.alt; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "H")) { res.modifierState |= ModifierState.windows; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "S")) { res.modifierState |= ModifierState.shift; continue tokenloop; }
|
||||||
|
} else {
|
||||||
|
allowEmascStyle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strEquCI(tk, "Ctrl")) { allowEmascStyle = false; res.modifierState |= ModifierState.ctrl; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "Alt")) { allowEmascStyle = false; res.modifierState |= ModifierState.alt; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "Win") || strEquCI(tk, "Windows")) { allowEmascStyle = false; res.modifierState |= ModifierState.windows; continue tokenloop; }
|
||||||
|
if (strEquCI(tk, "Shift")) { allowEmascStyle = false; res.modifierState |= ModifierState.shift; continue tokenloop; }
|
||||||
|
if (tk.length == 0) continue;
|
||||||
// try key name
|
// try key name
|
||||||
if (res.key == 0) {
|
if (res.key == 0) {
|
||||||
// little hack
|
// little hack
|
||||||
|
|
Loading…
Reference in New Issue