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
+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;
+ }
+ }
+ }
+}