Rearrange initialization to be clearer and shorter
[WebThing.git] / plugins / FFNav.cs
1 using System;
2 using Gtk;
3 using WebKit;
4 using bytex64.WebThing;
5
6 public class FFNav : WebThingPlugin {
7     WebThing wt;
8
9     public override void Init(WebThing wt) {
10         this.wt = wt;
11     }
12
13     public override void InitWebView(WebView wv) {
14         wv.KeyPressEvent += WebView_KeyPress;
15     }
16
17     private void WebView_KeyPress(object o, KeyPressEventArgs e) {
18         WebView wv = (WebView) o;
19         if ((e.Event.State & Gdk.ModifierType.Mod1Mask) != 0) {
20             switch(e.Event.Key) {
21             case Gdk.Key.Left:
22                 wv.GoBack();
23                 break;
24             case Gdk.Key.Right:
25                 wv.GoForward();
26                 break;
27             }
28         } else if ((e.Event.State & Gdk.ModifierType.ControlMask) != 0) {
29             switch(e.Event.Key) {
30             case Gdk.Key.t:
31                 wt.NewTab();
32                 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
33                 break;
34             case Gdk.Key.w:
35                 wt.CloseTab();
36                 break;
37             case Gdk.Key.ISO_Left_Tab:
38                 if (wt.Tabs.CurrentPage == 0)
39                     wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
40                 else
41                     wt.Tabs.PrevPage();
42                 break;
43             case Gdk.Key.Tab:
44                 if (wt.Tabs.CurrentPage == wt.Tabs.NPages - 1)
45                     wt.Tabs.CurrentPage = 0;
46                 else
47                     wt.Tabs.NextPage();
48                 break;
49             }
50         } else {
51             switch(e.Event.Key) {
52             case Gdk.Key.BackSpace:
53                 wv.GoBack();
54                 break;
55             }
56         }
57     }
58 }