mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-17 00:14:59 +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)
|
foreach (var line in lines)
|
||||||
ParseLine(line);
|
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;
|
return _changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
namespace SourceGit.Models
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
public static class NumericSort
|
public static class NumericSort
|
||||||
{
|
{
|
||||||
|
@ -23,7 +26,7 @@
|
||||||
bool isDigit1 = char.IsDigit(c1);
|
bool isDigit1 = char.IsDigit(c1);
|
||||||
bool isDigit2 = char.IsDigit(c2);
|
bool isDigit2 = char.IsDigit(c2);
|
||||||
if (isDigit1 != isDigit2)
|
if (isDigit1 != isDigit2)
|
||||||
return c1.CompareTo(c2);
|
return char.ToUpper(c1, CultureInfo.CurrentCulture).CompareTo(char.ToUpper(c2, CultureInfo.CurrentCulture));
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -55,7 +58,7 @@
|
||||||
if (isDigit1)
|
if (isDigit1)
|
||||||
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2;
|
||||||
else
|
else
|
||||||
result = string.CompareOrdinal(sub1, sub2);
|
result = string.Compare(sub1, sub2, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -449,7 +449,7 @@ namespace SourceGit.ViewModels
|
||||||
if (l.IsRepository != r.IsRepository)
|
if (l.IsRepository != r.IsRepository)
|
||||||
return l.IsRepository ? 1 : -1;
|
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)
|
if (_workingCopy == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
|
||||||
_workingCopy.SetData(changes);
|
_workingCopy.SetData(changes);
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
|
|
@ -71,7 +71,7 @@ namespace SourceGit.ViewModels
|
||||||
changes.Add(c);
|
changes.Add(c);
|
||||||
|
|
||||||
if (needSort)
|
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(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
|
|
@ -270,12 +270,7 @@ namespace SourceGit.Views
|
||||||
foreach (var obj in objects)
|
foreach (var obj in objects)
|
||||||
_tree.Add(new ViewModels.RevisionFileTreeNode { Backend = obj });
|
_tree.Add(new ViewModels.RevisionFileTreeNode { Backend = obj });
|
||||||
|
|
||||||
_tree.Sort((l, r) =>
|
SortNodes(_tree);
|
||||||
{
|
|
||||||
if (l.IsFolder == r.IsFolder)
|
|
||||||
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
|
||||||
return l.IsFolder ? -1 : 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
var topTree = new List<ViewModels.RevisionFileTreeNode>();
|
var topTree = new List<ViewModels.RevisionFileTreeNode>();
|
||||||
MakeRows(topTree, _tree, 0);
|
MakeRows(topTree, _tree, 0);
|
||||||
|
@ -341,13 +336,7 @@ namespace SourceGit.Views
|
||||||
foreach (var obj in objects)
|
foreach (var obj in objects)
|
||||||
node.Children.Add(new ViewModels.RevisionFileTreeNode() { Backend = obj });
|
node.Children.Add(new ViewModels.RevisionFileTreeNode() { Backend = obj });
|
||||||
|
|
||||||
node.Children.Sort((l, r) =>
|
SortNodes(node.Children);
|
||||||
{
|
|
||||||
if (l.IsFolder == r.IsFolder)
|
|
||||||
return Models.NumericSort.Compare(l.Name, r.Name);
|
|
||||||
return l.IsFolder ? -1 : 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
return 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 List<ViewModels.RevisionFileTreeNode> _tree = [];
|
||||||
private AvaloniaList<ViewModels.RevisionFileTreeNode> _rows = [];
|
private AvaloniaList<ViewModels.RevisionFileTreeNode> _rows = [];
|
||||||
private bool _disableSelectionChangingEvent = false;
|
private bool _disableSelectionChangingEvent = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue