Skip to content

Commit 52acdb9

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 138b236 commit 52acdb9

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

contrib/copy_attach_detach_tags.lua

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ local function _(msgid)
5151
return gettext.dgettext("copy_attach_detach_tags", msgid)
5252
end
5353

54+
local cadt = {}
55+
cadt.module_installed = false
56+
cadt.event_registered = false
57+
cadt.widget_table = {}
58+
5459

5560
local image_tags = {}
5661

@@ -156,6 +161,26 @@ local function replace_tags()
156161
dt.print(_('Tags replaced'))
157162
end
158163

164+
local function install_module()
165+
if not cadt.module_installed then
166+
dt.register_lib("tagging_addon","Tagging addon",true,true,{
167+
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",500}
168+
},
169+
dt.new_widget("box") {
170+
-- orientation = "vertical",
171+
reset_callback = function()
172+
taglist_label.label = ""
173+
image_tags = {}
174+
end,
175+
table.unpack(cadt.widget_table),
176+
},
177+
nil,
178+
nil
179+
)
180+
cadt.module_installed = true
181+
end
182+
end
183+
159184
-- create modul Tagging addons
160185
taglist_label.reset_callback = mcopy_tags
161186

@@ -190,31 +215,31 @@ local box2 = dt.new_widget("box"){
190215
local sep = dt.new_widget("separator"){}
191216

192217
-- pack elements into widget table for a nicer layout
193-
local widget_table = {}
194218

195-
widget_table[1] = box1
196-
widget_table[#widget_table+1] = box2
219+
cadt.widget_table[1] = box1
220+
cadt.widget_table[#cadt.widget_table+1] = box2
197221

198-
widget_table[#widget_table+1] = sep
199-
widget_table[#widget_table+1] = taglabel
200-
widget_table[#widget_table+1] = taglist_label
222+
cadt.widget_table[#cadt.widget_table+1] = sep
223+
cadt.widget_table[#cadt.widget_table+1] = taglabel
224+
cadt.widget_table[#cadt.widget_table+1] = taglist_label
201225

202226

203227
-- create modul
204-
dt.register_lib("tagging_addon","Tagging addon",true,true,{
205-
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",500}
206-
},
207-
dt.new_widget("box") {
208-
-- orientation = "vertical",
209-
reset_callback = function()
210-
taglist_label.label = ""
211-
image_tags = {}
212-
end,
213-
table.unpack(widget_table),
214-
},
215-
nil,
216-
nil
217-
)
228+
if dt.gui.current_view().name == "lighttable" then
229+
install_module()
230+
else
231+
if not cadt.event_registered then
232+
dt.register_event(
233+
"view-changed",
234+
function(event, old_view, new_view)
235+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
236+
install_module()
237+
end
238+
end
239+
)
240+
cadt.event_registered = true
241+
end
242+
end
218243

219244

220245
-- shortcut for copy

0 commit comments

Comments
 (0)