mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
shortcut attrib: allow multiple shortcuts per widget
This commit is contained in:
@@ -28,7 +28,7 @@ return { id = 'mainWindow',
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ style = 'toolbar',
|
{ style = 'toolbar',
|
||||||
{ id = 'newButton', style = 'toolButton', shortcut = 'z',
|
{ id = 'newButton', style = 'toolButton', shortcut = { 'z', 'x' },
|
||||||
icon = 'icon/32px/Blueprint.png',
|
icon = 'icon/32px/Blueprint.png',
|
||||||
status = 'Create a new thing' },
|
status = 'Create a new thing' },
|
||||||
{ id = 'loadButton', style = 'toolButton',
|
{ id = 'loadButton', style = 'toolButton',
|
||||||
|
|||||||
@@ -86,17 +86,6 @@ function Attribute.id.set (widget, value)
|
|||||||
widget.attributes.id = value
|
widget.attributes.id = value
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: formalize this bitfield somewhere
|
|
||||||
local function parseKeyCombo (value)
|
|
||||||
local mainKey = (value):match '[^%-]+$'
|
|
||||||
local alt = (value):match 'alt%-' and 1 or 0
|
|
||||||
local ctrl = (value):match 'ctrl%-' and 2 or 0
|
|
||||||
local shift = (value):match 'shift%-' and 4 or 0
|
|
||||||
local modifierFlags = alt + ctrl + shift
|
|
||||||
|
|
||||||
return mainKey, modifierFlags
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Widget value.
|
Widget value.
|
||||||
|
|
||||||
@@ -234,18 +223,43 @@ Setting this attribute re-registers the widget with its layout.
|
|||||||
--]]--
|
--]]--
|
||||||
Attribute.shortcut = {}
|
Attribute.shortcut = {}
|
||||||
|
|
||||||
|
-- TODO: formalize this bitfield somewhere
|
||||||
|
local function parseKeyCombo (value)
|
||||||
|
local mainKey = (value):match '[^%-]+$'
|
||||||
|
local alt = (value):match 'alt%-' and 1 or 0
|
||||||
|
local ctrl = (value):match 'ctrl%-' and 2 or 0
|
||||||
|
local shift = (value):match 'shift%-' and 4 or 0
|
||||||
|
local modifierFlags = alt + ctrl + shift
|
||||||
|
|
||||||
|
return mainKey, modifierFlags
|
||||||
|
end
|
||||||
|
|
||||||
function Attribute.shortcut.set (widget, value)
|
function Attribute.shortcut.set (widget, value)
|
||||||
local layout = widget.layout.master or widget.layout
|
local layout = widget.layout.master or widget.layout
|
||||||
local oldValue = widget.attributes.shortcut
|
local oldValue = widget.attributes.shortcut
|
||||||
|
|
||||||
if oldValue then
|
if oldValue then
|
||||||
local mainKey, modifierFlags = parseKeyCombo(oldValue)
|
if type(oldValue) == 'table' then
|
||||||
layout.shortcuts[modifierFlags][mainKey] = nil
|
for _, v in ipairs(oldValue) do
|
||||||
|
local mainKey, modifierFlags = parseKeyCombo(v)
|
||||||
|
layout.shortcuts[modifierFlags][mainKey] = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local mainKey, modifierFlags = parseKeyCombo(oldValue)
|
||||||
|
layout.shortcuts[modifierFlags][mainKey] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if value then
|
if value then
|
||||||
local mainKey, modifierFlags = parseKeyCombo(value)
|
if type(value) == 'table' then
|
||||||
layout.shortcuts[modifierFlags][mainKey] = widget
|
for _, v in ipairs(value) do
|
||||||
|
local mainKey, modifierFlags = parseKeyCombo(v)
|
||||||
|
layout.shortcuts[modifierFlags][mainKey] = widget
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local mainKey, modifierFlags = parseKeyCombo(value)
|
||||||
|
layout.shortcuts[modifierFlags][mainKey] = widget
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
widget.attributes.shortcut = value
|
widget.attributes.shortcut = value
|
||||||
|
|||||||
@@ -176,6 +176,8 @@ local function initialize (self)
|
|||||||
shortcut = ' '
|
shortcut = ' '
|
||||||
edgeType = 'menu.expander'
|
edgeType = 'menu.expander'
|
||||||
else
|
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:gsub('%f[%w].', string.upper) -- :gsub('-', '+')
|
||||||
end
|
end
|
||||||
self.height = font:getLineHeight() + pad * 2
|
self.height = font:getLineHeight() + pad * 2
|
||||||
|
|||||||
Reference in New Issue
Block a user