Added session management plugin
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;
+ }
}
}
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
+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<string> Uris = new List<string>();
+ foreach (WebThingView wtv in wt.Tabs) {
+ Uris.Add(wtv.WebView.MainFrame.Uri);
+ }
+ Options[SessionName] = String.Join(" ", Uris.ToArray());
+ SaveConfig();
+ }
+}
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:
}
}
- 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);
}