parts for storing a file history list

This commit is contained in:
Tim Young 2017-07-31 12:08:01 -05:00
parent cc6b5321d6
commit a6dc99253f
3 changed files with 53 additions and 1 deletions

View File

@ -18,8 +18,11 @@ namespace EduNetworkBuilder
/// </summary>
public class NBSettings
{
protected bool BelongsToUser = false;
public int FileHistoryCount = 5;
public string LastPath = "";
public List<string> ScoreList = new List<string>();
public List<string> RecentFiles = new List<string>();
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();
}
}

View File

@ -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;
}
}
}
}

View File

@ -32,5 +32,8 @@
<Setting Name="ProcessingLevel" Type="System.String" Scope="User">
<Value Profile="(Default)">none</Value>
</Setting>
<Setting Name="RecentFiles" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>