From f8b1fa3d664a7fd17be1522dc0f6f95f76b03b71 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 13 Jul 2019 17:04:47 -0700 Subject: [PATCH] Implement Edit Note --- SourceGenWPF/MainController.cs | 42 +++++- SourceGenWPF/SourceGenWPF.csproj | 7 + SourceGenWPF/WpfGui/EditLongComment.xaml | 2 +- SourceGenWPF/WpfGui/EditLongComment.xaml.cs | 2 +- SourceGenWPF/WpfGui/EditNote.xaml | 90 +++++++++++++ SourceGenWPF/WpfGui/EditNote.xaml.cs | 136 ++++++++++++++++++++ SourceGenWPF/WpfGui/MainWindow.xaml | 9 +- SourceGenWPF/WpfGui/MainWindow.xaml.cs | 8 ++ 8 files changed, 289 insertions(+), 7 deletions(-) create mode 100644 SourceGenWPF/WpfGui/EditNote.xaml create mode 100644 SourceGenWPF/WpfGui/EditNote.xaml.cs diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 89e2763..386737b 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -1355,11 +1355,9 @@ namespace SourceGenWPF { } break; case LineListGen.Line.Type.Note: -#if false - if (editNoteToolStripMenuItem.Enabled) { - EditNote_Click(sender, e); + if (CanEditNote()) { + EditNote(); } -#endif break; case LineListGen.Line.Type.Code: @@ -1592,6 +1590,42 @@ namespace SourceGenWPF { } } + public bool CanEditNote() { + if (SelectionAnalysis.mNumItemsSelected != 1) { + return false; + } + EntityCounts counts = SelectionAnalysis.mEntityCounts; + // Single line, code or data, or a note. + return (counts.mDataLines > 0 || counts.mCodeLines > 0 || + SelectionAnalysis.mLineType == LineListGen.Line.Type.Note); + } + + public void EditNote() { + int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex(); + int offset = CodeLineList[selIndex].FileOffset; + + MultiLineComment oldNote; + if (!mProject.Notes.TryGetValue(offset, out oldNote)) { + oldNote = new MultiLineComment(string.Empty); + } + EditNote dlg = new EditNote(mMainWin, oldNote); + dlg.ShowDialog(); + + if (dlg.DialogResult != true) { + return; + } + + MultiLineComment newNote = dlg.Note; + if (oldNote != newNote) { + Debug.WriteLine("Changing note at +" + offset.ToString("x6")); + + UndoableChange uc = UndoableChange.CreateNoteChange(offset, + oldNote, newNote); + ChangeSet cs = new ChangeSet(uc); + ApplyUndoableChanges(cs); + } + } + public bool CanEditOperand() { if (SelectionAnalysis.mNumItemsSelected == 0) { return false; diff --git a/SourceGenWPF/SourceGenWPF.csproj b/SourceGenWPF/SourceGenWPF.csproj index 3f403ce..7844dac 100644 --- a/SourceGenWPF/SourceGenWPF.csproj +++ b/SourceGenWPF/SourceGenWPF.csproj @@ -103,6 +103,9 @@ EditLongComment.xaml + + EditNote.xaml + EditProjectProperties.xaml @@ -248,6 +251,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/SourceGenWPF/WpfGui/EditLongComment.xaml b/SourceGenWPF/WpfGui/EditLongComment.xaml index da07ba4..542a590 100644 --- a/SourceGenWPF/WpfGui/EditLongComment.xaml +++ b/SourceGenWPF/WpfGui/EditLongComment.xaml @@ -71,7 +71,7 @@ limitations under the License. IsReadOnly="True"/> -