Rearrange initialization to be clearer and shorter
[WebThing.git] / plugins / Vimish.cs
index 8de862a..3b4969f 100644 (file)
@@ -10,15 +10,18 @@ public class Vimish : WebThingPlugin {
 
     public override void Init(WebThing wt) {
         this.wt = wt;
+        wt.Tabs.ShowTabs = false;
 
         wt.Window.KeyPressEvent += Window_KeyPress;
 
         commandline = new Gtk.Entry();
         commandline.Activated += command_Activate;
         commandline.KeyPressEvent += command_KeyPress;
-        wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink);
+        wt.AttachWidget(commandline, AttachPoint.S, AttachOptions.Fill, AttachOptions.Shrink);
 
         commandline.Hide();
+
+        ApplyOptions();
     }
 
     public override void InitWebView(WebView wv) {
@@ -30,9 +33,15 @@ public class Vimish : WebThingPlugin {
         case Gdk.Key.o:
             CommandStart("open ");
             break;
+        case Gdk.Key.O:
+            CommandStart("open " + wt.WebView.MainFrame.Uri);
+            break;
         case Gdk.Key.t:
             CommandStart("tabopen ");
             break;
+        case Gdk.Key.T:
+            CommandStart("tabopen " + wt.WebView.MainFrame.Uri);
+            break;
         case Gdk.Key.colon:
             CommandlineShow();
             break;
@@ -115,10 +124,47 @@ public class Vimish : WebThingPlugin {
         case "q":
             wt.Quit();
             break;
+        case "set":
+            if (args.Length == 2)
+                Options[args[1]] = null;
+            else
+                Options[args[1]] = args[2];
+            ApplyOptions();
+            break;
         }
         CommandlineHide();
     }
 
+    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) {
+        Console.WriteLine(format, values);
+    }
+
     private void command_KeyPress(object o, KeyPressEventArgs e) {
         if (e.Event.Key == Gdk.Key.Escape)
             CommandlineHide();