|
9 | 9 | language="Lua"
|
10 | 10 | purpose="Shows / changes global options"
|
11 | 11 | date_written="2010-09-17 08:28:51"
|
| 12 | + date_modified="2018-03-28 11:06" |
12 | 13 | requires="4.50"
|
13 |
| - version="1.0" |
| 14 | + version="2.0" |
14 | 15 | >
|
15 | 16 | <description trim="y">
|
16 | 17 | <![CDATA[
|
@@ -42,100 +43,137 @@ if you use the GUI interface (global preferences) it may put the option back aga
|
42 | 43 | <alias
|
43 | 44 | match="change_global_option * *"
|
44 | 45 | enabled="y"
|
45 |
| - send_to="12" |
46 | 46 | sequence="100"
|
| 47 | + script="ChangeOption" |
47 | 48 | >
|
48 |
| - <send> |
49 |
| - |
50 |
| --- open preferences database |
51 |
| -local db = assert (sqlite3.open (GetInfo (82))) |
52 |
| -local value = nil |
53 |
| - |
54 |
| --- see if this key already exists (if not, probably spelling error) |
55 |
| -for a in db:nrows "SELECT * FROM prefs WHERE name = '%1'" do |
56 |
| - value = a.value |
57 |
| -end -- for |
58 |
| - |
59 |
| --- if found, modify it |
60 |
| -if value then |
61 |
| - |
62 |
| - if db:execute ("UPDATE prefs SET value = '%2' WHERE name = '%1'") ~= sqlite3.OK then |
63 |
| - ColourNote ("red", "", "Unable to modify preferences: " .. db:errmsg ()) |
64 |
| - else |
65 |
| - if value ~= "%2" then |
66 |
| - ColourNote ("cyan", "", "Item '%1' changed from '" .. value .. "' to '%2'") |
67 |
| - else |
68 |
| - ColourNote ("cyan", "", "No change required, value of '%1' is already '%2'") |
69 |
| - end -- if |
70 |
| - end -- if updated OK |
71 |
| - |
72 |
| -else |
73 |
| - ColourNote ("red", "", "Item '%1' is not in preferences database") |
74 |
| -end -- does not exist |
75 |
| - |
76 |
| -db:close() |
77 |
| - |
78 |
| -</send> |
79 | 49 | </alias>
|
80 |
| - |
| 50 | + |
81 | 51 | <alias
|
82 | 52 | match="show_global_option *"
|
83 | 53 | enabled="y"
|
84 |
| - send_to="12" |
85 | 54 | sequence="100"
|
| 55 | + script="ShowOption" |
86 | 56 | >
|
87 |
| - <send> |
88 |
| - |
89 |
| --- open preferences database |
90 |
| -local db = assert (sqlite3.open (GetInfo (82))) |
91 |
| -local value = nil |
92 |
| - |
93 |
| --- find the item |
94 |
| -for a in db:nrows "SELECT * FROM prefs WHERE name = '%1'" do |
95 |
| - value = a.value |
96 |
| -end -- for |
97 |
| - |
98 |
| --- if found, display it |
99 |
| -if value then |
100 |
| - ColourNote ("cyan", "", "Item '%1' has value '" .. value .. "'") |
101 |
| -else |
102 |
| - ColourNote ("red", "", "Item '%1' is not in preferences database") |
103 |
| -end -- does not exist |
104 |
| - |
105 |
| -db:close() |
106 |
| - |
107 |
| -</send> |
108 | 57 | </alias>
|
109 | 58 |
|
110 | 59 | <alias
|
111 | 60 | match="list_global_options"
|
112 | 61 | enabled="y"
|
113 |
| - send_to="12" |
114 | 62 | sequence="100"
|
| 63 | + script="ListOptions" |
115 | 64 | >
|
116 |
| - <send> |
117 |
| - |
| 65 | + </alias> |
| 66 | + |
| 67 | +</aliases> |
| 68 | + |
| 69 | +<script> |
| 70 | + |
| 71 | +function ListOptions (name, line, wildcards) |
| 72 | + |
| 73 | + ColourNote ("cyan", "", "Global Options") |
| 74 | + ColourNote ("cyan", "", string.rep ("-", 40)) |
| 75 | + |
| 76 | + -- show all |
| 77 | + |
| 78 | + local t = GetGlobalOptionList () |
| 79 | + table.sort (t) |
| 80 | + |
| 81 | + for k, v in ipairs (t) do |
| 82 | + ColourNote ("cyan", "", v) |
| 83 | + end -- for |
| 84 | + |
| 85 | + ColourNote ("cyan", "", string.rep ("-", 40)) |
| 86 | +end -- ListOptions |
| 87 | + |
| 88 | +function ShowOption (name, line, wildcards) |
| 89 | + |
| 90 | + local whichOption = wildcards [1] |
| 91 | + |
| 92 | + -- find all possible keys |
| 93 | + local t = { } |
| 94 | + for k, v in ipairs (GetGlobalOptionList ()) do |
| 95 | + t [v] = true |
| 96 | + end -- for |
| 97 | + |
| 98 | + if not t [whichOption] then |
| 99 | + ColourNote ("red", "", "Item '" .. whichOption .. "' is not a global option. Try: list_global_options") |
| 100 | + ColourNote ("deepskyblue", "", "Option names are case-sensitive.") |
| 101 | + return |
| 102 | + end -- if option not found |
| 103 | + |
118 | 104 | -- open preferences database
|
119 |
| -local db = assert (sqlite3.open (GetInfo (82))) |
| 105 | + local db = assert (sqlite3.open (GetInfo (82))) |
| 106 | + local value = nil |
| 107 | + |
| 108 | + -- find the item |
| 109 | + for a in db:nrows ("SELECT * FROM prefs WHERE name = '" .. whichOption .. "'") do |
| 110 | + value = a.value |
| 111 | + end -- for |
| 112 | + |
| 113 | + -- if found, display it |
| 114 | + if value then |
| 115 | + ColourTell ("cyan", "", "Item '" .. whichOption .. "' has value '") |
| 116 | + ColourTell ("orange", "", value) |
| 117 | + ColourNote ("cyan", "", "'") |
| 118 | + else |
| 119 | + ColourNote ("red", "", "Item '" .. whichOption .. "' is not in preferences database") |
| 120 | + end -- does not exist |
120 | 121 |
|
121 |
| -ColourNote ("cyan", "", "Global Options") |
122 |
| -ColourNote ("cyan", "", string.rep ("-", 40)) |
| 122 | + db:close() |
123 | 123 |
|
124 |
| --- show all |
125 |
| -for a in db:nrows "SELECT * FROM prefs ORDER BY name" do |
126 |
| - ColourNote ("cyan", "", a.name) |
127 |
| -end -- for |
| 124 | +end -- ShowOption |
128 | 125 |
|
129 |
| -ColourNote ("cyan", "", string.rep ("-", 40)) |
| 126 | +function ChangeOption (name, line, wildcards) |
130 | 127 |
|
131 |
| -db:close() |
| 128 | + local whichOption = wildcards [1] |
| 129 | + local newValue = wildcards [2] |
132 | 130 |
|
133 |
| -</send> |
134 |
| - </alias> |
135 |
| - |
136 |
| -</aliases> |
| 131 | + -- find all possible keys |
| 132 | + local t = { } |
| 133 | + for k, v in ipairs (GetGlobalOptionList ()) do |
| 134 | + t [v] = true |
| 135 | + end -- for |
137 | 136 |
|
138 |
| -<script> |
| 137 | + if not t [whichOption] then |
| 138 | + ColourNote ("red", "", "Item '" .. whichOption .. "' is not a global option. Try: list_global_options") |
| 139 | + ColourNote ("deepskyblue", "", "Option names are case-sensitive.") |
| 140 | + return |
| 141 | + end -- if |
| 142 | + |
| 143 | + -- open preferences database |
| 144 | + local db = assert (sqlite3.open (GetInfo (82))) |
| 145 | + local value = '(nothing)' |
| 146 | + |
| 147 | + -- see if this key already exists and if so, what its value is |
| 148 | + for a in db:nrows ("SELECT * FROM prefs WHERE name = '" .. whichOption .. "'") do |
| 149 | + value = a.value |
| 150 | + end -- for |
| 151 | + |
| 152 | + -- fix up quotes |
| 153 | + newValueFixed = string.gsub (newValue, "'", "''") |
| 154 | + |
| 155 | + if db:execute ("INSERT OR REPLACE INTO prefs " .. |
| 156 | + "(name, value) VALUES ('" .. whichOption .. "', '" |
| 157 | + .. newValue .. "')") ~= sqlite3.OK then |
| 158 | + ColourNote ("red", "", "Unable to modify preferences: " .. db:errmsg ()) |
| 159 | + else |
| 160 | + if value ~= "%2" then |
| 161 | + ColourNote ("cyan", "", "Item '" .. whichOption .. "' changed from '" |
| 162 | + .. value .. "' to '" .. newValue .. "'") |
| 163 | + ColourNote ("orange", "", [[ |
| 164 | +After changing an option you should exit the client and re-open it, otherwise |
| 165 | +if you use the GUI interface (global preferences) it may put the option back again |
| 166 | +to its old value because the options are kept in memory.]]) |
| 167 | + |
| 168 | + else |
| 169 | + ColourNote ("cyan", "", "No change required, value of '" |
| 170 | + .. whichOption .. "' is already '" .. newValue .. "'") |
| 171 | + end -- if |
| 172 | + end -- if updated OK |
| 173 | + |
| 174 | + db:close() |
| 175 | + |
| 176 | +end -- ChangeOption |
139 | 177 |
|
140 | 178 | -- show help
|
141 | 179 | ColourNote ("cyan", "", GetPluginInfo (GetPluginID (), 3))
|
|
0 commit comments