From a7173b63fbac8673fdb4a86e59805553b08f7574 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Mon, 8 Jun 2009 23:05:34 -0500 Subject: [PATCH] Add QuickSearch plugin --- plugins/Makefile | 2 +- plugins/QuickSearch.cs | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 plugins/QuickSearch.cs 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; + } + } + } +} -- 2.25.1