mirror of https://github.com/buggins/dlangui.git
OSX native shortcuts support, part 1 - issue #121
This commit is contained in:
parent
29fb51bcd1
commit
f3f89282f8
|
@ -33,6 +33,28 @@ struct Accelerator {
|
||||||
/// Returns accelerator text description
|
/// Returns accelerator text description
|
||||||
@property dstring label() {
|
@property dstring label() {
|
||||||
dstring buf;
|
dstring buf;
|
||||||
|
version (OSX) {
|
||||||
|
static if (true) {
|
||||||
|
if (keyFlags & KeyFlag.Control)
|
||||||
|
buf ~= "Ctrl+";
|
||||||
|
if (keyFlags & KeyFlag.Shift)
|
||||||
|
buf ~= "Shift+";
|
||||||
|
if (keyFlags & KeyFlag.Option)
|
||||||
|
buf ~= "Opt+";
|
||||||
|
if (keyFlags & KeyFlag.Command)
|
||||||
|
buf ~= "Cmd+";
|
||||||
|
} else {
|
||||||
|
if (keyFlags & KeyFlag.Control)
|
||||||
|
buf ~= "⌃";
|
||||||
|
if (keyFlags & KeyFlag.Shift)
|
||||||
|
buf ~= "⇧";
|
||||||
|
if (keyFlags & KeyFlag.Option)
|
||||||
|
buf ~= "⌥";
|
||||||
|
if (keyFlags & KeyFlag.Command)
|
||||||
|
buf ~= "⌘";
|
||||||
|
}
|
||||||
|
buf ~= toUTF32(keyName(keyCode));
|
||||||
|
} else {
|
||||||
if (keyFlags & KeyFlag.Control)
|
if (keyFlags & KeyFlag.Control)
|
||||||
buf ~= "Ctrl+";
|
buf ~= "Ctrl+";
|
||||||
if (keyFlags & KeyFlag.Alt)
|
if (keyFlags & KeyFlag.Alt)
|
||||||
|
@ -40,6 +62,7 @@ struct Accelerator {
|
||||||
if (keyFlags & KeyFlag.Shift)
|
if (keyFlags & KeyFlag.Shift)
|
||||||
buf ~= "Shift+";
|
buf ~= "Shift+";
|
||||||
buf ~= toUTF32(keyName(keyCode));
|
buf ~= toUTF32(keyName(keyCode));
|
||||||
|
}
|
||||||
return cast(dstring)buf;
|
return cast(dstring)buf;
|
||||||
}
|
}
|
||||||
/// Serializes accelerator text description
|
/// Serializes accelerator text description
|
||||||
|
@ -51,6 +74,8 @@ struct Accelerator {
|
||||||
buf ~= "Alt+";
|
buf ~= "Alt+";
|
||||||
if (keyFlags & KeyFlag.Shift)
|
if (keyFlags & KeyFlag.Shift)
|
||||||
buf ~= "Shift+";
|
buf ~= "Shift+";
|
||||||
|
if (keyFlags & KeyFlag.Menu)
|
||||||
|
buf ~= "Menu+";
|
||||||
buf ~= keyName(keyCode);
|
buf ~= keyName(keyCode);
|
||||||
return cast(string)buf;
|
return cast(string)buf;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +101,11 @@ struct Accelerator {
|
||||||
s = s[6 .. $];
|
s = s[6 .. $];
|
||||||
flagFound = true;
|
flagFound = true;
|
||||||
}
|
}
|
||||||
|
if (s.startsWith("Menu+")) {
|
||||||
|
keyFlags |= KeyFlag.Menu;
|
||||||
|
s = s[5 .. $];
|
||||||
|
flagFound = true;
|
||||||
|
}
|
||||||
if (!flagFound)
|
if (!flagFound)
|
||||||
break;
|
break;
|
||||||
s = s.strip;
|
s = s.strip;
|
||||||
|
@ -226,12 +256,23 @@ class Action {
|
||||||
_id = id;
|
_id = id;
|
||||||
_label = labelResourceId;
|
_label = labelResourceId;
|
||||||
_iconId = iconResourceId;
|
_iconId = iconResourceId;
|
||||||
if (keyCode)
|
if (keyCode) {
|
||||||
|
version (OSX) {
|
||||||
|
if (keyFlags & KeyFlag.Control) {
|
||||||
|
_accelerators ~= Accelerator(keyCode, (keyFlags & ~KeyFlag.Control) | KeyFlag.Command);
|
||||||
|
}
|
||||||
|
}
|
||||||
_accelerators ~= Accelerator(keyCode, keyFlags);
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// action with accelerator, w/o label
|
/// action with accelerator, w/o label
|
||||||
this(int id, uint keyCode, uint keyFlags = 0) {
|
this(int id, uint keyCode, uint keyFlags = 0) {
|
||||||
_id = id;
|
_id = id;
|
||||||
|
version (OSX) {
|
||||||
|
if (keyFlags & KeyFlag.Control) {
|
||||||
|
_accelerators ~= Accelerator(keyCode, (keyFlags & ~KeyFlag.Control) | KeyFlag.Command);
|
||||||
|
}
|
||||||
|
}
|
||||||
_accelerators ~= Accelerator(keyCode, keyFlags);
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
}
|
}
|
||||||
/// action with label, icon, and accelerator
|
/// action with label, icon, and accelerator
|
||||||
|
@ -239,9 +280,15 @@ class Action {
|
||||||
_id = id;
|
_id = id;
|
||||||
_label = label;
|
_label = label;
|
||||||
_iconId = iconResourceId;
|
_iconId = iconResourceId;
|
||||||
if (keyCode)
|
if (keyCode) {
|
||||||
|
version (OSX) {
|
||||||
|
if (keyFlags & KeyFlag.Control) {
|
||||||
|
_accelerators ~= Accelerator(keyCode, (keyFlags & ~KeyFlag.Control) | KeyFlag.Command);
|
||||||
|
}
|
||||||
|
}
|
||||||
_accelerators ~= Accelerator(keyCode, keyFlags);
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// returs array of accelerators
|
/// returs array of accelerators
|
||||||
@property Accelerator[] accelerators() {
|
@property Accelerator[] accelerators() {
|
||||||
// check for accelerators override in settings
|
// check for accelerators override in settings
|
||||||
|
@ -290,6 +337,21 @@ class Action {
|
||||||
_accelerators ~= Accelerator(keyCode, keyFlags);
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/// adds one more accelerator only if platform is OSX
|
||||||
|
Action addMacAccelerator(uint keyCode, uint keyFlags = 0) {
|
||||||
|
version (OSX) {
|
||||||
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/// adds one more accelerator only if platform is not OSX
|
||||||
|
Action addNonMacAccelerator(uint keyCode, uint keyFlags = 0) {
|
||||||
|
version (OSX) {
|
||||||
|
} else {
|
||||||
|
_accelerators ~= Accelerator(keyCode, keyFlags);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
/// returns true if accelerator matches provided key code and flags
|
/// returns true if accelerator matches provided key code and flags
|
||||||
bool checkAccelerator(uint keyCode, uint keyFlags) {
|
bool checkAccelerator(uint keyCode, uint keyFlags) {
|
||||||
foreach(a; _accelerators)
|
foreach(a; _accelerators)
|
||||||
|
@ -692,6 +754,10 @@ enum KeyFlag : uint {
|
||||||
Shift = 0x0004,
|
Shift = 0x0004,
|
||||||
/// Alt key is down
|
/// Alt key is down
|
||||||
Alt = 0x0080,
|
Alt = 0x0080,
|
||||||
|
Option = Alt,
|
||||||
|
/// Menu key
|
||||||
|
Menu = 0x0040,
|
||||||
|
Command = Menu,
|
||||||
/// Right Ctrl key is down
|
/// Right Ctrl key is down
|
||||||
RControl = 0x0108,
|
RControl = 0x0108,
|
||||||
/// Right Shift key is down
|
/// Right Shift key is down
|
||||||
|
|
|
@ -735,6 +735,10 @@ class SDLWindow : Window {
|
||||||
return KeyCode.RSHIFT;
|
return KeyCode.RSHIFT;
|
||||||
case SDLK_RALT:
|
case SDLK_RALT:
|
||||||
return KeyCode.RALT;
|
return KeyCode.RALT;
|
||||||
|
case SDLK_LGUI:
|
||||||
|
return KeyCode.LWIN;
|
||||||
|
case SDLK_RGUI:
|
||||||
|
return KeyCode.RWIN;
|
||||||
case '/':
|
case '/':
|
||||||
return KeyCode.KEY_DIVIDE;
|
return KeyCode.KEY_DIVIDE;
|
||||||
default:
|
default:
|
||||||
|
@ -750,6 +754,8 @@ class SDLWindow : Window {
|
||||||
res |= KeyFlag.Shift;
|
res |= KeyFlag.Shift;
|
||||||
if (flags & KMOD_ALT)
|
if (flags & KMOD_ALT)
|
||||||
res |= KeyFlag.Alt;
|
res |= KeyFlag.Alt;
|
||||||
|
if (flags & KMOD_GUI)
|
||||||
|
res |= KeyFlag.Menu;
|
||||||
if (flags & KMOD_RCTRL)
|
if (flags & KMOD_RCTRL)
|
||||||
res |= KeyFlag.RControl | KeyFlag.Control;
|
res |= KeyFlag.RControl | KeyFlag.Control;
|
||||||
if (flags & KMOD_RSHIFT)
|
if (flags & KMOD_RSHIFT)
|
||||||
|
@ -796,6 +802,10 @@ class SDLWindow : Window {
|
||||||
case KeyCode.CONTROL:
|
case KeyCode.CONTROL:
|
||||||
flags |= KeyFlag.Control;
|
flags |= KeyFlag.Control;
|
||||||
break;
|
break;
|
||||||
|
case KeyCode.LWIN:
|
||||||
|
case KeyCode.RWIN:
|
||||||
|
flags |= KeyFlag.Menu;
|
||||||
|
break;
|
||||||
case KeyCode.RCONTROL:
|
case KeyCode.RCONTROL:
|
||||||
flags |= KeyFlag.Control | KeyFlag.RControl;
|
flags |= KeyFlag.Control | KeyFlag.RControl;
|
||||||
break;
|
break;
|
||||||
|
@ -811,6 +821,7 @@ class SDLWindow : Window {
|
||||||
case KeyCode.LSHIFT:
|
case KeyCode.LSHIFT:
|
||||||
flags |= KeyFlag.Shift | KeyFlag.LShift;
|
flags |= KeyFlag.Shift | KeyFlag.LShift;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<theme id="theme_default"
|
<theme id="theme_default"
|
||||||
fontSize="9pt"
|
fontSize="10pt"
|
||||||
fontFace="Verdana,Arial,DejaVu Sans,Liberation Sans"
|
fontFace="Helvetica Neue,Verdana,Arial,DejaVu Sans,Liberation Sans,Helvetica"
|
||||||
fontFamily="SansSerif"
|
fontFamily="SansSerif"
|
||||||
>
|
>
|
||||||
<color id="window_background" value="#FFFFFF"/>
|
<color id="window_background" value="#FFFFFF"/>
|
||||||
|
|
Loading…
Reference in New Issue