mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-16 16:05:00 +00:00
refactor: now all filesystem related trees/lists are sorted in case-insensitive mode
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
c3c7d32167
commit
5494093261
6 changed files with 22 additions and 19 deletions
|
@ -39,7 +39,7 @@ namespace SourceGit.Commands
|
|||
foreach (var line in lines)
|
||||
ParseLine(line);
|
||||
|
||||
_changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
||||
_changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
|
||||
return _changes;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
namespace SourceGit.Models
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public static class NumericSort
|
||||
{
|
||||
|
@ -23,7 +26,7 @@
|
|||
bool isDigit1 = char.IsDigit(c1);
|
||||
bool isDigit2 = char.IsDigit(c2);
|
||||
if (isDigit1 != isDigit2)
|
||||
return c1.CompareTo(c2);
|
||||
return char.ToUpper(c1, CultureInfo.CurrentCulture).CompareTo(char.ToUpper(c2, CultureInfo.CurrentCulture));
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -55,7 +58,7 @@
|
|||
if (isDigit1)
|
||||
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
||||
else
|
||||
result = string.CompareOrdinal(sub1, sub2);
|
||||
result = string.Compare(sub1, sub2, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
|
|
@ -449,7 +449,7 @@ namespace SourceGit.ViewModels
|
|||
if (l.IsRepository != r.IsRepository)
|
||||
return l.IsRepository ? 1 : -1;
|
||||
|
||||
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
||||
return Models.NumericSort.Compare(l.Name, r.Name);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1275,6 +1275,7 @@ namespace SourceGit.ViewModels
|
|||
if (_workingCopy == null)
|
||||
return;
|
||||
|
||||
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
|
||||
_workingCopy.SetData(changes);
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace SourceGit.ViewModels
|
|||
changes.Add(c);
|
||||
|
||||
if (needSort)
|
||||
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
||||
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
|
|
|
@ -270,12 +270,7 @@ namespace SourceGit.Views
|
|||
foreach (var obj in objects)
|
||||
_tree.Add(new ViewModels.RevisionFileTreeNode { Backend = obj });
|
||||
|
||||
_tree.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsFolder == r.IsFolder)
|
||||
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
||||
return l.IsFolder ? -1 : 1;
|
||||
});
|
||||
SortNodes(_tree);
|
||||
|
||||
var topTree = new List<ViewModels.RevisionFileTreeNode>();
|
||||
MakeRows(topTree, _tree, 0);
|
||||
|
@ -341,13 +336,7 @@ namespace SourceGit.Views
|
|||
foreach (var obj in objects)
|
||||
node.Children.Add(new ViewModels.RevisionFileTreeNode() { Backend = obj });
|
||||
|
||||
node.Children.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsFolder == r.IsFolder)
|
||||
return Models.NumericSort.Compare(l.Name, r.Name);
|
||||
return l.IsFolder ? -1 : 1;
|
||||
});
|
||||
|
||||
SortNodes(node.Children);
|
||||
return node.Children;
|
||||
}
|
||||
|
||||
|
@ -365,6 +354,16 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void SortNodes(List<ViewModels.RevisionFileTreeNode> nodes)
|
||||
{
|
||||
nodes.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsFolder == r.IsFolder)
|
||||
return Models.NumericSort.Compare(l.Name, r.Name);
|
||||
return l.IsFolder ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<ViewModels.RevisionFileTreeNode> _tree = [];
|
||||
private AvaloniaList<ViewModels.RevisionFileTreeNode> _rows = [];
|
||||
private bool _disableSelectionChangingEvent = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue