diff options
author | 2017-06-20 23:58:43 -0400 | |
---|---|---|
committer | 2017-06-20 23:58:43 -0400 | |
commit | 45c18f1229294e96a3603116aed8ffec2be7420b (patch) | |
tree | 0fc8d4bf617450d6d197b4c2498b6f4f1f67b999 | |
parent | 93d418c3fae83a32a48edbb43a71ba892401acaf (diff) | |
download | textadept-45c18f1229294e96a3603116aed8ffec2be7420b.tar.gz textadept-45c18f1229294e96a3603116aed8ffec2be7420b.zip |
Added support and documentation for new ui dialogs.
This requires gtdialog r108 (changeset 8465c20432e1).
-rw-r--r-- | core/.ui.dialogs.luadoc | 20 | ||||
-rw-r--r-- | core/ui.lua | 18 |
2 files changed, 38 insertions, 0 deletions
diff --git a/core/.ui.dialogs.luadoc b/core/.ui.dialogs.luadoc index ebc2a167..eaa03a6c 100644 --- a/core/.ui.dialogs.luadoc +++ b/core/.ui.dialogs.luadoc @@ -498,3 +498,23 @@ function optionselect(options) end -- @usage ui.dialogs.colorselect{title = 'Foreground color', color = 0x000000, -- palette = {'#000000', 0x0000FF, '#00FF00', 0xFF0000}} function colorselect(options) end + +--- +-- Prompts the user with a font selection dialog defined by dialog options +-- table *options*, returning the font selected (including style and size). +-- If the user canceled the dialog, returns `nil`. +-- @param options Table of key-value option pairs for the option select dialog. +-- +-- * `title`: The dialog's title text. +-- * `text`: The font preview text. +-- * `font-name`: The initially selected font name. +-- * `font-size`: The initially selected font size. The default value is `12`. +-- * `font-style`: The initially selected font style. The available options +-- are `"regular"`, `"bold"`, `"italic"`, and `"bold italic"`. The default +-- value is `"regular"`. +-- * `float`: Show the dialog on top of all desktop windows. The default value +-- is `false`. +-- @return selected font, including style and size +-- @usage ui.dialogs.fontselect{title = 'Font', font_name = 'Monospace', +-- font_size = 10} +function fontselect(options) end diff --git a/core/ui.lua b/core/ui.lua index 5f69f19f..39860ac0 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -113,6 +113,18 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) for option, value in pairs(options) do if value then args[#args + 1] = '--'..option:gsub('_', '-') + if option == 'color' or + option == 'palette' and type(value) ~= 'boolean' then + -- Transform 0xBBGGRR colors into "#RRGGBB" for color selector. + if type(value) ~= 'table' then value = {value} end + for i = 1, #value do + if type(value[i]) == 'number' then + local bbggrr = string.format('%06X', value[i]) + local b, g, r = bbggrr:match('^(%x%x)(%x%x)(%x%x)$') + if r and g and b then value[i] = '#'..r..g..b end + end + end + end if type(value) ~= 'boolean' then args[#args + 1] = value end end end @@ -143,6 +155,12 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) items[#items + 1] = options.string_output and item or tonumber(item) + 1 end return button, options.select_multiple and items or items[1] + elseif k == 'colorselect' then + if options.string_output then return result ~= '' and result or nil end + local r, g, b = result:match('^#(%x%x)(%x%x)(%x%x)$') + return r and g and b and tonumber('0x'..b..g..r) or nil + elseif k == 'fontselect' then + return result ~= '' and result or nil elseif not options.string_output then local i, value = result:match('^(%-?%d+)\n?(.*)$') i = tonumber(i) |