forked from darktable-org/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage_path_in_ui.lua
132 lines (105 loc) · 3.66 KB
/
image_path_in_ui.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--[[
This file is part of darktable,
copyright (c) 2014 Jérémy Rosen
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with darktable. If not, see <http://www.gnu.org/licenses/>.
]]
--[[
IMAGE_PATH_IN_UI
Add a widget with the path of the selected images for easy copy/past
Simple shortcuts to have multiple selection bufers
USAGE
* require this file from your main lua config file:
This plugin will add a widget at the bottom of the left column in lighttable mode
]]
local dt = require "darktable"
local du = require "lib/dtutils"
du.check_min_api_version("7.0.0", "image_path_in_ui")
local gettext = dt.gettext.gettext
local function _(msgid)
return gettext(msgid)
end
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = _("image path in UI"),
purpose = _("print the image path in the UI"),
author = "Jérémy Rosen",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/official/image_path_in_ui"
}
script_data.destroy = nil -- function to destory the script
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
script_data.show = nil -- only required for libs since the destroy_method only hides them
local ipiu = {}
ipiu.module_installed = false
ipiu.event_registered = false
local main_label = dt.new_widget("label"){selectable = true, ellipsize = "middle", halign = "start"}
local function install_module()
if not ipiu.module_installed then
dt.register_lib("image_path_no_ui",_("selected images path"),true,false,{
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_LEFT_CENTER",300}
}, main_label
)
ipiu.module_installed = true
end
end
local function reset_widget()
local selection = dt.gui.selection()
local result = ""
local array = {}
for _,img in pairs(selection) do
array[img.path] = true
end
for path in pairs(array) do
if result == "" then
result = path
else
result = result.."\n"..path
end
end
main_label.label = result
end
local function destroy()
dt.gui.libs["image_path_no_ui"].visible = false
dt.destroy_event("ipiu", "mouse-over-image-changed")
end
local function restart()
dt.register_event("ipiu", "mouse-over-image-changed", reset_widget);
dt.gui.libs["image_path_no_ui"].visible = true
end
local function show()
dt.gui.libs["image_path_no_ui"].visible = true
end
main_label.reset_callback = reset_widget
if dt.gui.current_view().id == "lighttable" then
install_module()
else
if not ipiu.event_registered then
dt.register_event(
"ipiu", "view-changed",
function(event, old_view, new_view)
if new_view.name == "lighttable" and old_view.name == "darkroom" then
install_module()
end
end
)
ipiu.event_registered = true
end
end
dt.register_event("ipiu", "mouse-over-image-changed", reset_widget);
script_data.destroy = destroy
script_data.restart = restart
script_data.destroy_method = "hide"
script_data.show = show
return script_data
--
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua