refactor: use popup to change tracking branch

This commit is contained in:
leo 2025-01-07 12:02:09 +08:00
parent 25a2bf603f
commit 6fe4d8162b
No known key found for this signature in database
13 changed files with 170 additions and 47 deletions

View file

@ -67,8 +67,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Push ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Rebase ${0}$ auf ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Benenne ${0}$ um...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Setze verfolgten Branch</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Upstream Verfolgung aufheben</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Setze verfolgten Branch...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Branch Vergleich</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Bytes</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">ABBRECHEN</x:String>

View file

@ -64,8 +64,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Push ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Rebase ${0}$ on ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Rename ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Set Tracking Branch</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Unset Upstream</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Set Tracking Branch...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Branch Compare</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Bytes</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">CANCEL</x:String>
@ -625,6 +624,10 @@
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Skip This Version</x:String>
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Software Update</x:String>
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">There are currently no updates available.</x:String>
<x:String x:Key="Text.SetUpstream" xml:space="preserve">Set Tracking Branch</x:String>
<x:String x:Key="Text.SetUpstream.Local" xml:space="preserve">Branch:</x:String>
<x:String x:Key="Text.SetUpstream.Unset" xml:space="preserve">Unset upstream</x:String>
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">Upstream:</x:String>
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copy SHA</x:String>
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">Go to</x:String>
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>

View file

@ -67,8 +67,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Push ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Rebase ${0}$ en ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Renombrar ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Establecer Rama de Seguimiento</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Desestablecer Upstream</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Establecer Rama de Seguimiento...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Comparar Ramas</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Bytes</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">CANCELAR</x:String>

View file

@ -66,8 +66,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Pousser ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Rebaser ${0}$ sur ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Renommer ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Définir la branche de suivi</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Ne plus suivre la branche distante</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Définir la branche de suivi...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Comparer les branches</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Octets</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">ANNULER</x:String>

View file

@ -66,8 +66,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Invia ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Riallinea ${0}$ su ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Rinomina ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Imposta Branch di Tracciamento</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Rimuovi Tracciamento</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Imposta Branch di Tracciamento...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Confronto Branch</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Byte</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">ANNULLA</x:String>

View file

@ -91,8 +91,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Subir ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Rebase ${0}$ em ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Renomear ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Definir Branch de Rastreamento</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Remover Upstream</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Definir Branch de Rastreamento...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Comparação de Branches</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Bytes</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">CANCELAR</x:String>

View file

@ -67,8 +67,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">Выложить ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">Переместить ${0}$ на ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Переименовать ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Отслеживать ветку</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">Отключить основной поток</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Отслеживать ветку...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Сравнение веток</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">Байты</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">ОТМЕНА</x:String>

View file

@ -67,8 +67,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">推送(push)${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">变基(rebase) ${0}$ 分支至 ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">重命名 ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切换上游分支</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">取消追踪</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切换上游分支 ...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">分支比较</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">字节</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">取 消</x:String>
@ -629,6 +628,10 @@
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">忽略此版本</x:String>
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">软件更新</x:String>
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">当前已是最新版本。</x:String>
<x:String x:Key="Text.SetUpstream" xml:space="preserve">切换上游分支</x:String>
<x:String x:Key="Text.SetUpstream.Local" xml:space="preserve">本地分支 </x:String>
<x:String x:Key="Text.SetUpstream.Unset" xml:space="preserve">取消追踪</x:String>
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">上游分支 </x:String>
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">复制提交指纹</x:String>
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">跳转到提交</x:String>
<x:String x:Key="Text.Squash" xml:space="preserve">压缩为单个提交</x:String>

View file

@ -67,8 +67,7 @@
<x:String x:Key="Text.BranchCM.Push" xml:space="preserve">推送 (push) ${0}$</x:String>
<x:String x:Key="Text.BranchCM.Rebase" xml:space="preserve">重定基底 (rebase) ${0}$ 分支至 ${1}$...</x:String>
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">重新命名 ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切換上游分支</x:String>
<x:String x:Key="Text.BranchCM.UnsetUpstream" xml:space="preserve">取消設定上游分支</x:String>
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切換上游分支...</x:String>
<x:String x:Key="Text.BranchCompare" xml:space="preserve">分支比較</x:String>
<x:String x:Key="Text.Bytes" xml:space="preserve">位元組</x:String>
<x:String x:Key="Text.Cancel" xml:space="preserve">取 消</x:String>
@ -628,6 +627,10 @@
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">忽略此版本</x:String>
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">軟體更新</x:String>
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">目前已是最新版本。</x:String>
<x:String x:Key="Text.SetUpstream" xml:space="preserve">切換上游分支</x:String>
<x:String x:Key="Text.SetUpstream.Local" xml:space="preserve">本機分支:</x:String>
<x:String x:Key="Text.SetUpstream.Unset" xml:space="preserve">取消設定上游分支</x:String>
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">上游分支:</x:String>
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">複製提交編號</x:String>
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">前往此提交</x:String>
<x:String x:Key="Text.Squash" xml:space="preserve">壓縮為單個提交</x:String>

