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