Skip to content

Commit 6764fc7

Browse files
committed
feat: support navigat filter to repository view
- Add branch and tag navigation support to the repository view model. - Increase filter item height and replace text block with clickable button for navigation. - Add navigation functionality for different filter types in the repository view.
1 parent 159466d commit 6764fc7

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/ViewModels/Repository.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,26 @@ public void NavigateToCommit(string sha, bool isDelayMode = false)
10061006
else if (_histories != null)
10071007
{
10081008
SelectedViewIndex = 0;
1009+
if (sha == "HEAD")
1010+
sha = _currentBranch.Head;
10091011
_histories.NavigateTo(sha);
10101012
}
10111013
}
10121014

1015+
public void NavigateToBranch(string branch, bool isDelayMode = false)
1016+
{
1017+
var b = _branches.Find(b => b.FullName.Equals(branch, StringComparison.Ordinal));
1018+
if (b != null)
1019+
NavigateToCommit(b.Head);
1020+
}
1021+
1022+
public void NavigateToTag(string tag, bool isDelayMode = false)
1023+
{
1024+
var t = _tags.Find(t => t.Name.Equals(tag, StringComparison.Ordinal));
1025+
if (t != null)
1026+
NavigateToCommit(t.SHA);
1027+
}
1028+
10131029
public void ClearCommitMessage()
10141030
{
10151031
if (_workingCopy is not null)

src/Views/Repository.axaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,16 +800,22 @@
800800

801801
<ItemsControl.ItemTemplate>
802802
<DataTemplate DataType="m:Filter">
803-
<Border Height="20"
803+
<Border Height="24"
804804
Margin="0,0,6,0"
805805
CornerRadius="12"
806806
BorderThickness="1"
807807
BorderBrush="{Binding Mode, Converter={x:Static c:FilterModeConverters.ToBorderBrush}}">
808808
<StackPanel Orientation="Horizontal" Margin="8,0">
809809
<Path Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}"/>
810810
<Path Width="10" Height="10" Data="{StaticResource Icons.Tag}" IsVisible="{Binding !IsBranch}"/>
811-
<TextBlock Classes="primary" Text="{Binding Pattern, Converter={x:Static c:StringConverters.TrimRefsPrefix}}" Margin="4,0,8,0"/>
812-
811+
<Button Margin="4,0,8,0"
812+
Padding="0"
813+
Background="Transparent"
814+
BorderThickness="0"
815+
Classes="icon_button"
816+
Click="OnNavigateToFilter"
817+
Content="{Binding Pattern, Converter={x:Static c:StringConverters.TrimRefsPrefix}}"
818+
/>
813819
<Button Classes="icon_button" VerticalAlignment="Center" Margin="0" Padding="0" Click="OnRemoveSelectedHistoriesFilter">
814820
<Path Width="8" Height="8" Data="{StaticResource Icons.Close}"/>
815821
</Button>

src/Views/Repository.axaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,35 @@ private async void OnAbortInProgress(object sender, RoutedEventArgs e)
659659
e.Handled = true;
660660
}
661661

662+
private void OnNavigateToFilter(object sender, RoutedEventArgs e)
663+
{
664+
if (DataContext is ViewModels.Repository repo && sender is Button { DataContext: Models.Filter filter })
665+
{
666+
if (filter.Mode == Models.FilterMode.Excluded)
667+
return;
668+
669+
switch (filter.Type)
670+
{
671+
default:
672+
case Models.FilterType.LocalBranchFolder:
673+
case Models.FilterType.RemoteBranchFolder:
674+
break;
675+
case Models.FilterType.LocalBranch:
676+
case Models.FilterType.RemoteBranch:
677+
repo.NavigateToBranch(filter.Pattern);
678+
break;
679+
case Models.FilterType.Tag:
680+
repo.NavigateToTag(filter.Pattern);
681+
break;
682+
case Models.FilterType.SoloCommits:
683+
repo.NavigateToCommit(filter.Pattern);
684+
break;
685+
}
686+
e.Handled = true;
687+
}
688+
}
689+
690+
662691
private void OnRemoveSelectedHistoriesFilter(object sender, RoutedEventArgs e)
663692
{
664693
if (DataContext is ViewModels.Repository repo && sender is Button { DataContext: Models.Filter filter })

0 commit comments

Comments
 (0)