Convert Vimish to use global config
[WebThing.git] / plugins / Vimish.cs
index 0b699d8..ebe088c 100644 (file)
@@ -20,6 +20,8 @@ public class Vimish : WebThingPlugin {
         wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink);
 
         commandline.Hide();
+
+        ApplyOptions();
     }
 
     public override void InitWebView(WebView wv) {
@@ -124,26 +126,39 @@ public class Vimish : WebThingPlugin {
             break;
         case "set":
             if (args.Length == 2)
-                SetVar(args[1], "");
+                Options[args[1]] = null;
             else
-                SetVar(args[1], args[2]);
+                Options[args[1]] = args[2];
+            ApplyOptions();
             break;
         }
         CommandlineHide();
     }
 
-    public void SetVar(string key, string val) {
-        switch(key) {
-        case "showtabs":
-            wt.Tabs.ShowTabs = true;
-            break;
-        case "hidetabs":
-            wt.Tabs.ShowTabs = false;
-            break;
-        default:
-            Error("No variable {0}", key);
-            break;
+    private void ApplyOptions() {
+        foreach (string key in Options.Keys) {
+            switch(key) {
+            case "ShowTabs":
+                bool v = ParseBool(Options[key]);
+                wt.Tabs.ShowTabs = v;
+                break;
+            default:
+                Error("No variable {0}", key);
+                break;
+            }
+        }
+    }
+
+    private bool ParseBool(string v) {
+        switch(v.ToLower()) {
+        case "true":
+        case "t":
+        case "1":
+        case "on":
+        case "yes":
+            return true;
         }
+        return false;
     }
 
     private void Error(string format, params object[] values) {