Skip to content

Commit

Permalink
Sort global labels to end
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 18, 2021
1 parent 726bb54 commit f4e3c75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions GUI/Dialogs/EditLabelsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -271,12 +272,6 @@ private bool TrySave(out string errMsg)
{
if (EditingValid(out errMsg))
{
if (!labels.Labels.Contains(currentlyEditing))
{
labels.Labels = labels.Labels
.Concat(new ModuleLabel[] { currentlyEditing })
.ToArray();
}
currentlyEditing.Name = NameTextBox.Text;
currentlyEditing.Color = ColorButton.BackColor;
currentlyEditing.InstanceName =
Expand All @@ -289,6 +284,14 @@ private bool TrySave(out string errMsg)
currentlyEditing.AlertOnInstall = AlertOnInstallCheckBox.Checked;
currentlyEditing.RemoveOnInstall = RemoveOnInstallCheckBox.Checked;
currentlyEditing.HoldVersion = HoldVersionCheckBox.Checked;
if (!labels.Labels.Contains(currentlyEditing))
{
labels.Labels = labels.Labels
.Concat(new ModuleLabel[] { currentlyEditing })
.OrderBy(l => l.InstanceName == null)
.ThenBy(l => l.InstanceName)
.ToArray();
}

EditDetailsPanel.Visible = false;
currentlyEditing = null;
Expand Down
10 changes: 10 additions & 0 deletions GUI/Labels/ModuleLabelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace CKAN
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4e3c75

Please sign in to comment.