|
| 1 | +<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 | +<!DOCTYPE muclient> |
| 3 | + |
| 4 | +<muclient> |
| 5 | +<plugin |
| 6 | + name="Global_Option_Updater" |
| 7 | + author="Nick Gammon" |
| 8 | + id="1204316574ebc1d41d7011b3" |
| 9 | + language="Lua" |
| 10 | + purpose="Shows / changes global options" |
| 11 | + date_written="2010-09-17 08:28:51" |
| 12 | + requires="4.50" |
| 13 | + version="1.0" |
| 14 | + > |
| 15 | +<description trim="y"> |
| 16 | +<![CDATA[ |
| 17 | +Usage: |
| 18 | +
|
| 19 | +list_global_options --> list all valid option names |
| 20 | +show_global_option x --> displays value of option |
| 21 | +change_global_option x y --> changes value of option x to y |
| 22 | +
|
| 23 | +
|
| 24 | +eg. |
| 25 | +
|
| 26 | +show_global_option FixedPitchFont |
| 27 | +
|
| 28 | +change_global_option FixedPitchFont Dina |
| 29 | +
|
| 30 | +After changing an option you should exit the client and re-open it, otherwise |
| 31 | +if you use the GUI interface (global preferences) it may put the option back again. |
| 32 | +
|
| 33 | +]]> |
| 34 | +</description> |
| 35 | + |
| 36 | +</plugin> |
| 37 | + |
| 38 | + |
| 39 | +<!-- Aliases --> |
| 40 | + |
| 41 | +<aliases> |
| 42 | + <alias |
| 43 | + match="change_global_option * *" |
| 44 | + enabled="y" |
| 45 | + send_to="12" |
| 46 | + sequence="100" |
| 47 | + > |
| 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 | + </alias> |
| 80 | + |
| 81 | + <alias |
| 82 | + match="show_global_option *" |
| 83 | + enabled="y" |
| 84 | + send_to="12" |
| 85 | + sequence="100" |
| 86 | + > |
| 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 | + </alias> |
| 109 | + |
| 110 | + <alias |
| 111 | + match="list_global_options" |
| 112 | + enabled="y" |
| 113 | + send_to="12" |
| 114 | + sequence="100" |
| 115 | + > |
| 116 | + <send> |
| 117 | + |
| 118 | + -- open preferences database |
| 119 | +local db = assert (sqlite3.open (GetInfo (82))) |
| 120 | + |
| 121 | +ColourNote ("cyan", "", "Global Options") |
| 122 | +ColourNote ("cyan", "", string.rep ("-", 40)) |
| 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 |
| 128 | + |
| 129 | +ColourNote ("cyan", "", string.rep ("-", 40)) |
| 130 | + |
| 131 | +db:close() |
| 132 | + |
| 133 | +</send> |
| 134 | + </alias> |
| 135 | + |
| 136 | +</aliases> |
| 137 | + |
| 138 | +<script> |
| 139 | + |
| 140 | +-- show help |
| 141 | +ColourNote ("cyan", "", GetPluginInfo (GetPluginID (), 3)) |
| 142 | + |
| 143 | +</script> |
| 144 | + |
| 145 | +</muclient> |
0 commit comments