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 public override void Deinit(WebThing wt) {
35 private void Window_KeyPress(object o, KeyPressEventArgs e) {
36 if ((Gdk.ModifierType.ControlMask & e.Event.State) != 0) {
48 CommandStart("open ");
51 CommandStart("open " + wt.WebView.MainFrame.Uri);
54 CommandStart("tabopen ");
57 CommandStart("tabopen " + wt.WebView.MainFrame.Uri);
66 private void WebView_KeyPress(object o, KeyPressEventArgs e) {
67 WebView wv = (WebView)o;
69 Console.WriteLine(e.Event.Key);
70 if (e.Event.State == Gdk.ModifierType.None) {
73 wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
76 wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
79 wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
82 wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
88 wv.ExecuteScript("document.activeElement.blur()");
94 public void CommandStart(string text) {
95 commandline.Text = text;
96 commandline.GrabFocus();
97 commandline.Position = text.Length;
101 public void CommandlineShow() {
103 commandline.GrabFocus();
106 public void CommandlineHide() {
108 wt.WebView.GrabFocus();
111 private void command_Activate(object o, EventArgs e) {
112 string[] args = Regex.Split(commandline.Text, @"\s+");
118 if (args.Length < 2) return;
122 if (args.Length < 2) return;
123 wt.OpenUriTab(args[1]);
124 wt.Tabs.CurrentPage = wt.Tabs.NPages - 1;
136 if (args.Length == 2)
137 Options[args[1]] = null;
139 Options[args[1]] = args[2];
146 private void ApplyOptions() {
147 foreach (string key in Options.Keys) {
150 bool v = ParseBool(Options[key]);
151 wt.Tabs.ShowTabs = v;
154 Error("No variable {0}", key);
160 private bool ParseBool(string v) {
161 switch(v.ToLower()) {
172 private void Error(string format, params object[] values) {
173 Console.WriteLine(format, values);
176 private void command_KeyPress(object o, KeyPressEventArgs e) {
177 if (e.Event.Key == Gdk.Key.Escape)