mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: allow to ignore local changes also when switching branch or pulling changes (#151)
This commit is contained in:
parent
69f9dceece
commit
0b09d210be
13 changed files with 253 additions and 212 deletions
9
src/Models/DealWithLocalChanges.cs
Normal file
9
src/Models/DealWithLocalChanges.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace SourceGit.Models
|
||||
{
|
||||
public enum DealWithLocalChanges
|
||||
{
|
||||
StashAndReaply,
|
||||
Discard,
|
||||
DoNothing,
|
||||
}
|
||||
}
|
|
@ -61,8 +61,9 @@
|
|||
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">Commit :</x:String>
|
||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.CherryPick" xml:space="preserve">Cherry-Pick This Commit</x:String>
|
||||
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">Commit :</x:String>
|
||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">Commit all changes</x:String>
|
||||
|
@ -118,8 +119,8 @@
|
|||
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">Check out after created</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">New Branch Name :</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">Enter branch name.</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
|
||||
|
@ -320,9 +321,12 @@
|
|||
<x:String x:Key="Text.Preference.Merger.Path.Placeholder" xml:space="preserve">Input path for merge tool</x:String>
|
||||
<x:String x:Key="Text.Preference.Merger.Type" xml:space="preserve">Merger</x:String>
|
||||
<x:String x:Key="Text.Pull" xml:space="preserve">Pull</x:String>
|
||||
<x:String x:Key="Text.Pull.AutoStash" xml:space="preserve">Stash & reapply local changes</x:String>
|
||||
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Branch :</x:String>
|
||||
<x:String x:Key="Text.Pull.Into" xml:space="preserve">Into :</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">Remote :</x:String>
|
||||
<x:String x:Key="Text.Pull.Title" xml:space="preserve">Pull (Fetch & Merge)</x:String>
|
||||
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">Use rebase instead of merge</x:String>
|
||||
|
|
|
@ -61,8 +61,9 @@
|
|||
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">提交 :</x:String>
|
||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目标分支 :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">忽略</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.DoNothing" xml:space="preserve">不做处理</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
|
||||
<x:String x:Key="Text.CherryPick" xml:space="preserve">挑选(cherry-pick)此提交</x:String>
|
||||
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">提交ID :</x:String>
|
||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">提交变化</x:String>
|
||||
|
@ -117,9 +118,9 @@
|
|||
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">新分支基于 :</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">完成后切换到新分支</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">放弃所有</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">不做处理</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">GIT默认</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">新分支名 :</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">填写分支名称。</x:String>
|
||||
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>
|
||||
|
@ -320,9 +321,12 @@
|
|||
<x:String x:Key="Text.Preference.Merger.Path.Placeholder" xml:space="preserve">填写工具可执行文件所在位置</x:String>
|
||||
<x:String x:Key="Text.Preference.Merger.Type" xml:space="preserve">工具</x:String>
|
||||
<x:String x:Key="Text.Pull" xml:space="preserve">拉回(pull)</x:String>
|
||||
<x:String x:Key="Text.Pull.AutoStash" xml:space="preserve">自动贮藏并恢复本地变更</x:String>
|
||||
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">拉取分支 :</x:String>
|
||||
<x:String x:Key="Text.Pull.Into" xml:space="preserve">本地分支 :</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.DoNothing" xml:space="preserve">不做处理</x:String>
|
||||
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
|
||||
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">远程 :</x:String>
|
||||
<x:String x:Key="Text.Pull.Title" xml:space="preserve">拉回(拉取并合并)</x:String>
|
||||
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">使用变基方式合并分支</x:String>
|
||||
|
|
|
@ -10,10 +10,10 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public bool AutoStash
|
||||
public Models.DealWithLocalChanges PreAction
|
||||
{
|
||||
get => _autoStash;
|
||||
set => SetProperty(ref _autoStash, value);
|
||||
get => _preAction;
|
||||
set => SetProperty(ref _preAction, value);
|
||||
}
|
||||
|
||||
public Checkout(Repository repo, string branch)
|
||||
|
@ -34,7 +34,7 @@ namespace SourceGit.ViewModels
|
|||
var needPopStash = false;
|
||||
if (hasLocalChanges)
|
||||
{
|
||||
if (AutoStash)
|
||||
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
|
||||
{
|
||||
SetProgressDescription("Adding untracked changes ...");
|
||||
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||
|
@ -52,7 +52,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
else
|
||||
else if (_preAction == Models.DealWithLocalChanges.Discard)
|
||||
{
|
||||
SetProgressDescription("Discard local changes ...");
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
|
@ -78,6 +78,6 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private bool _autoStash = true;
|
||||
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.StashAndReaply;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,6 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public enum BeforeCreateBranchAction
|
||||
{
|
||||
StashAndReaply,
|
||||
Discard,
|
||||
DoNothing,
|
||||
}
|
||||
|
||||
public class CreateBranch : Popup
|
||||
{
|
||||
[Required(ErrorMessage = "Branch name is required!")]
|
||||
|
@ -27,7 +20,7 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public BeforeCreateBranchAction PreAction
|
||||
public Models.DealWithLocalChanges PreAction
|
||||
{
|
||||
get => _preAction;
|
||||
set => SetProperty(ref _preAction, value);
|
||||
|
@ -97,7 +90,7 @@ namespace SourceGit.ViewModels
|
|||
bool needPopStash = false;
|
||||
if (_repo.WorkingCopyChangesCount > 0)
|
||||
{
|
||||
if (_preAction == BeforeCreateBranchAction.StashAndReaply)
|
||||
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
|
||||
{
|
||||
SetProgressDescription("Adding untracked changes...");
|
||||
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||
|
@ -115,7 +108,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
else if (_preAction == BeforeCreateBranchAction.Discard)
|
||||
else if (_preAction == Models.DealWithLocalChanges.Discard)
|
||||
{
|
||||
SetProgressDescription("Discard local changes...");
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
|
@ -144,6 +137,6 @@ namespace SourceGit.ViewModels
|
|||
private readonly Repository _repo = null;
|
||||
private string _name = null;
|
||||
private readonly string _baseOnRevision = null;
|
||||
private BeforeCreateBranchAction _preAction = BeforeCreateBranchAction.StashAndReaply;
|
||||
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.StashAndReaply;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -513,7 +513,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
_repo.CheckoutLocalBranch(branch.Name);
|
||||
_repo.CheckoutBranch(branch);
|
||||
e.Handled = true;
|
||||
};
|
||||
submenu.Items.Add(checkout);
|
||||
|
@ -585,20 +585,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
foreach (var b in _repo.Branches)
|
||||
{
|
||||
if (b.IsLocal && b.Upstream == branch.FullName)
|
||||
{
|
||||
if (!b.IsCurrent)
|
||||
_repo.CheckoutLocalBranch(b.Name);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
||||
|
||||
_repo.CheckoutBranch(branch);
|
||||
e.Handled = true;
|
||||
};
|
||||
submenu.Items.Add(checkout);
|
||||
|
|
|
@ -47,13 +47,13 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _selectedBranch, value);
|
||||
}
|
||||
|
||||
public bool UseRebase
|
||||
public Models.DealWithLocalChanges PreAction
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = true;
|
||||
get => _preAction;
|
||||
set => SetProperty(ref _preAction, value);
|
||||
}
|
||||
|
||||
public bool AutoStash
|
||||
public bool UseRebase
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -117,7 +117,9 @@ namespace SourceGit.ViewModels
|
|||
return Task.Run(() =>
|
||||
{
|
||||
var needPopStash = false;
|
||||
if (AutoStash && _repo.WorkingCopyChangesCount > 0)
|
||||
if (_repo.WorkingCopyChangesCount > 0)
|
||||
{
|
||||
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
|
||||
{
|
||||
SetProgressDescription("Adding untracked changes...");
|
||||
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||
|
@ -135,6 +137,12 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
else if (_preAction == Models.DealWithLocalChanges.Discard)
|
||||
{
|
||||
SetProgressDescription("Discard local changes ...");
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
}
|
||||
}
|
||||
|
||||
SetProgressDescription($"Pull {_selectedRemote.Name}/{_selectedBranch.Name}...");
|
||||
var rs = new Commands.Pull(_repo.FullPath, _selectedRemote.Name, _selectedBranch.Name, UseRebase, SetProgressDescription).Exec();
|
||||
|
@ -154,5 +162,6 @@ namespace SourceGit.ViewModels
|
|||
private Models.Remote _selectedRemote = null;
|
||||
private List<Models.Branch> _remoteBranches = null;
|
||||
private Models.Branch _selectedBranch = null;
|
||||
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.StashAndReaply;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -711,15 +711,33 @@ namespace SourceGit.ViewModels
|
|||
PopupHost.ShowPopup(new CreateBranch(this, current));
|
||||
}
|
||||
|
||||
public void CheckoutLocalBranch(string branch)
|
||||
public void CheckoutBranch(Models.Branch branch)
|
||||
{
|
||||
if (!PopupHost.CanCreatePopup())
|
||||
return;
|
||||
|
||||
if (branch.IsLocal)
|
||||
{
|
||||
if (WorkingCopyChangesCount > 0)
|
||||
PopupHost.ShowPopup(new Checkout(this, branch));
|
||||
PopupHost.ShowPopup(new Checkout(this, branch.Name));
|
||||
else
|
||||
PopupHost.ShowAndStartPopup(new Checkout(this, branch));
|
||||
PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var b in Branches)
|
||||
{
|
||||
if (b.IsLocal && b.Upstream == branch.FullName)
|
||||
{
|
||||
if (!b.IsCurrent)
|
||||
CheckoutBranch(b);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PopupHost.ShowPopup(new CreateBranch(this, branch));
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteMultipleBranches(List<Models.Branch> branches, bool isLocal)
|
||||
|
@ -880,7 +898,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
CheckoutLocalBranch(branch.Name);
|
||||
CheckoutBranch(branch);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
|
@ -1182,20 +1200,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
foreach (var b in Branches)
|
||||
{
|
||||
if (b.IsLocal && b.Upstream == branch.FullName)
|
||||
{
|
||||
if (b.IsCurrent)
|
||||
return;
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowAndStartPopup(new Checkout(this, b.Name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowPopup(new CreateBranch(this, branch));
|
||||
CheckoutBranch(branch);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
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"
|
||||
xmlns:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:ac="using:Avalonia.Controls.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.Checkout"
|
||||
x:DataType="vm:Checkout">
|
||||
|
@ -11,7 +13,7 @@
|
|||
Classes="bold"
|
||||
Text="{DynamicResource Text.Checkout}"/>
|
||||
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="140,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
|
@ -26,12 +28,21 @@
|
|||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
|
||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
|
||||
<StackPanel.Resources>
|
||||
<ac:EnumToBoolConverter x:Key="EnumToBoolConverter"/>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"/>
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.CreateBranch}"/>
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="150,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="140,*">
|
||||
<TextBlock Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
|
@ -67,15 +67,15 @@
|
|||
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.StashAndReaply}}"/>
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.Discard}}"/>
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.DoNothing}}"/>
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
|
||||
</StackPanel>
|
||||
|
||||
<CheckBox Grid.Row="3" Grid.Column="1"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
xmlns:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
xmlns:ac="using:Avalonia.Controls.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.Pull"
|
||||
x:DataType="vm:Pull">
|
||||
|
@ -12,7 +13,7 @@
|
|||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.Pull.Title}"/>
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32,32" ColumnDefinitions="150,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32,32" ColumnDefinitions="140,*">
|
||||
<TextBlock Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
|
@ -58,17 +59,35 @@
|
|||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Pull.Into}"/>
|
||||
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||
<Path Margin="0,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Branch}"/>
|
||||
<Path Margin="2,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Branch}"/>
|
||||
<TextBlock Text="{Binding Current.Name}"/>
|
||||
</StackPanel>
|
||||
|
||||
<CheckBox Grid.Row="3" Grid.Column="1"
|
||||
Content="{DynamicResource Text.Pull.UseRebase}"
|
||||
IsChecked="{Binding UseRebase, Mode=TwoWay}"/>
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Pull.LocalChanges}"/>
|
||||
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
|
||||
<StackPanel.Resources>
|
||||
<ac:EnumToBoolConverter x:Key="EnumToBoolConverter"/>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.StashAndReply}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.StashAndReaply}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.Discard}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.Discard}}"/>
|
||||
<RadioButton Content="{DynamicResource Text.Pull.LocalChanges.DoNothing}"
|
||||
GroupName="LocalChanges"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:DealWithLocalChanges.DoNothing}}"/>
|
||||
</StackPanel>
|
||||
|
||||
<CheckBox Grid.Row="4" Grid.Column="1"
|
||||
Content="{DynamicResource Text.Pull.AutoStash}"
|
||||
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
||||
Content="{DynamicResource Text.Pull.UseRebase}"
|
||||
IsChecked="{Binding UseRebase, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
|
||||
</Button>
|
||||
|
||||
<Button Classes="icon_button" Width="32" Click="OnOpenWithExternalTools" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
|
||||
<Button Classes="icon_button" Width="32" Click="OpenWithExternalTools" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
|
||||
</Button>
|
||||
|
||||
|
@ -222,7 +222,7 @@
|
|||
</TreeView.Styles>
|
||||
<TreeView.ItemTemplate>
|
||||
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type vm:BranchTreeNode}">
|
||||
<Grid Height="24" ColumnDefinitions="20,*,Auto,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedLocalBranchNode">
|
||||
<Grid Height="24" ColumnDefinitions="20,*,Auto,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode">
|
||||
<Path Grid.Column="0" Classes="folder_icon" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,1,0,0" IsVisible="{Binding IsFolder}"/>
|
||||
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,2,0,0" Data="{StaticResource Icons.Check}" IsVisible="{Binding IsCurrent}" VerticalAlignment="Center"/>
|
||||
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="2,0,0,0" Data="{StaticResource Icons.Branch}" VerticalAlignment="Center">
|
||||
|
@ -287,7 +287,7 @@
|
|||
|
||||
<TreeView.ItemTemplate>
|
||||
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type vm:BranchTreeNode}">
|
||||
<Grid Height="24" ColumnDefinitions="20,*,Auto" Background="Transparent">
|
||||
<Grid Height="24" ColumnDefinitions="20,*,Auto" Background="Transparent" DoubleTapped="OnDoubleTappedBranchNode">
|
||||
<Path Grid.Column="0" Classes="folder_icon" Width="10" Height="10" HorizontalAlignment="Left" Margin="0,2,0,0" IsVisible="{Binding IsFolder}" VerticalAlignment="Center"/>
|
||||
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="0,2,0,0" Data="{StaticResource Icons.Remote}" IsVisible="{Binding IsRemote}" VerticalAlignment="Center"/>
|
||||
<Path Grid.Column="0" Width="12" Height="12" HorizontalAlignment="Left" Margin="2,0,0,0" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}" VerticalAlignment="Center"/>
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace SourceGit.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnOpenWithExternalTools(object sender, RoutedEventArgs e)
|
||||
private void OpenWithExternalTools(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
|
@ -73,6 +73,58 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OpenGitFlowMenu(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var menu = repo.CreateContextMenuForGitFlow();
|
||||
(sender as Control)?.OpenContextMenu(menu);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void OpenStatistics(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var dialog = new Statistics() { DataContext = new ViewModels.Statistics(repo.FullPath) };
|
||||
await dialog.ShowDialog(TopLevel.GetTopLevel(this) as Window);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = sender as Grid;
|
||||
if (e.Property == IsVisibleProperty && grid.IsVisible)
|
||||
txtSearchCommitsBox.Focus();
|
||||
}
|
||||
|
||||
private void OnSearchKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
repo.StartSearchCommits();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSearchResultDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var commit = datagrid.SelectedItem as Models.Commit;
|
||||
repo.NavigateToCommit(commit.SHA);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnLocalBranchTreeSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is TreeView tree && tree.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
||||
|
@ -113,74 +165,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
||||
{
|
||||
localBranchTree.UnselectAll();
|
||||
remoteBranchTree.UnselectAll();
|
||||
|
||||
var tag = datagrid.SelectedItem as Models.Tag;
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
repo.NavigateToCommit(tag.SHA);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var grid = sender as Grid;
|
||||
if (e.Property == IsVisibleProperty && grid.IsVisible)
|
||||
txtSearchCommitsBox.Focus();
|
||||
}
|
||||
|
||||
private void OnSearchKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
repo.StartSearchCommits();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSearchResultDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var commit = datagrid.SelectedItem as Models.Commit;
|
||||
repo.NavigateToCommit(commit.SHA);
|
||||
}
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton toggle)
|
||||
{
|
||||
var filter = string.Empty;
|
||||
if (toggle.DataContext is ViewModels.BranchTreeNode node)
|
||||
{
|
||||
if (node.IsBranch)
|
||||
filter = (node.Backend as Models.Branch).FullName;
|
||||
}
|
||||
else if (toggle.DataContext is Models.Tag tag)
|
||||
{
|
||||
filter = tag.Name;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter) && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
repo.UpdateFilter(filter, toggle.IsChecked == true);
|
||||
}
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnLocalBranchContextMenuRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
remoteBranchTree.UnselectAll();
|
||||
|
@ -286,6 +270,39 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (!ViewModels.PopupHost.CanCreatePopup())
|
||||
return;
|
||||
|
||||
if (sender is Grid grid && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var node = grid.DataContext as ViewModels.BranchTreeNode;
|
||||
if (node != null && node.IsBranch)
|
||||
{
|
||||
var branch = node.Backend as Models.Branch;
|
||||
if (branch.IsCurrent)
|
||||
return;
|
||||
|
||||
repo.CheckoutBranch(branch);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
||||
{
|
||||
localBranchTree.UnselectAll();
|
||||
remoteBranchTree.UnselectAll();
|
||||
|
||||
var tag = datagrid.SelectedItem as Models.Tag;
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
repo.NavigateToCommit(tag.SHA);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTagContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
||||
|
@ -298,6 +315,30 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton toggle)
|
||||
{
|
||||
var filter = string.Empty;
|
||||
if (toggle.DataContext is ViewModels.BranchTreeNode node)
|
||||
{
|
||||
if (node.IsBranch)
|
||||
filter = (node.Backend as Models.Branch).FullName;
|
||||
}
|
||||
else if (toggle.DataContext is Models.Tag tag)
|
||||
{
|
||||
filter = tag.Name;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter) && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
repo.UpdateFilter(filter, toggle.IsChecked == true);
|
||||
}
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
||||
|
@ -310,17 +351,6 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OpenGitFlowMenu(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var menu = repo.CreateContextMenuForGitFlow();
|
||||
(sender as Control)?.OpenContextMenu(menu);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void UpdateSubmodules(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
|
@ -335,36 +365,6 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnDoubleTappedLocalBranchNode(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (!ViewModels.PopupHost.CanCreatePopup())
|
||||
return;
|
||||
|
||||
if (sender is Grid grid && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var node = grid.DataContext as ViewModels.BranchTreeNode;
|
||||
if (node != null && node.IsBranch)
|
||||
{
|
||||
var branch = node.Backend as Models.Branch;
|
||||
if (branch.IsCurrent)
|
||||
return;
|
||||
|
||||
repo.CheckoutLocalBranch(branch.Name);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void OpenStatistics(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var dialog = new Statistics() { DataContext = new ViewModels.Statistics(repo.FullPath) };
|
||||
await dialog.ShowDialog(TopLevel.GetTopLevel(this) as Window);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectBranchesFromNode(List<Models.Branch> outs, ViewModels.BranchTreeNode node)
|
||||
{
|
||||
if (node == null || node.IsRemote)
|
||||
|
|
Loading…
Reference in a new issue