commit:e754c4d8175a3e5b381d27b8eb5a11a8d6085d7f
author:Chip Black
committer:Chip Black
date:Sat Jun 6 04:15:57 2009 -0500
parents:fc785e55243b0a680c19ea6ccd77b759fe216766
Convert Vimish to use global config
diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs
line changes: +28/-13
index 0b699d8..ebe088c
--- a/plugins/Vimish.cs
+++ b/plugins/Vimish.cs
@@ -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) {