diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
index af85c2b..415e000 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
@@ -532,7 +532,7 @@ public partial class MainForm : Form
/// Gets called when user selects a different item from and changes accordingly.
private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{
- if ((profileDropDown.SelectedIndex == -1) && (profileDropDown.Items.Count == 0)) return;
+ if ((profileDropDown.SelectedIndex == -1) && (!profileDropDown.DataStore.Any())) return;
profileIndex = profileDropDown.SelectedIndex;
log.Debug("profileDropDown.SelectedIndex has been changed to " + profileIndex + ".");
@@ -779,7 +779,7 @@ public partial class MainForm : Form
// Reload list so mod gets recognized
LoadProfilesAndAdjustLists();
// Adjust profileIndex to point to newly added mod. if its not found for whatever reason, we default to first community updates
- modSettingsProfileDropDown.SelectedIndex = profileList.FindIndex(p => p.Name == profile.Name);
+ modSettingsProfileDropDown.SelectedIndex = profileList.IndexOf(profileList.FirstOrDefault(p => p.Name == profile.Name));
if (modSettingsProfileDropDown.SelectedIndex == -1)
modSettingsProfileDropDown.SelectedIndex = 0;
@@ -792,11 +792,11 @@ public partial class MainForm : Form
///
private void ModSettingsProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{
- if (modSettingsProfileDropDown.SelectedIndex == -1 && !modSettingsProfileDropDown.DataStore.Any()) return;
+ if (modSettingsProfileDropDown.SelectedIndex == -1 || !modSettingsProfileDropDown.DataStore.Any()) return;
string profileName = modSettingsProfileDropDown.SelectedKey;
- log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + modSettingsProfileDropDown.SelectedIndex + ".");
+ log.Info("ModSettingsProfileDropDown.SelectedIndex has been changed to " + modSettingsProfileDropDown.SelectedIndex + ".");
if (modSettingsProfileDropDown.SelectedIndex <= 0 || !modSettingsProfileDropDown.DataStore.Any())
{
deleteModButton.Enabled = false;
@@ -1067,7 +1067,7 @@ public partial class MainForm : Form
// Adjust our lists so it gets recognized
LoadProfilesAndAdjustLists();
- modSettingsProfileDropDown.SelectedIndex = profileList.FindIndex(p => p.Name == currentProfile.Name);
+ modSettingsProfileDropDown.SelectedIndex = profileList.IndexOf(profileList.FirstOrDefault(p => p.Name == currentProfile.Name));
if (modSettingsProfileDropDown.SelectedIndex == -1)
modSettingsProfileDropDown.SelectedIndex = 0;
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs
index c8217b7..6d12c51 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs
@@ -127,7 +127,7 @@ public partial class MainForm
case PlayButtonState.Playing: return;
case PlayButtonState.Install:
- case PlayButtonState.Play: apkButton.Enabled = true; apkButton.ToolTip = HelperMethods.GetText(Text.ApkButtonEnabledToolTip, profileDropDown?.Items[profileDropDown.SelectedIndex]?.Text ?? ""); break;
+ case PlayButtonState.Play: apkButton.Enabled = true; apkButton.ToolTip = HelperMethods.GetText(Text.ApkButtonEnabledToolTip, profileDropDown?.SelectedKey ?? ""); break;
}
}
@@ -280,7 +280,7 @@ public partial class MainForm
/// The tooltip as a , or if the current State is invalid.
private string GetPlayButtonTooltip()
{
- string profileName = ((profileDropDown != null) && (profileDropDown.Items.Count > 0)) ? profileDropDown.Items[profileDropDown.SelectedIndex].Text : "";
+ string profileName = ((profileDropDown != null) && (profileDropDown.DataStore.Any())) ? profileDropDown.SelectedKey : "";
switch (updateState)
{
case PlayButtonState.Download: return Text.PlayButtonDownloadToolTip;
@@ -314,15 +314,11 @@ public partial class MainForm
private void LoadProfilesAndAdjustLists()
{
// Reset loaded profiles
- profileDropDown.Items.Clear();
profileList.Clear();
profileIndex = null;
-
- // Load the profileList
- profileList = Profile.LoadProfiles();
-
+
// Add profile names to the profileDropDown
- foreach (ProfileXML profile in profileList)
+ foreach (ProfileXML profile in Profile.LoadProfiles())
{
// Archive version notes
if (!profile.Installable)
@@ -333,14 +329,14 @@ public partial class MainForm
profile.ProfileNotes = Text.ArchiveNotesMods + "\n\n" + profile.ProfileNotes;
}
- profileDropDown.Items.Add(profile.Name);
+ profileList.Add(profile);
}
// Read the value from the config
string profIndexString = ReadFromConfig("ProfileIndex");
// Check if either no profile was found or the setting says that the last current profile didn't exist
- if (profileDropDown.Items.Count == 0)
+ if (!profileDropDown.DataStore.Any())
profileIndex = null;
else
{
@@ -351,13 +347,13 @@ public partial class MainForm
// We parse from the settings, and check if profiles got deleted from the last time the launcher has been selected. if yes, we revert the last selection to 0;
int intParseResult = Int32.Parse(profIndexString);
profileIndex = intParseResult;
- if (profileIndex >= profileDropDown.Items.Count)
+ if (profileIndex >= profileDropDown.DataStore.Count())
profileIndex = 0;
profileDropDown.SelectedIndex = profileIndex.Value;
}
// Update stored profiles in the Profile Settings tab
- modSettingsProfileDropDown.SelectedIndex = profileDropDown.Items.Count != 0 ? 0 : -1;
+ modSettingsProfileDropDown.SelectedIndex = profileDropDown.DataStore.Any() ? 0 : -1;
// Refresh the author and version label on the main tab
if (profileList.Count > 0)
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
index 9508d29..0464a1f 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
@@ -7,6 +7,7 @@ using Eto.Forms;
using log4net;
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@@ -111,14 +112,6 @@ public partial class MainForm : Form
if (OS.IsMac)
Menu = new MenuBar();
- // Create array from validCount
- profileList = new List();
-
- //TODO: whenever profileDropDown gets rewritten to use a datastore, scrap this
- List profileNames = new List();
- foreach (ProfileXML profile in profileList)
- profileNames.Add(profile.Name);
-
// Custom splash texts
string splash = Splash.GetSplash();
log.Info($"Randomly chosen splash: {splash}");
@@ -228,7 +221,7 @@ public partial class MainForm : Form
if (OS.IsLinux)
profileDropDown = new DropDown();
- profileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans
+ profileDropDown.DataStore = (profileList);
centerInterface.AddRow(profileDropDown);
@@ -646,8 +639,7 @@ public partial class MainForm : Form
private readonly TrayIndicator trayIndicator;
/// of s, used for actually working with profile data.
- //TODO: this should be moved into AM2RLauncherLib
- private List profileList;
+ private ObservableCollection profileList = new ObservableCollection();
/// The planet Background.
private readonly Bitmap formBG = new Bitmap(Resources.bgCentered);
@@ -708,7 +700,6 @@ public partial class MainForm : Form
/// A where profiles can be chosen.
private readonly DropDown profileDropDown;
/// A where profiles can be chosen (located in Profile Settings).
- //TODO: Use MVVM bindings: https://github.com/picoe/Eto/wiki/Data-Binding#mvvm-binding
private readonly DropDown modSettingsProfileDropDown;
/// A , where the user can input their custom mirror.
diff --git a/AM2RLauncher/AM2RLauncherLib/XML/ProfileXML.cs b/AM2RLauncher/AM2RLauncherLib/XML/ProfileXML.cs
index 9459dba..167920a 100644
--- a/AM2RLauncher/AM2RLauncherLib/XML/ProfileXML.cs
+++ b/AM2RLauncher/AM2RLauncherLib/XML/ProfileXML.cs
@@ -95,4 +95,9 @@ public class ProfileXML
Installable = installable;
ProfileNotes = profileNotes;
}
+
+ public override string ToString()
+ {
+ return Name;
+ }
}
\ No newline at end of file