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

Implement Edit Comment

I still don't know why Windows wants to refer to semicolon as
"Oem1".  Happily it's possible to override the tip string.
This commit is contained in:
Andy McFadden 2019-07-11 15:55:43 -07:00
parent e97672697c
commit b1f84864d6
6 changed files with 186 additions and 5 deletions

View File

@ -1427,11 +1427,9 @@ namespace SourceGenWPF {
}
break;
case CodeListColumn.Comment:
#if false
if (editCommentToolStripMenuItem.Enabled) {
EditComment_Click(sender, e);
if (CanEditComment()) {
EditComment();
}
#endif
break;
}
@ -1486,6 +1484,33 @@ namespace SourceGenWPF {
}
}
public bool CanEditComment() {
if (SelectionAnalysis.mNumItemsSelected != 1) {
return false;
}
// Line must be code or data.
return (SelectionAnalysis.mLineType == LineListGen.Line.Type.Code ||
SelectionAnalysis.mLineType == LineListGen.Line.Type.Data);
}
public void EditComment() {
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
int offset = CodeLineList[selIndex].FileOffset;
string oldComment = mProject.Comments[offset];
EditComment dlg = new EditComment(mMainWin, oldComment);
if (dlg.ShowDialog() == true) {
if (!oldComment.Equals(dlg.CommentText)) {
Debug.WriteLine("Changing comment at +" + offset.ToString("x6"));
UndoableChange uc = UndoableChange.CreateCommentChange(offset,
oldComment, dlg.CommentText);
ChangeSet cs = new ChangeSet(uc);
ApplyUndoableChanges(cs);
}
}
}
public void EditHeaderComment() {
EditLongComment(LineListGen.Line.HEADER_COMMENT_OFFSET);
}

View File

@ -84,6 +84,9 @@
<Compile Include="WpfGui\EditAppSettings.xaml.cs">
<DependentUpon>EditAppSettings.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditComment.xaml.cs">
<DependentUpon>EditComment.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditDataOperand.xaml.cs">
<DependentUpon>EditDataOperand.xaml</DependentUpon>
</Compile>
@ -214,6 +217,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditComment.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditDataOperand.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,49 @@
<!--
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.EditComment"
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:system="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:SourceGenWPF.WpfGui"
mc:Ignorable="d"
Title="Edit Comment"
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
ContentRendered="Window_ContentRendered">
<StackPanel Margin="8">
<TextBlock Text="Enter comment:"/>
<TextBox Name="commentTextBox" Text="{Binding CommentText}" Width="480" Margin="0,4,0,0"
TextChanged="CommentTextBox_TextChanged"/>
<DockPanel>
<TextBlock DockPanel.Dock="Right"
Text="{Binding StringFormat={}{0} characters, ElementName=commentTextBox, Path=Text.Length}"/>
<TextBlock Name="asciiOnlyLabel" DockPanel.Dock="Left" Margin="0,4,0,0"
Text="• ASCII-only is recommended"/>
</DockPanel>
<TextBlock Name="maxLengthLabel" Text="• Limit to 52 or fewer characters for nice 80-column output"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
<Button Name="okButton" Content="OK" IsDefault="True" Width="70"
Click="OkButton_Click"/>
<Button Name="cancelButton" Content="Cancel" IsCancel="True"
Width="70" Margin="4,0,0,0"/>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,84 @@
/*
* 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.Media;
namespace SourceGenWPF.WpfGui {
/// <summary>
/// Comment editor.
/// </summary>
public partial class EditComment : Window, INotifyPropertyChanged {
private const int RECOMMENDED_MAX_LENGTH = 52;
/// <summary>
/// Edited comment string. Will be empty if the comment is to be deleted.
/// </summary>
public string CommentText {
get { return mCommentText; }
set {
mCommentText = value;
OnPropertyChanged();
}
}
private string mCommentText;
private Brush mDefaultLabelColor;
// INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public EditComment(Window owner, string comment) {
InitializeComponent();
Owner = owner;
DataContext = this;
CommentText = comment;
mDefaultLabelColor = asciiOnlyLabel.Foreground;
}
public void Window_ContentRendered(object sender, EventArgs e) {
commentTextBox.SelectAll();
commentTextBox.Focus();
}
private void OkButton_Click(object sender, RoutedEventArgs e) {
DialogResult = true;
}
private void CommentTextBox_TextChanged(object sender, TextChangedEventArgs e) {
if (!CommonUtil.TextUtil.IsPrintableAscii(commentTextBox.Text)) {
asciiOnlyLabel.Foreground = Brushes.Red;
} else {
asciiOnlyLabel.Foreground = mDefaultLabelColor;
}
if (commentTextBox.Text.Length > RECOMMENDED_MAX_LENGTH) {
maxLengthLabel.Foreground = Brushes.Red;
} else {
maxLengthLabel.Foreground = mDefaultLabelColor;
}
}
}
}

View File

@ -57,6 +57,12 @@ limitations under the License.
<RoutedUICommand x:Key="DebugSourceGenerationTestsCmd" Text="Source Generation Tests..."/>
<RoutedUICommand x:Key="EditAddressCmd" Text="Set Address..."/>
<RoutedUICommand x:Key="EditAppSettingsCmd" Text="Settings..."/>
<RoutedUICommand x:Key="EditCommentCmd" Text="Edit Comment...">
<RoutedUICommand.InputGestures>
<!-- this works, but appears as "Ctrl+Oem1", so override tip in menu items -->
<KeyGesture>Ctrl+Semicolon</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="EditHeaderCommentCmd" Text="Edit Header Comment..."/>
<RoutedUICommand x:Key="EditOperandCmd" Text="Edit Operand...">
<RoutedUICommand.InputGestures>
@ -146,6 +152,8 @@ limitations under the License.
Executed="DebugSourceGenerationTestsCmd_Executed"/>
<CommandBinding Command="{StaticResource EditAddressCmd}"
CanExecute="CanEditAddress" Executed="EditAddressCmd_Executed"/>
<CommandBinding Command="{StaticResource EditCommentCmd}"
CanExecute="CanEditComment" Executed="EditCommentCmd_Executed"/>
<CommandBinding Command="{StaticResource EditHeaderCommentCmd}"
CanExecute="IsProjectOpen" Executed="EditHeaderCommentCmd_Executed"/>
<CommandBinding Command="{StaticResource EditLabelCmd}"
@ -243,7 +251,7 @@ limitations under the License.
<MenuItem Command="{StaticResource EditStatusFlagsCmd}"/>
<MenuItem Command="{StaticResource EditLabelCmd}"/>
<MenuItem Command="{StaticResource EditOperandCmd}"/>
<MenuItem Header="Edit Comment..."/> <!-- Ctrl+; -->
<MenuItem Command="{StaticResource EditCommentCmd}" InputGestureText="Ctrl+;"/>
<MenuItem Command="{StaticResource EditLongCommentCmd}"/>
<MenuItem Header="Edit Note..."/> <!-- Ctrl+N -->
<MenuItem Header="Edit Project Symbol..."/>

View File

@ -749,6 +749,10 @@ namespace SourceGenWPF.WpfGui {
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditAddress();
}
private void CanEditComment(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditComment();
}
private void CanEditLabel(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = IsProjectOpen() && mMainCtrl.CanEditLabel();
}
@ -852,6 +856,10 @@ namespace SourceGenWPF.WpfGui {
mMainCtrl.EditAppSettings();
}
private void EditCommentCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.EditComment();
}
private void EditHeaderCommentCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.EditHeaderComment();
}