X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=plugins%2FVimish.cs;h=27543eeadb0f15569eaefe7cb1c34f1150a9633b;hb=02acfc22dbfa3d145d265157fdf616a950fa30c6;hp=7acdad2dcb0d905250324d8b66ebcd76733c1a98;hpb=80865e6b884a4bb289cb4a835a6fa66b3529c872;p=WebThing.git diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 7acdad2..27543ee 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -1,54 +1,93 @@ using System; using System.Text.RegularExpressions; using Gtk; +using WebKit; using bytex64.WebThing; public class Vimish : WebThingPlugin { WebThing wt; Gtk.Entry commandline; - public void Init(WebThing wt) { + public override void Init(WebThing wt) { this.wt = wt; - wt.WebView.KeyPressEvent += WebView_KeyPress; + 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) { + 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) { + case Gdk.Key.n: + wt.Tabs.NextPage(); + break; + case Gdk.Key.p: + wt.Tabs.PrevPage(); + 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); - switch(e.Event.Key) { - case Gdk.Key.j: - wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement; - break; - case Gdk.Key.k: - wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement; - break; - case Gdk.Key.l: - wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement; - break; - case Gdk.Key.h: - wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement; - break; - case Gdk.Key.o: - CommandStart("open "); - break; - case Gdk.Key.r: - wt.WebView.Reload(); - break; - case Gdk.Key.t: - CommandStart("tabopen "); - break; - case Gdk.Key.colon: - CommandlineShow(); - break; - case Gdk.Key.Escape: - wt.WebView.ExecuteScript("document.activeElement.blur()"); - break; + if (e.Event.State == Gdk.ModifierType.None) { + switch(e.Event.Key) { + case Gdk.Key.j: + wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement; + break; + case Gdk.Key.k: + wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement; + break; + case Gdk.Key.l: + wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement; + break; + case Gdk.Key.h: + wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement; + break; + case Gdk.Key.r: + wv.Reload(); + break; + case Gdk.Key.Escape: + wv.ExecuteScript("document.activeElement.blur()"); + break; + } } } @@ -72,17 +111,72 @@ public class Vimish : WebThingPlugin { private void command_Activate(object o, EventArgs e) { string[] args = Regex.Split(commandline.Text, @"\s+"); switch(args[0]) { + case "close": + wt.CloseTab(); + break; case "open": if (args.Length < 2) return; wt.OpenUri(args[1]); break; + case "tabopen": + if (args.Length < 2) return; + wt.OpenUriTab(args[1]); + wt.Tabs.CurrentPage = wt.Tabs.NPages - 1; + break; + case "n": + wt.Tabs.NextPage(); + break; + case "p": + wt.Tabs.PrevPage(); + break; case "q": wt.Quit(); break; + case "set": + if (args.Length == 2) + Options[args[1]] = null; + else + Options[args[1]] = args[2]; + ApplyOptions(); + 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 (!found) + Error("No function {0}({1}) found", args[0], String.Join(", ", callargs)); + } else { + found = wt.Plugins.Call(args[0]); + if (!found) + Error("No function {0}() found", args[0]); + } + if (found) + Console.WriteLine("Plugin function {0} called successfully", args[0]); + break; } CommandlineHide(); } + private void ApplyOptions() { + foreach (string key in Options.Keys) { + switch(key) { + case "ShowTabs": + bool v = Config.ParseBool(Options[key]); + wt.Tabs.ShowTabs = v; + break; + default: + Error("No variable {0}", key); + break; + } + } + } + + 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();