diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 30c4d14..aec5279 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -966,7 +966,10 @@ namespace SourceGenWPF { return false; } - // Save the project. If it hasn't been saved before, use save-as behavior instead. + /// + /// Save 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() { if (string.IsNullOrEmpty(mProjectPathName)) { return DoSaveAs(); @@ -1054,6 +1057,7 @@ namespace SourceGenWPF { } mDataPathName = null; mProjectPathName = null; + mTargetHighlightIndex = -1; #if false mSymbolSubset = new SymbolTableSubset(new SymbolTable()); #endif @@ -1101,11 +1105,9 @@ namespace SourceGenWPF { } break; case LineListGen.Line.Type.RegWidthDirective: -#if false - if (overrideStatusFlagsToolStripMenuItem.Enabled) { - EditStatusFlags_Click(sender, e); + if (CanEditStatusFlags()) { + EditStatusFlags(); } -#endif break; case LineListGen.Line.Type.LongComment: #if false @@ -1143,11 +1145,9 @@ namespace SourceGenWPF { #endif break; case ColumnIndex.Flags: -#if false - if (overrideStatusFlagsToolStripMenuItem.Enabled) { - EditStatusFlags_Click(sender, e); + if (CanEditStatusFlags()) { + EditStatusFlags(); } -#endif break; case ColumnIndex.Attributes: // does nothing @@ -1230,8 +1230,7 @@ namespace SourceGenWPF { Anattrib attr = mProject.GetAnattrib(offset); EditAddress dlg = new EditAddress(mMainWin, attr.Address, mProject.CpuDef.MaxAddressValue); - bool? ok = dlg.ShowDialog(); - if (ok != true) { + if (dlg.ShowDialog() != true) { return; } @@ -1258,6 +1257,34 @@ namespace SourceGenWPF { } } + public bool CanEditStatusFlags() { + if (SelectionAnalysis.mNumItemsSelected != 1) { + return false; + } + EntityCounts counts = SelectionAnalysis.mEntityCounts; + // Line must be code, or a RegWidth directive. + return (SelectionAnalysis.mLineType == LineListGen.Line.Type.Code || + SelectionAnalysis.mLineType == LineListGen.Line.Type.RegWidthDirective); + } + + public void EditStatusFlags() { + int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex(); + int offset = CodeLineList[selIndex].FileOffset; + + EditStatusFlags dlg = new EditStatusFlags(mMainWin, + mProject.StatusFlagOverrides[offset], mProject.CpuDef.HasEmuFlag); + if (dlg.ShowDialog() != true) { + return; + } + + if (dlg.FlagValue != mProject.StatusFlagOverrides[offset]) { + UndoableChange uc = UndoableChange.CreateStatusFlagChange(offset, + mProject.StatusFlagOverrides[offset], dlg.FlagValue); + ChangeSet cs = new ChangeSet(uc); + ApplyUndoableChanges(cs); + } + } + /// /// Moves the view and selection to the specified offset. We want to select stuff /// differently if we're jumping to a note vs. jumping to an instruction. @@ -1318,23 +1345,6 @@ namespace SourceGenWPF { } } - /// - /// Scrolls the code list so that the specified label is shown. - /// - /// Label symbol. - public void GoToLabel(Symbol sym) { - if (sym.IsInternalLabel) { - int offset = mProject.FindLabelOffsetByName(sym.Label); - if (offset >= 0) { - GoToOffset(offset, false, true); - } else { - Debug.WriteLine("DClick symbol: " + sym + ": label not found"); - } - } else { - Debug.WriteLine("DClick symbol: " + sym + ": not label"); - } - } - public bool CanNavigateBackward() { return mNavStack.HasBackward; } @@ -1353,6 +1363,23 @@ namespace SourceGenWPF { GoToOffset(fwdOff, false, false); } + /// + /// Scrolls the code list so that the specified label is shown. + /// + /// Label symbol. + public void GoToLabel(Symbol sym) { + if (sym.IsInternalLabel) { + int offset = mProject.FindLabelOffsetByName(sym.Label); + if (offset >= 0) { + GoToOffset(offset, false, true); + } else { + Debug.WriteLine("DClick symbol: " + sym + ": label not found"); + } + } else { + Debug.WriteLine("DClick symbol: " + sym + ": not label"); + } + } + public void SelectionChanged() { SelectionAnalysis = UpdateSelectionState(); diff --git a/SourceGenWPF/ProjWin/DiscardChanges.xaml b/SourceGenWPF/ProjWin/DiscardChanges.xaml index 7d31d58..38e16ee 100644 --- a/SourceGenWPF/ProjWin/DiscardChanges.xaml +++ b/SourceGenWPF/ProjWin/DiscardChanges.xaml @@ -22,15 +22,20 @@ limitations under the License. xmlns:local="clr-namespace:SourceGenWPF.ProjWin" mc:Ignorable="d" Title="Discard Changes?" + FocusManager.FocusedElement="{Binding ElementName=cancelButton}" SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"> + - private void Window_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.XButton1) { - Debug.WriteLine("TODO: navigate back"); + if (mMainCtrl.CanNavigateBackward()) { + mMainCtrl.NavigateBackward(); + } } } @@ -673,6 +675,14 @@ namespace SourceGenWPF.ProjWin { e.CanExecute = mMainCtrl.CanEditAddress(); } + private void CanEditStatusFlags(object sender, CanExecuteRoutedEventArgs e) { + if (mMainCtrl == null || !mMainCtrl.IsProjectOpen()) { + e.CanExecute = false; + return; + } + e.CanExecute = mMainCtrl.CanEditStatusFlags(); + } + private void CanHintAsCodeEntryPoint(object sender, CanExecuteRoutedEventArgs e) { if (mMainCtrl == null || !mMainCtrl.IsProjectOpen()) { e.CanExecute = false; @@ -744,6 +754,10 @@ namespace SourceGenWPF.ProjWin { mMainCtrl.EditAddress(); } + private void EditStatusFlags_Executed(object sender, ExecutedRoutedEventArgs e) { + mMainCtrl.EditStatusFlags(); + } + private void HelpCmd_Executed(object sender, ExecutedRoutedEventArgs e) { mMainCtrl.ShowHelp(); } diff --git a/SourceGenWPF/SourceGenWPF.csproj b/SourceGenWPF/SourceGenWPF.csproj index 3a99e62..96c6aab 100644 --- a/SourceGenWPF/SourceGenWPF.csproj +++ b/SourceGenWPF/SourceGenWPF.csproj @@ -84,6 +84,9 @@ EditAddress.xaml + + EditStatusFlags.xaml + ProjectLoadIssue.xaml @@ -168,6 +171,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile