1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-08-07 07:28:29 +00:00

Wire up undo, redo, and F1 help

Also, fixed some crashiness in the can-execute tests for hints.
If you crash an a can-execute method you get a really unhelpful
failure message.  Asserts don't work there either.  Yay WPF.
This commit is contained in:
Andy McFadden
2019-06-11 16:27:15 -07:00
parent 41b6a97408
commit 1a9f99098a
4 changed files with 154 additions and 37 deletions

View File

@@ -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 What we need in terms of API is a way to say, "show the help for XYZ". The rest can be
encapsulated here. 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 { namespace SourceGenWPF {

View File

@@ -978,6 +978,10 @@ namespace SourceGenWPF {
// Some totals. // Some totals.
public EntityCounts mEntityCounts; public EntityCounts mEntityCounts;
public SelectionState() {
mEntityCounts = new EntityCounts();
}
} }
/// <summary> /// <summary>
@@ -1134,7 +1138,6 @@ namespace SourceGenWPF {
} }
int lastIndex = mMainWin.GetLastSelectedIndex(); int lastIndex = mMainWin.GetLastSelectedIndex();
Debug.WriteLine("CHECK: first=" + firstIndex + ", last=" + lastIndex);
if (lastIndex == firstIndex) { if (lastIndex == firstIndex) {
// only one line is selected // only one line is selected
return true; return true;
@@ -1150,6 +1153,59 @@ namespace SourceGenWPF {
return false; return false;
} }
public bool CanUndo() {
return (mProject != null && mProject.CanUndo);
}
/// <summary>
/// Handles Edit - Undo.
/// </summary>
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);
}
/// <summary>
/// Handles Edit - Redo.
/// </summary>
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
}
/// <summary>
/// Handles the four Actions - edit hint commands.
/// </summary>
/// <param name="hint">Type of hint to apply.</param>
/// <param name="firstByteOnly">If set, only the first byte on each line is hinted.</param>
public void MarkAsType(CodeAnalysis.TypeHint hint, bool firstByteOnly) { public void MarkAsType(CodeAnalysis.TypeHint hint, bool firstByteOnly) {
RangeSet sel; RangeSet sel;
@@ -1224,6 +1280,13 @@ namespace SourceGenWPF {
return rs; return rs;
} }
/// <summary>
/// Handles Help - Help
/// </summary>
public void ShowHelp() {
HelpAccess.ShowHelp(HelpAccess.Topic.Contents);
}
#endregion Main window UI event handlers #endregion Main window UI event handlers
#region References panel #region References panel

View File

@@ -47,16 +47,27 @@ limitations under the License.
</RoutedUICommand.InputGestures> </RoutedUICommand.InputGestures>
</RoutedUICommand> </RoutedUICommand>
<RoutedUICommand x:Key="CloseCmd" Text="Close"/> <RoutedUICommand x:Key="CloseCmd" Text="Close"/>
<RoutedUICommand x:Key="HintAsCodeEntryPoint" Text="Hint As Code Entry Point"/> <RoutedUICommand x:Key="HintAsCodeEntryPointCmd" Text="Hint As Code Entry Point"/>
<RoutedUICommand x:Key="HintAsDataStart" Text="Hint As Data Start"/> <RoutedUICommand x:Key="HintAsDataStartCmd" Text="Hint As Data Start"/>
<RoutedUICommand x:Key="HintAsInlineData" Text="Hint As Inline Data"/> <RoutedUICommand x:Key="HintAsInlineDataCmd" Text="Hint As Inline Data"/>
<RoutedUICommand x:Key="RemoveHints" Text="Remove Hints"/> <RoutedUICommand x:Key="RemoveHintsCmd" Text="Remove Hints"/>
<RoutedUICommand x:Key="RecentProjectCmd"/> <RoutedUICommand x:Key="RecentProjectCmd"/>
<RoutedUICommand x:Key="RedoCmd" Text="Redo">
<RoutedUICommand.InputGestures>
<KeyGesture>Ctrl+Y</KeyGesture>
<KeyGesture>Ctrl+Shift+Z</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="SelectAllCmd" Text="Select All"> <RoutedUICommand x:Key="SelectAllCmd" Text="Select All">
<RoutedUICommand.InputGestures> <RoutedUICommand.InputGestures>
<KeyGesture>Ctrl+A</KeyGesture> <KeyGesture>Ctrl+A</KeyGesture>
</RoutedUICommand.InputGestures> </RoutedUICommand.InputGestures>
</RoutedUICommand> </RoutedUICommand>
<RoutedUICommand x:Key="UndoCmd" Text="Undo">
<RoutedUICommand.InputGestures>
<KeyGesture>Ctrl+Z</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
</ResourceDictionary> </ResourceDictionary>
</Window.Resources> </Window.Resources>
@@ -65,18 +76,24 @@ limitations under the License.
CanExecute="IsProjectOpen" Executed="AssembleCmd_Executed"/> CanExecute="IsProjectOpen" Executed="AssembleCmd_Executed"/>
<CommandBinding Command="{StaticResource CloseCmd}" <CommandBinding Command="{StaticResource CloseCmd}"
CanExecute="IsProjectOpen" Executed="CloseCmd_Executed"/> CanExecute="IsProjectOpen" Executed="CloseCmd_Executed"/>
<CommandBinding Command="{StaticResource HintAsCodeEntryPoint}" <CommandBinding Command="Help"
CanExecute="CanHintAsCodeEntryPoint" Executed="HintAsCodeEntryPoint_Executed"/> Executed="HelpCmd_Executed"/>
<CommandBinding Command="{StaticResource HintAsDataStart}" <CommandBinding Command="{StaticResource HintAsCodeEntryPointCmd}"
CanExecute="CanHintAsDataStart" Executed="HintAsDataStart_Executed"/> CanExecute="CanHintAsCodeEntryPoint" Executed="HintAsCodeEntryPointCmd_Executed"/>
<CommandBinding Command="{StaticResource HintAsInlineData}" <CommandBinding Command="{StaticResource HintAsDataStartCmd}"
CanExecute="CanHintAsInlineData" Executed="HintAsInlineData_Executed"/> CanExecute="CanHintAsDataStart" Executed="HintAsDataStartCmd_Executed"/>
<CommandBinding Command="{StaticResource RemoveHints}" <CommandBinding Command="{StaticResource HintAsInlineDataCmd}"
CanExecute="CanRemoveHints" Executed="RemoveHints_Executed"/> CanExecute="CanHintAsInlineData" Executed="HintAsInlineDataCmd_Executed"/>
<CommandBinding Command="{StaticResource RemoveHintsCmd}"
CanExecute="CanRemoveHints" Executed="RemoveHintsCmd_Executed"/>
<CommandBinding Command="{StaticResource RecentProjectCmd}" Executed="RecentProjectCmd_Executed"/> <CommandBinding Command="{StaticResource RecentProjectCmd}" Executed="RecentProjectCmd_Executed"/>
<!-- ListView has a built-in Ctrl+A handler; this only fires when codeListView not in focus --> <CommandBinding Command="{StaticResource RedoCmd}"
CanExecute="CanRedo" Executed="RedoCmd_Executed"/>
<!-- ListView has a built-in Ctrl+A handler; this only fires when codeListView is not in focus -->
<CommandBinding Command="{StaticResource SelectAllCmd}" <CommandBinding Command="{StaticResource SelectAllCmd}"
CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/> CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/>
<CommandBinding Command="{StaticResource UndoCmd}"
CanExecute="CanUndo" Executed="UndoCmd_Executed"/>
</Window.CommandBindings> </Window.CommandBindings>
<DockPanel> <DockPanel>
@@ -98,8 +115,8 @@ limitations under the License.
<MenuItem Header="Exit"/> <MenuItem Header="Exit"/>
</MenuItem> </MenuItem>
<MenuItem Header="_Edit"> <MenuItem Header="_Edit">
<MenuItem Command="Undo"/> <MenuItem Command="{StaticResource UndoCmd}"/>
<MenuItem Command="Redo"/> <!-- want both Ctrl+Y and Ctrl+Shift+Z --> <MenuItem Command="{StaticResource RedoCmd}"/>
<Separator/> <Separator/>
<MenuItem Command="Copy"/> <MenuItem Command="Copy"/>
<Separator/> <Separator/>
@@ -124,10 +141,10 @@ limitations under the License.
<MenuItem Header="Edit Note..."/> <MenuItem Header="Edit Note..."/>
<MenuItem Header="Edit Project Symbol..."/> <MenuItem Header="Edit Project Symbol..."/>
<Separator/> <Separator/>
<MenuItem Command="{StaticResource HintAsCodeEntryPoint}" InputGestureText="Ctrl+H, Ctrl+C"/> <MenuItem Command="{StaticResource HintAsCodeEntryPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>
<MenuItem Command="{StaticResource HintAsDataStart}" InputGestureText="Ctrl+H, Ctrl+D"/> <MenuItem Command="{StaticResource HintAsDataStartCmd}" InputGestureText="Ctrl+H, Ctrl+D"/>
<MenuItem Command="{StaticResource HintAsInlineData}" InputGestureText="Ctrl+H, Ctrl+I"/> <MenuItem Command="{StaticResource HintAsInlineDataCmd}" InputGestureText="Ctrl+H, Ctrl+I"/>
<MenuItem Command="{StaticResource RemoveHints}" InputGestureText="Ctrl+H, Ctrl+R"/> <MenuItem Command="{StaticResource RemoveHintsCmd}" InputGestureText="Ctrl+H, Ctrl+R"/>
<Separator/> <Separator/>
<MenuItem Header="Format Split-Address Table..."/> <MenuItem Header="Format Split-Address Table..."/>
<MenuItem Header="Toggle Single-Byte Format"/> <MenuItem Header="Toggle Single-Byte Format"/>

View File

@@ -78,6 +78,8 @@ namespace SourceGenWPF.ProjWin {
mMainCtrl = new MainController(this); mMainCtrl = new MainController(this);
mSelectionState = new MainController.SelectionState();
AddMultiKeyGestures(); AddMultiKeyGestures();
//GridView gv = (GridView)codeListView.View; //GridView gv = (GridView)codeListView.View;
@@ -87,25 +89,25 @@ namespace SourceGenWPF.ProjWin {
private void AddMultiKeyGestures() { private void AddMultiKeyGestures() {
RoutedUICommand ruic; RoutedUICommand ruic;
ruic = (RoutedUICommand)FindResource("HintAsCodeEntryPoint"); ruic = (RoutedUICommand)FindResource("HintAsCodeEntryPointCmd");
ruic.InputGestures.Add( ruic.InputGestures.Add(
new MultiKeyInputGesture(new KeyGesture[] { new MultiKeyInputGesture(new KeyGesture[] {
new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"),
new KeyGesture(Key.C, ModifierKeys.Control, "Ctrl+C") new KeyGesture(Key.C, ModifierKeys.Control, "Ctrl+C")
})); }));
ruic = (RoutedUICommand)FindResource("HintAsDataStart"); ruic = (RoutedUICommand)FindResource("HintAsDataStartCmd");
ruic.InputGestures.Add( ruic.InputGestures.Add(
new MultiKeyInputGesture(new KeyGesture[] { new MultiKeyInputGesture(new KeyGesture[] {
new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"),
new KeyGesture(Key.D, ModifierKeys.Control, "Ctrl+D") new KeyGesture(Key.D, ModifierKeys.Control, "Ctrl+D")
})); }));
ruic = (RoutedUICommand)FindResource("HintAsInlineData"); ruic = (RoutedUICommand)FindResource("HintAsInlineDataCmd");
ruic.InputGestures.Add( ruic.InputGestures.Add(
new MultiKeyInputGesture(new KeyGesture[] { new MultiKeyInputGesture(new KeyGesture[] {
new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"),
new KeyGesture(Key.I, ModifierKeys.Control, "Ctrl+I") new KeyGesture(Key.I, ModifierKeys.Control, "Ctrl+I")
})); }));
ruic = (RoutedUICommand)FindResource("RemoveHints"); ruic = (RoutedUICommand)FindResource("RemoveHintsCmd");
ruic.InputGestures.Add( ruic.InputGestures.Add(
new MultiKeyInputGesture(new KeyGesture[] { new MultiKeyInputGesture(new KeyGesture[] {
new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"), new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"),
@@ -304,6 +306,7 @@ namespace SourceGenWPF.ProjWin {
const int MAX_SEL_COUNT = 2000; const int MAX_SEL_COUNT = 2000;
if (sel.IsAllSelected()) { if (sel.IsAllSelected()) {
Debug.WriteLine("SetSelection: re-selecting all items");
codeListView.SelectAll(); codeListView.SelectAll();
return; return;
} }
@@ -312,7 +315,7 @@ namespace SourceGenWPF.ProjWin {
if (sel.Count > MAX_SEL_COUNT) { if (sel.Count > MAX_SEL_COUNT) {
// Too much for WPF -- only restore the first item. // 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()]); codeListView.SelectedItems.Add(CodeDisplayList[sel.GetFirstSelectedIndex()]);
return; return;
} }
@@ -360,30 +363,49 @@ namespace SourceGenWPF.ProjWin {
} }
private void CanHintAsCodeEntryPoint(object sender, CanExecuteRoutedEventArgs e) { private void CanHintAsCodeEntryPoint(object sender, CanExecuteRoutedEventArgs e) {
if (!mMainCtrl.IsProjectOpen()) {
e.CanExecute = false;
return;
}
MainController.EntityCounts counts = mSelectionState.mEntityCounts; MainController.EntityCounts counts = mSelectionState.mEntityCounts;
e.CanExecute = mMainCtrl.IsProjectOpen() && e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mDataHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0); (counts.mDataHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0);
} }
private void CanHintAsDataStart(object sender, CanExecuteRoutedEventArgs e) { private void CanHintAsDataStart(object sender, CanExecuteRoutedEventArgs e) {
if (!mMainCtrl.IsProjectOpen()) {
e.CanExecute = false;
return;
}
MainController.EntityCounts counts = mSelectionState.mEntityCounts; MainController.EntityCounts counts = mSelectionState.mEntityCounts;
e.CanExecute = mMainCtrl.IsProjectOpen() && e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mCodeHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0); (counts.mCodeHints != 0 || counts.mInlineDataHints != 0 || counts.mNoHints != 0);
} }
private void CanHintAsInlineData(object sender, CanExecuteRoutedEventArgs e) { private void CanHintAsInlineData(object sender, CanExecuteRoutedEventArgs e) {
if (!mMainCtrl.IsProjectOpen()) {
e.CanExecute = false;
return;
}
MainController.EntityCounts counts = mSelectionState.mEntityCounts; MainController.EntityCounts counts = mSelectionState.mEntityCounts;
e.CanExecute = mMainCtrl.IsProjectOpen() && e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mNoHints != 0); (counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mNoHints != 0);
} }
private void CanRemoveHints(object sender, CanExecuteRoutedEventArgs e) { private void CanRemoveHints(object sender, CanExecuteRoutedEventArgs e) {
if (!mMainCtrl.IsProjectOpen()) {
e.CanExecute = false;
return;
}
MainController.EntityCounts counts = mSelectionState.mEntityCounts; MainController.EntityCounts counts = mSelectionState.mEntityCounts;
e.CanExecute = mMainCtrl.IsProjectOpen() && e.CanExecute = (counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mDataLines > 0 || counts.mCodeLines > 0) &&
(counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mInlineDataHints != 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 #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"); Debug.WriteLine("hint as code entry point");
mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.Code, true); 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"); Debug.WriteLine("hint as data start");
mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.Data, true); 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"); Debug.WriteLine("hint as inline data");
mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.InlineData, false); 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"); Debug.WriteLine("remove hints");
mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.NoHint, false); mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.NoHint, false);
} }
private void RedoCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.RedoChanges();
}
private void SelectAllCmd_Executed(object sender, ExecutedRoutedEventArgs e) { private void SelectAllCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
@@ -448,6 +478,10 @@ namespace SourceGenWPF.ProjWin {
mMainCtrl.OpenRecentProject(recentIndex); mMainCtrl.OpenRecentProject(recentIndex);
} }
private void UndoCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.UndoChanges();
}
#endregion Command handlers #endregion Command handlers