From 2502774fb34996757b1648cf52b774ff1efe89a1 Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 12 Jun 2014 08:44:36 +0200 Subject: [PATCH] Auto-sort when saving word to user dic --- src/Logic/Utilities.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Logic/Utilities.cs b/src/Logic/Utilities.cs index 05aab3f63..40498448c 100644 --- a/src/Logic/Utilities.cs +++ b/src/Logic/Utilities.cs @@ -2002,9 +2002,23 @@ namespace Nikse.SubtitleEdit.Logic else userWords.LoadXml(""); - XmlNode node = userWords.CreateElement("word"); - node.InnerText = word; - userWords.DocumentElement.AppendChild(node); + var words = new List(); + foreach (XmlNode node in userWords.DocumentElement.SelectNodes("word")) + { + string w = node.InnerText.Trim(); + if (w.Length > 0) + words.Add(w); + } + words.Add(word); + words.Sort(); + + userWords.DocumentElement.RemoveAll(); + foreach (string w in words) + { + XmlNode node = userWords.CreateElement("word"); + node.InnerText = w; + userWords.DocumentElement.AppendChild(node); + } userWords.Save(userWordsXmlFileName); } }