Index: Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -r00bf02e3c099d01fbdb84735d8fc64de0fb98aaa -r0ea17b610f66d122fd9f0c8ef9db30740be455d8 --- Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 00bf02e3c099d01fbdb84735d8fc64de0fb98aaa) +++ Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 0ea17b610f66d122fd9f0c8ef9db30740be455d8) @@ -1008,21 +1008,13 @@ private void OnFileOptionsClicked(object sender, RoutedEventArgs e) { - var optionsDialog = new OptionsDialog + var optionsDialog = new OptionsDialog(Gui.UserSettings); + if (optionsDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - UserSettings = Gui.UserSettings, - ColorTheme = (ColorTheme) Gui.UserSettings["colorTheme"], - OnAcceptChanges = ApplyColorTheme - }; - - optionsDialog.ShowDialog(); + SetColorTheme((ColorTheme) Gui.UserSettings["colorTheme"]); + } } - private void ApplyColorTheme(OptionsDialog dialog) - { - SetColorTheme(dialog.ColorTheme); - } - private void SetColorTheme(ColorTheme colorTheme) { if (colorTheme == ColorTheme.Dark && !(DockingManager.Theme is ExpressionDarkTheme)) Index: Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.Designer.cs =================================================================== diff -u -r700ba80f40cd595e5227ab8338beb2446fe3a829 -r0ea17b610f66d122fd9f0c8ef9db30740be455d8 --- Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.Designer.cs (.../OptionsDialog.Designer.cs) (revision 700ba80f40cd595e5227ab8338beb2446fe3a829) +++ Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.Designer.cs (.../OptionsDialog.Designer.cs) (revision 0ea17b610f66d122fd9f0c8ef9db30740be455d8) @@ -53,23 +53,21 @@ this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // // buttonOk // resources.ApplyResources(this.buttonOk, "buttonOk"); this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; this.buttonOk.Name = "buttonOk"; this.buttonOk.UseVisualStyleBackColor = true; - this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + this.buttonOk.Click += new System.EventHandler(this.ButtonOkClick); // // comboBoxTheme // this.comboBoxTheme.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxTheme.FormattingEnabled = true; resources.ApplyResources(this.comboBoxTheme, "comboBoxTheme"); this.comboBoxTheme.Name = "comboBoxTheme"; - this.comboBoxTheme.SelectedIndexChanged += new System.EventHandler(this.comboBoxTheme_SelectedIndexChanged); // // label1 // Index: Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs =================================================================== diff -u -r00bf02e3c099d01fbdb84735d8fc64de0fb98aaa -r0ea17b610f66d122fd9f0c8ef9db30740be455d8 --- Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs (.../OptionsDialog.cs) (revision 00bf02e3c099d01fbdb84735d8fc64de0fb98aaa) +++ Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs (.../OptionsDialog.cs) (revision 0ea17b610f66d122fd9f0c8ef9db30740be455d8) @@ -1,60 +1,22 @@ using System; using System.Collections.ObjectModel; using System.Configuration; -using System.Security.Permissions; using System.Windows.Forms; using Core.Common.Utils.Reflection; namespace Core.Common.Gui.Forms.Options { public partial class OptionsDialog : Form { - private ApplicationSettingsBase userSettings; + private readonly ApplicationSettingsBase userSettings; - public OptionsDialog() + public OptionsDialog(ApplicationSettingsBase userSettings) { InitializeComponent(); - SetColorThemeOptions(); - } - public ApplicationSettingsBase UserSettings - { - get - { - return userSettings; - } - set - { - UpdateUserSettings(value); - } - } + this.userSettings = userSettings; - public ColorTheme ColorTheme - { - get - { - return (ColorTheme) comboBoxTheme.SelectedValue; - } - set - { - comboBoxTheme.SelectedValue = value; - } - } - - // TODO: Call this method - public Action OnAcceptChanges { get; set; } - - private void AcceptChanges() - { - SetValuesToSettings(); - if (OnAcceptChanges != null) - { - OnAcceptChanges(this); - } - } - - private void DeclineChanges() - { + SetColorThemeOptions(); SetSettingsValuesToControls(); } @@ -74,38 +36,28 @@ comboBoxTheme.DisplayMember = TypeUtils.GetMemberName(cti => cti.DisplayName); } - /// - /// Safe call because of linkdemand - /// - /// - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] - private void UpdateUserSettings(ApplicationSettingsBase settings) - { - userSettings = settings; - SetSettingsValuesToControls(); - } - - /// - /// Dialog created. - /// private void SetSettingsValuesToControls() { + if (userSettings == null) + { + return; + } + checkBoxStartPage.Checked = (bool) userSettings["showStartPage"]; + comboBoxTheme.SelectedValue = (ColorTheme) userSettings["colorTheme"]; } - /// - /// Ok clicked. - /// - private void SetValuesToSettings() + private void ButtonOkClick(object sender, EventArgs e) { - if ((bool) userSettings["showStartPage"] != checkBoxStartPage.Checked) + if (userSettings == null) { - userSettings["showStartPage"] = checkBoxStartPage.Checked; + return; } + + userSettings["showStartPage"] = checkBoxStartPage.Checked; + userSettings["colorTheme"] = comboBoxTheme.SelectedValue; } - private void comboBoxTheme_SelectedIndexChanged(object sender, EventArgs e) {} - /// /// Used for localizing the items in the theme selection combo box. /// @@ -121,25 +73,5 @@ /// public string DisplayName { get; set; } } - - protected override void OnFormClosed(FormClosedEventArgs e) - { - if (DialogResult != DialogResult.OK) - { - DeclineChanges(); - } - - base.OnFormClosed(e); - } - - private void buttonOk_Click(object sender, EventArgs e) - { - AcceptChanges(); - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - DeclineChanges(); - } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Forms/Options/OptionsDialogTest.cs =================================================================== diff -u -r00bf02e3c099d01fbdb84735d8fc64de0fb98aaa -r0ea17b610f66d122fd9f0c8ef9db30740be455d8 --- Core/Common/test/Core.Common.Gui.Test/Forms/Options/OptionsDialogTest.cs (.../OptionsDialogTest.cs) (revision 00bf02e3c099d01fbdb84735d8fc64de0fb98aaa) +++ Core/Common/test/Core.Common.Gui.Test/Forms/Options/OptionsDialogTest.cs (.../OptionsDialogTest.cs) (revision 0ea17b610f66d122fd9f0c8ef9db30740be455d8) @@ -9,7 +9,7 @@ [Test] public void GivenGeneralOptionsControlCreated_WhenRetrievingOptionsItems_ThenOptionsShouldBeTranslated() { - using (var control = new Gui.Forms.Options.OptionsDialog()) + using (var control = new Gui.Forms.Options.OptionsDialog(null)) { var subControl = (ComboBox)control.Controls.Find("comboBoxTheme", true)[0];