Fix scrolling functionality
[WebThing.git] / plugins / FFNav.cs
index 1a3145c..15d3504 100644 (file)
@@ -1,31 +1,70 @@
 using System;
 using Gtk;
+using WebKit;
 using bytex64.WebThing;
 
-public class Plugin {
-       WebThing wt;
+public class FFNav : WebThingPlugin {
+    WebThing wt;
 
-       public Plugin(WebThing wt) {
-               this.wt = wt;
-               wt.WebView.KeyPressEvent += WebView_KeyPress;
-       }
+    public override void Init(WebThing wt) {
+        this.wt = wt;
 
-       private void WebView_KeyPress(object o, KeyPressEventArgs e) {
-               if ((e.Event.State & Gdk.ModifierType.Mod1Mask) != 0) {
-                       switch(e.Event.Key) {
-                       case Gdk.Key.Left:
-                               wt.WebView.GoBack();
-                               break;
-                       case Gdk.Key.Right:
-                               wt.WebView.GoForward();
-                               break;
-                       }
-               } else {
-                       switch(e.Event.Key) {
-                       case Gdk.Key.BackSpace:
-                               wt.WebView.GoBack();
-                               break;
-                       }
-               }
-       }
+        wt.Window.KeyPressEvent += Window_KeyPress;
+    }
+
+    public override void InitWebView(WebView wv) {
+        wv.KeyPressEvent += WebView_KeyPress;
+    }
+
+    private void Window_KeyPress(object o, KeyPressEventArgs e) {
+        if ((e.Event.State & Gdk.ModifierType.ControlMask) != 0) {
+            switch(e.Event.Key) {
+            case Gdk.Key.t:
+                wt.NewTab();
+                wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
+                break;
+            case Gdk.Key.w:
+                wt.CloseTab();
+                break;
+            }
+        }
+    }
+
+    private void WebView_KeyPress(object o, KeyPressEventArgs e) {
+        WebView wv = (WebView) o;
+        if ((e.Event.State & Gdk.ModifierType.Mod1Mask) != 0) {
+            switch(e.Event.Key) {
+            case Gdk.Key.Left:
+                wv.GoBack();
+                break;
+            case Gdk.Key.Right:
+                wv.GoForward();
+                break;
+            }
+        } else if ((e.Event.State & Gdk.ModifierType.ControlMask) != 0) {
+            switch(e.Event.Key) {
+            case Gdk.Key.ISO_Left_Tab:
+                if (wt.Tabs.CurrentPage == 0)
+                    wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
+                else
+                    wt.Tabs.PrevPage();
+                break;
+            case Gdk.Key.Tab:
+                if (wt.Tabs.CurrentPage == wt.Tabs.NPages - 1)
+                    wt.Tabs.CurrentPage = 0;
+                else
+                    wt.Tabs.NextPage();
+                break;
+            }
+        } else {
+            switch(e.Event.Key) {
+            case Gdk.Key.BackSpace:
+                wv.GoBack();
+                break;
+            case Gdk.Key.Escape:
+                wv.StopLoading();
+                break;
+            }
+        }
+    }
 }