Sort make/models droplists

This commit is contained in:
John Lewin 2016-07-29 13:47:58 -07:00
parent 152d54e9df
commit 01f2d4485f
2 changed files with 9 additions and 12 deletions

View file

@ -185,25 +185,19 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e)
{
activeMake = ((Agg.UI.DropDownList)sender).SelectedValue;
activeMake = ((DropDownList)sender).SelectedValue;
activeModel = null;
// Select the dictionary containing the printerName->printerToken mappings for the current OEM
Dictionary<string, string> printers;
if (!OemSettings.Instance.OemProfiles.TryGetValue(activeMake, out printers))
{
// Fall back to an empty dictionary if no match
printers = new Dictionary<string, string>();
}
var models = printers.Select(profile => new KeyValuePair<string, string>(profile.Key, profile.Value)).ToList();
// sort by key (model name)
models.Sort(
delegate (KeyValuePair<string, string> pair1,
KeyValuePair<string, string> pair2)
{
return pair1.Key.CompareTo(pair2.Key);
}
);
printerModelSelector.ListSource = models;
// Models - sort dictionary results by key and assign to .ListSource
printerModelSelector.ListSource = printers.OrderBy(p => p.Key).ToList();
if (printerModelSelector.MenuItems.Count == 1)
{
// SelectIfOnlyOneModel

View file

@ -83,8 +83,11 @@ namespace MatterHackers.MatterControl.SettingsManagement
public List<string> PreloadedLibraryFiles { get; } = new List<string>();
internal void SetManufacturers(IEnumerable<KeyValuePair<string, string>> manufacturers, List<string> whitelist = null)
internal void SetManufacturers(IEnumerable<KeyValuePair<string, string>> unorderedManufacturers, List<string> whitelist = null)
{
// Sort manufacturers by name
var manufacturers = unorderedManufacturers.OrderBy(k => k.Value);
if (whitelist != null)
{
this.PrinterWhiteList = whitelist;