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"/>
-
+
diff --git a/SourceGenWPF/WpfGui/EditLongComment.xaml.cs b/SourceGenWPF/WpfGui/EditLongComment.xaml.cs
index c27eb8b..b03cd2f 100644
--- a/SourceGenWPF/WpfGui/EditLongComment.xaml.cs
+++ b/SourceGenWPF/WpfGui/EditLongComment.xaml.cs
@@ -110,7 +110,7 @@ namespace SourceGenWPF.WpfGui {
entryTextBox.Focus();
}
- private void OkButton_Clicked(object sender, RoutedEventArgs e) {
+ private void OkButton_Click(object sender, RoutedEventArgs e) {
DialogResult = true;
}
diff --git a/SourceGenWPF/WpfGui/EditNote.xaml b/SourceGenWPF/WpfGui/EditNote.xaml
new file mode 100644
index 0000000..f9bef0b
--- /dev/null
+++ b/SourceGenWPF/WpfGui/EditNote.xaml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+ Ctrl+Enter
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SourceGenWPF/WpfGui/EditNote.xaml.cs b/SourceGenWPF/WpfGui/EditNote.xaml.cs
new file mode 100644
index 0000000..2e9d28d
--- /dev/null
+++ b/SourceGenWPF/WpfGui/EditNote.xaml.cs
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2019 faddenSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace SourceGenWPF.WpfGui {
+ ///
+ /// Note editor.
+ ///
+ public partial class EditNote : Window, INotifyPropertyChanged {
+ ///
+ /// Note result object. Will be set to null if the note was deleted.
+ ///
+ public MultiLineComment Note { get; private set; }
+
+ ///
+ /// Text input by user. This is bound to the input TextBox.
+ ///
+ public string UserInput {
+ get { return mUserInput; }
+ set {
+ mUserInput = value;
+ OnPropertyChanged();
+ }
+ }
+ private string mUserInput;
+
+ // Highlight color palette. Unless the user has funky theme, the color will be
+ // replacing a white background, and will be overlaid with black text, so should
+ // be on the lighter end of the spectrum.
+ private enum ColorList {
+ None = 0, Green, Blue, Yellow, Pink, Orange
+ }
+ private static Color[] sColors = new Color[] {
+ Color.FromArgb(0, 0, 0, 0), // no highlight
+ Colors.LightGreen,
+ Colors.LightBlue,
+ Colors.Yellow, //LightGoldenrodYellow,
+ Colors.LightPink,
+ Colors.Orange
+ };
+ private RadioButton[] mColorButtons;
+
+ // INotifyPropertyChanged implementation
+ public event PropertyChangedEventHandler PropertyChanged;
+ private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
+
+ public EditNote(Window owner, MultiLineComment note) {
+ InitializeComponent();
+ Owner = owner;
+ DataContext = this;
+
+ Note = note;
+
+ mColorButtons = new RadioButton[] {
+ colorDefaultRadio,
+ colorGreenRadio,
+ colorBlueRadio,
+ colorYellowRadio,
+ colorPinkRadio,
+ colorOrangeRadio
+ };
+ Debug.Assert(mColorButtons.Length == sColors.Length);
+ }
+
+ public void Window_Loaded(object sender, RoutedEventArgs e) {
+ UserInput = Note.Text;
+
+ // Configure radio buttons.
+ colorDefaultRadio.IsChecked = true;
+ if (Note != null) {
+ Color curColor = Note.BackgroundColor;
+ for (int i = 0; i < sColors.Length; i++) {
+ if (sColors[i].Equals(curColor)) {
+ mColorButtons[i].IsChecked = true;
+ break;
+ }
+ }
+ }
+
+ }
+
+ // Handle Ctrl+Enter as a way to close the dialog, since plain Enter just
+ // moves to a new line.
+ private void CloseCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
+ DialogResult = true;
+ }
+ public void OkButton_Click(object sender, RoutedEventArgs e) {
+ DialogResult = true;
+ }
+
+ private void Window_Closing(object sender, CancelEventArgs e) {
+ if (DialogResult != true) {
+ Debug.WriteLine("Skip it");
+ return;
+ }
+
+ if (string.IsNullOrEmpty(UserInput)) {
+ Note = null;
+ } else {
+ Color bkgndColor = Colors.Fuchsia;
+ for (int i = 0; i < mColorButtons.Length; i++) {
+ if (mColorButtons[i].IsChecked == true) {
+ bkgndColor = sColors[i];
+ break;
+ }
+ }
+ Note = new MultiLineComment(UserInput, bkgndColor);
+ }
+ }
+ }
+}
diff --git a/SourceGenWPF/WpfGui/MainWindow.xaml b/SourceGenWPF/WpfGui/MainWindow.xaml
index cbf507c..2f79ca1 100644
--- a/SourceGenWPF/WpfGui/MainWindow.xaml
+++ b/SourceGenWPF/WpfGui/MainWindow.xaml
@@ -79,6 +79,11 @@ limitations under the License.
Ctrl+M
+
+
+ Ctrl+N
+
+
@@ -163,6 +168,8 @@ limitations under the License.
CanExecute="CanEditLabel" Executed="EditLabelCmd_Executed"/>
+
-
+
diff --git a/SourceGenWPF/WpfGui/MainWindow.xaml.cs b/SourceGenWPF/WpfGui/MainWindow.xaml.cs
index d40f133..4569bc1 100644
--- a/SourceGenWPF/WpfGui/MainWindow.xaml.cs
+++ b/SourceGenWPF/WpfGui/MainWindow.xaml.cs
@@ -761,6 +761,10 @@ namespace SourceGenWPF.WpfGui {
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditLongComment();
}
+ private void CanEditNote(object sender, CanExecuteRoutedEventArgs e) {
+ e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditNote();
+ }
+
private void CanEditOperand(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditOperand();
}
@@ -876,6 +880,10 @@ namespace SourceGenWPF.WpfGui {
mMainCtrl.EditLongComment();
}
+ private void EditNoteCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
+ mMainCtrl.EditNote();
+ }
+
private void EditOperandCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.EditOperand();
}