Rearrange key handling in FFNav and Vimish
[WebThing.git] / plugins / Vimish.cs
index 0b699d8..968fae9 100644 (file)
@@ -17,9 +17,11 @@ public class Vimish : WebThingPlugin {
         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) {
@@ -27,27 +29,6 @@ public class Vimish : WebThingPlugin {
     }
 
     private void Window_KeyPress(object o, KeyPressEventArgs e) {
-        switch(e.Event.Key) {
-        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;
-        }
-    }
-
-    private void WebView_KeyPress(object o, KeyPressEventArgs e) {
-        Console.WriteLine(e.Event.Key);
         if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
             switch(e.Event.Key) {
             case Gdk.Key.n:
@@ -58,6 +39,31 @@ public class Vimish : WebThingPlugin {
                 break;
             }
         } else {
+            switch(e.Event.Key) {
+            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;
+            }
+        }
+    }
+
+    private void WebView_KeyPress(object o, KeyPressEventArgs e) {
+        WebView wv = (WebView)o;
+
+        Console.WriteLine(e.Event.Key);
+        if (e.Event.State == Gdk.ModifierType.None) {
             switch(e.Event.Key) {
             case Gdk.Key.j:
                 wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
@@ -72,10 +78,10 @@ public class Vimish : WebThingPlugin {
                 wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
                 break;
             case Gdk.Key.r:
-                wt.WebView.Reload();
+                wv.Reload();
                 break;
             case Gdk.Key.Escape:
-                wt.WebView.ExecuteScript("document.activeElement.blur()");
+                wv.ExecuteScript("document.activeElement.blur()");
                 break;
             }
         }
@@ -124,26 +130,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) {