-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPWExtraOptions.lua
More file actions
136 lines (116 loc) · 4.62 KB
/
PWExtraOptions.lua
File metadata and controls
136 lines (116 loc) · 4.62 KB
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
133
134
135
136
--[[
PWExtraOptions.lua
Copyright (C) 2024 Fiona Boston <fiona@fbphotography.uk>.
This file is part of PiwigoPublish
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
]]
---@diagnostic disable: undefined-global
require "UIHelpers"
-- *************************************************
-- Define a value_equal function for the popup_menu
local function valueEqual(a, b)
return a == b
end
-- *************************************************
local function main()
local share = LrView.share
LrFunctionContext.callWithContext("PWExtraOptionsContext", function(context)
-- Create a property table inside the context
log:info("PWExtraOptions")
local allServices = PiwigoAPI.getPublishServicesForPlugin(_PLUGIN.id)
if #allServices == 0 then
LrDialogs.message("No Piwigo publish services found.")
return
end
local serviceItems = {}
local serviceNames = {}
for i, s in ipairs(allServices) do
table.insert(serviceItems, {
title = s:getName(),
value = s,
})
table.insert(serviceNames, {
title = s:getName(),
value = i
})
end
log:info("serviceItems\n" .. utils.serialiseVar(serviceItems))
log:info("serviceNames\n" .. utils.serialiseVar(serviceNames))
local props = LrBinding.makePropertyTable(context)
local bind = LrView.bind
-- Property table for UI bindings
local props = bind {
selectedService = 1, -- default to first service
}
local f = LrView.osFactory()
local c = f:column {
spacing = f:dialog_spacing(),
UIHelpers.createPluginHeader(f, share, iconPath, pluginVersion),
f:row {
spacing = f:label_spacing(),
f:static_text {
title = "Select publish service:",
alignment = 'right',
width = 150,
},
f:popup_menu {
value = LrView.bind{ key = 'selectedService', bind_to_object = props },
items = serviceNames,
value_equal = valueEqual,
width = 300,
},
},
f:spacer { height = 20 },
f:row {
f:static_text {
title = "Applies to selected images",
font = "<system/bold>",
alignment = 'left',
fill_horizontal = 1,
},
},
f:spacer { height = 1 },
f:row {
f:push_button {
title = "Set Piwigo Album Cover",
tooltip = "Sets selected image as Piwigo album cover ",
action = function(button)
LrTasks.startAsyncTask(function()
local serviceNo = props.selectedService
-- get service object for selected service
local service = serviceItems[serviceNo].value
if not service then
LrDialogs.message("Error", "Could not find publish service", "error")
return
end
PiwigoAPI.setAlbumCover(service )
end)
end,
},
f:static_text {
title = "Sets selected image as Piwigo album cover for this collection",
alignment = 'left',
-- width = share 'labelWidth',
width_in_chars = 50,
},
},
}
dialog = LrDialogs.presentModalDialog({
title = "Piwigo Extra Options",
contents = c,
actionVerb = "Close",
})
end)
end
-- *************************************************
-- Run main()
LrTasks.startAsyncTask(main)