-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClipboardWizard.lua
125 lines (107 loc) · 4.28 KB
/
ClipboardWizard.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
luanet.load_assembly("System.Windows.Forms");
local Clipboard = luanet.import_type("System.Windows.Forms.Clipboard");
local Application = luanet.import_type("System.Windows.Forms.Application");
-- Retrieve our settings and store them in local variables to prevent redundant fetching of settings.
local settings = {}
settings.ComparatorFormat = GetSetting("ComparatorFormat");
settings.ComparatorValue = GetSetting("ComparatorValue");
settings.PrimaryFormatString = GetSetting("PrimaryFormatString");
settings.SecondaryFormatString = GetSetting("SecondaryFormatString");
function Init()
if settings.ComparatorFormat == "{Default}" then
if Application.ProductName == "Aeon" then
settings.ComparatorFormat = "";
elseif Application.ProductName == "Ares" then
settings.ComparatorFormat = "";
elseif Application.ProductName == "ILLiad" then
settings.ComparatorFormat = "{TableField:Transaction.RequestType}";
end
end
if settings.ComparatorValue == "{Default}" then
if Application.ProductName == "Aeon" then
settings.ComparatorValue = "";
elseif Application.ProductName == "Ares" then
settings.ComparatorValue = "";
elseif Application.ProductName == "ILLiad" then
settings.ComparatorValue = "Loan";
end
end
if settings.PrimaryFormatString == "{Default}" then
if Application.ProductName == "Aeon" then
settings.PrimaryFormatString = "{TableField:Transaction.ItemTitle}";
elseif Application.ProductName == "Ares" then
settings.PrimaryFormatString = "{TableField:Item.Title}";
elseif Application.ProductName == "ILLiad" then
settings.PrimaryFormatString = "{TableField:Transaction.LoanTitle}";
end
end
if settings.SecondaryFormatString == "{Default}" then
if Application.ProductName == "Aeon" then
settings.SecondaryFormatString = "";
elseif Application.ProductName == "Ares" then
settings.SecondaryFormatString = "";
elseif Application.ProductName == "ILLiad" then
settings.SecondaryFormatString = "{TableField:Transaction.PhotoJournalTitle}";
end
end
local success = pcall(SetClipboardContents);
if (not success) then
LogDebug("[Clipboard Wizard] Error setting clipboard contents");
end
end
function SetClipboardContents()
local formatString = GetFormatString();
local value = ReplaceTags(formatString);
if ((value == nil) or (value == null) or (value == "")) then
LogDebug("[Clipboard Wizard] Clearing clipboard contents");
Clipboard.Clear();
else
LogDebug("[Clipboard Wizard] Setting clipboard contents: " .. value);
Clipboard.SetText(value);
end
end
function GetFormatString()
local value = ReplaceTags(settings.ComparatorFormat);
if ((value == nil) or (value == null) or (value == "") or (value:lower() == settings.ComparatorValue:lower())) then
return settings.PrimaryFormatString;
else
return settings.SecondaryFormatString;
end
end
function ReplaceTags(input)
LogDebug("[Clipboard Wizard] Getting replacement for ".. input);
return input:gsub( "{(.-)}", function( token ) return ReplaceTag(token) end )
end
function ReplaceTag(input)
--The replacement must not return nil otherwise input.gsub will not process the replacement and leave the tagging syntax in place
LogDebug("[Clipboard Wizard] Process tag replacements for "..input);
if (input:sub(1,11):lower() == "tablefield:") then
return MapFieldValue(input:sub(12));
else
return "";
end
end
function MapFieldValue(fieldDefinition)
if (fieldDefinition) then
LogDebug("[Clipboard Wizard] Mapping FieldValue for " .. fieldDefinition);
local separatorIndex = string.find(fieldDefinition, "%.");
if (separatorIndex and separatorIndex > 0) then
local table = string.sub(fieldDefinition, 1, separatorIndex - 1);
local field = string.sub(fieldDefinition, separatorIndex + 1);
local value = nil;
if (table == "Setting") then
LogDebug("[Clipboard Wizard] Getting TableField. Setting: " .. field);
value = GetSetting(field);
else
LogDebug("[Clipboard Wizard] Getting TableField. Table: ".. table .. ". Field: " .. field);
value = GetFieldValue(table, field);
end
if (value == null) then
LogDebug("[Clipboard Wizard] Replacement value is null.");
value = "";
end
return value;
end
end
return "";
end