Fix scrolling functionality
[WebThing.git] / plugins / Vimish.cs
index 27543ee..22f2532 100644 (file)
@@ -28,10 +28,6 @@ public class Vimish : WebThingPlugin {
         wv.KeyPressEvent += WebView_KeyPress;
     }
 
-    public override void Deinit(WebThing wt) {
-        SaveConfig();
-    }
-
     private void Window_KeyPress(object o, KeyPressEventArgs e) {
         if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
             switch(e.Event.Key) {
@@ -70,16 +66,16 @@ public class Vimish : WebThingPlugin {
         if (e.Event.State == Gdk.ModifierType.None) {
             switch(e.Event.Key) {
             case Gdk.Key.j:
-                wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, 1);
                 break;
             case Gdk.Key.k:
-                wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, -1);
                 break;
             case Gdk.Key.l:
-                wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(1, 0);
                 break;
             case Gdk.Key.h:
-                wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(-1, 0);
                 break;
             case Gdk.Key.r:
                 wv.Reload();
@@ -110,18 +106,28 @@ public class Vimish : WebThingPlugin {
 
     private void command_Activate(object o, EventArgs e) {
         string[] args = Regex.Split(commandline.Text, @"\s+");
-        switch(args[0]) {
+        if (args.Length == 0) return;
+        string cmd = args[0];
+        string[] tmp = new string[args.Length - 1];
+        Array.Copy(args, 1, tmp, 0, tmp.Length);
+        args = tmp;
+        string query = Regex.Replace(commandline.Text, String.Format(@"^{0}\s+", cmd), "");
+
+        switch(cmd) {
         case "close":
             wt.CloseTab();
             break;
         case "open":
-            if (args.Length < 2) return;
-            wt.OpenUri(args[1]);
+            if (args.Length < 1) return;
+            if (!wt.Open(query))
+                Error("Could not open query");
             break;
         case "tabopen":
-            if (args.Length < 2) return;
-            wt.OpenUriTab(args[1]);
-            wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
+            if (args.Length < 1) return;
+            if (wt.OpenTab(query))
+                wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
+            else
+                Error("Could not open query");
             break;
         case "n":
             wt.Tabs.NextPage();
@@ -133,27 +139,28 @@ public class Vimish : WebThingPlugin {
             wt.Quit();
             break;
         case "set":
-            if (args.Length == 2)
-                Options[args[1]] = null;
+            if (args.Length == 1)
+                Options[args[0]] = null;
             else
-                Options[args[1]] = args[2];
+                Options[args[0]] = args[1];
             ApplyOptions();
             break;
+        case "save":
+            SaveConfig();
+            break;
         default:
             bool found;
-            if (args.Length > 1) {
-                string[] callargs = new string[args.Length - 1];
-                Array.Copy(args, 1, callargs, 0, args.Length - 1);
-                found = wt.Plugins.Call(args[0], callargs);
+            if (args.Length > 0) {
+                found = wt.Plugins.Call(cmd, args);
                 if (!found)
-                    Error("No function {0}({1}) found", args[0], String.Join(", ", callargs));
+                    Error("No function {0}({1}) found", cmd, String.Join(", ", args));
             } else {
-                found = wt.Plugins.Call(args[0]);
+                found = wt.Plugins.Call(cmd);
                 if (!found)
-                    Error("No function {0}() found", args[0]);
+                    Error("No function {0}() found", cmd);
             }
             if (found)
-                Console.WriteLine("Plugin function {0} called successfully", args[0]);
+                Console.WriteLine("Plugin function {0} called successfully", cmd);
             break;
         }
         CommandlineHide();