ux: only show Set as tracking branch option if selected remote branch is not upstream of selected local branch

This commit is contained in:
leo 2024-06-18 14:27:59 +08:00
parent 6dface0b62
commit 08567a7420
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
2 changed files with 17 additions and 22 deletions

View file

@ -19,25 +19,7 @@ namespace SourceGit.ViewModels
set
{
if (SetProperty(ref _selectedLocalBranch, value))
{
// If selected local branch has upstream branch. Try to find it's remote.
if (!string.IsNullOrEmpty(value.Upstream))
{
var branch = _repo.Branches.Find(x => x.FullName == value.Upstream);
if (branch != null)
{
var remote = _repo.Remotes.Find(x => x.Name == branch.Remote);
if (remote != null && remote != _selectedRemote)
{
SelectedRemote = remote;
return;
}
}
}
// Re-generate remote branches and auto-select remote branches.
AutoSelectBranchByRemote();
}
}
}
@ -73,7 +55,11 @@ namespace SourceGit.ViewModels
public Models.Branch SelectedRemoteBranch
{
get => _selectedRemoteBranch;
set => SetProperty(ref _selectedRemoteBranch, value);
set
{
if (SetProperty(ref _selectedRemoteBranch, value))
IsSetTrackOptionVisible = value != null && _selectedLocalBranch.Upstream != value.FullName;
}
}
public bool PushAllTags
@ -82,6 +68,12 @@ namespace SourceGit.ViewModels
set;
}
public bool IsSetTrackOptionVisible
{
get => _isSetTrackOptionVisible;
private set => SetProperty(ref _isSetTrackOptionVisible, value);
}
public bool Tracking
{
get;
@ -160,7 +152,7 @@ namespace SourceGit.ViewModels
remoteBranchName,
PushAllTags,
ForcePush,
Tracking,
_isSetTrackOptionVisible && Tracking,
SetProgressDescription).Exec();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
@ -218,5 +210,6 @@ namespace SourceGit.ViewModels
private Models.Remote _selectedRemote = null;
private List<Models.Branch> _remoteBranches = new List<Models.Branch>();
private Models.Branch _selectedRemoteBranch = null;
private bool _isSetTrackOptionVisible = false;
}
}

View file

@ -13,7 +13,7 @@
Classes="bold"
Text="{DynamicResource Text.Push.Title}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32,32,32" ColumnDefinitions="150,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto,32,32" ColumnDefinitions="150,*">
<TextBlock Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@ -73,8 +73,10 @@
</ComboBox>
<CheckBox Grid.Row="3" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Push.Tracking}"
IsChecked="{Binding Tracking, Mode=TwoWay}"/>
IsChecked="{Binding Tracking, Mode=TwoWay}"
IsVisible="{Binding IsSetTrackOptionVisible}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
Content="{DynamicResource Text.Push.WithAllTags}"