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+");
109 if (args.Length == 0) return;
110 string cmd = args[0];
111 string[] tmp = new string[args.Length - 1];
112 Array.Copy(args, 1, tmp, 0, tmp.Length);
114 string query = Regex.Replace(commandline.Text, String.Format(@"^{0}\s+", cmd), "");
121 if (args.Length < 1) return;
123 Error("Could not open query");
126 if (args.Length < 1) return;
127 if (wt.OpenTab(query))
128 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
130 Error("Could not open query");
142 if (args.Length == 1)
143 Options[args[0]] = null;
145 Options[args[0]] = args[1];
153 if (args.Length > 0) {
154 found = wt.Plugins.Call(cmd, args);
156 Error("No function {0}({1}) found", cmd, String.Join(", ", args));
158 found = wt.Plugins.Call(cmd);
160 Error("No function {0}() found", cmd);
163 Console.WriteLine("Plugin function {0} called successfully", cmd);
169 private void ApplyOptions() {
170 foreach (string key in Options.Keys) {
173 bool v = Config.ParseBool(Options[key]);
174 wt.Tabs.ShowTabs = v;
177 Error("No variable {0}", key);
183 private void Error(string format, params object[] values) {
184 Console.WriteLine(format, values);
187 private void command_KeyPress(object o, KeyPressEventArgs e) {
188 if (e.Event.Key == Gdk.Key.Escape)