X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=WebThing.cs;h=5e2000b0882e720d020f11dc479dbba746fe45ce;hb=11835c28c3407f9bbd4aa68b875a528d13ff0d73;hp=08cfb1bae7c1a346f83183ffef81f0445db317d3;hpb=bf0210888b2c1a7eb26656fdcaec4e0559569772;p=WebThing.git diff --git a/WebThing.cs b/WebThing.cs index 08cfb1b..5e2000b 100644 --- a/WebThing.cs +++ b/WebThing.cs @@ -44,6 +44,7 @@ namespace bytex64.WebThing { private Gtk.Alignment InteriorOverlay; public PluginManager Plugins; + public SearchHandler Search; [DllImport ("SoupSettings.dll")] private static extern void soup_settings(); @@ -95,10 +96,13 @@ namespace bytex64.WebThing { Plugins = new PluginManager(this); Plugins.Load(); + // Load Search Handlers + Search = new SearchHandler(this); + // Create a new, default WebThingView if one has not already // been created. if (Tabs.NPages == 0) - OpenUriTab("http://dominionofawesome.com/"); + OpenTab("http://dominionofawesome.com/"); WebView.GrabFocus(); Application.Run(); @@ -175,20 +179,36 @@ namespace bytex64.WebThing { } // Uri loading - public string FixUri(string Uri) { - if (!Regex.IsMatch(Uri, @"://")) { - return String.Format("http://{0}", Uri); + private string GetUri(string query) { + Uri u; + try { + u = new Uri(query); + return u.ToString(); + } catch(UriFormatException) { + try { + u = new Uri(String.Format("http://{0}", query)); + return u.ToString(); + } catch (UriFormatException) { + return Search.Transform(query); + } } - return Uri; } - public void OpenUri(string Uri) { - wv.Open(FixUri(Uri)); + public bool Open(string query) { + string uri = GetUri(query); + if (uri == null) return false; + + wv.Open(uri); + return true; } - public void OpenUriTab(string Uri) { + public bool OpenTab(string query) { WebThingView wtv = NewTab(); - wtv.WebView.Open(FixUri(Uri)); + string uri = GetUri(query); + if (uri == null) return false; + + wtv.WebView.Open(uri); + return true; } } }