2019-08-25 21:14:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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;
|
2019-10-02 01:20:51 +00:00
|
|
|
|
using System.Collections;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2019-10-02 01:20:51 +00:00
|
|
|
|
using System.Windows.Data;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
using Asm65;
|
|
|
|
|
using CommonWPF;
|
|
|
|
|
|
2019-08-25 21:14:44 +00:00
|
|
|
|
namespace SourceGen.WpfGui {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit a LocalVariableTable.
|
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
public partial class EditLocalVariableTable : Window, INotifyPropertyChanged {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// Output. Will be null if the table was deleted, or if cancel was hit while
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// creating a new table.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public LocalVariableTable NewTable { get; private set; }
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output. If the table was moved, the new offset will be different from the old.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int NewOffset { get; private set; }
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Item for the symbol list view ItemsSource.
|
2019-08-25 21:14:44 +00:00
|
|
|
|
public class FormattedSymbol {
|
|
|
|
|
public string Label { get; private set; }
|
|
|
|
|
public string Value { get; private set; }
|
|
|
|
|
public string Type { get; private set; }
|
2019-10-02 01:20:51 +00:00
|
|
|
|
public int Width { get; private set; }
|
2019-08-25 21:14:44 +00:00
|
|
|
|
public string Comment { get; private set; }
|
|
|
|
|
|
2019-11-09 04:44:45 +00:00
|
|
|
|
public DefSymbol DefSym;
|
2019-10-02 01:20:51 +00:00
|
|
|
|
|
2019-11-09 04:44:45 +00:00
|
|
|
|
public FormattedSymbol(DefSymbol defSym, string label, string value,
|
|
|
|
|
string type, int width, string comment) {
|
2019-08-25 21:14:44 +00:00
|
|
|
|
Label = label;
|
|
|
|
|
Value = value;
|
|
|
|
|
Type = type;
|
|
|
|
|
Width = width;
|
|
|
|
|
Comment = comment;
|
2019-10-02 01:20:51 +00:00
|
|
|
|
|
2019-11-09 04:44:45 +00:00
|
|
|
|
DefSym = defSym;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-02 01:20:51 +00:00
|
|
|
|
|
|
|
|
|
// List of items. The Label is guaranteed to be unique.
|
2019-08-25 21:14:44 +00:00
|
|
|
|
public ObservableCollection<FormattedSymbol> Variables { get; private set; } =
|
|
|
|
|
new ObservableCollection<FormattedSymbol>();
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear-previous flag.
|
|
|
|
|
/// </summary>
|
2019-08-26 00:25:15 +00:00
|
|
|
|
public bool ClearPrevious {
|
|
|
|
|
get { return mWorkTable.ClearPrevious; }
|
|
|
|
|
set { mWorkTable.ClearPrevious = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if this is not a new table. (Using "not" because that's the sense we
|
|
|
|
|
/// need in XAML.)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsNotNewTable {
|
|
|
|
|
get { return mIsNotNewTable; }
|
|
|
|
|
set { mIsNotNewTable = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private bool mIsNotNewTable;
|
|
|
|
|
|
2019-09-19 22:53:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Table header text string, formatted at load time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TableHeaderText {
|
|
|
|
|
get { return mTableHeaderText; }
|
|
|
|
|
set { mTableHeaderText = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private string mTableHeaderText;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Working set. Used internally to hold state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private LocalVariableTable mWorkTable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// Project reference.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
private DisasmProject mProject;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Format object to use when formatting addresses and constants.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Formatter mFormatter;
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Symbol table for uniqueness check.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SymbolTable mSymbolTable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Table offset, for move ops.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int mOffset;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor. lvt will be null when creating a new entry.
|
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
public EditLocalVariableTable(Window owner, DisasmProject project, Formatter formatter,
|
|
|
|
|
LocalVariableTable lvt, int offset) {
|
2019-08-25 21:14:44 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
Owner = owner;
|
|
|
|
|
DataContext = this;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
mProject = project;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
mFormatter = formatter;
|
2019-09-01 23:40:54 +00:00
|
|
|
|
mSymbolTable = project.SymbolTable;
|
|
|
|
|
mOffset = NewOffset = offset;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
|
|
|
|
if (lvt != null) {
|
|
|
|
|
mWorkTable = new LocalVariableTable(lvt);
|
2019-08-26 23:58:53 +00:00
|
|
|
|
mIsNotNewTable = true;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
mWorkTable = new LocalVariableTable();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
for (int i = 0; i < mWorkTable.Count; i++) {
|
|
|
|
|
DefSymbol defSym = mWorkTable[i];
|
|
|
|
|
Variables.Add(CreateFormattedSymbol(defSym));
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Window_Loaded(object sender, RoutedEventArgs e) {
|
2019-09-19 22:53:23 +00:00
|
|
|
|
string fmt = (string)FindResource("str_TableHeaderFmt");
|
|
|
|
|
TableHeaderText = string.Format(fmt, mFormatter.FormatOffset24(mOffset));
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads entries from the work table into the items source.
|
|
|
|
|
/// </summary>
|
2019-10-02 01:20:51 +00:00
|
|
|
|
private FormattedSymbol CreateFormattedSymbol(DefSymbol defSym) {
|
|
|
|
|
string typeStr;
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (defSym.IsConstant) {
|
2019-10-02 01:20:51 +00:00
|
|
|
|
typeStr = Res.Strings.ABBREV_STACK_RELATIVE;
|
|
|
|
|
} else {
|
|
|
|
|
typeStr = Res.Strings.ABBREV_ADDRESS;
|
|
|
|
|
}
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
FormattedSymbol fsym = new FormattedSymbol(
|
2019-11-09 04:44:45 +00:00
|
|
|
|
defSym,
|
2019-11-13 01:24:41 +00:00
|
|
|
|
defSym.GenerateDisplayLabel(mFormatter),
|
2019-10-02 01:20:51 +00:00
|
|
|
|
mFormatter.FormatValueInBase(defSym.Value, defSym.DataDescriptor.NumBase),
|
|
|
|
|
typeStr,
|
|
|
|
|
defSym.DataDescriptor.Length,
|
|
|
|
|
defSym.Comment);
|
|
|
|
|
return fsym;
|
|
|
|
|
}
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles a Sorting event. We need to sort by numeric value on the Value field, but
|
|
|
|
|
/// we want to use custom-formatted numeric values in multiple bases.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SymbolsList_Sorting(object sender, DataGridSortingEventArgs e) {
|
|
|
|
|
DataGridColumn col = e.Column;
|
|
|
|
|
|
|
|
|
|
// Set the SortDirection to a specific value. If we don't do this, SortDirection
|
|
|
|
|
// remains un-set, and the column header doesn't show up/down arrows or change
|
|
|
|
|
// direction when clicked twice.
|
|
|
|
|
ListSortDirection direction = (col.SortDirection != ListSortDirection.Ascending) ?
|
|
|
|
|
ListSortDirection.Ascending : ListSortDirection.Descending;
|
|
|
|
|
col.SortDirection = direction;
|
|
|
|
|
|
|
|
|
|
bool isAscending = direction != ListSortDirection.Descending;
|
|
|
|
|
|
|
|
|
|
IComparer comparer = new SymbolsListComparer(col.DisplayIndex, isAscending);
|
|
|
|
|
ListCollectionView lcv =
|
|
|
|
|
(ListCollectionView)CollectionViewSource.GetDefaultView(symbolsList.ItemsSource);
|
|
|
|
|
lcv.CustomSort = comparer;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
private class SymbolsListComparer : IComparer {
|
|
|
|
|
// Must match order of items in DataGrid. DataGrid must not allow columns to be
|
|
|
|
|
// reordered. We could check col.Header instead, but then we have to assume that
|
|
|
|
|
// the Header is a string that doesn't get renamed.
|
|
|
|
|
private enum SortField {
|
|
|
|
|
Label = 0, Value = 1, Type = 2, Width = 3, Comment = 4
|
|
|
|
|
}
|
|
|
|
|
private SortField mSortField;
|
|
|
|
|
private bool mIsAscending;
|
|
|
|
|
|
|
|
|
|
public SymbolsListComparer(int displayIndex, bool isAscending) {
|
|
|
|
|
Debug.Assert(displayIndex >= 0 && displayIndex <= 4);
|
|
|
|
|
mIsAscending = isAscending;
|
|
|
|
|
mSortField = (SortField)displayIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IComparer interface
|
|
|
|
|
public int Compare(object o1, object o2) {
|
|
|
|
|
FormattedSymbol fsym1 = (FormattedSymbol)o1;
|
|
|
|
|
FormattedSymbol fsym2 = (FormattedSymbol)o2;
|
|
|
|
|
|
|
|
|
|
// Sort primarily by specified field, secondarily by label (which should
|
|
|
|
|
// be unique).
|
|
|
|
|
int cmp;
|
|
|
|
|
switch (mSortField) {
|
|
|
|
|
case SortField.Label:
|
|
|
|
|
cmp = string.Compare(fsym1.Label, fsym2.Label);
|
|
|
|
|
break;
|
|
|
|
|
case SortField.Value:
|
2019-11-09 04:44:45 +00:00
|
|
|
|
cmp = fsym1.DefSym.Value - fsym2.DefSym.Value;
|
2019-10-02 01:20:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case SortField.Type:
|
|
|
|
|
cmp = string.Compare(fsym1.Type, fsym2.Type);
|
|
|
|
|
break;
|
|
|
|
|
case SortField.Width:
|
|
|
|
|
cmp = fsym1.Width - fsym2.Width;
|
|
|
|
|
break;
|
|
|
|
|
case SortField.Comment:
|
|
|
|
|
cmp = string.Compare(fsym1.Comment, fsym2.Comment);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmp == 0) {
|
|
|
|
|
cmp = string.Compare(fsym1.Label, fsym2.Label);
|
|
|
|
|
}
|
|
|
|
|
if (!mIsAscending) {
|
|
|
|
|
cmp = -cmp;
|
|
|
|
|
}
|
|
|
|
|
return cmp;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateControls() {
|
|
|
|
|
// Enable or disable the edit/remove buttons based on how many items are selected.
|
|
|
|
|
// (We're currently configured for single-select, so this is really just a != 0 test.)
|
2019-10-02 01:20:51 +00:00
|
|
|
|
int symSelCount = symbolsList.SelectedItems.Count;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
removeSymbolButton.IsEnabled = (symSelCount == 1);
|
|
|
|
|
editSymbolButton.IsEnabled = (symSelCount == 1);
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
NewTable = mWorkTable;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 00:09:18 +00:00
|
|
|
|
private void Window_KeyEventHandler(object sender, KeyEventArgs e) {
|
|
|
|
|
if (e.Key == Key.Return && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) {
|
|
|
|
|
OkButton_Click(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-25 21:14:44 +00:00
|
|
|
|
private void DeleteTableButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 23:58:53 +00:00
|
|
|
|
MessageBoxResult result = MessageBox.Show((string)FindResource("str_ConfirmDelete"),
|
|
|
|
|
(string)FindResource("str_ConfirmDeleteCaption"),
|
|
|
|
|
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
if (result == MessageBoxResult.Yes) {
|
|
|
|
|
NewTable = null;
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
private void MoveTableButton_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
EditLvTableLocation dlg = new EditLvTableLocation(this, mProject, mOffset, NewOffset);
|
|
|
|
|
if (dlg.ShowDialog() == true) {
|
|
|
|
|
NewOffset = dlg.NewOffset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
private void SymbolsList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
private void SymbolsList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
|
|
|
|
if (!symbolsList.GetClickRowColItem(e, out int unusedRow, out int unusedCol,
|
|
|
|
|
out object objItem)) {
|
|
|
|
|
// Header or empty area; ignore.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-10-02 01:20:51 +00:00
|
|
|
|
FormattedSymbol item = (FormattedSymbol)objItem;
|
2019-11-09 04:44:45 +00:00
|
|
|
|
DoEditSymbol(item.DefSym);
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewSymbolButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
EditDefSymbol dlg = new EditDefSymbol(this, mFormatter, mWorkTable.GetSortedByLabel(),
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
null, mSymbolTable, true, false);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
if (dlg.DialogResult == true) {
|
|
|
|
|
Debug.WriteLine("ADD: " + dlg.NewSym);
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mWorkTable.AddOrReplace(dlg.NewSym);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
// Add it to the display list, select it, and scroll it into view.
|
|
|
|
|
FormattedSymbol newItem = CreateFormattedSymbol(dlg.NewSym);
|
|
|
|
|
Variables.Add(newItem);
|
|
|
|
|
symbolsList.SelectedItem = newItem;
|
|
|
|
|
symbolsList.ScrollIntoView(newItem);
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditSymbolButton_Click(object sender, EventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Single-select list view, button dimmed when no selection.
|
2019-10-02 01:20:51 +00:00
|
|
|
|
Debug.Assert(symbolsList.SelectedItems.Count == 1);
|
|
|
|
|
FormattedSymbol item = (FormattedSymbol)symbolsList.SelectedItems[0];
|
2019-11-09 04:44:45 +00:00
|
|
|
|
DoEditSymbol(item.DefSym);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DoEditSymbol(DefSymbol defSym) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
EditDefSymbol dlg = new EditDefSymbol(this, mFormatter, mWorkTable.GetSortedByLabel(),
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
defSym, mSymbolTable, true, false);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
if (dlg.DialogResult == true) {
|
|
|
|
|
// Label might have changed, so remove old before adding new.
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mWorkTable.RemoveByLabel(defSym.Label);
|
|
|
|
|
mWorkTable.AddOrReplace(dlg.NewSym);
|
2019-10-02 01:20:51 +00:00
|
|
|
|
|
|
|
|
|
// Replace entry in items source.
|
|
|
|
|
for (int i = 0; i < Variables.Count; i++) {
|
2019-11-09 04:44:45 +00:00
|
|
|
|
if (Variables[i].DefSym == defSym) {
|
2019-10-02 01:20:51 +00:00
|
|
|
|
Variables[i] = CreateFormattedSymbol(dlg.NewSym);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveSymbolButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Single-select list view, button dimmed when no selection.
|
2019-10-02 01:20:51 +00:00
|
|
|
|
Debug.Assert(symbolsList.SelectedItems.Count == 1);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-10-02 01:20:51 +00:00
|
|
|
|
int selectionIndex = symbolsList.SelectedIndex;
|
|
|
|
|
FormattedSymbol item = (FormattedSymbol)symbolsList.SelectedItems[0];
|
2019-11-09 04:44:45 +00:00
|
|
|
|
DefSymbol defSym = item.DefSym;
|
|
|
|
|
mWorkTable.RemoveByLabel(defSym.Label);
|
2019-10-02 01:20:51 +00:00
|
|
|
|
for (int i = 0; i < Variables.Count; i++) {
|
2019-11-09 04:44:45 +00:00
|
|
|
|
if (Variables[i].DefSym == defSym) {
|
2019-10-02 01:20:51 +00:00
|
|
|
|
Variables.RemoveAt(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
|
|
|
|
|
|
|
|
|
// Restore selection to the item that used to come after the one we just deleted,
|
|
|
|
|
// so you can hit "Remove" repeatedly to delete multiple items.
|
2019-10-02 01:20:51 +00:00
|
|
|
|
int newCount = symbolsList.Items.Count;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (selectionIndex >= newCount) {
|
|
|
|
|
selectionIndex = newCount - 1;
|
|
|
|
|
}
|
|
|
|
|
if (selectionIndex >= 0) {
|
2019-10-02 01:20:51 +00:00
|
|
|
|
symbolsList.SelectedIndex = selectionIndex;
|
|
|
|
|
removeSymbolButton.Focus(); // so you can keep banging on Enter
|
2019-08-26 00:25:15 +00:00
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|