Skip to content

Commit 50be8a9

Browse files
committed
Added check to ensure we are in lighttable view prior to callling darktable.register_lib. If darktable was invoked in single image (darkroom) mode, then an event handler is registered to detect the change from darkroom mode to lighttable mode so that we can then call darktable.register_lib.
1 parent d1e330e commit 50be8a9

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

official/enfuse.lua

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,35 @@ du.check_min_api_version("3.0.0", "enfuse")
4646
-- Tell gettext where to find the .mo file translating messages for a particular domain
4747
gettext.bindtextdomain("enfuse",dt.configuration.config_dir..PS .. "lua" .. PS .. "locale" .. PS)
4848

49+
local enf = {}
50+
enf.event_registered = false
51+
enf.module_installed = false
52+
enf.lib_widgets = {}
53+
4954
local function _(msgid)
5055
return gettext.dgettext("enfuse", msgid)
5156
end
5257

58+
local function install_module()
59+
if not enf.module_installed then
60+
dt.register_lib(
61+
"enfuse", -- plugin name
62+
"enfuse", -- name
63+
true, -- expandable
64+
false, -- resetable
65+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers
66+
dt.new_widget("box") -- widget
67+
{
68+
orientation = "vertical",
69+
sensitive = enfuse_installed,
70+
table.unpack(enf.lib_widgets)
71+
},
72+
nil,-- view_enter
73+
nil -- view_leave
74+
)
75+
enf.module_installed = true
76+
end
77+
end
5378
-- add a new lib
5479
-- is enfuse installed?
5580
local enfuse_installed = df.check_if_bin_exists("enfuse")
@@ -229,30 +254,31 @@ if enfuse_installed then
229254
local lib_widgets = {}
230255

231256
if not enfuse_installed then
232-
table.insert(lib_widgets, df.executable_path_widget({"ffmpeg"}))
257+
table.insert(enf.lib_widgets, df.executable_path_widget({"ffmpeg"}))
233258
end
234-
table.insert(lib_widgets, exposure_mu)
235-
table.insert(lib_widgets, depth)
236-
table.insert(lib_widgets, blend_colorspace)
237-
table.insert(lib_widgets, enfuse_button)
259+
table.insert(enf.lib_widgets, exposure_mu)
260+
table.insert(enf.lib_widgets, depth)
261+
table.insert(enf.lib_widgets, blend_colorspace)
262+
table.insert(enf.lib_widgets, enfuse_button)
238263

239264

240265
-- ... and tell dt about it all
241-
dt.register_lib(
242-
"enfuse", -- plugin name
243-
"enfuse", -- name
244-
true, -- expandable
245-
false, -- resetable
246-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 100}}, -- containers
247-
dt.new_widget("box") -- widget
248-
{
249-
orientation = "vertical",
250-
sensitive = enfuse_installed,
251-
table.unpack(lib_widgets)
252-
},
253-
nil,-- view_enter
254-
nil -- view_leave
255-
)
266+
if dt.gui.current_view().name == "lighttable" then
267+
install_module()
268+
else
269+
if not enf.event_registered then
270+
dt.register_event(
271+
"view-changed",
272+
function(event, old_view, new_view)
273+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
274+
dt.print_log("view changed from darkroom to lighttable")
275+
install_module()
276+
end
277+
end
278+
)
279+
enf.event_registered = true
280+
end
281+
end
256282
else
257283
dt.print_error("enfuse executable not found")
258284
error("enfuse executable not found")

0 commit comments

Comments
 (0)