@@ -16,14 +16,15 @@ Create thumbnails plugin for darktable
16
16
]]
17
17
18
18
--[[ About this Plugin
19
- This plugin adds the button 'create thumbnails' to 'selected image[s]' module of darktable's lighttable view.
19
+ This plugin adds the buttons 'create thumbnails' and 'delete thumbnails' to 'selected image[s]' module of darktable's lighttable view.
20
20
21
21
22
22
----USAGE----
23
23
Click the 'create thumbnails' button in the 'selected image[s]' module to let the script create full sized previews of all selected images.
24
+ Click the 'delete thumbnails' button in the 'selected image[s]' module to let the script delete all previews/thumbnails of all selected images.
24
25
25
- To create previews of all images of a collection:
26
- Use CTRL+A to select all images of current collection and then press the button.
26
+ To create (or delete) previews of all images of a collection:
27
+ Use CTRL+A to select all images of current collection and then press the corresponding button.
27
28
]]
28
29
29
30
local dt = require " darktable"
@@ -86,9 +87,49 @@ dt.gui.libs.image.register_action(
86
87
" create full sized previews of all selected images"
87
88
)
88
89
90
+
91
+ -- add button to 'selected images' module
92
+ dt .gui .libs .image .register_action (
93
+ " delete_thumbnails_button" ,
94
+ " delete thumbnails" ,
95
+ function (event , images )
96
+ print_and_log (" deleting thumbnails of " .. image_count_to_text (# images ) .. " ..." )
97
+
98
+ -- create a new progress_bar displayed in darktable.gui.libs.backgroundjobs
99
+ job = dt .gui .create_job (" deleting thumbnails..." , true , stop_job )
100
+
101
+ for i , image in pairs (images ) do
102
+ -- delete all thumbnails
103
+ image :drop_cache ()
104
+
105
+ -- update progress_bar
106
+ job .percent = i / # images
107
+
108
+ -- sleep for a short moment to give stop_job callback function a chance to run
109
+ dt .control .sleep (10 )
110
+
111
+ -- stop early if darktable is shutdown or the cancle button of the progress bar is pressed
112
+ if dt .control .ending or not job .valid then
113
+ print_and_log (" deleting thumbnails canceled after processing " .. i .. " /" .. image_count_to_text (# images ) .. " !" )
114
+ break
115
+ end
116
+ end
117
+
118
+ -- if job was not canceled
119
+ if (job .valid ) then
120
+ -- stop job and remove progress_bar from ui
121
+ job .valid = false
122
+
123
+ print_and_log (" deleting thumbnails of " .. image_count_to_text (# images ) .. " done!" )
124
+ end
125
+ end ,
126
+ " delete all thumbnails of all selected images"
127
+ )
128
+
89
129
-- clean up function that is called when this module is getting disabled
90
130
local function destroy ()
91
131
dt .gui .libs .image .destroy_action (" create_thumbnails_button" )
132
+ dt .gui .libs .image .destroy_action (" delete_thumbnails_button" )
92
133
end
93
134
94
135
0 commit comments