diff --git a/SourceGenWPF/HelpAccess.cs b/SourceGenWPF/HelpAccess.cs index 1bb3800..ca7dd07 100644 --- a/SourceGenWPF/HelpAccess.cs +++ b/SourceGenWPF/HelpAccess.cs @@ -42,6 +42,9 @@ just opens the TOC, and individual UI items don't have help buttons. What we need in terms of API is a way to say, "show the help for XYZ". The rest can be encapsulated here. + +TODO(maybe): the web viewer accessible from WPF appears to be much better, so we could create a +simple browser window. */ namespace SourceGenWPF { diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index c22ce89..90ac14f 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -978,6 +978,10 @@ namespace SourceGenWPF { // Some totals. public EntityCounts mEntityCounts; + + public SelectionState() { + mEntityCounts = new EntityCounts(); + } } /// @@ -1134,7 +1138,6 @@ namespace SourceGenWPF { } int lastIndex = mMainWin.GetLastSelectedIndex(); - Debug.WriteLine("CHECK: first=" + firstIndex + ", last=" + lastIndex); if (lastIndex == firstIndex) { // only one line is selected return true; @@ -1150,6 +1153,59 @@ namespace SourceGenWPF { return false; } + public bool CanUndo() { + return (mProject != null && mProject.CanUndo); + } + + /// + /// Handles Edit - Undo. + /// + public void UndoChanges() { + if (!mProject.CanUndo) { + Debug.Assert(false, "Nothing to undo"); + return; + } + ChangeSet cs = mProject.PopUndoSet(); + ApplyChanges(cs, true); +#if false + UpdateMenuItemsAndTitle(); + + // If the debug dialog is visible, update it. + if (mShowUndoRedoHistoryDialog != null) { + mShowUndoRedoHistoryDialog.BodyText = mProject.DebugGetUndoRedoHistory(); + } +#endif + } + + public bool CanRedo() { + return (mProject != null && mProject.CanRedo); + } + + /// + /// Handles Edit - Redo. + /// + public void RedoChanges() { + if (!mProject.CanRedo) { + Debug.Assert(false, "Nothing to redo"); + return; + } + ChangeSet cs = mProject.PopRedoSet(); + ApplyChanges(cs, false); +#if false + UpdateMenuItemsAndTitle(); + + // If the debug dialog is visible, update it. + if (mShowUndoRedoHistoryDialog != null) { + mShowUndoRedoHistoryDialog.BodyText = mProject.DebugGetUndoRedoHistory(); + } +#endif + } + + /// + /// Handles the four Actions - edit hint commands. + /// + /// Type of hint to apply. + /// If set, only the first byte on each line is hinted. public void MarkAsType(CodeAnalysis.TypeHint hint, bool firstByteOnly) { RangeSet sel; @@ -1224,6 +1280,13 @@ namespace SourceGenWPF { return rs; } + /// + /// Handles Help - Help + /// + public void ShowHelp() { + HelpAccess.ShowHelp(HelpAccess.Topic.Contents); + } + #endregion Main window UI event handlers #region References panel diff --git a/SourceGenWPF/ProjWin/MainWindow.xaml b/SourceGenWPF/ProjWin/MainWindow.xaml index d1ca76c..96f625a 100644 --- a/SourceGenWPF/ProjWin/MainWindow.xaml +++ b/SourceGenWPF/ProjWin/MainWindow.xaml @@ -47,16 +47,27 @@ limitations under the License. - - - - + + + + + + + Ctrl+Y + Ctrl+Shift+Z + + Ctrl+A + + + Ctrl+Z + + @@ -65,18 +76,24 @@ limitations under the License. CanExecute="IsProjectOpen" Executed="AssembleCmd_Executed"/> - - - - + + + + + - + + + @@ -98,8 +115,8 @@ limitations under the License. - - + + @@ -124,10 +141,10 @@ limitations under the License. - - - - + + + + diff --git a/SourceGenWPF/ProjWin/MainWindow.xaml.cs b/SourceGenWPF/ProjWin/MainWindow.xaml.cs index cbe74c2..9bf0d33 100644 --- a/SourceGenWPF/ProjWin/MainWindow.xaml.cs +++ b/SourceGenWPF/ProjWin/MainWindow.xaml.cs @@ -78,6 +78,8 @@ namespace SourceGenWPF.ProjWin { mMainCtrl = new MainController(this); + mSelectionState = new MainController.SelectionState(); + AddMultiKeyGestures(); //GridView gv = (GridView)codeListView.View; @@ -87,25 +89,25 @@ namespace SourceGenWPF.ProjWin { private void AddMultiKeyGestures() { RoutedUICommand ruic; - ruic = (RoutedUICommand)FindResource("HintAsCodeEntryPoint"); + ruic = (RoutedUICommand)FindResource("HintAsCodeEntryPointCmd"); ruic.InputGestures.Add( new MultiKeyInputGesture(new KeyGesture[] { new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.C, ModifierKeys.Control, "Ctrl+C") })); - ruic = (RoutedUICommand)FindResource("HintAsDataStart"); + ruic = (RoutedUICommand)FindResource("HintAsDataStartCmd"); ruic.InputGestures.Add( new MultiKeyInputGesture(new KeyGesture[] { new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.D, ModifierKeys.Control, "Ctrl+D") })); - ruic = (RoutedUICommand)FindResource("HintAsInlineData"); + ruic = (RoutedUICommand)FindResource("HintAsInlineDataCmd"); ruic.InputGestures.Add( new MultiKeyInputGesture(new KeyGesture[] { new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.I, ModifierKeys.Control, "Ctrl+I") })); - ruic = (RoutedUICommand)FindResource("RemoveHints"); + ruic = (RoutedUICommand)FindResource("RemoveHintsCmd"); ruic.InputGestures.Add( new MultiKeyInputGesture(new KeyGesture[] { new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), @@ -304,6 +306,7 @@ namespace SourceGenWPF.ProjWin { const int MAX_SEL_COUNT = 2000; if (sel.IsAllSelected()) { + Debug.WriteLine("SetSelection: re-selecting all items"); codeListView.SelectAll(); return; } @@ -312,7 +315,7 @@ namespace SourceGenWPF.ProjWin { if (sel.Count > MAX_SEL_COUNT) { // Too much for WPF -- only restore the first item. - Debug.WriteLine("Not restoring selection (" + sel.Count + " items)"); + Debug.WriteLine("SetSelection: not restoring (" + sel.Count + " items)"); codeListView.SelectedItems.Add(CodeDisplayList[sel.GetFirstSelectedIndex()]); return; } @@ -360,30 +363,49 @@ namespace SourceGenWPF.ProjWin { } private void CanHintAsCodeEntryPoint(object sender, CanExecuteRoutedEventArgs e) { + if (!mMainCtrl.IsProjectOpen()) { + e.CanExecute = false; + return; + } MainController.EntityCounts counts = mSelectionState.mEntityCounts; - e.CanExecute = mMainCtrl.IsProjectOpen() && - (counts.mDataLines > 0 || counts.mCodeLines > 0) && + e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) && (counts.mDataHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0); } private void CanHintAsDataStart(object sender, CanExecuteRoutedEventArgs e) { + if (!mMainCtrl.IsProjectOpen()) { + e.CanExecute = false; + return; + } MainController.EntityCounts counts = mSelectionState.mEntityCounts; - e.CanExecute = mMainCtrl.IsProjectOpen() && - (counts.mDataLines > 0 || counts.mCodeLines > 0) && + e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) && (counts.mCodeHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0); } private void CanHintAsInlineData(object sender, CanExecuteRoutedEventArgs e) { + if (!mMainCtrl.IsProjectOpen()) { + e.CanExecute = false; + return; + } MainController.EntityCounts counts = mSelectionState.mEntityCounts; - e.CanExecute = mMainCtrl.IsProjectOpen() && - (counts.mDataLines > 0 || counts.mCodeLines > 0) && + e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) && (counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mNoHints != 0); } private void CanRemoveHints(object sender, CanExecuteRoutedEventArgs e) { + if (!mMainCtrl.IsProjectOpen()) { + e.CanExecute = false; + return; + } MainController.EntityCounts counts = mSelectionState.mEntityCounts; - e.CanExecute = mMainCtrl.IsProjectOpen() && - (counts.mDataLines > 0 || counts.mCodeLines > 0) && + e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) && (counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mInlineDataHints != 0); } + private void CanRedo(object sender, CanExecuteRoutedEventArgs e) { + e.CanExecute = mMainCtrl.CanRedo(); + } + private void CanUndo(object sender, CanExecuteRoutedEventArgs e) { + e.CanExecute = mMainCtrl.CanUndo(); + } + #endregion Can-execute handlers @@ -400,26 +422,34 @@ namespace SourceGenWPF.ProjWin { } } - private void HintAsCodeEntryPoint_Executed(object sender, ExecutedRoutedEventArgs e) { + private void HelpCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.ShowHelp(); + } + + private void HintAsCodeEntryPointCmd_Executed(object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("hint as code entry point"); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.Code, true); } - private void HintAsDataStart_Executed(object sender, ExecutedRoutedEventArgs e) { + private void HintAsDataStartCmd_Executed(object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("hint as data start"); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.Data, true); } - private void HintAsInlineData_Executed(object sender, ExecutedRoutedEventArgs e) { + private void HintAsInlineDataCmd_Executed(object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("hint as inline data"); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.InlineData, false); } - private void RemoveHints_Executed(object sender, ExecutedRoutedEventArgs e) { + private void RemoveHintsCmd_Executed(object sender, ExecutedRoutedEventArgs e) { Debug.WriteLine("remove hints"); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.NoHint, false); } + private void RedoCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.RedoChanges(); + } + private void SelectAllCmd_Executed(object sender, ExecutedRoutedEventArgs e) { DateTime start = DateTime.Now; @@ -448,6 +478,10 @@ namespace SourceGenWPF.ProjWin { mMainCtrl.OpenRecentProject(recentIndex); } + private void UndoCmd_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.UndoChanges(); + } + #endregion Command handlers