From c87d79ec9ed7ba07d787716a05883436a7ee9606 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 21 Jun 2019 16:27:58 -0700 Subject: [PATCH] Wire up Open, Save, and Save As These just needed to have methods added to the command definitions. Also, added a style to the toolbar buttons so they fade when not enabled. Also, fixed the DataFileLoadIssue dialog, which was seriously broken. --- SourceGenWPF/MainController.cs | 47 +++++++++++-------- SourceGenWPF/Res/CommandIcons.xaml | 31 +++++++++--- SourceGenWPF/WpfGui/DataFileLoadIssue.xaml | 30 +++++------- SourceGenWPF/WpfGui/DataFileLoadIssue.xaml.cs | 16 +++---- SourceGenWPF/WpfGui/MainWindow.xaml | 18 +++++-- SourceGenWPF/WpfGui/MainWindow.xaml.cs | 26 +++++++--- 6 files changed, 104 insertions(+), 64 deletions(-) diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 7c2b760..f169b58 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -772,7 +772,7 @@ namespace SourceGenWPF { /// /// Handles opening an existing project by letting the user select the project file. /// - private void DoOpen() { + public void OpenProject() { if (!CloseProject()) { return; } @@ -941,7 +941,11 @@ namespace SourceGenWPF { return newPath; } - private bool DoSaveAs() { + /// + /// Saves the project, querying for the filename. + /// + /// True on success, false if the save attempt failed or was canceled. + public bool SaveProjectAs() { SaveFileDialog fileDlg = new SaveFileDialog() { Filter = ProjectFile.FILENAME_FILTER + "|" + Res.Strings.FILE_FILTER_ALL, FilterIndex = 1, @@ -949,30 +953,33 @@ namespace SourceGenWPF { AddExtension = true, FileName = Path.GetFileName(mDataPathName) + ProjectFile.FILENAME_EXT }; - if (fileDlg.ShowDialog() == true) { - string pathName = Path.GetFullPath(fileDlg.FileName); - Debug.WriteLine("Project save path: " + pathName); - if (DoSave(pathName)) { - // Success, record the path name. - mProjectPathName = mProject.ProjectPathName = pathName; - - // add it to the title bar -#if false - UpdateMenuItemsAndTitle(); -#endif - return true; - } + if (fileDlg.ShowDialog() != true) { + Debug.WriteLine("SaveAs canceled by user"); + return false; } - return false; + string pathName = Path.GetFullPath(fileDlg.FileName); + Debug.WriteLine("Project save path: " + pathName); + if (!DoSave(pathName)) { + return false; + } + + // Success, record the path name. + mProjectPathName = mProject.ProjectPathName = pathName; + + // add it to the title bar +#if false + UpdateMenuItemsAndTitle(); +#endif + return true; } /// - /// Save the project. If it hasn't been saved before, use save-as behavior instead. + /// Saves the project. If it hasn't been saved before, use save-as behavior instead. /// /// True on success, false if the save attempt failed. - private bool DoSave() { + public bool SaveProject() { if (string.IsNullOrEmpty(mProjectPathName)) { - return DoSaveAs(); + return SaveProjectAs(); } return DoSave(mProjectPathName); } @@ -1028,7 +1035,7 @@ namespace SourceGenWPF { if (ok != true) { return false; } else if (dlg.UserChoice == DiscardChanges.Choice.SaveAndContinue) { - if (!DoSave()) { + if (!SaveProject()) { return false; } } diff --git a/SourceGenWPF/Res/CommandIcons.xaml b/SourceGenWPF/Res/CommandIcons.xaml index 6e877b1..5d5c424 100644 --- a/SourceGenWPF/Res/CommandIcons.xaml +++ b/SourceGenWPF/Res/CommandIcons.xaml @@ -13,10 +13,21 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SourceGenWPF.Res"> + + + - + @@ -41,7 +52,8 @@ - + @@ -64,7 +76,8 @@ - + @@ -88,7 +101,8 @@ - + @@ -112,7 +126,8 @@ - + @@ -135,7 +150,8 @@ - + @@ -157,7 +173,8 @@ - + diff --git a/SourceGenWPF/WpfGui/DataFileLoadIssue.xaml b/SourceGenWPF/WpfGui/DataFileLoadIssue.xaml index b03ed51..8183b43 100644 --- a/SourceGenWPF/WpfGui/DataFileLoadIssue.xaml +++ b/SourceGenWPF/WpfGui/DataFileLoadIssue.xaml @@ -24,21 +24,17 @@ limitations under the License. Title="Data File Load Issue" SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"> - - There was an error while loading the data file: - - - - - - - - - - - - - @@ -229,7 +237,7 @@ limitations under the License. - diff --git a/SourceGenWPF/WpfGui/MainWindow.xaml.cs b/SourceGenWPF/WpfGui/MainWindow.xaml.cs index dc940e9..abc8c2c 100644 --- a/SourceGenWPF/WpfGui/MainWindow.xaml.cs +++ b/SourceGenWPF/WpfGui/MainWindow.xaml.cs @@ -720,13 +720,6 @@ namespace SourceGenWPF.WpfGui { (counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mInlineDataHints != 0); } - private void CanRedo(object sender, CanExecuteRoutedEventArgs e) { - e.CanExecute = mMainCtrl != null && mMainCtrl.CanRedo(); - } - private void CanUndo(object sender, CanExecuteRoutedEventArgs e) { - e.CanExecute = mMainCtrl != null && mMainCtrl.CanUndo(); - } - private void CanNavigateBackward(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = mMainCtrl != null && mMainCtrl.CanNavigateBackward(); } @@ -734,6 +727,13 @@ namespace SourceGenWPF.WpfGui { e.CanExecute = mMainCtrl != null && mMainCtrl.CanNavigateForward(); } + private void CanRedo(object sender, CanExecuteRoutedEventArgs e) { + e.CanExecute = mMainCtrl != null && mMainCtrl.CanRedo(); + } + private void CanUndo(object sender, CanExecuteRoutedEventArgs e) { + e.CanExecute = mMainCtrl != null && mMainCtrl.CanUndo(); + } + #endregion Can-execute handlers @@ -785,6 +785,10 @@ namespace SourceGenWPF.WpfGui { mMainCtrl.NavigateForward(); } + private void OpenCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.OpenProject(); + } + private void RemoveHintsCmd_Executed(object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("remove hints"); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.NoHint, false); @@ -794,6 +798,14 @@ namespace SourceGenWPF.WpfGui { mMainCtrl.RedoChanges(); } + private void SaveCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.SaveProject(); + } + + private void SaveAsCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.SaveProjectAs(); + } + private void SelectAllCmd_Executed(object sender, ExecutedRoutedEventArgs e) { DateTime start = DateTime.Now;