mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
Display appropriate strings for shortcuts
This commit is contained in:
@@ -7,9 +7,9 @@ return { id = 'mainWindow',
|
|||||||
status = 'Quit the demo' },
|
status = 'Quit the demo' },
|
||||||
},
|
},
|
||||||
{ text = 'Edit',
|
{ text = 'Edit',
|
||||||
{ text = 'Cut', shortcut = 'ctrl-c' },
|
{ text = 'Cut', shortcut = { 'win-ctrl-c', 'mac-gui-c' } },
|
||||||
{ text = 'Copy', shortcut = 'ctrl-x' },
|
{ text = 'Copy', shortcut = 'c-x' },
|
||||||
{ text = 'Paste', shortcut = 'ctrl-v' },
|
{ text = 'Paste', shortcut = { 'command-v', 'win-ctrl-v' } },
|
||||||
{ type = 'slider' },
|
{ type = 'slider' },
|
||||||
},
|
},
|
||||||
{ text = 'View',
|
{ text = 'View',
|
||||||
|
|||||||
@@ -15,18 +15,28 @@ local CTRL = 2
|
|||||||
local SHIFT = 4
|
local SHIFT = 4
|
||||||
local GUI = 8
|
local GUI = 8
|
||||||
|
|
||||||
function Shortcut.parseKeyCombo (value)
|
function Shortcut.appliesToPlatform (value)
|
||||||
-- expand command- and option- aliases
|
if isMac and value:match '%f[%a]win%-'
|
||||||
value = value
|
or not isMac and value:match '%f[%a]mac%-' then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function Shortcut.expandAliases (value)
|
||||||
|
return value
|
||||||
:gsub('%f[%a]command%-', 'mac-gui-')
|
:gsub('%f[%a]command%-', 'mac-gui-')
|
||||||
:gsub('%f[%a]option%-', 'mac-alt-')
|
:gsub('%f[%a]option%-', 'mac-alt-')
|
||||||
|
end
|
||||||
|
|
||||||
|
function Shortcut.parseKeyCombo (value)
|
||||||
|
-- expand command- and option- aliases
|
||||||
|
value = Shortcut.expandAliases(value)
|
||||||
|
|
||||||
-- exit early if shortcut is for different platform
|
-- exit early if shortcut is for different platform
|
||||||
if isMac and value:match 'win%-' or not isMac and value:match 'mac%-' then
|
if not Shortcut.appliesToPlatform(value) then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- expand c- alias
|
-- expand c- special modifier
|
||||||
if isMac then
|
if isMac then
|
||||||
value = value:gsub('%f[%a]c%-', 'gui-')
|
value = value:gsub('%f[%a]c%-', 'gui-')
|
||||||
else
|
else
|
||||||
@@ -53,4 +63,28 @@ function Shortcut.getModifierFlags ()
|
|||||||
return alt + ctrl + shift + gui
|
return alt + ctrl + shift + gui
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Shortcut.stringify (shortcut)
|
||||||
|
if type(shortcut) ~= 'table' then
|
||||||
|
shortcut = { shortcut }
|
||||||
|
end
|
||||||
|
for _, value in ipairs(shortcut) do
|
||||||
|
value = Shortcut.expandAliases(value)
|
||||||
|
if Shortcut.appliesToPlatform(value) then
|
||||||
|
if isMac then
|
||||||
|
value = value
|
||||||
|
:gsub('%f[%a]c%-', 'command-')
|
||||||
|
:gsub('%f[%a]gui%-', 'command-')
|
||||||
|
:gsub('%f[%a]alt%-', 'option-')
|
||||||
|
else
|
||||||
|
value = value
|
||||||
|
:gsub('%f[%a]c%-', 'ctrl-')
|
||||||
|
:gsub('%f[%a]gui%-', 'windows-')
|
||||||
|
end
|
||||||
|
value = value:gsub('%f[%a]win%-', ''):gsub('%f[%a]mac%-', '')
|
||||||
|
value = value:gsub('%f[%w].', string.upper)
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return Shortcut
|
return Shortcut
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ not be explicitly created.
|
|||||||
local ROOT = (...):gsub('[^.]*.[^.]*.[^.]*$', '')
|
local ROOT = (...):gsub('[^.]*.[^.]*.[^.]*$', '')
|
||||||
|
|
||||||
local Backend = require(ROOT .. 'backend')
|
local Backend = require(ROOT .. 'backend')
|
||||||
|
local Shortcut = require(ROOT .. 'shortcut')
|
||||||
|
|
||||||
local Layout, Event
|
local Layout, Event
|
||||||
|
|
||||||
@@ -176,9 +177,7 @@ local function initialize (self)
|
|||||||
shortcut = ' '
|
shortcut = ' '
|
||||||
edgeType = 'menu.expander'
|
edgeType = 'menu.expander'
|
||||||
else
|
else
|
||||||
--TODO: only displays first of multiple shortcuts, change this?
|
shortcut = Shortcut.stringify(shortcut)
|
||||||
if type(shortcut) == 'table' then shortcut = shortcut[1] end
|
|
||||||
shortcut = shortcut:gsub('%f[%w].', string.upper) -- :gsub('-', '+')
|
|
||||||
end
|
end
|
||||||
self.height = font:getLineHeight() + pad * 2
|
self.height = font:getLineHeight() + pad * 2
|
||||||
self.flow = 'x'
|
self.flow = 'x'
|
||||||
|
|||||||
Reference in New Issue
Block a user