mirror of
https://github.com/fadden/6502bench.git
synced 2025-01-16 19:32:31 +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:
parent
41b6a97408
commit
1a9f99098a
@ -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 {
|
||||
|
@ -978,6 +978,10 @@ namespace SourceGenWPF {
|
||||
|
||||
// Some totals.
|
||||
public EntityCounts mEntityCounts;
|
||||
|
||||
public SelectionState() {
|
||||
mEntityCounts = new EntityCounts();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
RangeSet sel;
|
||||
|
||||
@ -1224,6 +1280,13 @@ namespace SourceGenWPF {
|
||||
return rs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles Help - Help
|
||||
/// </summary>
|
||||
public void ShowHelp() {
|
||||
HelpAccess.ShowHelp(HelpAccess.Topic.Contents);
|
||||
}
|
||||
|
||||
#endregion Main window UI event handlers
|
||||
|
||||
#region References panel
|
||||
|
@ -47,16 +47,27 @@ limitations under the License.
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
<RoutedUICommand x:Key="CloseCmd" Text="Close"/>
|
||||
<RoutedUICommand x:Key="HintAsCodeEntryPoint" Text="Hint As Code Entry Point"/>
|
||||
<RoutedUICommand x:Key="HintAsDataStart" Text="Hint As Data Start"/>
|
||||
<RoutedUICommand x:Key="HintAsInlineData" Text="Hint As Inline Data"/>
|
||||
<RoutedUICommand x:Key="RemoveHints" Text="Remove Hints"/>
|
||||
<RoutedUICommand x:Key="HintAsCodeEntryPointCmd" Text="Hint As Code Entry Point"/>
|
||||
<RoutedUICommand x:Key="HintAsDataStartCmd" Text="Hint As Data Start"/>
|
||||
<RoutedUICommand x:Key="HintAsInlineDataCmd" Text="Hint As Inline Data"/>
|
||||
<RoutedUICommand x:Key="RemoveHintsCmd" Text="Remove Hints"/>
|
||||
<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.InputGestures>
|
||||
<KeyGesture>Ctrl+A</KeyGesture>
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
<RoutedUICommand x:Key="UndoCmd" Text="Undo">
|
||||
<RoutedUICommand.InputGestures>
|
||||
<KeyGesture>Ctrl+Z</KeyGesture>
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
@ -65,18 +76,24 @@ limitations under the License.
|
||||
CanExecute="IsProjectOpen" Executed="AssembleCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource CloseCmd}"
|
||||
CanExecute="IsProjectOpen" Executed="CloseCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsCodeEntryPoint}"
|
||||
CanExecute="CanHintAsCodeEntryPoint" Executed="HintAsCodeEntryPoint_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsDataStart}"
|
||||
CanExecute="CanHintAsDataStart" Executed="HintAsDataStart_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsInlineData}"
|
||||
CanExecute="CanHintAsInlineData" Executed="HintAsInlineData_Executed"/>
|
||||
<CommandBinding Command="{StaticResource RemoveHints}"
|
||||
CanExecute="CanRemoveHints" Executed="RemoveHints_Executed"/>
|
||||
<CommandBinding Command="Help"
|
||||
Executed="HelpCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsCodeEntryPointCmd}"
|
||||
CanExecute="CanHintAsCodeEntryPoint" Executed="HintAsCodeEntryPointCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsDataStartCmd}"
|
||||
CanExecute="CanHintAsDataStart" Executed="HintAsDataStartCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsInlineDataCmd}"
|
||||
CanExecute="CanHintAsInlineData" Executed="HintAsInlineDataCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource RemoveHintsCmd}"
|
||||
CanExecute="CanRemoveHints" Executed="RemoveHintsCmd_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}"
|
||||
CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource UndoCmd}"
|
||||
CanExecute="CanUndo" Executed="UndoCmd_Executed"/>
|
||||
</Window.CommandBindings>
|
||||
|
||||
<DockPanel>
|
||||
@ -98,8 +115,8 @@ limitations under the License.
|
||||
<MenuItem Header="Exit"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Edit">
|
||||
<MenuItem Command="Undo"/>
|
||||
<MenuItem Command="Redo"/> <!-- want both Ctrl+Y and Ctrl+Shift+Z -->
|
||||
<MenuItem Command="{StaticResource UndoCmd}"/>
|
||||
<MenuItem Command="{StaticResource RedoCmd}"/>
|
||||
<Separator/>
|
||||
<MenuItem Command="Copy"/>
|
||||
<Separator/>
|
||||
@ -124,10 +141,10 @@ limitations under the License.
|
||||
<MenuItem Header="Edit Note..."/>
|
||||
<MenuItem Header="Edit Project Symbol..."/>
|
||||
<Separator/>
|
||||
<MenuItem Command="{StaticResource HintAsCodeEntryPoint}" InputGestureText="Ctrl+H, Ctrl+C"/>
|
||||
<MenuItem Command="{StaticResource HintAsDataStart}" InputGestureText="Ctrl+H, Ctrl+D"/>
|
||||
<MenuItem Command="{StaticResource HintAsInlineData}" InputGestureText="Ctrl+H, Ctrl+I"/>
|
||||
<MenuItem Command="{StaticResource RemoveHints}" InputGestureText="Ctrl+H, Ctrl+R"/>
|
||||
<MenuItem Command="{StaticResource HintAsCodeEntryPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>
|
||||
<MenuItem Command="{StaticResource HintAsDataStartCmd}" InputGestureText="Ctrl+H, Ctrl+D"/>
|
||||
<MenuItem Command="{StaticResource HintAsInlineDataCmd}" InputGestureText="Ctrl+H, Ctrl+I"/>
|
||||
<MenuItem Command="{StaticResource RemoveHintsCmd}" InputGestureText="Ctrl+H, Ctrl+R"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Format Split-Address Table..."/>
|
||||
<MenuItem Header="Toggle Single-Byte Format"/>
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user