X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=WebThing.cs;h=ff5135467b97ddbbd81d411c4e787fd0e61fe450;hb=2744fefc32dbe9b59a570f6515d51121b8fcfbe3;hp=fd2eb991ab38e8f83f1cb78e92ee843b53f47742;hpb=924fc4da5643fb24b86a1a61e5a04649e6623979;p=WebThing.git diff --git a/WebThing.cs b/WebThing.cs index fd2eb99..ff51354 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(); @@ -64,6 +65,21 @@ namespace bytex64.WebThing { // based on the executable name, which I don't like. _Window.SetWmclass("webthing", "WebThing"); _Window.Role = "browser"; + { + int w, h; + + if (Config.Options.ContainsKey("Width")) + w = Convert.ToInt32(Config.Options["Width"]); + else + w = 640; + + if (Config.Options.ContainsKey("Height")) + h = Convert.ToInt32(Config.Options["Height"]); + else + h = 480; + + _Window.DefaultSize = new Gdk.Size(w, h); + } _Window.Destroyed += delegate { Quit(); }; // Initialize WidgetGrid @@ -95,17 +111,20 @@ 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(); } public void Quit() { - // TODO: Create a way of shutting down plugins + Plugins.Deinit(); Application.Quit(); } @@ -175,20 +194,49 @@ 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; + } + + public void Scroll(double x, double y) { + ScrolledWindow.Hadjustment.Value += x; + if (ScrolledWindow.Hadjustment.Value > ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize) + ScrolledWindow.Hadjustment.Value = ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize; + ScrolledWindow.Vadjustment.Value += y; + if (ScrolledWindow.Vadjustment.Value > ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize) + ScrolledWindow.Vadjustment.Value = ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize; + } + + public void Bump(int x, int y) { + Scroll(x * ScrolledWindow.Hadjustment.StepIncrement, y * ScrolledWindow.Vadjustment.StepIncrement); } } }