mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-26 21:17:20 -08:00
Compare commits
2 commits
85b83990a8
...
8e31ea9140
Author | SHA1 | Date | |
---|---|---|---|
|
8e31ea9140 | ||
|
a8ce4e6d95 |
6 changed files with 60 additions and 21 deletions
|
@ -15,10 +15,15 @@ namespace SourceGit.ViewModels
|
|||
public string Name { get; private set; } = string.Empty;
|
||||
public object Backend { get; private set; } = null;
|
||||
public int Depth { get; set; } = 0;
|
||||
public bool IsFiltered { get; set; } = false;
|
||||
public bool IsSelected { get; set; } = false;
|
||||
public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>();
|
||||
|
||||
public bool IsFiltered
|
||||
{
|
||||
get => _isFiltered;
|
||||
set => SetProperty(ref _isFiltered, value);
|
||||
}
|
||||
|
||||
public bool IsExpanded
|
||||
{
|
||||
get => _isExpanded;
|
||||
|
@ -46,6 +51,7 @@ namespace SourceGit.ViewModels
|
|||
get => Backend is Models.Branch b ? b.FriendlyName : null;
|
||||
}
|
||||
|
||||
private bool _isFiltered = false;
|
||||
private bool _isExpanded = false;
|
||||
private CornerRadius _cornerRadius = new CornerRadius(4);
|
||||
|
||||
|
|
|
@ -643,20 +643,24 @@ namespace SourceGit.ViewModels
|
|||
NavigateToCommit(_currentBranch.Head);
|
||||
}
|
||||
|
||||
public void UpdateFilter(string filter, bool toggle)
|
||||
public void UpdateFilters(List<string> filters, bool toggle)
|
||||
{
|
||||
var changed = false;
|
||||
if (toggle)
|
||||
{
|
||||
if (!_settings.Filters.Contains(filter))
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
_settings.Filters.Add(filter);
|
||||
changed = true;
|
||||
if (!_settings.Filters.Contains(filter))
|
||||
{
|
||||
_settings.Filters.Add(filter);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = _settings.Filters.Remove(filter);
|
||||
foreach (var filter in filters)
|
||||
changed |= _settings.Filters.Remove(filter);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
|
|
|
@ -54,10 +54,10 @@
|
|||
|
||||
<!-- Name -->
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding Name}"
|
||||
Classes="primary"
|
||||
FontWeight="{Binding NameFontWeight}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
Text="{Binding Name}"
|
||||
Classes="primary"
|
||||
FontWeight="{Binding NameFontWeight}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
|
||||
<!-- Tracking status -->
|
||||
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
||||
|
@ -72,9 +72,9 @@
|
|||
Classes="filter"
|
||||
Margin="0,0,8,0"
|
||||
Background="Transparent"
|
||||
IsCheckedChanged="OnToggleFilter"
|
||||
IsVisible="{Binding IsBranch}"
|
||||
IsChecked="{Binding IsFiltered}"
|
||||
Click="OnToggleFilterClicked"
|
||||
ToolTip.Tip="{DynamicResource Text.Filter}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
@ -428,12 +428,23 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
||||
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton toggle && DataContext is ViewModels.Repository repo)
|
||||
if (DataContext is ViewModels.Repository repo &&
|
||||
sender is ToggleButton toggle &&
|
||||
toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node)
|
||||
{
|
||||
if (toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
||||
repo.UpdateFilter(branch.FullName, toggle.IsChecked == true);
|
||||
bool filtered = toggle.IsChecked == true;
|
||||
List<string> filters = [branch.FullName];
|
||||
if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream))
|
||||
{
|
||||
filters.Add(branch.Upstream);
|
||||
|
||||
node.IsFiltered = filtered;
|
||||
UpdateUpstreamFilterState(repo.RemoteBranchTrees, branch.Upstream, filtered);
|
||||
}
|
||||
|
||||
repo.UpdateFilters(filters, filtered);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
@ -466,6 +477,23 @@ namespace SourceGit.Views
|
|||
CollectBranchesInNode(outs, sub);
|
||||
}
|
||||
|
||||
private bool UpdateUpstreamFilterState(List<ViewModels.BranchTreeNode> collection, string upstream, bool isFiltered)
|
||||
{
|
||||
foreach (var node in collection)
|
||||
{
|
||||
if (node.Backend is Models.Branch b && b.FullName == upstream)
|
||||
{
|
||||
node.IsFiltered = isFiltered;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.Backend is Models.Remote r && upstream.StartsWith($"refs/remotes/{r.Name}/", StringComparison.Ordinal))
|
||||
return UpdateUpstreamFilterState(node.Children, upstream, isFiltered);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool _disableSelectionChangingEvent = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,9 @@
|
|||
Classes="filter"
|
||||
Margin="0,0,8,0"
|
||||
Background="Transparent"
|
||||
IsCheckedChanged="OnToggleFilter"
|
||||
IsChecked="{Binding IsFiltered}"
|
||||
Click="OnToggleFilterClicked"
|
||||
IsChecked="{Binding IsFiltered, Mode=TwoWay}"
|
||||
IsVisible="{Binding !IsFolder}"
|
||||
ToolTip.Tip="{DynamicResource Text.Filter}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
@ -78,8 +79,8 @@
|
|||
Classes="filter"
|
||||
Margin="0,0,8,0"
|
||||
Background="Transparent"
|
||||
IsCheckedChanged="OnToggleFilter"
|
||||
IsChecked="{Binding IsFiltered}"
|
||||
Click="OnToggleFilterClicked"
|
||||
IsChecked="{Binding IsFiltered, Mode=TwoWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.Filter}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -247,7 +247,7 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
||||
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton toggle && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
|
@ -258,7 +258,7 @@ namespace SourceGit.Views
|
|||
target = tag;
|
||||
|
||||
if (target != null)
|
||||
repo.UpdateFilter(target.Name, toggle.IsChecked == true);
|
||||
repo.UpdateFilters([target.Name], toggle.IsChecked == true);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
|
Loading…
Reference in a new issue