This commit is contained in:
Alex Z 2020-03-07 01:43:10 +03:00
parent 3b53622c49
commit 3a33fde10a
5 changed files with 54 additions and 13 deletions

View File

@ -57,7 +57,14 @@ namespace UniversalValveToolbox.Model.ViewModel {
}
}
public AddonDtoModel SelectAddon => addons[selectAddonIndex];
public AddonDtoModel SelectAddon {
get {
if (addons == null || addons.Length == 0)
return null;
return addons[selectAddonIndex];
}
}
public DictionaryEntry SelectCategory {
get { return categories[selectCategoryIndex]; }

View File

@ -61,7 +61,16 @@ namespace UniversalValveToolbox.Properties.translations {
}
/// <summary>
/// Looks up a localized string similar to &lt;new project&gt;.
/// Looks up a localized string similar to &lt;New Addon&gt;.
/// </summary>
internal static string strNewAddon {
get {
return ResourceManager.GetString("strNewAddon", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;New Project&gt;.
/// </summary>
internal static string strNewProject {
get {

View File

@ -117,7 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="strNewAddon" xml:space="preserve">
<value>&lt;New Addon&gt;</value>
</data>
<data name="strNewProject" xml:space="preserve">
<value>&lt;new project&gt;</value>
<value>&lt;New Project&gt;</value>
</data>
</root>

View File

@ -117,7 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="strNewAddon" xml:space="preserve">
<value>&lt;Новое Дополнение&gt;</value>
</data>
<data name="strNewProject" xml:space="preserve">
<value>&lt;новый проект&gt;</value>
<value>&lt;Новый Проект&gt;</value>
</data>
</root>

View File

@ -75,11 +75,18 @@ namespace UniversalValveToolbox {
engineCheckedListBox.Items.Clear();
engineCheckedListBox.Items.AddRange(model.Engines);
for (var i = 0; i < model.Engines.Length; i++) {
var engine = model.Engines[i];
if (model.SelectAddon != null) {
for (var i = 0; i < model.Engines.Length; i++) {
var engine = model.Engines[i];
if (model.SelectAddon.Engines.Contains(engine.Appid)) {
engineCheckedListBox.SetItemChecked(i, true);
if (model.SelectAddon.Engines.Contains(engine.Appid)) {
engineCheckedListBox.SetItemChecked(i, true);
}
}
}
else {
for (var i = 0; i < model.Engines.Length; i++) {
engineCheckedListBox.SetItemChecked(i, false);
}
}
@ -87,9 +94,15 @@ namespace UniversalValveToolbox {
}
private void UpdateAddonsComboBox() {
comboBox_Addon.Items.Clear();
comboBox_Addon.Items.AddRange(model.Addons);
comboBox_Addon.SelectedIndex = 0;
if (model.Addons.Length == 0) {
New();
}
else {
comboBox_Addon.Items.Clear();
comboBox_Addon.Items.AddRange(model.Addons);
comboBox_Addon.SelectedIndex = 0;
}
}
private void UpdateAddonCategoryComboBox() {
@ -136,8 +149,7 @@ namespace UniversalValveToolbox {
}
private void New() {
var newAddon = new AddonDtoModel();
newAddon.Name = "<new addon>";
var newAddon = CreateNewEmptyAddon();
var newAddonList = new List<AddonDtoModel>(model.Addons);
newAddonList.Insert(0, newAddon);
@ -147,6 +159,13 @@ namespace UniversalValveToolbox {
UpdateAddonsComboBox();
}
private AddonDtoModel CreateNewEmptyAddon() {
var newAddon = new AddonDtoModel();
newAddon.Name = Properties.translations.VarStrings.strNewAddon;
return newAddon;
}
private void Save() {
JsonFileUtil.SaveValues(DataProvider.AddonsPath, "json", model.Addons.ToList());
}