From: Chip Black Date: Tue, 9 Jun 2009 04:05:34 +0000 (-0500) Subject: Add QuickSearch plugin X-Git-Url: http://git.bytex64.net/?a=commitdiff_plain;h=a7173b63fbac8673fdb4a86e59805553b08f7574;hp=7fb9b863fd1a574f5402a3c00640380ee2767c95;p=WebThing.git Add QuickSearch plugin --- diff --git a/plugins/Makefile b/plugins/Makefile index b122c20..54f3996 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -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 index 0000000..60ebdf1 --- /dev/null +++ b/plugins/QuickSearch.cs @@ -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; + } + } + } +}