X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=plugins%2FVimish.cs;h=0b699d8c66efa098870f4bd4c66dc8ca2a816630;hb=59c54a6d56a8e161b527c980e2cb468bcf54f371;hp=bb56ed0f2fc7e7f6e6dc939a89b5a4ae98d677ea;hpb=126f2111e41f6b2595ffde1de6828ef12246e545;p=WebThing.git diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index bb56ed0..0b699d8 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -1,85 +1,157 @@ using System; using System.Text.RegularExpressions; using Gtk; +using WebKit; using bytex64.WebThing; -public class Plugin { - WebThing wt; - Gtk.Entry commandline; +public class Vimish : WebThingPlugin { + WebThing wt; + Gtk.Entry commandline; - public Plugin(WebThing wt) { - this.wt = wt; - wt.WebView.KeyPressEvent += WebView_KeyPress; + public override void Init(WebThing wt) { + this.wt = wt; + wt.Tabs.ShowTabs = false; - commandline = new Gtk.Entry(); - commandline.Activated += command_Activate; - commandline.KeyPressEvent += command_KeyPress; - wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink); + wt.Window.KeyPressEvent += Window_KeyPress; - commandline.Hide(); - } + commandline = new Gtk.Entry(); + commandline.Activated += command_Activate; + commandline.KeyPressEvent += command_KeyPress; + wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink); - private void WebView_KeyPress(object o, KeyPressEventArgs e) { - 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.t: - CommandStart("tabopen "); - break; - case Gdk.Key.BackSpace: - wt.WebView.GoBack(); - break; - case Gdk.Key.colon: - CommandlineShow(); - break; - } - } + commandline.Hide(); + } - public void CommandStart(string text) { - commandline.Text = text; - commandline.GrabFocus(); - commandline.Position = text.Length; - commandline.Show(); - } + public override void InitWebView(WebView wv) { + wv.KeyPressEvent += WebView_KeyPress; + } - public void CommandlineShow() { - commandline.Show(); - commandline.GrabFocus(); - } + 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; + } + } - public void CommandlineHide() { - commandline.Hide(); - wt.WebView.GrabFocus(); - } + 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: + wt.Tabs.NextPage(); + break; + case Gdk.Key.p: + wt.Tabs.PrevPage(); + break; + } + } else { + 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: + wt.WebView.Reload(); + break; + case Gdk.Key.Escape: + wt.WebView.ExecuteScript("document.activeElement.blur()"); + break; + } + } + } - private void command_Activate(object o, EventArgs e) { - string[] args = Regex.Split(commandline.Text, @"\s+"); - switch(args[0]) { - case "open": - if (args.Length < 2) return; - wt.WebView.Open(args[1]); - break; - } - commandline.Text = ""; - CommandlineHide(); - } + public void CommandStart(string text) { + commandline.Text = text; + commandline.GrabFocus(); + commandline.Position = text.Length; + commandline.Show(); + } - private void command_KeyPress(object o, KeyPressEventArgs e) { - if (e.Event.Key == Gdk.Key.Escape) - CommandlineHide(); - } + public void CommandlineShow() { + commandline.Show(); + commandline.GrabFocus(); + } + + public void CommandlineHide() { + commandline.Hide(); + wt.WebView.GrabFocus(); + } + + 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) + SetVar(args[1], ""); + else + SetVar(args[1], args[2]); + 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 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(); + } }