using System; using System.Text.RegularExpressions; using Gtk; using bytex64.WebThing; public class Plugin { WebThing wt; Gtk.Entry commandline; public Plugin(WebThing wt) { this.wt = wt; wt.WebView.KeyPressEvent += WebView_KeyPress; commandline = new Gtk.Entry(); commandline.Activated += command_Activate; commandline.KeyPressEvent += command_KeyPress; wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink); commandline.Hide(); } 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.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; } } public void CommandStart(string text) { commandline.Text = text; commandline.GrabFocus(); commandline.Position = text.Length; commandline.Show(); } 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 "open": if (args.Length < 2) return; wt.OpenUri(args[1]); break; case "q": wt.Quit(); break; } CommandlineHide(); } private void command_KeyPress(object o, KeyPressEventArgs e) { if (e.Event.Key == Gdk.Key.Escape) CommandlineHide(); } }