Skip to content

Commit dfb8d4e

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 b8e3ec4 commit dfb8d4e

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

contrib/LabelsToTags.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ du.check_min_api_version("3.0.0", "LabelsToTags")
5555
-- Lua 5.3 no longer has "unpack" but "table.unpack"
5656
unpack = unpack or table.unpack
5757

58+
local ltt = {}
59+
ltt.module_installed = false
60+
ltt.event_registered = false
61+
5862
local LIB_ID = "LabelsToTags"
5963

6064
-- Helper functions: BEGIN
@@ -184,7 +188,7 @@ local function doTagging(selfC)
184188
job.valid = false
185189
end
186190

187-
local my_widget = darktable.new_widget("box") {
191+
ltt.my_widget = darktable.new_widget("box") {
188192
orientation = "vertical",
189193
mappingComboBox,
190194
darktable.new_widget("button") {
@@ -217,6 +221,15 @@ darktable.register_tag_mapping = function(name, mapping)
217221
mappingComboBox.reset_callback(mappingComboBox)
218222
end
219223

224+
local function install_module()
225+
if not ltt.module_installed then
226+
darktable.register_lib(LIB_ID,"labels to tags",true,true,{
227+
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20},
228+
},ltt.my_widget,nil,nil)
229+
ltt.module_installed = true
230+
end
231+
end
232+
220233
--[[
221234
darktable.register_tag_mapping("Example",
222235
{ ["+----*"] = { "Red", "Only red" },
@@ -229,6 +242,19 @@ darktable.register_tag_mapping("Example",
229242
["*****R"] = { "Rejected" } })
230243
]]
231244

232-
darktable.register_lib(LIB_ID,"labels to tags",true,true,{
233-
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20},
234-
},my_widget,nil,nil)
245+
if darktable.gui.current_view().name == "lighttable" then
246+
install_module()
247+
else
248+
if not ltt.event_registered then
249+
darktable.register_event(
250+
"view-changed",
251+
function(event, old_view, new_view)
252+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
253+
install_module()
254+
end
255+
end
256+
)
257+
ltt.event_registered = true
258+
end
259+
end
260+

0 commit comments

Comments
 (0)