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.

This commit is contained in:
Bill Ferguson
2020-08-09 01:48:36 -04:00
parent b8e3ec4302
commit dfb8d4e7c6

View File

@@ -55,6 +55,10 @@ du.check_min_api_version("3.0.0", "LabelsToTags")
-- Lua 5.3 no longer has "unpack" but "table.unpack" -- Lua 5.3 no longer has "unpack" but "table.unpack"
unpack = unpack or table.unpack unpack = unpack or table.unpack
local ltt = {}
ltt.module_installed = false
ltt.event_registered = false
local LIB_ID = "LabelsToTags" local LIB_ID = "LabelsToTags"
-- Helper functions: BEGIN -- Helper functions: BEGIN
@@ -184,7 +188,7 @@ local function doTagging(selfC)
job.valid = false job.valid = false
end end
local my_widget = darktable.new_widget("box") { ltt.my_widget = darktable.new_widget("box") {
orientation = "vertical", orientation = "vertical",
mappingComboBox, mappingComboBox,
darktable.new_widget("button") { darktable.new_widget("button") {
@@ -217,6 +221,15 @@ darktable.register_tag_mapping = function(name, mapping)
mappingComboBox.reset_callback(mappingComboBox) mappingComboBox.reset_callback(mappingComboBox)
end end
local function install_module()
if not ltt.module_installed then
darktable.register_lib(LIB_ID,"labels to tags",true,true,{
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20},
},ltt.my_widget,nil,nil)
ltt.module_installed = true
end
end
--[[ --[[
darktable.register_tag_mapping("Example", darktable.register_tag_mapping("Example",
{ ["+----*"] = { "Red", "Only red" }, { ["+----*"] = { "Red", "Only red" },
@@ -229,6 +242,19 @@ darktable.register_tag_mapping("Example",
["*****R"] = { "Rejected" } }) ["*****R"] = { "Rejected" } })
]] ]]
darktable.register_lib(LIB_ID,"labels to tags",true,true,{ if darktable.gui.current_view().name == "lighttable" then
[darktable.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER",20}, install_module()
},my_widget,nil,nil) else
if not ltt.event_registered then
darktable.register_event(
"view-changed",
function(event, old_view, new_view)
if new_view.name == "lighttable" and old_view.name == "darkroom" then
install_module()
end
end
)
ltt.event_registered = true
end
end