forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defaults to file path sorting as it was pre 3.0 and was changed by accident. Context menu in a diff list will provide you with the ability to select the sorting method. Changing one will affect all others and is persisted across processes. Added ImageIndexListSorter to sort by change type according to the image they have then by file path. Added GitItemStatusFileExtensionComparer to sort by the file extension then by the file path.
- Loading branch information
1 parent
dd029a5
commit 0b80258
Showing
16 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GitCommands | ||
{ | ||
public class DiffListSortService : IDiffListSortService | ||
{ | ||
private static readonly Lazy<DiffListSortService> _lazyDiffListSorting = new Lazy<DiffListSortService>(() => new DiffListSortService()); | ||
public static DiffListSortService Instance => _lazyDiffListSorting.Value; | ||
private DiffListSortType _diffListSorting; | ||
public event EventHandler DiffListSortingChanged; | ||
|
||
public DiffListSortType DiffListSorting | ||
{ | ||
get { return _diffListSorting; } | ||
set | ||
{ | ||
var previous = _diffListSorting; | ||
if (previous != value) | ||
{ | ||
_diffListSorting = value; | ||
AppSettings.DiffListSorting = value; | ||
OnDiffListSortingChanged(); | ||
} | ||
} | ||
} | ||
|
||
public DiffListSortService() | ||
{ | ||
DiffListSorting = GetSettingValueOrDefault(); | ||
} | ||
|
||
private DiffListSortType GetSettingValueOrDefault() | ||
{ | ||
return AppSettings.DiffListSorting; | ||
} | ||
|
||
protected void OnDiffListSortingChanged() | ||
{ | ||
DiffListSortingChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GitCommands.Git | ||
{ | ||
/// <summary> | ||
/// Compares the file extension of <see cref="GitItemStatus.Name"/> and then by <see cref="GitItemStatus.CompareTo(GitItemStatus)"/>. | ||
/// </summary> | ||
public class GitItemStatusFileExtensionComparer : Comparer<GitItemStatus> | ||
{ | ||
public override int Compare(GitItemStatus x, GitItemStatus y) | ||
{ | ||
if (ReferenceEquals(x, y)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (x == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (y == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
var lhsPath = GetPrimarySortingPath(x); | ||
var rhsPath = GetPrimarySortingPath(y); | ||
var lhsExt = Path.GetExtension(lhsPath); | ||
var rhsExt = Path.GetExtension(rhsPath); | ||
|
||
var comparisonResult = StringComparer.InvariantCulture.Compare(lhsExt, rhsExt); | ||
if (comparisonResult == 0) | ||
{ | ||
// originally used Comparer<GitItemStatus>.Default.Compare(x, y) but this would | ||
// produce incorrect results when the oldName was the only available path on an item. | ||
return StringComparer.InvariantCulture.Compare(lhsPath, rhsPath); | ||
} | ||
|
||
return comparisonResult; | ||
} | ||
|
||
private static string GetPrimarySortingPath(GitItemStatus itemStatus) | ||
{ | ||
return !string.IsNullOrEmpty(itemStatus.Name) | ||
? itemStatus.Name | ||
: itemStatus.OldName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace GitCommands | ||
{ | ||
public enum DiffListSortType | ||
{ | ||
/// <summary> | ||
/// Sorts by file path alphanumerically | ||
/// </summary> | ||
FilePath, | ||
|
||
/// <summary> | ||
/// Sorts by file extension then by path | ||
/// </summary> | ||
FileExtension, | ||
|
||
/// <summary> | ||
/// Sorts by git change type. Addition, Deletions, edits, etc. then by path | ||
/// </summary> | ||
FileStatus | ||
} | ||
|
||
public interface IDiffListSortService | ||
{ | ||
DiffListSortType DiffListSorting { get; set; } | ||
|
||
event EventHandler DiffListSortingChanged; | ||
} | ||
|
||
public static class DiffListSortServiceExtensions | ||
{ | ||
/// <summary> | ||
/// Provides the <see cref="IDiffListSortService.DiffListSorting"/> immediately and then an element for each <see cref="IDiffListSortService.DiffListSortingChanged"/>. | ||
/// </summary> | ||
/// <param name="diffListSortService">The diff list service</param> | ||
/// <returns>A hot stream with one immediate cold element.</returns> | ||
public static IObservable<DiffListSortType> CurrentAndFutureSorting(this IDiffListSortService diffListSortService) | ||
{ | ||
return Observable.Return(diffListSortService.DiffListSorting) | ||
.Concat(Observable.FromEventPattern( | ||
h => diffListSortService.DiffListSortingChanged += h, | ||
h => diffListSortService.DiffListSortingChanged -= h) | ||
.Select(_ => diffListSortService.DiffListSorting)) | ||
.DistinctUntilChanged(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.