Index: src/DeltaShell/DeltaShell.Gui/GuiCommandHandler.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -rdd8fa121d83cc3dd233c4a44d27d9683180f844b --- src/DeltaShell/DeltaShell.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/DeltaShell/DeltaShell.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision dd8fa121d83cc3dd233c4a44d27d9683180f844b) @@ -5,7 +5,6 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Threading; using System.Windows.Forms; using System.Windows.Forms.Integration; using System.Windows.Input; @@ -16,7 +15,6 @@ using DelftTools.Utils; using DelftTools.Utils.Aop; using DelftTools.Utils.Collections; -using DeltaShell.Core; using DeltaShell.Gui.Forms; using DeltaShell.Gui.Forms.MainWindow; using DeltaShell.Gui.Forms.ViewManager; @@ -46,6 +44,21 @@ guiExportHandler = CreateGuiExportHandler(); } + public void TryCreateNewWTIProject() + { + if (!TryCloseWTIProject()) + { + Log.Warn(Resources.Opening_new_wti_project_cancelled); + return; + } + + Log.Info(Resources.Opening_new_wti_project); + gui.Application.CreateNewProject(); + Log.Info(Resources.New_wti_project_successfully_opened); + + RefreshGui(); + } + public bool TryOpenExistingWTIProject() { var openFileDialog = new OpenFileDialog @@ -78,71 +91,16 @@ ProgressBarDialog.PerformTask(Resources.Loading_wti_project_from_selected_file, () => result = gui.Application.OpenProject(filePath)); - RefreshMainWindowTitle(); + RefreshGui(); return result; } - public IProjectItem GetProjectItemForActiveView() - { - var activeView = gui.DocumentViews.ActiveView; - if (activeView == null || activeView.Data == null) - { - return null; - } - - var projectItemActiveView = activeView.Data as IProjectItem; - if (projectItemActiveView != null) - { - return projectItemActiveView; - } - - return null; - } - - /// - /// Create new project in the temporary path. - /// - /// - public void CreateNewProject() - { - while (DeltaShellApplication.TemporaryProjectBeingSaved) // called second time, wait ... - { - Application.DoEvents(); - Thread.Sleep(250); - } - - if (gui.Application.Project != null) - { - if (!TryCloseWTIProject()) - { - return; - } - } - - gui.Application.CreateNewProject(); - - if (DeltaShellApplication.TemporaryProjectSavedAsynchroneously) - { - while (!DeltaShellApplication.TemporaryProjectSaved) - { - Application.DoEvents(); - Thread.Sleep(250); - } - } - - gui.Selection = gui.Application.Project; - - RefreshMainWindowTitle(); - } - public bool TryCloseWTIProject() { - gui.Selection = null; - if (gui.Application.Project != null) { - Log.Info(Resources.GuiCommandHandler_CloseProject_Closing_current_project____); + Log.Info("Closing current WTI project."); // Ask to save any changes first if (gui.Application.Project.IsChanged) @@ -158,11 +116,12 @@ if (alwaysOkResult != DialogResult.OK) { if (!SaveProject()) - return false; - AddProjectToMruListIfNotYetAdded(); + { + + } } } - + if (result == DialogResult.Cancel) { return false; @@ -182,13 +141,31 @@ gui.Application.CloseProject(); - RefreshMainWindowTitle(); + RefreshGui(); Log.Info(Resources.GuiCommandHandler_CloseProject_Project_closed); } + return true; } + public IProjectItem GetProjectItemForActiveView() + { + var activeView = gui.DocumentViews.ActiveView; + if (activeView == null || activeView.Data == null) + { + return null; + } + + var projectItemActiveView = activeView.Data as IProjectItem; + if (projectItemActiveView != null) + { + return projectItemActiveView; + } + + return null; + } + public bool SaveProject() { var project = gui.Application.Project; @@ -204,8 +181,11 @@ UnselectActiveControlToForceBinding(); SaveProjectWithProgressDialog(path); - RefreshMainWindowTitle(); + AddProjectToMruList(); + + RefreshGui(); + return true; } @@ -251,8 +231,10 @@ return false; } - RefreshMainWindowTitle(); + AddProjectToMruList(); + RefreshGui(); + return true; } @@ -516,13 +498,15 @@ } } - private void AddProjectToMruListIfNotYetAdded() + private void AddProjectToMruList() { - if (gui.Application.Project.IsTemporary) //first save, so not yet added to mru list before + var mruList = (StringCollection) Settings.Default["mruList"]; + if (mruList.Contains(gui.Application.ProjectFilePath)) { - var mruList = (StringCollection) Settings.Default["mruList"]; - mruList.Add(gui.Application.ProjectFilePath); + mruList.Remove(gui.Application.ProjectFilePath); } + + mruList.Insert(0, gui.Application.ProjectFilePath); } private static void UnselectActiveControlToForceBinding() @@ -609,7 +593,7 @@ return; } - RefreshMainWindowTitle(); + RefreshGui(); } [InvokeRequired] @@ -623,14 +607,17 @@ } [InvokeRequired] - private void RefreshMainWindowTitle() + private void RefreshGui() { - string mainWindowTitle = gui.Application.Settings != null - ? gui.Application.Settings["mainWindowTitle"] - : "DeltaShell"; - var project = gui.Application.Project; + // Set the gui selection to the current project + gui.Selection = gui.Application.Project; + + var mainWindowTitle = gui.Application.Settings != null + ? gui.Application.Settings["mainWindowTitle"] + : "DeltaShell"; + if (project == null) { gui.MainWindow.Title = string.Format(Resources.GuiCommandHandler_UpdateGui__no_project_opened_____0_, mainWindowTitle);