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) {
34 CommandStart("open ");
37 CommandStart("open " + wt.WebView.MainFrame.Uri);
40 CommandStart("tabopen ");
43 CommandStart("tabopen " + wt.WebView.MainFrame.Uri);
51 private void WebView_KeyPress(object o, KeyPressEventArgs e) {
52 Console.WriteLine(e.Event.Key);
53 if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
65 wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
68 wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
71 wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
74 wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
80 wt.WebView.ExecuteScript("document.activeElement.blur()");
86 public void CommandStart(string text) {
87 commandline.Text = text;
88 commandline.GrabFocus();
89 commandline.Position = text.Length;
93 public void CommandlineShow() {
95 commandline.GrabFocus();
98 public void CommandlineHide() {
100 wt.WebView.GrabFocus();
103 private void command_Activate(object o, EventArgs e) {
104 string[] args = Regex.Split(commandline.Text, @"\s+");
110 if (args.Length < 2) return;
114 if (args.Length < 2) return;
115 wt.OpenUriTab(args[1]);
116 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
128 if (args.Length == 2)
129 Options[args[1]] = null;
131 Options[args[1]] = args[2];
138 private void ApplyOptions() {
139 foreach (string key in Options.Keys) {
142 bool v = ParseBool(Options[key]);
143 wt.Tabs.ShowTabs = v;
146 Error("No variable {0}", key);
152 private bool ParseBool(string v) {
153 switch(v.ToLower()) {
164 private void Error(string format, params object[] values) {
165 Console.WriteLine(format, values);
168 private void command_KeyPress(object o, KeyPressEventArgs e) {
169 if (e.Event.Key == Gdk.Key.Escape)