Skip to content

Commit d05536b

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 cc4f1d7 commit d05536b

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

contrib/AutoGrouper.lua

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ local function _(msgid)
4545
return gettext.dgettext("AutoGrouper", msgid)
4646
end
4747

48+
local Ag = {}
49+
Ag.module_installed = false
50+
Ag.event_registered = false
51+
52+
local GUI = {
53+
gap = {},
54+
selected = {},
55+
collection = {}
56+
}
57+
58+
4859
local function InRange(test, low, high) --tests if test value is within range of low and high (inclusive)
4960
if test >= low and test <= high then
5061
return true
@@ -111,12 +122,26 @@ local function main(on_collection)
111122
end
112123
end
113124

125+
local function install_module()
126+
if not Ag.module_installed then
127+
dt.register_lib(
128+
'AutoGroup_Lib', -- Module name
129+
_('auto group'), -- name
130+
true, -- expandable
131+
true, -- resetable
132+
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
133+
dt.new_widget("box"){
134+
orientation = "vertical",
135+
GUI.gap,
136+
GUI.selected,
137+
GUI.collection
138+
}
139+
)
140+
Ag.module_installed = true
141+
end
142+
end
143+
114144
-- GUI --
115-
GUI = {
116-
gap = {},
117-
selected = {},
118-
collection = {}
119-
}
120145
temp = dt.preferences.read(MOD, 'active_gap', 'integer')
121146
if not InRange(temp, 1, 86400) then temp = 3 end
122147
GUI.gap = dt.new_widget('slider'){
@@ -143,16 +168,20 @@ GUI.collection = dt.new_widget("button"){
143168
tooltip =_('auto group the entire collection'),
144169
clicked_callback = function() main(true) end
145170
}
146-
dt.register_lib(
147-
'AutoGroup_Lib', -- Module name
148-
_('auto group'), -- name
149-
true, -- expandable
150-
true, -- resetable
151-
{[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers
152-
dt.new_widget("box"){
153-
orientation = "vertical",
154-
GUI.gap,
155-
GUI.selected,
156-
GUI.collection
157-
}
158-
)
171+
172+
if dt.gui.current_view().name == "lighttable" then
173+
install_module()
174+
else
175+
if not Ag.event_registered then
176+
dt.register_event(
177+
"view-changed",
178+
function(event, old_view, new_view)
179+
if new_view.name == "lighttable" and old_view.name == "darkroom" then
180+
install_module()
181+
end
182+
end
183+
)
184+
Ag.event_registered = true
185+
end
186+
end
187+

0 commit comments

Comments
 (0)