mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 21:30:37 +08:00
feature: show branches count in branch tree (#1306)
This commit is contained in:
@@ -17,8 +17,10 @@ namespace SourceGit.Commands
|
||||
Args = "branch -l --all -v --format=\"%(refname)%00%(committerdate:unix)%00%(objectname)%00%(HEAD)%00%(upstream)%00%(upstream:trackshort)\"";
|
||||
}
|
||||
|
||||
public List<Models.Branch> Result()
|
||||
public List<Models.Branch> Result(out int localBranchesCount)
|
||||
{
|
||||
localBranchesCount = 0;
|
||||
|
||||
var branches = new List<Models.Branch>();
|
||||
var rs = ReadToEnd();
|
||||
if (!rs.IsSuccess)
|
||||
@@ -34,6 +36,8 @@ namespace SourceGit.Commands
|
||||
branches.Add(b);
|
||||
if (!b.IsLocal)
|
||||
remoteBranches.Add(b.FullName);
|
||||
else
|
||||
localBranchesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace SourceGit.ViewModels
|
||||
public int Depth { get; set; } = 0;
|
||||
public bool IsSelected { get; set; } = false;
|
||||
public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>();
|
||||
public int Counter { get; set; } = 0;
|
||||
|
||||
public Models.FilterMode FilterMode
|
||||
{
|
||||
@@ -48,6 +49,11 @@ namespace SourceGit.ViewModels
|
||||
get => Backend is Models.Branch { IsUpstreamGone: true };
|
||||
}
|
||||
|
||||
public string BranchesCount
|
||||
{
|
||||
get => Counter > 0 ? $"({Counter})" : string.Empty;
|
||||
}
|
||||
|
||||
public string Tooltip
|
||||
{
|
||||
get => Backend is Models.Branch b ? b.FriendlyName : null;
|
||||
@@ -107,7 +113,10 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var rk = $"refs/remotes/{branch.Remote}";
|
||||
if (folders.TryGetValue(rk, out var remote))
|
||||
{
|
||||
remote.Counter++;
|
||||
MakeBranchNode(branch, remote.Children, folders, rk, bForceExpanded);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var path in _expanded)
|
||||
@@ -157,6 +166,7 @@ namespace SourceGit.ViewModels
|
||||
if (folders.TryGetValue(folder, out var val))
|
||||
{
|
||||
lastFolder = val;
|
||||
lastFolder.Counter++;
|
||||
lastFolder.TimeToSort = Math.Max(lastFolder.TimeToSort, time);
|
||||
if (!lastFolder.IsExpanded)
|
||||
lastFolder.IsExpanded |= (branch.IsCurrent || _expanded.Contains(folder));
|
||||
@@ -169,6 +179,7 @@ namespace SourceGit.ViewModels
|
||||
Path = folder,
|
||||
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
||||
TimeToSort = time,
|
||||
Counter = 1,
|
||||
};
|
||||
roots.Add(lastFolder);
|
||||
folders.Add(folder, lastFolder);
|
||||
@@ -181,6 +192,7 @@ namespace SourceGit.ViewModels
|
||||
Path = folder,
|
||||
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
|
||||
TimeToSort = time,
|
||||
Counter = 1,
|
||||
};
|
||||
lastFolder.Children.Add(cur);
|
||||
folders.Add(folder, cur);
|
||||
|
||||
@@ -228,6 +228,12 @@ namespace SourceGit.ViewModels
|
||||
private set => SetProperty(ref _stashesCount, value);
|
||||
}
|
||||
|
||||
public int LocalBranchesCount
|
||||
{
|
||||
get => _localBranchesCount;
|
||||
private set => SetProperty(ref _localBranchesCount, value);
|
||||
}
|
||||
|
||||
public bool IncludeUntracked
|
||||
{
|
||||
get => _settings.IncludeUntrackedInLocalChanges;
|
||||
@@ -1020,7 +1026,7 @@ namespace SourceGit.ViewModels
|
||||
|
||||
public void RefreshBranches()
|
||||
{
|
||||
var branches = new Commands.QueryBranches(_fullpath).Result();
|
||||
var branches = new Commands.QueryBranches(_fullpath).Result(out var localBranchesCount);
|
||||
var remotes = new Commands.QueryRemotes(_fullpath).Result();
|
||||
var builder = BuildBranchTree(branches, remotes);
|
||||
|
||||
@@ -1033,6 +1039,7 @@ namespace SourceGit.ViewModels
|
||||
CurrentBranch = branches.Find(x => x.IsCurrent);
|
||||
LocalBranchTrees = builder.Locals;
|
||||
RemoteBranchTrees = builder.Remotes;
|
||||
LocalBranchesCount = localBranchesCount;
|
||||
|
||||
if (_workingCopy != null)
|
||||
_workingCopy.HasRemotes = remotes.Count > 0;
|
||||
@@ -2726,6 +2733,7 @@ namespace SourceGit.ViewModels
|
||||
private int _selectedViewIndex = 0;
|
||||
private object _selectedView = null;
|
||||
|
||||
private int _localBranchesCount = 0;
|
||||
private int _localChangesCount = 0;
|
||||
private int _stashesCount = 0;
|
||||
|
||||
|
||||
@@ -60,9 +60,11 @@
|
||||
<!-- Name -->
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
Text="{Binding Name}"
|
||||
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
TextTrimming="CharacterEllipsis">
|
||||
<Run Text="{Binding Name}"/>
|
||||
<Run Text="{Binding BranchesCount}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</TextBlock>
|
||||
|
||||
<!-- Upstream invalid tip -->
|
||||
<Border Grid.Column="2"
|
||||
|
||||
@@ -204,7 +204,10 @@
|
||||
<ToggleButton Grid.Row="0" Classes="group_expander" IsChecked="{Binding IsLocalBranchGroupExpanded, Mode=TwoWay}">
|
||||
<Grid ColumnDefinitions="16,*,Auto,Auto">
|
||||
<Path Grid.Column="0" Width="11" Height="11" HorizontalAlignment="Left" Data="{StaticResource Icons.Local}" Fill="{DynamicResource Brush.FG2}"/>
|
||||
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.LocalBranches}"/>
|
||||
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0">
|
||||
<Run Text="{DynamicResource Text.Repository.LocalBranches}"/>
|
||||
<Run Text="{Binding LocalBranchesCount, StringFormat='({0})'}"/>
|
||||
</TextBlock>
|
||||
<Button Grid.Column="2"
|
||||
Classes="icon_button"
|
||||
Width="14"
|
||||
@@ -231,7 +234,10 @@
|
||||
<ToggleButton Grid.Row="2" Classes="group_expander" IsChecked="{Binding IsRemoteGroupExpanded, Mode=TwoWay}">
|
||||
<Grid ColumnDefinitions="16,*,Auto,Auto">
|
||||
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Data="{StaticResource Icons.Remotes}" Fill="{DynamicResource Brush.FG2}"/>
|
||||
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Remotes}"/>
|
||||
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0">
|
||||
<Run Text="{DynamicResource Text.Repository.Remotes}"/>
|
||||
<Run Text="{Binding Remotes, Converter={x:Static c:ListConverters.ToCount}}"/>
|
||||
</TextBlock>
|
||||
<Button Grid.Column="2"
|
||||
Classes="icon_button"
|
||||
Width="14"
|
||||
|
||||
Reference in New Issue
Block a user