Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc72175

Browse files
committed
Update index when items have been sorted.
git-tfs-id: [https://tfs.codeplex.com:443/tfs/TFS36]$/ResXResourceManager/Main;C37739
1 parent 7aee2b8 commit fc72175

12 files changed

Lines changed: 218 additions & 21 deletions

File tree

ResXManager.Model/CodeReferenceTracker.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,17 @@ private void ObjectInvariant()
246246

247247
private class FileInfo
248248
{
249+
[NotNull]
249250
private static readonly Regex _regex = new Regex(@"\W+", RegexOptions.Compiled);
250251
[NotNull]
251252
private readonly ProjectFile _projectFile;
252-
private readonly string[] _lines;
253253
[NotNull]
254254
private readonly Dictionary<string, HashSet<int>> _keyLinesLookup = new Dictionary<string, HashSet<int>>();
255255
[NotNull, ItemNotNull]
256256
private readonly CodeReferenceConfigurationItem[] _configurations;
257257

258+
private readonly string[] _lines;
259+
258260
public FileInfo([NotNull] ProjectFile projectFile, [NotNull, ItemNotNull] IEnumerable<CodeReferenceConfigurationItem> configurations, [NotNull] ICollection<string> keys, ref long visited)
259261
{
260262
Contract.Requires(projectFile != null);
@@ -354,6 +356,7 @@ private void ObjectInvariant()
354356
Contract.Invariant(_projectFile != null);
355357
Contract.Invariant(_keyLinesLookup != null);
356358
Contract.Invariant(_configurations != null);
359+
Contract.Invariant(_regex != null);
357360
}
358361
}
359362
}

ResXManager.Model/Properties/Resources.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ResXManager.Model/ResourceEntity.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class ResourceEntity : ObservableObject, IComparable<ResourceEntity>, ICo
3333
private readonly string _baseName;
3434
[NotNull]
3535
private readonly string _directoryName;
36-
[NotNull]
36+
[NotNull, ItemNotNull]
3737
private readonly ObservableCollection<ResourceTableEntry> _resourceTableEntries;
38-
[NotNull]
38+
[NotNull, ItemNotNull]
3939
private readonly ReadOnlyObservableCollection<ResourceTableEntry> _readOnlyResourceTableEntries;
4040
[NotNull]
4141
private readonly string _displayName;
@@ -353,6 +353,23 @@ internal void OnIndexChanged([NotNull] ResourceTableEntry resourceTableEntry)
353353
}
354354
}
355355

356+
public void OnItemOrderChanged([NotNull] ResourceLanguage resourceLanguage)
357+
{
358+
Contract.Requires(resourceLanguage != null);
359+
360+
if (resourceLanguage.CultureKey != CultureKey.Neutral)
361+
return;
362+
363+
var index = 0;
364+
365+
var entries = _resourceTableEntries.ToDictionary(entry => entry.Key);
366+
367+
foreach (var key in resourceLanguage.ResourceKeys)
368+
{
369+
entries.GetValueOrDefault(key)?.UpdateIndex(index++);
370+
}
371+
}
372+
356373
internal bool EqualsAll(string projectName, string baseName, string directoryName)
357374
{
358375
return string.Equals(projectName, _projectName, StringComparison.OrdinalIgnoreCase)

ResXManager.Model/ResourceLanguage.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ResourceLanguage : IEquatable<ResourceLanguage>
4040
[NotNull]
4141
private readonly ProjectFile _file;
4242
[NotNull]
43-
private readonly IDictionary<string, Node> _nodes;
43+
private IDictionary<string, Node> _nodes;
4444
[NotNull]
4545
private readonly CultureKey _cultureKey;
4646

@@ -91,6 +91,11 @@ internal ResourceLanguage([NotNull] ResourceEntity container, [NotNull] CultureK
9191
_valueNodeName = defaultNamespace.GetName(@"value");
9292
_commentNodeName = defaultNamespace.GetName(@"comment");
9393

94+
UpdateNodes(file, duplicateKeyHandling);
95+
}
96+
97+
private void UpdateNodes(ProjectFile file, DuplicateKeyHandling duplicateKeyHandling)
98+
{
9499
var data = _documentRoot.Elements(_dataNodeName);
95100

96101
var elements = data
@@ -135,7 +140,7 @@ public CultureInfo Culture
135140
/// <summary>
136141
/// Gets all the resource keys defined in this language.
137142
/// </summary>
138-
[NotNull]
143+
[NotNull, ItemNotNull]
139144
public IEnumerable<string> ResourceKeys
140145
{
141146
get
@@ -258,6 +263,10 @@ public void Save(StringComparison? fileContentSorting)
258263
if (SortNodes(fileContentSorting.Value))
259264
{
260265
_file.Changed();
266+
267+
UpdateNodes(_file, DuplicateKeyHandling.Rename);
268+
269+
Container.OnItemOrderChanged(this);
261270
}
262271
}
263272

@@ -461,7 +470,7 @@ internal bool IsContentEqual([NotNull] ResourceLanguage other)
461470
{
462471
Contract.Requires(other != null);
463472

464-
return _document.ToString(SaveOptions.DisableFormatting) == other._document?.ToString(SaveOptions.DisableFormatting);
473+
return _document.ToString(SaveOptions.DisableFormatting) == other._document.ToString(SaveOptions.DisableFormatting);
465474
}
466475

467476
private static void MakeKeysUnique([NotNull] ICollection<Node> elements)
@@ -504,7 +513,7 @@ public override string ToString()
504513
return Culture?.DisplayName ?? Resources.Neutral;
505514
}
506515

507-
class Node
516+
private class Node
508517
{
509518
[NotNull]
510519
private readonly ResourceLanguage _owner;

ResXManager.Model/ResourceTableEntry.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ internal void Update(int index, [NotNull] IDictionary<CultureKey, ResourceLangua
142142
Refresh();
143143
}
144144

145+
internal void UpdateIndex(int index)
146+
{
147+
_index = index;
148+
OnPropertyChanged(nameof(Index));
149+
}
145150

146151
[NotNull]
147152
public ResourceEntity Container

ResXManager.Translators/MyMemoryTranslator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private static Response TranslateText([NotNull] string input, string key, [NotNu
131131

132132
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
133133
[DataContract]
134-
class ResponseData
134+
private class ResponseData
135135
{
136136
[DataMember(Name = "translatedText")]
137137
public string TranslatedText
@@ -150,7 +150,7 @@ public double? Match
150150

151151
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
152152
[DataContract]
153-
class MatchData
153+
private class MatchData
154154
{
155155
[DataMember(Name = "translation")]
156156
public string Translation
@@ -176,7 +176,7 @@ public double? Match
176176

177177
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
178178
[DataContract]
179-
class Response
179+
private class Response
180180
{
181181
[DataMember(Name = "responseData")]
182182
public ResponseData ResponseData

0 commit comments

Comments
 (0)