From 3e8420aae09916f860b38bc27584b5acbe9e49b0 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 17 Aug 2021 17:06:52 +0000 Subject: [PATCH] Sort global labels to end --- GUI/Dialogs/EditLabelsDialog.cs | 5 ++++- GUI/Labels/ModuleLabelList.cs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GUI/Dialogs/EditLabelsDialog.cs b/GUI/Dialogs/EditLabelsDialog.cs index 605882f7e6..dbfe970cd8 100644 --- a/GUI/Dialogs/EditLabelsDialog.cs +++ b/GUI/Dialogs/EditLabelsDialog.cs @@ -36,7 +36,8 @@ private void LoadTree() LabelSelectionTree.Nodes.Clear(); var groups = this.labels.Labels .GroupBy(l => l.InstanceName) - .OrderBy(g => g.Key); + .OrderBy(g => g.Key == null) + .ThenBy(g => g.Key); foreach (var group in groups) { string groupName = string.IsNullOrEmpty(group.Key) @@ -275,6 +276,8 @@ private bool TrySave(out string errMsg) { labels.Labels = labels.Labels .Concat(new ModuleLabel[] { currentlyEditing }) + .OrderBy(l => l.InstanceName == null) + .ThenBy(l => l.InstanceName) .ToArray(); } currentlyEditing.Name = NameTextBox.Text; diff --git a/GUI/Labels/ModuleLabelList.cs b/GUI/Labels/ModuleLabelList.cs index a807ae9cfd..f2d2747e4e 100644 --- a/GUI/Labels/ModuleLabelList.cs +++ b/GUI/Labels/ModuleLabelList.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Drawing; +using System.Runtime.Serialization; using Newtonsoft.Json; namespace CKAN @@ -63,6 +64,15 @@ public static ModuleLabelList Load(string path) } } + [OnDeserialized] + private void OnDeserialized(StreamingContext context) + { + // false < true + Labels = Labels.OrderBy(l => l.InstanceName == null) + .ThenBy(l => l.InstanceName) + .ToArray(); + } + public bool Save(string path) { try