Skip to content

Commit b682284

Browse files
authored
Update with 'local' variable designation
Updated variable definitions with 'local' designation. Doing so slightly broke the script so I modified the function calls a tad to pass variables in and out as needed for "CollectOnAll" function to work.
1 parent ff0352c commit b682284

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

contrib/CollectHelper.lua

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,29 @@ In the "Selected Images" module click on "Collect on this Image"
4646
]]
4747

4848
local dt = require "darktable"
49-
previous = nil
50-
all_active = false
49+
local previous = nil
50+
local all_active = false
5151

5252
-- FUNCTION --
5353
local function CheckSingleImage(selection)
5454
if #selection ~= 1 then
5555
dt.print("Please select a single image")
56-
return 1
56+
return true
5757
end
58-
return 0
58+
return false
5959
end
6060
local function PreviousCollection()
6161
if previous ~= nil then
6262
previous = dt.gui.libs.collect.filter(previous)
6363
end
6464
end
65-
local function CollectOnFolder()
65+
local function CollectOnFolder(all_rules, all_active)
6666
local images = dt.gui.selection()
67-
if CheckSingleImage(images) == 1 then
67+
if CheckSingleImage(images) then
6868
return
6969
end
70-
rules = {}
71-
all_rules = {}
72-
rule = dt.gui.libs.collect.new_rule()
70+
local rules = {}
71+
local rule = dt.gui.libs.collect.new_rule()
7372
rule.mode = "DT_LIB_COLLECT_MODE_AND"
7473
rule.data = images[1].path
7574
rule.item = "DT_COLLECTION_PROP_FOLDERS"
@@ -78,47 +77,48 @@ local function CollectOnFolder()
7877
for _,active_rule in pairs(rules) do
7978
table.insert(all_rules, active_rule)
8079
end
80+
return all_rules
8181
else
8282
previous = dt.gui.libs.collect.filter(rules)
8383
end
8484
end
85-
local function CollectOnColors()
85+
local function CollectOnColors(all_rules, all_active)
8686
local images = dt.gui.selection()
87-
if CheckSingleImage(images) == 1 then
87+
if CheckSingleImage(images) then
8888
return
8989
end
9090
for _,image in pairs(images) do
91-
rules = {}
91+
local rules = {}
9292
if image.red then
93-
red_rule = dt.gui.libs.collect.new_rule()
93+
local red_rule = dt.gui.libs.collect.new_rule()
9494
red_rule.mode = "DT_LIB_COLLECT_MODE_AND"
9595
red_rule.data = "red"
9696
red_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
9797
table.insert(rules, red_rule)
9898
end
9999
if image.blue then
100-
blue_rule = dt.gui.libs.collect.new_rule()
100+
local blue_rule = dt.gui.libs.collect.new_rule()
101101
blue_rule.mode = "DT_LIB_COLLECT_MODE_AND"
102102
blue_rule.data = "blue"
103103
blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
104104
table.insert(rules, blue_rule)
105105
end
106106
if image.green then
107-
green_rule = dt.gui.libs.collect.new_rule()
107+
local green_rule = dt.gui.libs.collect.new_rule()
108108
green_rule.mode = "DT_LIB_COLLECT_MODE_AND"
109109
green_rule.data = "green"
110110
green_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
111111
table.insert(rules, green_rule)
112112
end
113113
if image.yellow then
114-
yellow_rule = dt.gui.libs.collect.new_rule()
114+
local yellow_rule = dt.gui.libs.collect.new_rule()
115115
yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND"
116116
yellow_rule.data = "yellow"
117117
yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
118118
table.insert(rules, yellow_rule)
119119
end
120120
if image.purple then
121-
purple_rule = dt.gui.libs.collect.new_rule()
121+
local purple_rule = dt.gui.libs.collect.new_rule()
122122
purple_rule.mode = "DT_LIB_COLLECT_MODE_AND"
123123
purple_rule.data = "purple"
124124
purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
@@ -128,26 +128,25 @@ local function CollectOnColors()
128128
for _,active_rule in pairs(rules) do
129129
table.insert(all_rules, active_rule)
130130
end
131+
return all_rules
131132
else
132133
previous = dt.gui.libs.collect.filter(rules)
133134
end
134135
end
135136
end
136137
local function CollectOnAll_AND()
137138
local images = dt.gui.selection()
138-
if CheckSingleImage(images) == 1 then
139+
if CheckSingleImage(images) then
139140
return
140141
end
141-
all_rules = {}
142-
all_active = true
142+
local rules = {}
143143
if dt.preferences.read('module_CollectHelper','folder','bool') then
144-
CollectOnFolder()
144+
rules = CollectOnFolder(rules, true)
145145
end
146146
if dt.preferences.read('module_CollectHelper','colors','bool') then
147-
CollectOnColors()
147+
rules = CollectOnColors(rules, true)
148148
end
149-
all_active = false
150-
previous = dt.gui.libs.collect.filter(all_rules)
149+
previous = dt.gui.libs.collect.filter(rules)
151150
end
152151

153152
-- GUI --
@@ -159,14 +158,14 @@ dt.gui.libs.image.register_action(
159158
if dt.preferences.read('module_CollectHelper','folder','bool') then
160159
dt.gui.libs.image.register_action(
161160
"collect: folder",
162-
function() CollectOnFolder() end,
161+
function() CollectOnFolder(_ , false) end,
163162
"Sets the Collect parameters to be the selected images's folder"
164163
)
165164
end
166165
if dt.preferences.read('module_CollectHelper','colors','bool') then
167166
dt.gui.libs.image.register_action(
168167
"collect: color label(s)",
169-
function() CollectOnColors() end,
168+
function() CollectOnColors(_ , false) end,
170169
"Sets the Collect parameters to be the selected images's color label(s)"
171170
)
172171
end
@@ -196,4 +195,4 @@ dt.preferences.register("module_CollectHelper", "folder", -- name
196195
'CollectHelper: Folder', -- label
197196
'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
198197
true -- default
199-
)
198+
)

0 commit comments

Comments
 (0)