Add QuickSearch plugin
authorChip Black <bytex64@bytex64.net>
Tue, 9 Jun 2009 04:05:34 +0000 (23:05 -0500)
committerChip Black <bytex64@bytex64.net>
Tue, 9 Jun 2009 04:05:34 +0000 (23:05 -0500)
plugins/Makefile
plugins/QuickSearch.cs [new file with mode: 0644]

index b122c20..54f3996 100644 (file)
@@ -1,7 +1,7 @@
 CSFLAGS = -debug
 references = -r:../webkit-sharp.dll -pkg:gtk-sharp-2.0
 
-all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll
+all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll
 
 clean:
        rm -f *.dll *.mdb *.so
diff --git a/plugins/QuickSearch.cs b/plugins/QuickSearch.cs
new file mode 100644 (file)
index 0000000..60ebdf1
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+using Gtk;
+using bytex64.WebThing;
+
+public class QuickSearch : WebThingPlugin {
+    WebThing wt;
+    Gtk.Entry SearchEntry;
+
+    public override void Init(WebThing wt) {
+        SearchEntry = new Gtk.Entry();
+        SearchEntry.KeyPressEvent += SearchEntry_KeyPress;
+        SearchEntry.Changed += SearchEntry_Changed;
+        SearchEntry.Activated += SearchEntry_Activated;
+        wt.AttachWidget(SearchEntry, AttachPoint.S, AttachOptions.Fill, AttachOptions.Shrink);
+
+        wt.Window.KeyPressEvent += Window_KeyPress;
+        this.wt = wt;
+    }
+
+    private void Window_KeyPress(object o, Gtk.KeyPressEventArgs e) {
+        if (e.Event.State == Gdk.ModifierType.None &&
+            e.Event.Key == Gdk.Key.slash) {
+            SearchEntry.Show();
+            SearchEntry.GrabFocus();
+        }
+    }
+
+    private void SearchEntry_Changed(object o, EventArgs e) {
+        Console.WriteLine("Search {0}", SearchEntry.Text);
+        wt.WebView.SearchText(SearchEntry.Text, false, true, true);
+    }
+
+    private void SearchEntry_Activated(object o, EventArgs e) {
+        SearchEntry.Hide();
+        wt.WebView.GrabFocus();
+    }
+
+    private void SearchEntry_KeyPress(object o, Gtk.KeyPressEventArgs e) {
+        if ((e.Event.State & Gdk.ModifierType.ControlMask) != 0) {
+            switch(e.Event.Key) {
+            case Gdk.Key.g:
+                wt.WebView.SearchText(SearchEntry.Text, false, true, true);
+                break;
+            }
+        } else {
+            switch(e.Event.Key) {
+            case Gdk.Key.Escape:
+            case Gdk.Key.Return:
+                SearchEntry.Hide();
+                wt.WebView.GrabFocus();
+                break;
+            }
+        }
+    }
+}