From a6dc99253fbbdb91c53fbbe13a5231f8f19c6c7b Mon Sep 17 00:00:00 2001 From: Tim Young Date: Mon, 31 Jul 2017 12:08:01 -0500 Subject: [PATCH] parts for storing a file history list --- EduNetworkBuilder/NBSettings.cs | 38 +++++++++++++++++++ .../Properties/Settings.Designer.cs | 13 ++++++- .../Properties/Settings.settings | 3 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/EduNetworkBuilder/NBSettings.cs b/EduNetworkBuilder/NBSettings.cs index 308a680..4467aa8 100644 --- a/EduNetworkBuilder/NBSettings.cs +++ b/EduNetworkBuilder/NBSettings.cs @@ -18,8 +18,11 @@ namespace EduNetworkBuilder /// public class NBSettings { + protected bool BelongsToUser = false; + public int FileHistoryCount = 5; public string LastPath = ""; public List ScoreList = new List(); + public List RecentFiles = new List(); public bool AutoStartPuzzles = true; public string ChosenLanguage = "en"; public bool LanguageHasBeenChosen = false; @@ -33,6 +36,7 @@ namespace EduNetworkBuilder public NBSettings() { //We need this for reflection + BelongsToUser = true; //Only true when using reflection (serialization) } public NBSettings(NBSettings fromSettings) { @@ -47,6 +51,8 @@ namespace EduNetworkBuilder // if (Properties.Settings.Default.ScoreList == null) Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection(); + if (Properties.Settings.Default.RecentFiles == null) + Properties.Settings.Default.RecentFiles = new System.Collections.Specialized.StringCollection(); ToClass.LastPath = FromClass.LastPath; ToClass.AutoStartPuzzles = FromClass.AutoStartPuzzles; @@ -56,12 +62,19 @@ namespace EduNetworkBuilder ToClass.MainWindowY = FromClass.MainWindowY; ToClass.MainWindowHeight = FromClass.MainWindowHeight; ToClass.MainWindowWidth = FromClass.MainWindowWidth; + ToClass.BelongsToUser = FromClass.BelongsToUser; foreach (string one in FromClass.ScoreList) { if (!ToClass.ScoreList.Contains(one)) ToClass.ScoreList.Add(one); } + foreach (string one in FromClass.RecentFiles) + { + if (!ToClass.RecentFiles.Contains(one)) + ToClass.RecentFiles.Add(one); + } + } public NBSettings(bool UsingMono) @@ -90,6 +103,8 @@ namespace EduNetworkBuilder { if (Properties.Settings.Default.ScoreList == null) Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection(); + if (Properties.Settings.Default.RecentFiles == null) + Properties.Settings.Default.RecentFiles = new System.Collections.Specialized.StringCollection(); LastPath = Properties.Settings.Default.LastPath; AutoStartPuzzles = Properties.Settings.Default.AutoStartPuzzles; @@ -135,6 +150,28 @@ namespace EduNetworkBuilder return Path.Combine(BaseDir, FileName); } + public void RegisterFileAsLoaded(string FilenameWithPath) + { + //Remove it from these settings + if (RecentFiles.Contains(FilenameWithPath)) RecentFiles.Remove(FilenameWithPath); + RecentFiles.Insert(0,FilenameWithPath); + if(RecentFiles.Count > FileHistoryCount) + for (int index = RecentFiles.Count - 1; index >= FileHistoryCount; index--) + RecentFiles.RemoveAt(index); + + if (!NB.IsRunningOnMono()) + { + if (Properties.Settings.Default.RecentFiles.Contains(FilenameWithPath)) + Properties.Settings.Default.RecentFiles.Remove(FilenameWithPath); + Properties.Settings.Default.RecentFiles.Insert(0, FilenameWithPath); + if (Properties.Settings.Default.RecentFiles.Count > FileHistoryCount) + { + for (int index = Properties.Settings.Default.RecentFiles.Count - 1; index >= FileHistoryCount; index--) + Properties.Settings.Default.RecentFiles.RemoveAt(index); + } + Properties.Settings.Default.Save(); + } + } public void Save() { @@ -187,6 +224,7 @@ namespace EduNetworkBuilder { Properties.Settings.Default.ScoreList.Add(One); } + Properties.Settings.Default.Save(); } } diff --git a/EduNetworkBuilder/Properties/Settings.Designer.cs b/EduNetworkBuilder/Properties/Settings.Designer.cs index dcdb7af..6767089 100644 --- a/EduNetworkBuilder/Properties/Settings.Designer.cs +++ b/EduNetworkBuilder/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace EduNetworkBuilder.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -141,5 +141,16 @@ namespace EduNetworkBuilder.Properties { this["ProcessingLevel"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection RecentFiles { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["RecentFiles"])); + } + set { + this["RecentFiles"] = value; + } + } } } diff --git a/EduNetworkBuilder/Properties/Settings.settings b/EduNetworkBuilder/Properties/Settings.settings index 1dd92c8..5698311 100644 --- a/EduNetworkBuilder/Properties/Settings.settings +++ b/EduNetworkBuilder/Properties/Settings.settings @@ -32,5 +32,8 @@ none + + + \ No newline at end of file