From 7471086bd3287f4b80607924c389f61152d481f3 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Sun, 15 Mar 2020 18:07:30 +0300 Subject: [PATCH] fix save last selected project --- .../UI/FormMain.Designer.cs | 3 --- src/UniversalValveToolbox/UI/FormMain.cs | 27 +++++-------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/UniversalValveToolbox/UI/FormMain.Designer.cs b/src/UniversalValveToolbox/UI/FormMain.Designer.cs index 6cd6ae7..591a2f6 100644 --- a/src/UniversalValveToolbox/UI/FormMain.Designer.cs +++ b/src/UniversalValveToolbox/UI/FormMain.Designer.cs @@ -59,9 +59,6 @@ this.comboBoxProjects.Name = "comboBoxProjects"; this.comboBoxProjects.Size = new System.Drawing.Size(449, 21); this.comboBoxProjects.TabIndex = 1; - this.comboBoxProjects.SelectedIndexChanged += new System.EventHandler(this.comboBoxGameConfig_SelectedIndexChanged); - this.comboBoxProjects.SelectionChangeCommitted += new System.EventHandler(this.comboBoxProjects_SelectionChangeCommitted); - this.comboBoxProjects.SelectedValueChanged += new System.EventHandler(this.comboBoxProjects_SelectedValueChanged); // // comboBoxEngine // diff --git a/src/UniversalValveToolbox/UI/FormMain.cs b/src/UniversalValveToolbox/UI/FormMain.cs index 03da859..63aacc5 100644 --- a/src/UniversalValveToolbox/UI/FormMain.cs +++ b/src/UniversalValveToolbox/UI/FormMain.cs @@ -53,7 +53,7 @@ namespace UniversalValveToolbox { } private void UpdateLastSelectedProject() { - var lastSelectedProject = dataProvider.Projects.First(project => project.Name.Equals(dataProvider.Settings.LastSelectedProject)); + var lastSelectedProject = dataProvider.Projects.FirstOrDefault(project => project.Name.Equals(dataProvider.Settings.LastSelectedProject)); if (lastSelectedProject != null) { var indexEngine = comboBoxEngine.Items.IndexOf(Engines.First(engine => engine.Appid.Equals(lastSelectedProject.Engine)).Name); @@ -65,6 +65,11 @@ namespace UniversalValveToolbox { comboBoxProjects.SelectedIndex = indexProject; } } + private void SaveLastSelectedProject() { + var settings = dataProvider.Settings; + settings.LastSelectedProject = SelectedProject?.Name; + dataProvider.Settings = settings; + } private void UpdateFormData() { @@ -86,12 +91,6 @@ namespace UniversalValveToolbox { UpdateFormData(); } - private void QuickSaveSettings() { - var settings = dataProvider.Settings; - settings.LastSelectedProject = SelectedProject.Name; - dataProvider.Settings = settings; - } - public void FillBaseMenuItems() { #region static content, do not edit //creating groups (categores) @@ -436,20 +435,8 @@ namespace UniversalValveToolbox { } } - private void comboBoxGameConfig_SelectedIndexChanged(object sender, EventArgs e) { - QuickSaveSettings(); - } - private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { - QuickSaveSettings(); - } - - private void comboBoxProjects_SelectionChangeCommitted(object sender, EventArgs e) { - QuickSaveSettings(); - } - - private void comboBoxProjects_SelectedValueChanged(object sender, EventArgs e) { - QuickSaveSettings(); + SaveLastSelectedProject(); } } }