Skip to content

Commit a71097a

Browse files
authored
Merge pull request darktable-org#327 from Mark-64/ext_editor_darkroom
External editors: make gui visible in darkroom
2 parents aa33ae0 + 931e448 commit a71097a

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

contrib/ext_editor.lua

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
2121
This script provides helpers to edit image files with programs external to darktable. It adds:
2222
- a new target storage "collection". Image exported will be reimported to collection for further edit with external programs
23-
- a new lighttable module "external editors", to select a program from a list of up to
24-
- 9 external editors and run it on a selected image (adjust this limit by changing MAX_EDITORS)
23+
- a new module "external editors", visible in lightable and darkroom, to select a program from a list
24+
- of up to 9 external editors and run it on a selected image (adjust this limit by changing MAX_EDITORS)
2525
- a set of lua preferences in order to configure name and path of up to 9 external editors
2626
- a set of lua shortcuts in order to quick launch the external editors
2727
@@ -32,29 +32,27 @@
3232
* in "preferences/lua options" configure name and path/command of external programs
3333
* note that if a program name is left empty, that and all following entries will be ignored
3434
* in "preferences/shortcuts/lua" configure shortcuts for external programs (optional)
35-
* whenever programs preferences are changed, in lighttable/external editors, press "update list"
35+
* whenever programs preferences are changed, in external editors GUI, press "update list"
3636
3737
-- use --
3838
* in the export dialog choose "collection" and select the format and bit depth for the
3939
exported image
4040
* press "export"
4141
* the exported image will be imported into collection and grouped with the original image
4242
43-
* select an image for editing with en external program, and:
44-
* in lighttable/external editors, select program and press "edit"
43+
* in lighttable, select an image for editing with en external program
44+
* (or in darkroom for the image being edited):
45+
* in external editors GUI, select program and press "edit"
4546
* edit the image with the external editor, overwite the file, quit the external program
4647
* the selected image will be updated
4748
or
48-
* in lighttable/external editors, select program and press "edit a copy"
49+
* in external editors GUI, select program and press "edit a copy"
4950
* edit the image with the external editor, overwite the file, quit the external program
5051
* a copy of the selected image will be created and updated
5152
or
52-
* in lighttable select target storage "collection"
53-
* enter in darkroom
54-
* to create an export or a copy press CRTL+E
5553
* use the shortcut to edit the current image with the corresponding external editor
5654
* overwite the file, quit the external program
57-
* the darkroom view will be updated
55+
* the image will be updated
5856
5957
* warning: mouseover on lighttable/filmstrip will prevail on current image
6058
* this is the default DT behavior, not a bug of this script
@@ -280,13 +278,9 @@ local function OpenWith(images, choice, copy)
280278
new_image = dt.database.import(name)
281279
new_image:group_with(image_leader)
282280
end
283-
-- refresh darkroom view
284-
if dt.gui.current_view() == dt.gui.views.darkroom then
285-
dt.gui.views.darkroom.display_image(new_image)
286-
end
287281
end
288282

289-
-- restore image tags, rating and color, must be put after refresh darkroom view
283+
-- restore image tags, rating and color
290284
for i, tag in ipairs(tags) do dt.tags.attach(tag, new_image) end
291285
new_image.rating = rating
292286
new_image.red = red
@@ -298,8 +292,12 @@ local function OpenWith(images, choice, copy)
298292
-- select the new image
299293
local selection = {}
300294
table.insert(selection, new_image)
301-
dt.gui.selection (selection)
295+
dt.gui.selection(selection)
302296

297+
-- refresh darkroom view
298+
if dt.gui.current_view().id == "darkroom" then
299+
dt.gui.views.darkroom.display_image(new_image)
300+
end
303301
end
304302

305303

@@ -334,19 +332,27 @@ local function export2collection(storage, image_table, extra_data)
334332
new_image:group_with(image.group_leader)
335333
end
336334

337-
dt.print (_("finished exporting"))
335+
dt.print(_("finished exporting"))
338336
end
339337

340-
-- install the module in the UI
341-
local function install_module()
338+
339+
-- install the module in the UI -----------------------------------------------
340+
local function install_module(dr)
341+
342+
local views = {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}
343+
if dr then
344+
views = {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100},
345+
[dt.gui.views.darkroom] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER", 100}}
346+
end
347+
342348
if not ee.module_installed then
343-
-- register new module "external editors" in lighttable ------------------------
349+
-- register new module "external editors" in lighttable and darkroom ----
344350
dt.register_lib(
345351
MODULE_NAME,
346352
_("external editors"),
347353
true, -- expandable
348354
false, -- resetable
349-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}},
355+
views,
350356
dt.new_widget("box") {
351357
orientation = "vertical",
352358
table.unpack(ee.widgets),
@@ -358,6 +364,7 @@ local function install_module()
358364
end
359365
end
360366

367+
361368
-- combobox, with variable number of entries ----------------------------------
362369
local combobox = dt.new_widget("combobox") {
363370
label = _("choose program"),
@@ -409,19 +416,23 @@ local box1 = dt.new_widget("box") {
409416
button_update_list
410417
}
411418

419+
420+
-- table with all the widgets --------------------------------------------------
412421
table.insert(ee.widgets, combobox)
413422
table.insert(ee.widgets, box1)
414423

415-
-- register new module "external editors" in lighttable ------------------------
424+
425+
-- register new module, but only when in lighttable ----------------------------
426+
local show_dr = dt.preferences.read(MODULE_NAME, "show_in_darkrooom", "bool")
416427
if dt.gui.current_view().id == "lighttable" then
417-
install_module()
428+
install_module(show_dr)
418429
else
419430
if not ee.event_registered then
420431
dt.register_event(
421432
MODULE_NAME, "view-changed",
422433
function(event, old_view, new_view)
423434
if new_view.name == "lighttable" and old_view.name == "darkroom" then
424-
install_module()
435+
install_module(show_dr)
425436
end
426437
end
427438
)
@@ -430,7 +441,6 @@ else
430441
end
431442

432443

433-
434444
-- initialize list of programs and widgets ------------------------------------
435445
UpdateProgramList(combobox, button_edit, button_edit_copy, false)
436446

@@ -449,6 +459,9 @@ for i = MAX_EDITORS, 1, -1 do
449459
_("name of external editor ")..i,
450460
_("friendly name of external editor"), "")
451461
end
462+
dt.preferences.register(MODULE_NAME, "show_in_darkrooom", "bool",
463+
_("show external editors in darkroom"),
464+
_("check to show external editors module also in darkroom (requires restart)"), false)
452465

453466

454467
-- register the new shortcuts -------------------------------------------------

0 commit comments

Comments
 (0)