1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-25 05:29:31 +00:00

Implement Edit Note

This commit is contained in:
Andy McFadden 2019-07-13 17:04:47 -07:00
parent e49ee6f20b
commit f8b1fa3d66
8 changed files with 289 additions and 7 deletions

View File

@ -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;

View File

@ -103,6 +103,9 @@
<Compile Include="WpfGui\EditLongComment.xaml.cs">
<DependentUpon>EditLongComment.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditNote.xaml.cs">
<DependentUpon>EditNote.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditProjectProperties.xaml.cs">
<DependentUpon>EditProjectProperties.xaml</DependentUpon>
</Compile>
@ -248,6 +251,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditNote.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditProjectProperties.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -71,7 +71,7 @@ limitations under the License.
IsReadOnly="True"/>
<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"/>
</StackPanel>
</Grid>

View File

@ -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;
}

View 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>

View 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);
}
}
}
}

View File

@ -79,6 +79,11 @@ limitations under the License.
<KeyGesture>Ctrl+M</KeyGesture>
</RoutedUICommand.InputGestures>
</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="ExitCmd" Text="Exit"/>
<RoutedUICommand x:Key="FindNextCmd" Text="Find Next">
@ -163,6 +168,8 @@ limitations under the License.
CanExecute="CanEditLabel" Executed="EditLabelCmd_Executed"/>
<CommandBinding Command="{StaticResource EditLongCommentCmd}"
CanExecute="CanEditLongComment" Executed="EditLongCommentCmd_Executed"/>
<CommandBinding Command="{StaticResource EditNoteCmd}"
CanExecute="CanEditNote" Executed="EditNoteCmd_Executed"/>
<CommandBinding Command="{StaticResource EditOperandCmd}"
CanExecute="CanEditOperand" Executed="EditOperandCmd_Executed"/>
<CommandBinding Command="{StaticResource EditStatusFlagsCmd}"
@ -262,7 +269,7 @@ limitations under the License.
<MenuItem Command="{StaticResource EditOperandCmd}"/>
<MenuItem Command="{StaticResource EditCommentCmd}" InputGestureText="Ctrl+;"/>
<MenuItem Command="{StaticResource EditLongCommentCmd}"/>
<MenuItem Header="Edit Note..."/> <!-- Ctrl+N -->
<MenuItem Command="{StaticResource EditNoteCmd}"/>
<MenuItem Header="Edit Project Symbol..."/>
<Separator/>
<MenuItem Command="{StaticResource HintAsCodeEntryPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>

View File

@ -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();
}