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, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink);
25 public override void InitWebView(WebView wv) {
26 wv.KeyPressEvent += WebView_KeyPress;
29 private void Window_KeyPress(object o, KeyPressEventArgs e) {
32 CommandStart("open ");
35 CommandStart("open " + wt.WebView.MainFrame.Uri);
38 CommandStart("tabopen ");
41 CommandStart("tabopen " + wt.WebView.MainFrame.Uri);
49 private void WebView_KeyPress(object o, KeyPressEventArgs e) {
50 Console.WriteLine(e.Event.Key);
51 if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
63 wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
66 wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
69 wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
72 wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
78 wt.WebView.ExecuteScript("document.activeElement.blur()");
84 public void CommandStart(string text) {
85 commandline.Text = text;
86 commandline.GrabFocus();
87 commandline.Position = text.Length;
91 public void CommandlineShow() {
93 commandline.GrabFocus();
96 public void CommandlineHide() {
98 wt.WebView.GrabFocus();
101 private void command_Activate(object o, EventArgs e) {
102 string[] args = Regex.Split(commandline.Text, @"\s+");
108 if (args.Length < 2) return;
112 if (args.Length < 2) return;
113 wt.OpenUriTab(args[1]);
114 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
126 if (args.Length == 2)
129 SetVar(args[1], args[2]);
135 public void SetVar(string key, string val) {
138 wt.Tabs.ShowTabs = true;
141 wt.Tabs.ShowTabs = false;
144 Error("No variable {0}", key);
149 private void Error(string format, params object[] values) {
150 Console.WriteLine(format, values);
153 private void command_KeyPress(object o, KeyPressEventArgs e) {
154 if (e.Event.Key == Gdk.Key.Escape)