From a875e9685526f28076048f31ed4bb279ab46abc6 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Tue, 9 Jun 2009 01:08:48 -0500 Subject: [PATCH] Added session management plugin --- Config.cs | 13 ++++++++++++ plugins/Makefile | 2 +- plugins/Session.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/Vimish.cs | 14 +------------ 4 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 plugins/Session.cs diff --git a/Config.cs b/Config.cs index ac70dc8..3ffd66d 100644 --- a/Config.cs +++ b/Config.cs @@ -226,5 +226,18 @@ namespace bytex64.WebThing { f.Close(); } + + // Data parsers + public static bool ParseBool(string v) { + switch(v.ToLower()) { + case "true": + case "t": + case "1": + case "on": + case "yes": + return true; + } + return false; + } } } diff --git a/plugins/Makefile b/plugins/Makefile index 54f3996..105e807 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 QuickSearch.dll +all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll Session.dll clean: rm -f *.dll *.mdb *.so diff --git a/plugins/Session.cs b/plugins/Session.cs new file mode 100644 index 0000000..37d848c --- /dev/null +++ b/plugins/Session.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using bytex64.WebThing; + +public class Session : WebThingPlugin { + WebThing wt; + + public override void Init(WebThing wt) { + this.wt = wt; + if (Config.Arguments.Length == 0) { + if (Config.Options.ContainsKey("Session")) { + RestoreSession(Config.Options["Session"]); + } else if (Options.ContainsKey("Default")) { + RestoreSession("Default"); + } + } + } + + public override void Deinit(WebThing wt) { + if (Options.ContainsKey("AutoSave") && Config.ParseBool(Options["AutoSave"])) { + SaveSession("Default"); + } + } + + public void RestoreSession(string SessionName) { + if (Options.ContainsKey(SessionName)) { + while (wt.Tabs.NPages > 0) { + WebThingView wtv = wt.Tabs.CurrentPageWidget as WebThingView; + wt.Tabs.Remove(wtv); + wtv.Dispose(); + } + string[] pages = Regex.Split(Options[SessionName], @"\s+"); + foreach (string page in pages) { + wt.OpenUriTab(page); + } + } else { + Console.WriteLine("Could not restore session {0} because it does not exist.", SessionName); + } + } + + public void SaveSession(string SessionName) { + List Uris = new List(); + foreach (WebThingView wtv in wt.Tabs) { + Uris.Add(wtv.WebView.MainFrame.Uri); + } + Options[SessionName] = String.Join(" ", Uris.ToArray()); + SaveConfig(); + } +} diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 4dddb6a..bcb1546 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -147,7 +147,7 @@ public class Vimish : WebThingPlugin { foreach (string key in Options.Keys) { switch(key) { case "ShowTabs": - bool v = ParseBool(Options[key]); + bool v = Config.ParseBool(Options[key]); wt.Tabs.ShowTabs = v; break; default: @@ -157,18 +157,6 @@ public class Vimish : WebThingPlugin { } } - private bool ParseBool(string v) { - switch(v.ToLower()) { - case "true": - case "t": - case "1": - case "on": - case "yes": - return true; - } - return false; - } - private void Error(string format, params object[] values) { Console.WriteLine(format, values); } -- 2.25.1