From b7b55254135936e012b0f0486ac6a648f33beaf9 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Mon, 31 Jul 2017 13:39:46 -0500 Subject: [PATCH] Working on recent file load system --- EduNetworkBuilder/NBSettings.cs | 18 ++++++++++++++++++ EduNetworkBuilder/NetworkBuilder.cs | 28 +++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/EduNetworkBuilder/NBSettings.cs b/EduNetworkBuilder/NBSettings.cs index 4467aa8..df98617 100644 --- a/EduNetworkBuilder/NBSettings.cs +++ b/EduNetworkBuilder/NBSettings.cs @@ -173,6 +173,24 @@ namespace EduNetworkBuilder } } + public List GetRecentFiles() + { + //If we do not have a user and are not using mono, grab the settings from properties.settings + //Otherwise, we grab the settings from this settings object + List TheFiles = new List(); + if(NB.GetUser() == null && !NB.IsRunningOnMono()) + { + foreach (string one in Properties.Settings.Default.RecentFiles) + TheFiles.Add(one); + } + else + { + //This is the repository of recent files. Use it + TheFiles.AddRange(RecentFiles); + } + return TheFiles; + } + public void Save() { Save(NB.IsRunningOnMono()); diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index e6cd35b..009d01f 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -404,6 +404,21 @@ namespace EduNetworkBuilder addToClassworkToolStripMenuItem.Visible = false; else addToClassworkToolStripMenuItem.Visible = true; + + List tLoadList = new List(); + loadToolStripMenuItem.DropDownItems.Clear(); + if(OurSettings != null) + { + foreach (string one in OurSettings.GetRecentFiles()) + { + if (tLoadList.Contains(one)) continue; + string JustFile = Path.GetFileName(one); + int i = loadToolStripMenuItem.DropDownItems.Count; + loadToolStripMenuItem.DropDownItems.Add(JustFile, null, loadRecentFilename); + loadToolStripMenuItem.DropDownItems[i].Name = one; + tLoadList.Add(one); + } + } } public void UpdateLinks() @@ -1666,18 +1681,29 @@ namespace EduNetworkBuilder } else if(extension == ".enbu") { CurrentUser = new PersonClass(filename); + OurSettings = NB.GetSettings(); //Grab the new settings from the user UpdateMenu(); //Now, open a new window to edit them. PersonProfileForm PPF = new PersonProfileForm(CurrentUser); - CurrentUser = PPF.Edit(); + CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu. UpdateMenu(); } else { MessageBox.Show(NB.Translate("NB_InvalidFile")); Close(); + return; //We return here so we do not register the filename... } + if (OurSettings != null) OurSettings.RegisterFileAsLoaded(filename); + } + + private void loadRecentFilename(object sender, EventArgs e) + { + //find the full filename & load that. + ToolStripDropDownItem TSDDI = (ToolStripDropDownItem)sender; + LoadInitialFile(TSDDI.Name); + UpdateMenu(); } private void BuilderWindow_Load(object sender, EventArgs e)