From 612c43f3b1c0351fe2601ed73024d39bacd4ed52 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 18 Mar 2020 22:43:27 -0400 Subject: Added `ui.dialogs.progressbar()` and utilize it with Find in Files. --- core/.ui.dialogs.luadoc | 26 ++++++++++++++++++++++++++ core/locale.conf | 4 ---- core/locales/locale.ar.conf | 4 ---- core/locales/locale.de.conf | 4 ---- core/locales/locale.es.conf | 4 ---- core/locales/locale.fr.conf | 4 ---- core/locales/locale.it.conf | 4 ---- core/locales/locale.pl.conf | 4 ---- core/locales/locale.ru.conf | 4 ---- core/locales/locale.sv.conf | 4 ---- core/locales/locale.zh.conf | 4 ---- core/ui.lua | 8 ++++++-- 12 files changed, 32 insertions(+), 42 deletions(-) (limited to 'core') diff --git a/core/.ui.dialogs.luadoc b/core/.ui.dialogs.luadoc index 0a6579d1..08a810d1 100644 --- a/core/.ui.dialogs.luadoc +++ b/core/.ui.dialogs.luadoc @@ -324,6 +324,32 @@ function filesave(options) end -- informative_text = 'You agree to:', text_from_file = _HOME..'/LICENSE'} function textbox(options) end +--- +-- Displays a progressbar dialog defined by dialog options table *options* and +-- updates from function *f*. +-- Returns "stopped" if *options*.`stoppable` is `true` and the user clicked the +-- "Stop" button. Otherwise, returns `nil`. +-- @param options Table of key-value option pairs for the progressbar dialog. +-- +-- * `title`: The dialog's title text. +-- * `percent`: The initial progressbar percentage between 0 and 100. +-- * `text`: The initial progressbar display text (GTK only). +-- * `indeterminate`: Show the progress bar as "busy", with no percentage +-- updates. +-- * `stoppable`: Show the "Stop" button. +-- * `width`: The dialog's pixel width. +-- * `height`: The dialog's pixel height. +-- @param f Function repeatedly called to do work and provide progress updates. +-- The function is called without arguments and must return either `nil`, +-- which indicates work is complete, or a progress percentage number in the +-- range 0-100 and optional string text to display (GTK only). If the text +-- is either "stop disable" or "stop enable" and *options*.`stoppable` is +-- `true`, the "Stop" button is disabled or enabled, respectively. +-- @return nil or "stopped" +-- @usage ui.dialogs.progressbar({stoppable = true}, +-- function() if work() then return percent, status else return nil end end) +function progressbar(options, f) end + --- -- Prompts the user with a drop-down item selection dialog defined by dialog -- options table *options*, returning the selected button's index along with the diff --git a/core/locale.conf b/core/locale.conf index bdeb6a84..ea100822 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -121,10 +121,6 @@ Select Directory = Select Directory # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Binary file matches. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.ar.conf b/core/locales/locale.ar.conf index e8a1b9fa..32a82f20 100644 --- a/core/locales/locale.ar.conf +++ b/core/locales/locale.ar.conf @@ -121,10 +121,6 @@ Select Directory = ابحث في الملفات # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Binary file matches. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index 84e79bb0..2207fe6e 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -121,10 +121,6 @@ Select Directory = In Dateien suchen # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Übereinstimmungen in Binärdatei. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Fortsetzen? -Still searching in files... Continue waiting? = Suche noch in Dateien ... Weiter warten? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Suche in Dateien abgebrochen # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index 895a99c1..68de3735 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -121,10 +121,6 @@ Select Directory = Buscar en ficheros # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Coincidencia en fichero binario. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index ae8e826b..ec72f531 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -122,10 +122,6 @@ Select Directory = Rechercher dans les fichiers # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Correspondances dans un fichier binaire -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.it.conf b/core/locales/locale.it.conf index dc14be61..1faf8045 100644 --- a/core/locales/locale.it.conf +++ b/core/locales/locale.it.conf @@ -121,10 +121,6 @@ Select Directory = Trova nei file # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Corrispondenze in un file binario. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.pl.conf b/core/locales/locale.pl.conf index f48bd677..dbae0312 100644 --- a/core/locales/locale.pl.conf +++ b/core/locales/locale.pl.conf @@ -122,10 +122,6 @@ Select Directory = Znajdź w plikach # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Znalezione w pliku binarnym. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Kontynuować? -Still searching in files... Continue waiting? = Wciąż trwa szukanie w plikach... Kontynuować czekanie? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Szukanie w plikach przerwane # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index 20218cee..a1ad36ab 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -121,10 +121,6 @@ Select Directory = Найти в файлах # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Соответствие в двоичном файле. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf index 0d4b5d89..691dce71 100644 --- a/core/locales/locale.sv.conf +++ b/core/locales/locale.sv.conf @@ -121,10 +121,6 @@ Select Directory = Sök i filer # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = Binär fil matchar. -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = Continue? -Still searching in files... Continue waiting? = Still searching in files... Continue waiting? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = Find in Files aborted # The statusbar text shown after performing a "Replace All". diff --git a/core/locales/locale.zh.conf b/core/locales/locale.zh.conf index cd1f7ed0..d38fb2fb 100644 --- a/core/locales/locale.zh.conf +++ b/core/locales/locale.zh.conf @@ -121,10 +121,6 @@ Select Directory = 在文件中查找 # The "Find in Files" result for text found in a binary file. This result is # shown in place of binary buffer text. Binary file matches. = 二进制文件匹配。 -# The text displayed in a dialog when the user is prompted to continue a "Find -# in Files" search that has taken longer than X seconds to complete. -Continue? = 继续吗? -Still searching in files... Continue waiting? = 仍在搜索文件... 继续等待? # The message displayed when a "Find in Files" search is aborted by the user. Find in Files aborted = 在文件中查找已中止 # The statusbar text shown after performing a "Replace All". diff --git a/core/ui.lua b/core/ui.lua index 5adbc758..21217609 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -99,8 +99,9 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) -- a set of command line arguments and transforming the resulting standard -- output into Lua objects. -- @param options Table of key-value command line options for gtdialog. + -- @param f Work function for progressbar dialogs. -- @return Lua objects depending on the dialog kind - return function(options) + return function(options, f) if not options.button1 then options.button1 = _L['OK'] end if k == 'filteredlist' and not options.width then options.width = ui.size[1] - 2 * (CURSES and 1 or 100) @@ -129,6 +130,9 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) if type(value) ~= 'boolean' then args[#args + 1] = value end end end + if k == 'progressbar' then + args[#args + 1] = assert_type(f, 'function', 2) + end -- Call gtdialog, stripping any trailing newline in the standard output. local result = ui.dialog( k:gsub('_', '-'), table.unpack(args)):match('^(.-)\n?$') @@ -161,7 +165,7 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) local r, g, b = result:match('^#(%x%x)(%x%x)(%x%x)$') local bgr = r and g and b and string.format('0x%s%s%s', b, g, r) or nil return tonumber(bgr) - elseif k == 'fontselect' then + elseif k == 'fontselect' or k == 'progressbar' then return result ~= '' and result or nil elseif not options.string_output then local i, value = result:match('^(%-?%d+)\n?(.*)$') -- cgit v1.2.3