View file

@ -1624,38 +1624,12 @@ namespace SourceGit.ViewModels
var tracking = new MenuItem();
tracking.Header = App.Text("BranchCM.Tracking");
tracking.Icon = App.CreateMenuIcon("Icons.Track");
foreach (var b in remoteBranches)
tracking.Click += (_, e) =>
{
var upstream = b.FullName.Replace("refs/remotes/", "");
var target = new MenuItem();
target.Header = upstream;
if (branch.Upstream == b.FullName)
target.Icon = App.CreateMenuIcon("Icons.Check");
target.Click += (_, e) =>
{
if (Commands.Branch.SetUpstream(_fullpath, branch.Name, upstream))
Task.Run(RefreshBranches);
e.Handled = true;
};
tracking.Items.Add(target);
}
var unsetUpstream = new MenuItem();
unsetUpstream.Header = App.Text("BranchCM.UnsetUpstream");
unsetUpstream.Click += (_, e) =>
{
if (Commands.Branch.SetUpstream(_fullpath, branch.Name, string.Empty))
Task.Run(RefreshBranches);
if (PopupHost.CanCreatePopup())
PopupHost.ShowPopup(new SetUpstream(this, branch, remoteBranches));
e.Handled = true;
};
tracking.Items.Add(new MenuItem() { Header = "-" });
tracking.Items.Add(unsetUpstream);
menu.Items.Add(tracking);
}

View file

@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Threading;
namespace SourceGit.ViewModels
{
public class SetUpstream : Popup
{
public Models.Branch Local
{
get;
private set;
}
public List<Models.Branch> RemoteBranches
{
get;
private set;
}
public Models.Branch SelectedRemoteBranch
{
get;
set;
}
public bool Unset
{
get => _unset;
set => SetProperty(ref _unset, value);
}
public SetUpstream(Repository repo, Models.Branch local, List<Models.Branch> remoteBranches)
{
_repo = repo;
Local = local;
RemoteBranches = remoteBranches;
Unset = false;
if (!string.IsNullOrEmpty(local.Upstream))
{
var upstream = remoteBranches.Find(x => x.FullName == local.Upstream);
if (upstream != null)
SelectedRemoteBranch = upstream;
}
if (SelectedRemoteBranch == null)
{
var upstream = remoteBranches.Find(x => x.Name == local.Name);
if (upstream != null)
SelectedRemoteBranch = upstream;
}
View = new Views.SetUpstream() { DataContext = this };
}
public override Task<bool> Sure()
{
SetProgressDescription("Setting upstream...");
var upstream = (_unset || SelectedRemoteBranch == null) ? string.Empty : SelectedRemoteBranch.FullName;
if (upstream == Local.Upstream)
return null;
return Task.Run(() =>
{
var succ = Commands.Branch.SetUpstream(_repo.FullPath, Local.Name, upstream.Replace("refs/remotes/", ""));
if (succ)
_repo.RefreshBranches();
return true;
});
}
private Repository _repo;
private bool _unset = false;
}
}

View file

@ -0,0 +1,56 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
x:Class="SourceGit.Views.SetUpstream"
x:DataType="vm:SetUpstream">
<StackPanel Orientation="Vertical" Margin="8,0">
<TextBlock FontSize="18"
Classes="bold"
Text="{DynamicResource Text.SetUpstream}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.SetUpstream.Local}"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Height="20" VerticalAlignment="Center">
<Path Margin="2,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Branch}"/>
<TextBlock Text="{Binding Local.Name}"/>
</StackPanel>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.SetUpstream.Upstream}"/>
<ComboBox Grid.Row="1" Grid.Column="1"
Height="28" Padding="8,0"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
ItemsSource="{Binding RemoteBranches}"
SelectedItem="{Binding SelectedRemoteBranch, Mode=TwoWay}"
IsTextSearchEnabled="True"
IsEnabled="{Binding !Unset, Mode=OneWay}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="{x:Type m:Branch}">
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
<Path Margin="0,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Branch}"/>
<TextBlock Text="{Binding FriendlyName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerTheme>
<ControlTheme TargetType="ComboBoxItem" x:DataType="m:Branch" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
<Setter Property="TextSearch.Text" Value="{Binding Name}"/>
</ControlTheme>
</ComboBox.ItemContainerTheme>
</ComboBox>
<CheckBox Grid.Row="2" Grid.Column="1"
Content="{DynamicResource Text.SetUpstream.Unset}"
IsChecked="{Binding Unset, Mode=TwoWay}"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -0,0 +1,12 @@
using Avalonia.Controls;
namespace SourceGit.Views
{
public partial class SetUpstream : UserControl
{
public SetUpstream()
{
InitializeComponent();
}
}
}