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];
142 private void ApplyOptions() {
143 foreach (string key in Options.Keys) {
146 bool v = ParseBool(Options[key]);
147 wt.Tabs.ShowTabs = v;
150 Error("No variable {0}", key);
156 private bool ParseBool(string v) {
157 switch(v.ToLower()) {
168 private void Error(string format, params object[] values) {
169 Console.WriteLine(format, values);
172 private void command_KeyPress(object o, KeyPressEventArgs e) {
173 if (e.Event.Key == Gdk.Key.Escape)