1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-07-14 05:28:55 +00:00
6502bench/SourceGen/Tools/WpfGui/ProblemListViewer.xaml.cs
Andy McFadden 41cd30a8c6 Add Problem List Viewer to debug menu
The analyzer sometimes runs into things that don't seem right, like
hidden labels or references to non-existent symbols, but has no way
to report them.  This adds a problem viewer.

I'm not quite ready to turn this into a real feature, so for now it's
a free-floating window accessed from the debug menu.

Also, updated some documentation.
2019-09-21 13:43:01 -07:00

128 lines
4.5 KiB
C#

/*
* 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.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
namespace SourceGen.Tools.WpfGui {
/// <summary>
/// Floating problem list window.
/// </summary>
public partial class ProblemListViewer : Window, INotifyPropertyChanged {
public class ProblemsListItem {
public string Severity { get; private set; }
public string Offset { get; private set; }
public string Type { get; private set; }
public string Context { get; private set; }
public string Resolution { get; private set; }
public ProblemsListItem(string severity, string offset, string type, string context,
string resolution) {
Severity = severity;
Offset = offset;
Type = type;
Context = context;
Resolution = resolution;
}
}
/// <summary>
/// Reference to project.
/// </summary>
private DisasmProject mProject;
/// <summary>
/// Text formatter.
/// </summary>
private Asm65.Formatter mFormatter;
/// <summary>
/// ItemsSource for DataGrid.
/// </summary>
public ObservableCollection<ProblemsListItem> FormattedProblems { get; private set; } =
new ObservableCollection<ProblemsListItem>();
// INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ProblemListViewer(Window owner, DisasmProject project, Asm65.Formatter formatter) {
InitializeComponent();
Owner = owner;
DataContext = this;
mProject = project;
mFormatter = formatter;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
Update();
}
/// <summary>
/// Updates the contents of the DataGrid to the current values in mProject.Problems.
/// </summary>
public void Update() {
FormattedProblems.Clear();
foreach (ProblemList.ProblemEntry entry in mProject.Problems) {
ProblemsListItem newItem = FormatEntry(entry);
FormattedProblems.Add(newItem);
}
}
private ProblemsListItem FormatEntry(ProblemList.ProblemEntry entry) {
string severity = entry.Severity.ToString(); // enum
string offset = mFormatter.FormatOffset24(entry.Offset);
string problem;
switch (entry.Problem) {
case ProblemList.ProblemEntry.ProblemType.HiddenLabel:
problem = (string)FindResource("str_HiddenLabel");
break;
case ProblemList.ProblemEntry.ProblemType.UnresolvedWeakRef:
problem = (string)FindResource("str_UnresolvedWeakRef");
break;
default:
problem = "???";
break;
}
string context = entry.Context.ToString();
string resolution;
switch (entry.Resolution) {
case ProblemList.ProblemEntry.ProblemResolution.LabelIgnored:
resolution = (string)FindResource("str_LabelIgnored");
break;
case ProblemList.ProblemEntry.ProblemResolution.FormatDescriptorIgnored:
resolution = (string)FindResource("str_FormatDescriptorIgnored");
break;
default:
resolution = "???";
break;
}
return new ProblemsListItem(severity, offset, problem, context, resolution);
}
}
}