mirror of
https://github.com/fadden/6502bench.git
synced 2025-02-14 13:32:58 +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>
|
/// <summary>
|
||||||
/// Sets the app window's location and size. This should be called before the window has
|
/// Sets the app window's location and size. This should be called before the window has
|
||||||
/// finished initialization.
|
/// finished initialization.
|
||||||
@ -1519,22 +1505,30 @@ namespace SourceGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the application settings dialog. All changes to settings are made directly
|
/// Handles Edit > App Settings.
|
||||||
/// to the AppSettings.Global object.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void EditAppSettings() {
|
public void EditAppSettings() {
|
||||||
ShowAppSettings(mMainWin, WpfGui.EditAppSettings.Tab.Unknown,
|
ShowAppSettings(mMainWin, WpfGui.EditAppSettings.Tab.Unknown,
|
||||||
AsmGen.AssemblerInfo.Id.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,
|
public void ShowAppSettings(Window owner, EditAppSettings.Tab initialTab,
|
||||||
AsmGen.AssemblerInfo.Id initialAsmId) {
|
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, initialTab, initialAsmId);
|
||||||
EditAppSettings dlg = new EditAppSettings(owner, mMainWin, this,
|
dlg.SettingsApplied += SetAppSettings; // called when "Apply" is clicked
|
||||||
initialTab, initialAsmId);
|
|
||||||
dlg.ShowDialog();
|
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) {
|
public void HandleCodeListDoubleClick(int row, int col) {
|
||||||
|
@ -37,18 +37,19 @@ namespace SourceGen.WpfGui {
|
|||||||
/// Application settings dialog.
|
/// Application settings dialog.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class EditAppSettings : Window, INotifyPropertyChanged {
|
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>
|
/// <summary>
|
||||||
/// Reference to main window. Needed for examination of the code list font and
|
/// Reference to main window. Needed for examination of the code list font and
|
||||||
/// column widths.
|
/// column widths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MainWindow mMainWin;
|
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>
|
/// <summary>
|
||||||
/// Copy of settings that we make changes to. On "Apply" or "OK", this is pushed
|
/// 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.
|
/// 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,
|
public EditAppSettings(Window owner, MainWindow mainWin, Tab initialTab,
|
||||||
Tab initialTab, AssemblerInfo.Id initialAsmId) {
|
AssemblerInfo.Id initialAsmId) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
DataContext = this;
|
DataContext = this;
|
||||||
|
|
||||||
mMainWin = mainWin;
|
mMainWin = mainWin;
|
||||||
mMainCtrl = mainCtrl;
|
|
||||||
mInitialTab = initialTab;
|
mInitialTab = initialTab;
|
||||||
mInitialAsmId = initialAsmId;
|
mInitialAsmId = initialAsmId;
|
||||||
|
|
||||||
@ -204,7 +204,8 @@ namespace SourceGen.WpfGui {
|
|||||||
// QueryVersions() can sometimes be slow under Win10 (mid 2019), possibly
|
// QueryVersions() can sometimes be slow under Win10 (mid 2019), possibly
|
||||||
// because of the built-in malware detection, so pop up a wait cursor.
|
// because of the built-in malware detection, so pop up a wait cursor.
|
||||||
Mouse.OverrideCursor = Cursors.Wait;
|
Mouse.OverrideCursor = Cursors.Wait;
|
||||||
mMainCtrl.SetAppSettings(mSettings);
|
AppSettings.Global.ReplaceSettings(mSettings);
|
||||||
|
OnSettingsApplied();
|
||||||
AsmGen.AssemblerVersionCache.QueryVersions();
|
AsmGen.AssemblerVersionCache.QueryVersions();
|
||||||
} finally {
|
} finally {
|
||||||
Mouse.OverrideCursor = null;
|
Mouse.OverrideCursor = null;
|
||||||
@ -213,6 +214,16 @@ namespace SourceGen.WpfGui {
|
|||||||
IsDirty = false;
|
IsDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raises the "settings applied" event.
|
||||||
|
/// </summary>
|
||||||
|
private void OnSettingsApplied() {
|
||||||
|
SettingsAppliedHandler handler = SettingsApplied;
|
||||||
|
if (handler != null) {
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Code View
|
#region Code View
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user