further improvements

This commit is contained in:
U-DESKTOP-HQME86J\marco
2020-01-01 19:27:41 +01:00
parent a2850cac6b
commit 5116d645db
3 changed files with 94 additions and 62 deletions

View File

@@ -83,26 +83,29 @@ local PS = dt.configuration.running_os == "windows" and "\\" or "/"
-- translation -- translation
local gettext = dt.gettext local gettext = dt.gettext
gettext.bindtextdomain(MODULE_NAME, dt.configuration.config_dir..PS.."lua"..PS.."locale"..PS) gettext.bindtextdomain(MODULE_NAME, dt.configuration.config_dir..PS.."lua"..PS.."locale"..PS)
local function _(msgid) local function _(msgid)
return gettext.dgettext(MODULE_NAME, msgid) return gettext.dgettext(MODULE_NAME, msgid)
end end
-- number of valid entries in the list of external programs -- number of valid entries in the list of external programs
local n_entries = 0 local n_entries
-- allowed file extensions, to exclude RAW, which cannot be edited externally
local allowed_file_types = {"JPG", "jpg", "JPEG", "jpeg", "TIF", "tif", "TIFF", "tiff", "EXR", "exr"}
-- last used editor initialization -- last used editor initialization
if not dt.preferences.read(MODULE_NAME,"initialized", "bool") then if not dt.preferences.read(MODULE_NAME,"initialized", "bool") then
dt.preferences.write(MODULE_NAME,"lastchoice", "integer", 1) dt.preferences.write(MODULE_NAME,"lastchoice", "integer", 0)
dt.preferences.write(MODULE_NAME,"initialized", "bool", true) dt.preferences.write(MODULE_NAME,"initialized", "bool", true)
end end
local lastchoice = 1 local lastchoice = 0
-- update lists of program names and paths, as well as combobox --------------- -- update lists of program names and paths, as well as combobox ---------------
local function UpdateProgramList(combobox, button_pressed) local function UpdateProgramList(combobox, button1, button2, update_button_pressed)
-- initialize lists -- initialize lists
program_names = {} program_names = {}
@@ -111,6 +114,7 @@ local function UpdateProgramList(combobox, button_pressed)
-- build lists from preferences -- build lists from preferences
local name local name
local last = false local last = false
n_entries = 0
for i = 1, 9 do for i = 1, 9 do
name = dt.preferences.read(MODULE_NAME,"program_name_"..i, "string") name = dt.preferences.read(MODULE_NAME,"program_name_"..i, "string")
if (name == "" or name == nil) then last = true end if (name == "" or name == nil) then last = true end
@@ -123,13 +127,20 @@ local function UpdateProgramList(combobox, button_pressed)
n_entries = i n_entries = i
end end
end end
lastchoice = dt.preferences.read(MODULE_NAME, "lastchoice", "integer") lastchoice = dt.preferences.read(MODULE_NAME, "lastchoice", "integer")
if lastchoice > n_entries then if lastchoice == 0 and n_entries > 0 then lastchoice = 1 end
lastchoice = 1 if lastchoice > n_entries then lastchoice = n_entries end
dt.preferences.write(MODULE_NAME, "lastchoice", "integer", lastchoice) dt.preferences.write(MODULE_NAME, "lastchoice", "integer", lastchoice)
end
combobox.value = lastchoice -- widgets enabled if there is at least one program configured
if button_pressed then dt.print(_("list updated")) end combobox.selected = lastchoice
local active = n_entries > 0
combobox.sensitive = active
button1.sensitive = active
button2.sensitive = active
if update_button_pressed then dt.print(n_entries.._(" editors configured")) end
end end
@@ -169,9 +180,19 @@ local function OpenWith(images, choice, copy)
i, image = next(images) i, image = next(images)
local name = image.path..PS..image.filename local name = image.path..PS..image.filename
-- check if image is raw, return if is -- check if image is raw, return if it is
if image.is_raw then -- please note that the image property image.is_raw fails when filepath contains spaces
dt.print(_("RAW not allowed")) -- so as a workaround we allow only TIF, JPG and EXR
local file_ext = df.get_filetype (image.filename)
local allowed = false
for i,v in pairs(allowed_file_types) do
if v == file_ext then
allowed = true
break
end
end
if not allowed then
dt.print(_("file type not allowed"))
return return
end end
@@ -283,8 +304,6 @@ local function OpenWith(images, choice, copy)
table.insert(selection, new_image) table.insert(selection, new_image)
dt.gui.selection (selection) dt.gui.selection (selection)
-- remember the last editor used
dt.preferences.write(MODULE_NAME, "lastchoice", "integer", choice)
end end
@@ -340,16 +359,18 @@ dt.register_storage("exp2coll", _("collection"), show_status, export2collection)
local combobox = dt.new_widget("combobox") { local combobox = dt.new_widget("combobox") {
label = _("choose program"), label = _("choose program"),
tooltip = _("select the external editor from the list"), tooltip = _("select the external editor from the list"),
value = 1, changed_callback = function(self)
dt.preferences.write(MODULE_NAME, "lastchoice", "integer", self.selected)
end,
"" ""
} }
UpdateProgramList(combobox, false) -- initialize list of programs and combobox
-- button edit ---------------------------------------------------------------- -- button edit ----------------------------------------------------------------
local button1 = dt.new_widget("button") { local button1 = dt.new_widget("button") {
label = _("edit"), label = _("edit"),
tooltip = _("open the selected image in external editor"), tooltip = _("open the selected image in external editor"),
--sensitive = false,
clicked_callback = function() clicked_callback = function()
OpenWith(dt.gui.action_images, combobox.selected, false) OpenWith(dt.gui.action_images, combobox.selected, false)
end end
@@ -371,7 +392,7 @@ local button3 = dt.new_widget("button") {
label = _("update list"), label = _("update list"),
tooltip = _("update list of programs if lua preferences are changed"), tooltip = _("update list of programs if lua preferences are changed"),
clicked_callback = function() clicked_callback = function()
UpdateProgramList(combobox, true) UpdateProgramList(combobox, button1, button2, true)
end end
} }
@@ -403,10 +424,18 @@ dt.register_lib(
) )
-- initialize list of programs and widgets ------------------------------------
UpdateProgramList(combobox, button1, button2, false)
-- register the new preferences ----------------------------------------------- -- register the new preferences -----------------------------------------------
for i = 9, 1, -1 do for i = 9, 1, -1 do
dt.preferences.register(MODULE_NAME, "program_path_"..i, "string", _("command for external editor ")..i, _("command for external editor, including full path if needed"), "") dt.preferences.register(MODULE_NAME, "program_path_"..i, "file",
dt.preferences.register(MODULE_NAME, "program_name_"..i, "string", _("name of external editor ")..i, _("friendly name of external editor"), "") _("executable for external editor ")..i,
_("select executable for external editor") , _("(None)"))
dt.preferences.register(MODULE_NAME, "program_name_"..i, "string",
_("name of external editor ")..i,
_("friendly name of external editor"), "")
end end

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: ext_editor\n" "Project-Id-Version: ext_editor\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-29 15:33+0100\n" "POT-Creation-Date: 2020-01-01 19:15+0100\n"
"PO-Revision-Date: 2019-12-28 21:45+0100\n" "PO-Revision-Date: 2019-12-28 21:45+0100\n"
"Last-Translator: marco <marco.carrarini@gmail.com>\n" "Last-Translator: marco <marco.carrarini@gmail.com>\n"
"Language-Team: Italian\n" "Language-Team: Italian\n"
@@ -17,103 +17,106 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: ext_editor.lua:132 #: ext_editor.lua:143
msgid "list updated" msgid " editors configured"
msgstr "Lista aggiornata" msgstr " editor configurati"
#: ext_editor.lua:139 #: ext_editor.lua:150
msgid "exporting image " msgid "exporting image "
msgstr "Esportazione immagine " msgstr "Esportazione immagine "
#: ext_editor.lua:148 #: ext_editor.lua:159
msgid "not a valid choice" msgid "not a valid choice"
msgstr "Scelta non valida" msgstr "Scelta non valida"
#: ext_editor.lua:154 #: ext_editor.lua:165
msgid "please select one image" msgid "please select one image"
msgstr "Selezionare un'immagine" msgstr "Selezionare una immagine"
#: ext_editor.lua:163 #: ext_editor.lua:174
msgid " not found" msgid " not found"
msgstr " non trovato" msgstr " non trovato"
#: ext_editor.lua:174 #: ext_editor.lua:195
msgid "RAW not allowed" msgid "file type not allowed"
msgstr "RAW non consentito" msgstr "tipo di file non consentito"
#: ext_editor.lua:211 #: ext_editor.lua:232
msgid "error copying file " msgid "error copying file "
msgstr "Errore copia file " msgstr "Errore copia file "
#: ext_editor.lua:218 #: ext_editor.lua:239
msgid "launching " msgid "launching "
msgstr "Lancio " msgstr "Lancio "
#: ext_editor.lua:221 #: ext_editor.lua:242
msgid "error launching " msgid "error launching "
msgstr "Errore lancio " msgstr "Errore lancio "
#: ext_editor.lua:322 #: ext_editor.lua:341
msgid "error moving file " msgid "error moving file "
msgstr "Errore spostamento file " msgstr "Errore spostamento file "
#: ext_editor.lua:336 #: ext_editor.lua:355
msgid "collection" msgid "collection"
msgstr "Collezione" msgstr "Collezione"
#: ext_editor.lua:341 #: ext_editor.lua:360
msgid "choose program" msgid "choose program"
msgstr "Scegli programma" msgstr "Scegli programma"
#: ext_editor.lua:342 #: ext_editor.lua:361
msgid "select the external editor from the list" msgid "select the external editor from the list"
msgstr "Seleziona l'editor esterno dalla lista" msgstr "Seleziona un editor esterno dalla lista"
#: ext_editor.lua:351 #: ext_editor.lua:371
msgid "edit" msgid "edit"
msgstr "Modifica" msgstr "Modifica"
#: ext_editor.lua:352 #: ext_editor.lua:372
msgid "open the selected image in external editor" msgid "open the selected image in external editor"
msgstr "Apre l'immagine selezionata nell'editor esterno" msgstr "Apre immagine selezionata in editor esterno"
#: ext_editor.lua:361 #: ext_editor.lua:382
msgid "edit a copy" msgid "edit a copy"
msgstr "Modifica copia" msgstr "Modifica copia"
#: ext_editor.lua:362 #: ext_editor.lua:383
msgid "create a copy of the selected image and open it in external editor" msgid "create a copy of the selected image and open it in external editor"
msgstr "apre una copia dell'immagine selezionata nell'editor esterno" msgstr "Apre una copia della immagine selezionata in editor esterno"
#: ext_editor.lua:371 #: ext_editor.lua:392
msgid "update list" msgid "update list"
msgstr "Aggiorna lista" msgstr "Aggiorna lista"
#: ext_editor.lua:372 #: ext_editor.lua:393
msgid "update list of programs if lua preferences are changed" msgid "update list of programs if lua preferences are changed"
msgstr "Aggiorna la lista dei programmi se le preferenze di lua sono cambiate" msgstr "Aggiorna la lista dei programmi se le preferenze di lua sono cambiate"
#: ext_editor.lua:392 #: ext_editor.lua:413
msgid "external editors" msgid "external editors"
msgstr "Editor esterni" msgstr "Editor esterni"
#: ext_editor.lua:408 #: ext_editor.lua:434
msgid "command for external editor " msgid "executable for external editor "
msgstr "Comando per l'editor esterno " msgstr "Eseguibile per editor esterno "
#: ext_editor.lua:408 #: ext_editor.lua:435
msgid "command for external editor, including full path if needed" msgid "select executable for external editor"
msgstr "" msgstr "seleziona eseguibile per editor esterno "
"Comando per l'editor esterno, compreso il percorso completo se necessario"
#: ext_editor.lua:409 #: ext_editor.lua:435
msgid "(None)"
msgstr "(Nessuno)"
#: ext_editor.lua:437
msgid "name of external editor " msgid "name of external editor "
msgstr "Nome dell'editor esterno " msgstr "Nome editor esterno "
#: ext_editor.lua:409 #: ext_editor.lua:438
msgid "friendly name of external editor" msgid "friendly name of external editor"
msgstr "Nome comune dell'editor esterno" msgstr "Nome comune editor esterno"
#: ext_editor.lua:415 #: ext_editor.lua:444
msgid "edit with program " msgid "edit with program "
msgstr "Modifica con programma " msgstr "Modifica con programma "