X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=plugins%2FVimish.cs;h=51c2cfcb769b016c5fa5a0d2648967188ce4db4c;hb=11835c28c3407f9bbd4aa68b875a528d13ff0d73;hp=0b699d8c66efa098870f4bd4c66dc8ca2a816630;hpb=59c54a6d56a8e161b527c980e2cb468bcf54f371;p=WebThing.git diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 0b699d8..51c2cfc 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -17,9 +17,11 @@ public class Vimish : WebThingPlugin { 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) { @@ -27,27 +29,6 @@ public class Vimish : WebThingPlugin { } 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; - } - } - - 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: @@ -58,6 +39,31 @@ public class Vimish : WebThingPlugin { 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); + if (e.Event.State == Gdk.ModifierType.None) { switch(e.Event.Key) { case Gdk.Key.j: wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement; @@ -72,10 +78,10 @@ public class Vimish : WebThingPlugin { wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement; break; case Gdk.Key.r: - wt.WebView.Reload(); + wv.Reload(); break; case Gdk.Key.Escape: - wt.WebView.ExecuteScript("document.activeElement.blur()"); + wv.ExecuteScript("document.activeElement.blur()"); break; } } @@ -100,18 +106,28 @@ public class Vimish : WebThingPlugin { private void command_Activate(object o, EventArgs e) { string[] args = Regex.Split(commandline.Text, @"\s+"); - switch(args[0]) { + if (args.Length == 0) return; + string cmd = args[0]; + string[] tmp = new string[args.Length - 1]; + Array.Copy(args, 1, tmp, 0, tmp.Length); + args = tmp; + string query = Regex.Replace(commandline.Text, String.Format(@"^{0}\s+", cmd), ""); + + switch(cmd) { case "close": wt.CloseTab(); break; case "open": - if (args.Length < 2) return; - wt.OpenUri(args[1]); + if (args.Length < 1) return; + if (!wt.Open(query)) + Error("Could not open query"); break; case "tabopen": - if (args.Length < 2) return; - wt.OpenUriTab(args[1]); - wt.Tabs.CurrentPage = wt.Tabs.NPages - 1; + if (args.Length < 1) return; + if (wt.OpenTab(query)) + wt.Tabs.CurrentPage = wt.Tabs.NPages - 1; + else + Error("Could not open query"); break; case "n": wt.Tabs.NextPage(); @@ -123,26 +139,44 @@ public class Vimish : WebThingPlugin { wt.Quit(); break; case "set": - if (args.Length == 2) - SetVar(args[1], ""); + if (args.Length == 1) + Options[args[0]] = null; else - SetVar(args[1], args[2]); + Options[args[0]] = args[1]; + ApplyOptions(); + break; + case "save": + SaveConfig(); + break; + default: + bool found; + if (args.Length > 0) { + found = wt.Plugins.Call(cmd, args); + if (!found) + Error("No function {0}({1}) found", cmd, String.Join(", ", args)); + } else { + found = wt.Plugins.Call(cmd); + if (!found) + Error("No function {0}() found", cmd); + } + if (found) + Console.WriteLine("Plugin function {0} called successfully", cmd); 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 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; + } } }