-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8427 from RussKie/fix_6310_sort_branches
- Loading branch information
Showing
33 changed files
with
793 additions
and
206 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 |
---|---|---|
|
@@ -75,3 +75,4 @@ tree.txt | |
*.binlog | ||
artifacts/ | ||
.tools/vswhere/ | ||
.dotnet/ |
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
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
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
73 changes: 73 additions & 0 deletions
73
GitUI/BranchTreePanel/ContextMenu/GitRefsSortByContextMenuItem.cs
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,73 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using GitCommands; | ||
using GitCommands.Utils; | ||
using GitUI.Properties; | ||
using GitUIPluginInterfaces; | ||
|
||
namespace GitUI.BranchTreePanel.ContextMenu | ||
{ | ||
internal class GitRefsSortByContextMenuItem : ToolStripMenuItem | ||
{ | ||
private readonly Action _onSortByChanged; | ||
|
||
public GitRefsSortByContextMenuItem(Action onSortByChanged) | ||
{ | ||
_onSortByChanged = onSortByChanged; | ||
|
||
Image = Images.SortBy; | ||
Text = Strings.SortBy; | ||
|
||
foreach (var option in EnumHelper.GetValues<GitRefsSortBy>().Select(e => (Text: e.GetDescription(), Value: e))) | ||
{ | ||
var item = new ToolStripMenuItem() | ||
{ | ||
Text = option.Text, | ||
Image = null, | ||
Tag = option.Value | ||
}; | ||
|
||
item.Click += Item_Click; | ||
DropDownItems.Add(item); | ||
} | ||
|
||
DropDownOpening += (s, e) => RequerySortingMethod(); | ||
RequerySortingMethod(); | ||
} | ||
|
||
private void RequerySortingMethod() | ||
{ | ||
var currentSort = AppSettings.RefsSortBy; | ||
foreach (ToolStripMenuItem item in DropDownItems) | ||
{ | ||
item.Checked = currentSort.Equals(item.Tag); | ||
} | ||
} | ||
|
||
private void Item_Click(object sender, EventArgs e) | ||
{ | ||
if (sender is ToolStripMenuItem item) | ||
{ | ||
var sortingType = (GitRefsSortBy)item.Tag; | ||
AppSettings.RefsSortBy = sortingType; | ||
|
||
_onSortByChanged?.Invoke(); | ||
} | ||
} | ||
|
||
internal TestAccessor GetTestAccessor() => new TestAccessor(this); | ||
|
||
internal struct TestAccessor | ||
{ | ||
private readonly GitRefsSortByContextMenuItem _contextMenuItem; | ||
|
||
public TestAccessor(GitRefsSortByContextMenuItem menuitem) | ||
{ | ||
_contextMenuItem = menuitem; | ||
} | ||
|
||
public void RaiseDropDownOpening() => _contextMenuItem.RequerySortingMethod(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
GitUI/BranchTreePanel/ContextMenu/GitRefsSortOrderContextMenuItem.cs
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,75 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using GitCommands; | ||
using GitCommands.Utils; | ||
using GitUI.Properties; | ||
using GitUIPluginInterfaces; | ||
|
||
namespace GitUI.BranchTreePanel.ContextMenu | ||
{ | ||
internal class GitRefsSortOrderContextMenuItem : ToolStripMenuItem | ||
{ | ||
internal const string MenuItemName = "GitRefsSortOrderContextMenuItem"; | ||
private readonly Action _onSortOrderChanged; | ||
|
||
public GitRefsSortOrderContextMenuItem(Action onSortOrderChanged) | ||
{ | ||
_onSortOrderChanged = onSortOrderChanged; | ||
|
||
Image = Images.SortBy; | ||
Text = Strings.SortOrder; | ||
Name = MenuItemName; | ||
|
||
foreach (var option in EnumHelper.GetValues<GitRefsSortOrder>().Select(e => (Text: e.GetDescription(), Value: e))) | ||
{ | ||
var item = new ToolStripMenuItem() | ||
{ | ||
Text = option.Text, | ||
Image = null, | ||
Tag = option.Value | ||
}; | ||
|
||
item.Click += Item_Click; | ||
DropDownItems.Add(item); | ||
} | ||
|
||
DropDownOpening += (s, e) => RequerySortingMethod(); | ||
RequerySortingMethod(); | ||
} | ||
|
||
private void RequerySortingMethod() | ||
{ | ||
var currentSort = AppSettings.RefsSortOrder; | ||
foreach (ToolStripMenuItem item in DropDownItems) | ||
{ | ||
item.Checked = currentSort.Equals(item.Tag); | ||
} | ||
} | ||
|
||
private void Item_Click(object sender, EventArgs e) | ||
{ | ||
if (sender is ToolStripMenuItem item) | ||
{ | ||
var sortingType = (GitRefsSortOrder)item.Tag; | ||
AppSettings.RefsSortOrder = sortingType; | ||
|
||
_onSortOrderChanged?.Invoke(); | ||
} | ||
} | ||
|
||
internal TestAccessor GetTestAccessor() => new TestAccessor(this); | ||
|
||
internal struct TestAccessor | ||
{ | ||
private readonly GitRefsSortOrderContextMenuItem _contextMenuItem; | ||
|
||
public TestAccessor(GitRefsSortOrderContextMenuItem menuitem) | ||
{ | ||
_contextMenuItem = menuitem; | ||
} | ||
|
||
public void RaiseDropDownOpening() => _contextMenuItem.RequerySortingMethod(); | ||
} | ||
} | ||
} |
Oops, something went wrong.