X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=inline;f=plugins%2FQuickSearch.cs;fp=plugins%2FQuickSearch.cs;h=60ebdf10ec1df43d9bfd287782594d071a2d51b4;hb=a7173b63fbac8673fdb4a86e59805553b08f7574;hp=0000000000000000000000000000000000000000;hpb=7fb9b863fd1a574f5402a3c00640380ee2767c95;p=WebThing.git 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; + } + } + } +}