mirror of
https://github.com/fadden/6502bench.git
synced 2025-02-12 15:30:48 +00:00
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.
This commit is contained in:
parent
c637d6549c
commit
110a9ae818
@ -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,22 +1505,30 @@ namespace SourceGen {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the application settings dialog. All changes to settings are made directly
|
||||
/// to the AppSettings.Global object.
|
||||
/// Handles Edit > 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) {
|
||||
// TODO: this can be done in a less-awkward way by subscribing to an event
|
||||
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) {
|
||||
|
@ -37,18 +37,19 @@ namespace SourceGen.WpfGui {
|
||||
/// 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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user