2 using System.Text.RegularExpressions;
5 using bytex64.WebThing;
7 public class Vimish : WebThingPlugin {
11 public override void Init(WebThing wt) {
13 wt.Tabs.ShowTabs = false;
15 wt.Window.KeyPressEvent += Window_KeyPress;
17 commandline = new Gtk.Entry();
18 commandline.Activated += command_Activate;
19 commandline.KeyPressEvent += command_KeyPress;
20 wt.AttachWidget(commandline, AttachPoint.S, AttachOptions.Fill, AttachOptions.Shrink);
27 public override void InitWebView(WebView wv) {
28 wv.KeyPressEvent += WebView_KeyPress;
31 private void Window_KeyPress(object o, KeyPressEventArgs e) {
32 if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
44 CommandStart("open ");
47 CommandStart("open " + wt.WebView.MainFrame.Uri);
50 CommandStart("tabopen ");
53 CommandStart("tabopen " + wt.WebView.MainFrame.Uri);
62 private void WebView_KeyPress(object o, KeyPressEventArgs e) {
63 WebView wv = (WebView)o;
65 Console.WriteLine(e.Event.Key);
66 if (e.Event.State == Gdk.ModifierType.None) {
69 wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
72 wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
75 wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
78 wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
84 wv.ExecuteScript("document.activeElement.blur()");
90 public void CommandStart(string text) {
91 commandline.Text = text;
92 commandline.GrabFocus();
93 commandline.Position = text.Length;
97 public void CommandlineShow() {
99 commandline.GrabFocus();
102 public void CommandlineHide() {
104 wt.WebView.GrabFocus();
107 private void command_Activate(object o, EventArgs e) {
108 string[] args = Regex.Split(commandline.Text, @"\s+");
114 if (args.Length < 2) return;
118 if (args.Length < 2) return;
119 wt.OpenUriTab(args[1]);
120 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
132 if (args.Length == 2)
133 Options[args[1]] = null;
135 Options[args[1]] = args[2];
143 if (args.Length > 1) {
144 string[] callargs = new string[args.Length - 1];
145 Array.Copy(args, 1, callargs, 0, args.Length - 1);
146 found = wt.Plugins.Call(args[0], callargs);
148 Error("No function {0}({1}) found", args[0], String.Join(", ", callargs));
150 found = wt.Plugins.Call(args[0]);
152 Error("No function {0}() found", args[0]);
155 Console.WriteLine("Plugin function {0} called successfully", args[0]);
161 private void ApplyOptions() {
162 foreach (string key in Options.Keys) {
165 bool v = Config.ParseBool(Options[key]);
166 wt.Tabs.ShowTabs = v;
169 Error("No variable {0}", key);
175 private void Error(string format, params object[] values) {
176 Console.WriteLine(format, values);
179 private void command_KeyPress(object o, KeyPressEventArgs e) {
180 if (e.Event.Key == Gdk.Key.Escape)