mirror of
https://github.com/fadden/6502bench.git
synced 2025-08-11 18:25:04 +00:00
Implement Edit Note
This commit is contained in:
@@ -1355,11 +1355,9 @@ namespace SourceGenWPF {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LineListGen.Line.Type.Note:
|
case LineListGen.Line.Type.Note:
|
||||||
#if false
|
if (CanEditNote()) {
|
||||||
if (editNoteToolStripMenuItem.Enabled) {
|
EditNote();
|
||||||
EditNote_Click(sender, e);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LineListGen.Line.Type.Code:
|
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() {
|
public bool CanEditOperand() {
|
||||||
if (SelectionAnalysis.mNumItemsSelected == 0) {
|
if (SelectionAnalysis.mNumItemsSelected == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -103,6 +103,9 @@
|
|||||||
<Compile Include="WpfGui\EditLongComment.xaml.cs">
|
<Compile Include="WpfGui\EditLongComment.xaml.cs">
|
||||||
<DependentUpon>EditLongComment.xaml</DependentUpon>
|
<DependentUpon>EditLongComment.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="WpfGui\EditNote.xaml.cs">
|
||||||
|
<DependentUpon>EditNote.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="WpfGui\EditProjectProperties.xaml.cs">
|
<Compile Include="WpfGui\EditProjectProperties.xaml.cs">
|
||||||
<DependentUpon>EditProjectProperties.xaml</DependentUpon>
|
<DependentUpon>EditProjectProperties.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -248,6 +251,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="WpfGui\EditNote.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="WpfGui\EditProjectProperties.xaml">
|
<Page Include="WpfGui\EditProjectProperties.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
@@ -71,7 +71,7 @@ limitations under the License.
|
|||||||
IsReadOnly="True"/>
|
IsReadOnly="True"/>
|
||||||
|
|
||||||
<StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
|
<StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
|
||||||
<Button Content="OK" IsDefault="True" Width="70" Click="OkButton_Clicked"/>
|
<Button Content="OK" IsDefault="True" Width="70" Click="OkButton_Click"/>
|
||||||
<Button Content="Cancel" IsCancel="True" Width="70" Margin="4,0,0,0"/>
|
<Button Content="Cancel" IsCancel="True" Width="70" Margin="4,0,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@@ -110,7 +110,7 @@ namespace SourceGenWPF.WpfGui {
|
|||||||
entryTextBox.Focus();
|
entryTextBox.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OkButton_Clicked(object sender, RoutedEventArgs e) {
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
||||||
DialogResult = true;
|
DialogResult = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
90
SourceGenWPF/WpfGui/EditNote.xaml
Normal file
90
SourceGenWPF/WpfGui/EditNote.xaml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Window x:Class="SourceGenWPF.WpfGui.EditNote"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:SourceGenWPF.WpfGui"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Edit Note"
|
||||||
|
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
|
||||||
|
ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||||
|
Loaded="Window_Loaded"
|
||||||
|
Closing="Window_Closing">
|
||||||
|
|
||||||
|
<Window.Resources>
|
||||||
|
<RoutedUICommand x:Key="CloseCmd">
|
||||||
|
<RoutedUICommand.InputGestures>
|
||||||
|
<KeyGesture>Ctrl+Enter</KeyGesture>
|
||||||
|
</RoutedUICommand.InputGestures>
|
||||||
|
</RoutedUICommand>
|
||||||
|
</Window.Resources>
|
||||||
|
<Window.CommandBindings>
|
||||||
|
<CommandBinding Command="{StaticResource CloseCmd}" Executed="CloseCmd_Executed"/>
|
||||||
|
</Window.CommandBindings>
|
||||||
|
|
||||||
|
<Grid Margin="8">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="0" Text="Enter note:"/>
|
||||||
|
|
||||||
|
<TextBox Name="inputTextBox" Grid.Row="1" Width="551" Height="120"
|
||||||
|
Text="{Binding UserInput, UpdateSourceTrigger=PropertyChanged,
|
||||||
|
FallbackValue=01234567890123456789012345678901234567890123456789012345678901234567890123456789}"
|
||||||
|
FontFamily="{StaticResource GeneralMonoFont}"
|
||||||
|
VerticalScrollBarVisibility="Auto"
|
||||||
|
AcceptsReturn="True" TextWrapping="Wrap"/>
|
||||||
|
|
||||||
|
<GroupBox Grid.Row="2" Header="Select Highlight Color" Width="200" HorizontalAlignment="Left">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<RadioButton Name="colorDefaultRadio" Grid.Column="0" Grid.Row="0" Margin="0,4,0,0"
|
||||||
|
Content="_None"/>
|
||||||
|
<RadioButton Name="colorGreenRadio" Grid.Column="0" Grid.Row="1" Margin="0,4,0,0"
|
||||||
|
Content="_Green" Background="LightGreen"/>
|
||||||
|
<RadioButton Name="colorBlueRadio" Grid.Column="0" Grid.Row="2" Margin="0,4,0,0"
|
||||||
|
Content="_Blue" Background="LightBlue"/>
|
||||||
|
<RadioButton Name="colorYellowRadio" Grid.Column="1" Grid.Row="0" Margin="0,4,0,0"
|
||||||
|
Content="_Yellow" Background="Yellow"/>
|
||||||
|
<RadioButton Name="colorPinkRadio" Grid.Column="1" Grid.Row="1" Margin="0,4,0,0"
|
||||||
|
Content="_Pink" Background="LightPink"/>
|
||||||
|
<RadioButton Name="colorOrangeRadio" Grid.Column="1" Grid.Row="2" Margin="0,4,0,0"
|
||||||
|
Content="_Orange" Background="Orange"/>
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="2" Orientation="Horizontal"
|
||||||
|
HorizontalAlignment="Right" VerticalAlignment="Bottom">
|
||||||
|
<Button Content="OK" IsDefault="True" Width="70" Click="OkButton_Click"/>
|
||||||
|
<Button Content="Cancel" IsCancel="True" Width="70" Margin="4,0,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
136
SourceGenWPF/WpfGui/EditNote.xaml.cs
Normal file
136
SourceGenWPF/WpfGui/EditNote.xaml.cs
Normal file
@@ -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 {
|
||||||
|
/// <summary>
|
||||||
|
/// Note editor.
|
||||||
|
/// </summary>
|
||||||
|
public partial class EditNote : Window, INotifyPropertyChanged {
|
||||||
|
/// <summary>
|
||||||
|
/// Note result object. Will be set to null if the note was deleted.
|
||||||
|
/// </summary>
|
||||||
|
public MultiLineComment Note { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Text input by user. This is bound to the input TextBox.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -79,6 +79,11 @@ limitations under the License.
|
|||||||
<KeyGesture>Ctrl+M</KeyGesture>
|
<KeyGesture>Ctrl+M</KeyGesture>
|
||||||
</RoutedUICommand.InputGestures>
|
</RoutedUICommand.InputGestures>
|
||||||
</RoutedUICommand>
|
</RoutedUICommand>
|
||||||
|
<RoutedUICommand x:Key="EditNoteCmd" Text="Edit Note...">
|
||||||
|
<RoutedUICommand.InputGestures>
|
||||||
|
<KeyGesture>Ctrl+N</KeyGesture>
|
||||||
|
</RoutedUICommand.InputGestures>
|
||||||
|
</RoutedUICommand>
|
||||||
<RoutedUICommand x:Key="EditStatusFlagsCmd" Text="Override Status Flags..."/>
|
<RoutedUICommand x:Key="EditStatusFlagsCmd" Text="Override Status Flags..."/>
|
||||||
<RoutedUICommand x:Key="ExitCmd" Text="Exit"/>
|
<RoutedUICommand x:Key="ExitCmd" Text="Exit"/>
|
||||||
<RoutedUICommand x:Key="FindNextCmd" Text="Find Next">
|
<RoutedUICommand x:Key="FindNextCmd" Text="Find Next">
|
||||||
@@ -163,6 +168,8 @@ limitations under the License.
|
|||||||
CanExecute="CanEditLabel" Executed="EditLabelCmd_Executed"/>
|
CanExecute="CanEditLabel" Executed="EditLabelCmd_Executed"/>
|
||||||
<CommandBinding Command="{StaticResource EditLongCommentCmd}"
|
<CommandBinding Command="{StaticResource EditLongCommentCmd}"
|
||||||
CanExecute="CanEditLongComment" Executed="EditLongCommentCmd_Executed"/>
|
CanExecute="CanEditLongComment" Executed="EditLongCommentCmd_Executed"/>
|
||||||
|
<CommandBinding Command="{StaticResource EditNoteCmd}"
|
||||||
|
CanExecute="CanEditNote" Executed="EditNoteCmd_Executed"/>
|
||||||
<CommandBinding Command="{StaticResource EditOperandCmd}"
|
<CommandBinding Command="{StaticResource EditOperandCmd}"
|
||||||
CanExecute="CanEditOperand" Executed="EditOperandCmd_Executed"/>
|
CanExecute="CanEditOperand" Executed="EditOperandCmd_Executed"/>
|
||||||
<CommandBinding Command="{StaticResource EditStatusFlagsCmd}"
|
<CommandBinding Command="{StaticResource EditStatusFlagsCmd}"
|
||||||
@@ -262,7 +269,7 @@ limitations under the License.
|
|||||||
<MenuItem Command="{StaticResource EditOperandCmd}"/>
|
<MenuItem Command="{StaticResource EditOperandCmd}"/>
|
||||||
<MenuItem Command="{StaticResource EditCommentCmd}" InputGestureText="Ctrl+;"/>
|
<MenuItem Command="{StaticResource EditCommentCmd}" InputGestureText="Ctrl+;"/>
|
||||||
<MenuItem Command="{StaticResource EditLongCommentCmd}"/>
|
<MenuItem Command="{StaticResource EditLongCommentCmd}"/>
|
||||||
<MenuItem Header="Edit Note..."/> <!-- Ctrl+N -->
|
<MenuItem Command="{StaticResource EditNoteCmd}"/>
|
||||||
<MenuItem Header="Edit Project Symbol..."/>
|
<MenuItem Header="Edit Project Symbol..."/>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Command="{StaticResource HintAsCodeEntryPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>
|
<MenuItem Command="{StaticResource HintAsCodeEntryPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>
|
||||||
|
@@ -761,6 +761,10 @@ namespace SourceGenWPF.WpfGui {
|
|||||||
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditLongComment();
|
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditLongComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CanEditNote(object sender, CanExecuteRoutedEventArgs e) {
|
||||||
|
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditNote();
|
||||||
|
}
|
||||||
|
|
||||||
private void CanEditOperand(object sender, CanExecuteRoutedEventArgs e) {
|
private void CanEditOperand(object sender, CanExecuteRoutedEventArgs e) {
|
||||||
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditOperand();
|
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditOperand();
|
||||||
}
|
}
|
||||||
@@ -876,6 +880,10 @@ namespace SourceGenWPF.WpfGui {
|
|||||||
mMainCtrl.EditLongComment();
|
mMainCtrl.EditLongComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EditNoteCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
mMainCtrl.EditNote();
|
||||||
|
}
|
||||||
|
|
||||||
private void EditOperandCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
private void EditOperandCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||||
mMainCtrl.EditOperand();
|
mMainCtrl.EditOperand();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user