From 73cd301ff443410ed88c3ff35fcda4e8a9d7a6a3 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Sun, 21 Feb 2021 20:55:23 +0100 Subject: [PATCH 1/6] ext_editor visible in darkroom --- contrib/ext_editor.lua | 68 ++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index 2df2237..b546184 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -20,8 +20,8 @@ This script provides helpers to edit image files with programs external to darktable. It adds: - a new target storage "collection". Image exported will be reimported to collection for further edit with external programs - - a new lighttable module "external editors", to select a program from a list of up to - - 9 external editors and run it on a selected image (adjust this limit by changing MAX_EDITORS) + - a new module "external editors", visible in lightable and darkroom, to select a program from a list + - of up to 9 external editors and run it on a selected image (adjust this limit by changing MAX_EDITORS) - a set of lua preferences in order to configure name and path of up to 9 external editors - a set of lua shortcuts in order to quick launch the external editors @@ -32,7 +32,7 @@ * in "preferences/lua options" configure name and path/command of external programs * note that if a program name is left empty, that and all following entries will be ignored * in "preferences/shortcuts/lua" configure shortcuts for external programs (optional) - * whenever programs preferences are changed, in lighttable/external editors, press "update list" + * whenever programs preferences are changed, in external editors GUI, press "update list" -- use -- * in the export dialog choose "collection" and select the format and bit depth for the @@ -40,21 +40,19 @@ * press "export" * the exported image will be imported into collection and grouped with the original image - * select an image for editing with en external program, and: - * in lighttable/external editors, select program and press "edit" + * in lighttable, select an image for editing with en external program + * (or in darkroom for the image being edited): + * in external editors GUI, select program and press "edit" * edit the image with the external editor, overwite the file, quit the external program * the selected image will be updated or - * in lighttable/external editors, select program and press "edit a copy" + * in external editors GUI, select program and press "edit a copy" * edit the image with the external editor, overwite the file, quit the external program * a copy of the selected image will be created and updated or - * in lighttable select target storage "collection" - * enter in darkroom - * to create an export or a copy press CRTL+E * use the shortcut to edit the current image with the corresponding external editor * overwite the file, quit the external program - * the darkroom view will be updated + * the image will be updated * warning: mouseover on lighttable/filmstrip will prevail on current image * this is the default DT behavior, not a bug of this script @@ -101,7 +99,7 @@ local function _(msgid) end -- maximum number of external programs, can be increased to necessity -local MAX_EDITORS = 9 +local MAX_EDITORS = 12 -- number of valid entries in the list of external programs local n_entries @@ -280,13 +278,9 @@ local function OpenWith(images, choice, copy) new_image = dt.database.import(name) new_image:group_with(image_leader) end - -- refresh darkroom view - if dt.gui.current_view() == dt.gui.views.darkroom then - dt.gui.views.darkroom.display_image(new_image) - end end - -- restore image tags, rating and color, must be put after refresh darkroom view + -- restore image tags, rating and color for i, tag in ipairs(tags) do dt.tags.attach(tag, new_image) end new_image.rating = rating new_image.red = red @@ -298,8 +292,12 @@ local function OpenWith(images, choice, copy) -- select the new image local selection = {} table.insert(selection, new_image) - dt.gui.selection (selection) + dt.gui.selection(selection) + -- refresh darkroom view + if dt.gui.current_view().id == "darkroom" then + dt.gui.views.darkroom.display_image(new_image) + end end @@ -334,19 +332,21 @@ local function export2collection(storage, image_table, extra_data) new_image:group_with(image.group_leader) end - dt.print (_("finished exporting")) + dt.print(_("finished exporting")) end --- install the module in the UI + +-- install the module in the UI ----------------------------------------------- local function install_module() if not ee.module_installed then - -- register new module "external editors" in lighttable ------------------------ + -- register new module "external editors" in lighttable and darkroom ------ dt.register_lib( MODULE_NAME, _("external editors"), true, -- expandable false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, + [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}}, dt.new_widget("box") { orientation = "vertical", table.unpack(ee.widgets), @@ -358,6 +358,7 @@ local function install_module() end end + -- combobox, with variable number of entries ---------------------------------- local combobox = dt.new_widget("combobox") { label = _("choose program"), @@ -409,30 +410,11 @@ local box1 = dt.new_widget("box") { button_update_list } + +-- install module in lighttable and darkroom ---------------------------------- table.insert(ee.widgets, combobox) table.insert(ee.widgets, box1) - --- register new module "external editors" in lighttable ------------------------ -if dt.gui.current_view().id == "lighttable" then - install_module() -else - if not ee.event_registered then - dt.register_event( - MODULE_NAME, "view-changed", - function(event, old_view, new_view) - if new_view.name == "lighttable" and old_view.name == "darkroom" then - install_module() - end - end - ) - ee.event_registered = true - end -end - - - --- initialize list of programs and widgets ------------------------------------ -UpdateProgramList(combobox, button_edit, button_edit_copy, false) +install_module() -- register new storage ------------------------------------------------------- From c9fa13b97b480ef61cafb96b6e72ac87a2aee610 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Sun, 21 Feb 2021 20:59:30 +0100 Subject: [PATCH 2/6] revert MAX_EDITORS to 9 --- contrib/ext_editor.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index b546184..b5a1684 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -99,7 +99,7 @@ local function _(msgid) end -- maximum number of external programs, can be increased to necessity -local MAX_EDITORS = 12 +local MAX_EDITORS = 9 -- number of valid entries in the list of external programs local n_entries From 8112472df5d9af97b721a8b43796c3eed6163941 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Mon, 22 Feb 2021 08:17:46 +0100 Subject: [PATCH 3/6] restore initialization line deleted by mistake --- contrib/ext_editor.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index b5a1684..0ac6258 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -416,6 +416,9 @@ table.insert(ee.widgets, combobox) table.insert(ee.widgets, box1) install_module() +-- initialize list of programs and widgets ------------------------------------ +UpdateProgramList(combobox, button_edit, button_edit_copy, false) + -- register new storage ------------------------------------------------------- dt.register_storage("exp2coll", _("collection"), nil, export2collection) From aee1f82d04c220dcf522cb84420e0196e118d237 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Tue, 23 Feb 2021 07:40:30 +0100 Subject: [PATCH 4/6] restore current module registration --- contrib/ext_editor.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index 0ac6258..d16c6af 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -411,10 +411,28 @@ local box1 = dt.new_widget("box") { } --- install module in lighttable and darkroom ---------------------------------- +-- table with all the widgets -------------------------------------------------- table.insert(ee.widgets, combobox) table.insert(ee.widgets, box1) -install_module() + + +-- register new module, but only when in lighttable ---------------------------- +if dt.gui.current_view().id == "lighttable" then + install_module() +else + if not ee.event_registered then + dt.register_event( + MODULE_NAME, "view-changed", + function(event, old_view, new_view) + if new_view.name == "lighttable" and old_view.name == "darkroom" then + install_module() + end + end + ) + ee.event_registered = true + end +end + -- initialize list of programs and widgets ------------------------------------ UpdateProgramList(combobox, button_edit, button_edit_copy, false) From abd8bf4a608dc108e9f4049f724712fc9b699218 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Wed, 24 Feb 2021 14:14:38 +0100 Subject: [PATCH 5/6] option to display module in darkroom --- contrib/ext_editor.lua | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index d16c6af..3a94f98 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -337,23 +337,40 @@ local function export2collection(storage, image_table, extra_data) -- install the module in the UI ----------------------------------------------- -local function install_module() +local function install_module(dr) if not ee.module_installed then - -- register new module "external editors" in lighttable and darkroom ------ - dt.register_lib( - MODULE_NAME, - _("external editors"), - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, - [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}}, - dt.new_widget("box") { - orientation = "vertical", - table.unpack(ee.widgets), - }, - nil, -- view_enter - nil -- view_leave - ) + if dr then + -- register new module "external editors" in lighttable and darkroom ---- + dt.register_lib( + MODULE_NAME, + _("external editors"), + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, + [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}}, + dt.new_widget("box") { + orientation = "vertical", + table.unpack(ee.widgets), + }, + nil, -- view_enter + nil -- view_leave + ) + else + -- register new module "external editors" in lighttable only ------------ + dt.register_lib( + MODULE_NAME, + _("external editors"), + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, + dt.new_widget("box") { + orientation = "vertical", + table.unpack(ee.widgets), + }, + nil, -- view_enter + nil -- view_leave + ) + end ee.module_installed = true end end @@ -417,15 +434,16 @@ table.insert(ee.widgets, box1) -- register new module, but only when in lighttable ---------------------------- +local show_dr = dt.preferences.read(MODULE_NAME, "show_in_darkrooom", "bool") if dt.gui.current_view().id == "lighttable" then - install_module() + install_module(show_dr) else if not ee.event_registered then dt.register_event( MODULE_NAME, "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then - install_module() + install_module(show_dr) end end ) @@ -452,6 +470,9 @@ for i = MAX_EDITORS, 1, -1 do _("name of external editor ")..i, _("friendly name of external editor"), "") end +dt.preferences.register(MODULE_NAME, "show_in_darkrooom", "bool", + _("show external editors in darkroom"), + _("check to show external editors module also in darkroom (requires restart)"), false) -- register the new shortcuts ------------------------------------------------- From 931e448ebde9f503fa1ca90aea213eb6612e5fc1 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-HQME86J\\marco" Date: Wed, 24 Feb 2021 19:21:32 +0100 Subject: [PATCH 6/6] more compact code --- contrib/ext_editor.lua | 53 +++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index 3a94f98..7e1460c 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -338,39 +338,28 @@ local function export2collection(storage, image_table, extra_data) -- install the module in the UI ----------------------------------------------- local function install_module(dr) + + local views = {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}} + if dr then + views = {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, + [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}} + end + if not ee.module_installed then - if dr then - -- register new module "external editors" in lighttable and darkroom ---- - dt.register_lib( - MODULE_NAME, - _("external editors"), - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}, - [dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}}, - dt.new_widget("box") { - orientation = "vertical", - table.unpack(ee.widgets), - }, - nil, -- view_enter - nil -- view_leave - ) - else - -- register new module "external editors" in lighttable only ------------ - dt.register_lib( - MODULE_NAME, - _("external editors"), - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, - dt.new_widget("box") { - orientation = "vertical", - table.unpack(ee.widgets), - }, - nil, -- view_enter - nil -- view_leave - ) - end + -- register new module "external editors" in lighttable and darkroom ---- + dt.register_lib( + MODULE_NAME, + _("external editors"), + true, -- expandable + false, -- resetable + views, + dt.new_widget("box") { + orientation = "vertical", + table.unpack(ee.widgets), + }, + nil, -- view_enter + nil -- view_leave + ) ee.module_installed = true end end