From 3f057d100e182592e107e594fbeb9c0c16383b0f Mon Sep 17 00:00:00 2001 From: Alex Z Date: Tue, 10 Mar 2020 02:06:08 +0300 Subject: [PATCH] [not working yet] --- .../Model/Dto/SettingsDtoModel.cs | 19 ++----- .../UI/FormMain.Designer.cs | 33 ++++++------ src/UniversalValveToolbox/UI/FormMain.cs | 54 +++++++++++++++---- src/UniversalValveToolbox/json/settings.json | 3 +- 4 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/UniversalValveToolbox/Model/Dto/SettingsDtoModel.cs b/src/UniversalValveToolbox/Model/Dto/SettingsDtoModel.cs index fc9678c..0bbd269 100644 --- a/src/UniversalValveToolbox/Model/Dto/SettingsDtoModel.cs +++ b/src/UniversalValveToolbox/Model/Dto/SettingsDtoModel.cs @@ -2,20 +2,14 @@ namespace UniversalValveToolbox.Model.Dto { public class SettingsDtoModel : DtoModel { - private string defaultProject; - private int[] availableEnginies; + private string lastSelectedProject; private string[] availableLanguages; private string language; private string theme; - public string DefaultProject { - get => defaultProject; - set => UpdateField(value, ref defaultProject); - } - - public int[] AvailableEnginies { - get => availableEnginies; - set => UpdateField(value, ref availableEnginies); + public string LastSelectedProject { + get => lastSelectedProject; + set => UpdateField(value, ref lastSelectedProject); } public string[] AvailableLanguages { @@ -27,10 +21,5 @@ namespace UniversalValveToolbox.Model.Dto { get => language; set => UpdateField(value, ref language); } - - public string Theme { - get => theme; - set => UpdateField(value, ref theme); - } } } diff --git a/src/UniversalValveToolbox/UI/FormMain.Designer.cs b/src/UniversalValveToolbox/UI/FormMain.Designer.cs index 5797112..6cd6ae7 100644 --- a/src/UniversalValveToolbox/UI/FormMain.Designer.cs +++ b/src/UniversalValveToolbox/UI/FormMain.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); - this.comboBoxGameConfig = new System.Windows.Forms.ComboBox(); + this.comboBoxProjects = new System.Windows.Forms.ComboBox(); this.comboBoxEngine = new System.Windows.Forms.ComboBox(); this.listView = new System.Windows.Forms.ListView(); this.imageListLarge = new System.Windows.Forms.ImageList(this.components); @@ -45,21 +45,23 @@ this.statusStrip.SuspendLayout(); this.SuspendLayout(); // - // comboBoxGameConfig + // comboBoxProjects // - this.comboBoxGameConfig.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + this.comboBoxProjects.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.comboBoxGameConfig.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxGameConfig.Enabled = false; - this.comboBoxGameConfig.FormattingEnabled = true; - this.comboBoxGameConfig.ItemHeight = 13; - this.comboBoxGameConfig.Items.AddRange(new object[] { + this.comboBoxProjects.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxProjects.Enabled = false; + this.comboBoxProjects.FormattingEnabled = true; + this.comboBoxProjects.ItemHeight = 13; + this.comboBoxProjects.Items.AddRange(new object[] { "No project configured"}); - this.comboBoxGameConfig.Location = new System.Drawing.Point(12, 412); - this.comboBoxGameConfig.Name = "comboBoxGameConfig"; - this.comboBoxGameConfig.Size = new System.Drawing.Size(449, 21); - this.comboBoxGameConfig.TabIndex = 1; - this.comboBoxGameConfig.SelectedIndexChanged += new System.EventHandler(this.comboBoxGameConfig_SelectedIndexChanged); + this.comboBoxProjects.Location = new System.Drawing.Point(12, 412); + 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 // @@ -192,13 +194,14 @@ this.Controls.Add(this.statusStrip); this.Controls.Add(this.listView); this.Controls.Add(this.comboBoxEngine); - this.Controls.Add(this.comboBoxGameConfig); + this.Controls.Add(this.comboBoxProjects); this.DoubleBuffered = true; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MinimumSize = new System.Drawing.Size(373, 474); this.Name = "FormMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Universal Valve Toolbox"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing); this.Load += new System.EventHandler(this.FormMain_Load); this.statusStrip.ResumeLayout(false); this.statusStrip.PerformLayout(); @@ -208,7 +211,7 @@ } #endregion - private System.Windows.Forms.ComboBox comboBoxGameConfig; + private System.Windows.Forms.ComboBox comboBoxProjects; private System.Windows.Forms.ComboBox comboBoxEngine; private System.Windows.Forms.ListView listView; private System.Windows.Forms.StatusStrip statusStrip; diff --git a/src/UniversalValveToolbox/UI/FormMain.cs b/src/UniversalValveToolbox/UI/FormMain.cs index 94fa157..03da859 100644 --- a/src/UniversalValveToolbox/UI/FormMain.cs +++ b/src/UniversalValveToolbox/UI/FormMain.cs @@ -28,8 +28,8 @@ namespace UniversalValveToolbox { private EngineDtoModel SelectedEngine { get => Engines[comboBoxEngine.SelectedIndex]; } private ProjectDtoModel SelectedProject { - get => (ProjectDtoModel)((comboBoxGameConfig.Enabled) - ? comboBoxGameConfig.SelectedItem + get => (ProjectDtoModel)((comboBoxProjects.Enabled) + ? Projects.First(project => project.Name.Equals(comboBoxProjects.SelectedItem)) : null); } @@ -47,16 +47,34 @@ namespace UniversalValveToolbox { UpdateAddonsList(); }; } + private void FormMain_Load(object sender, EventArgs e) { } + private void UpdateLastSelectedProject() { + var lastSelectedProject = dataProvider.Projects.First(project => project.Name.Equals(dataProvider.Settings.LastSelectedProject)); + + if (lastSelectedProject != null) { + var indexEngine = comboBoxEngine.Items.IndexOf(Engines.First(engine => engine.Appid.Equals(lastSelectedProject.Engine)).Name); + comboBoxEngine.SelectedIndex = indexEngine; + + UpdateProjectList(); + + var indexProject = comboBoxProjects.Items.IndexOf(lastSelectedProject.Name); + comboBoxProjects.SelectedIndex = indexProject; + } + } + + private void UpdateFormData() { UpdateEngineList(); UpdateProjectList(); UpdateToolsList(); UpdateAddonsList(); UpdateNavigationBar(); + + UpdateLastSelectedProject(); } private void UpdateNavigationBar() { @@ -68,6 +86,12 @@ 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) @@ -151,17 +175,17 @@ namespace UniversalValveToolbox { AvailableProjects = Projects.Where(project => project.Engine == selectEngine.Appid).ToArray(); if (AvailableProjects != null && AvailableProjects.Length != 0) { - comboBoxGameConfig.Enabled = true; + comboBoxProjects.Enabled = true; - comboBoxGameConfig.Items.Clear(); - comboBoxGameConfig.Items.AddRange(AvailableProjects.ToArray()); + comboBoxProjects.Items.Clear(); + comboBoxProjects.Items.AddRange(AvailableProjects.Select(project => project.Name).ToArray()); - comboBoxGameConfig.SelectedIndex = 0; + comboBoxProjects.SelectedIndex = 0; } else { - comboBoxGameConfig.Enabled = false; + comboBoxProjects.Enabled = false; - comboBoxGameConfig.Items.Clear(); + comboBoxProjects.Items.Clear(); } } @@ -338,7 +362,7 @@ namespace UniversalValveToolbox { if (!finalArg.Contains("-game")) { finalArg += $"-game \"{SelectedProject?.Path ?? ""}\""; - } + } Process.Start(toolPath, finalArg); } @@ -413,7 +437,19 @@ 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(); } } } diff --git a/src/UniversalValveToolbox/json/settings.json b/src/UniversalValveToolbox/json/settings.json index 0857413..6f2bd6f 100644 --- a/src/UniversalValveToolbox/json/settings.json +++ b/src/UniversalValveToolbox/json/settings.json @@ -1,6 +1,5 @@ { - "DefaultProject": null, - "AvailableEnginies": null, + "LastSelectedProject": null, "Language": "en-US", "AvailableLanguages": [ "en-US", "ru-RU" ], "Theme": null