Compare commits

...

2 Commits

Author SHA1 Message Date
Andy McFadden 110a9ae818 Change the way app settings Apply button works
We were passing a reference to MainController in, and calling a
method on it, which is a little convoluted.  Now the main controller
subscribes to a "settings applied" event, and handles the update with
an event handler.

No change in behavior.
2024-03-02 14:48:06 -08:00
Andy McFadden c637d6549c Minor updates 2024-03-02 11:17:52 -08:00
4 changed files with 39 additions and 33 deletions

View File

@ -256,7 +256,7 @@ namespace SourceGen {
// Load the settings from the file. If this fails we have no way to tell the user,
// so just keep going.
LoadAppSettings();
SetAppWindowLocation();
SetAppWindowLocation(); // <-- this causes WindowLoaded to fire
}
/// <summary>
@ -453,20 +453,6 @@ namespace SourceGen {
}
}
/// <summary>
/// Replaces the contents of the global settings object with the new settings,
/// then applies them to the project.
/// </summary>
/// <param name="settings">New settings.</param>
public void SetAppSettings(AppSettings settings) {
AppSettings.Global.ReplaceSettings(settings);
ApplyAppSettings();
// We get called whenever Apply or OK is hit in the settings editor, so it's
// a pretty good time to save the settings out.
SaveAppSettings();
}
/// <summary>
/// Sets the app window's location and size. This should be called before the window has
/// finished initialization.
@ -1519,21 +1505,30 @@ namespace SourceGen {
}
/// <summary>
/// Opens the application settings dialog. All changes to settings are made directly
/// to the AppSettings.Global object.
/// Handles Edit &gt; App Settings.
/// </summary>
public void EditAppSettings() {
ShowAppSettings(mMainWin, WpfGui.EditAppSettings.Tab.Unknown,
AsmGen.AssemblerInfo.Id.Unknown);
}
/// <summary>
/// Opens the application settings dialog. All changes to settings are made directly
/// to the AppSettings.Global object.
/// </summary>
public void ShowAppSettings(Window owner, EditAppSettings.Tab initialTab,
AsmGen.AssemblerInfo.Id initialAsmId) {
EditAppSettings dlg = new EditAppSettings(owner, mMainWin, this,
initialTab, initialAsmId);
EditAppSettings dlg = new EditAppSettings(owner, mMainWin, initialTab, initialAsmId);
dlg.SettingsApplied += SetAppSettings; // called when "Apply" is clicked
dlg.ShowDialog();
}
// The settings code calls SetAppSettings() directly whenever "Apply" is hit.
/// <summary>
/// Applies settings to the project, and saves them to the settings files.
/// </summary>
private void SetAppSettings() {
ApplyAppSettings();
SaveAppSettings();
}
public void HandleCodeListDoubleClick(int row, int col) {

View File

@ -165,7 +165,7 @@ namespace SourceGen.Tools.Omf {
}
first = false;
Debug.Assert(seg.FileLength > 0);
Debug.Assert(seg != null && seg.FileLength > 0);
SegmentList.Add(seg);
offset += seg.FileLength;

View File

@ -22,6 +22,7 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Asm65;
@ -30,25 +31,25 @@ using CommonUtil;
using AssemblerInfo = SourceGen.AsmGen.AssemblerInfo;
using AssemblerConfig = SourceGen.AsmGen.AssemblerConfig;
using ExpressionMode = Asm65.Formatter.FormatConfig.ExpressionMode;
using System.Windows.Input;
namespace SourceGen.WpfGui {
/// <summary>
/// Application settings dialog.
/// </summary>
public partial class EditAppSettings : Window, INotifyPropertyChanged {
/// <summary>
/// Event that the controller can subscribe to if it wants to be notified when the
/// "Apply" or "OK" button is hit.
/// </summary>
public event SettingsAppliedHandler SettingsApplied;
public delegate void SettingsAppliedHandler();
/// <summary>
/// Reference to main window. Needed for examination of the code list font and
/// column widths.
/// </summary>
private MainWindow mMainWin;
/// <summary>
/// Reference to main controller. Needed to push settings out when Apply/OK is clicked.
/// TODO: use an Event instead?
/// </summary>
private MainController mMainCtrl;
/// <summary>
/// Copy of settings that we make changes to. On "Apply" or "OK", this is pushed
/// into the global settings object, and applied to the ProjectView.
@ -103,14 +104,13 @@ namespace SourceGen.WpfGui {
}
public EditAppSettings(Window owner, MainWindow mainWin, MainController mainCtrl,
Tab initialTab, AssemblerInfo.Id initialAsmId) {
public EditAppSettings(Window owner, MainWindow mainWin, Tab initialTab,
AssemblerInfo.Id initialAsmId) {
InitializeComponent();
Owner = owner;
DataContext = this;
mMainWin = mainWin;
mMainCtrl = mainCtrl;
mInitialTab = initialTab;
mInitialAsmId = initialAsmId;
@ -204,7 +204,8 @@ namespace SourceGen.WpfGui {
// QueryVersions() can sometimes be slow under Win10 (mid 2019), possibly
// because of the built-in malware detection, so pop up a wait cursor.
Mouse.OverrideCursor = Cursors.Wait;
mMainCtrl.SetAppSettings(mSettings);
AppSettings.Global.ReplaceSettings(mSettings);
OnSettingsApplied();
AsmGen.AssemblerVersionCache.QueryVersions();
} finally {
Mouse.OverrideCursor = null;
@ -213,6 +214,16 @@ namespace SourceGen.WpfGui {
IsDirty = false;
}
/// <summary>
/// Raises the "settings applied" event.
/// </summary>
private void OnSettingsApplied() {
SettingsAppliedHandler handler = SettingsApplied;
if (handler != null) {
handler();
}
}
#region Code View

View File

@ -183,7 +183,7 @@ CopyData lda #&lt;addrs ;get pointer into
</div>
</div> <!-- grid-container -->
</div> <!-- main -->
<div id="prevnext">
<a href="using-sourcegen.html" class="btn-next">Next &raquo;</a>