mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
Adding checkout commit menu and dialog
This commit is contained in:
parent
b0c00340a8
commit
8aa1690cde
7 changed files with 181 additions and 0 deletions
|
@ -53,7 +53,11 @@
|
||||||
<x:String x:Key="Text.ChangeDisplayMode.List" xml:space="preserve">Show as List</x:String>
|
<x:String x:Key="Text.ChangeDisplayMode.List" xml:space="preserve">Show as List</x:String>
|
||||||
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">Show as Tree</x:String>
|
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">Show as Tree</x:String>
|
||||||
<x:String x:Key="Text.Checkout" xml:space="preserve">Checkout Branch</x:String>
|
<x:String x:Key="Text.Checkout" xml:space="preserve">Checkout Branch</x:String>
|
||||||
|
<x:String x:Key="Text.Checkout.Commit" xml:space="preserve">Checkout Commit</x:String>
|
||||||
|
<x:String x:Key="Text.Checkout.Commit.Warning" xml:space="preserve">Warning: By doing a commit checkout, your Head will be detached</x:String>
|
||||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch :</x:String>
|
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch :</x:String>
|
||||||
|
<x:String x:Key="Text.Checkout.CommitTarget.Sha" xml:space="preserve">Commit SHA :</x:String>
|
||||||
|
<x:String x:Key="Text.Checkout.CommitTarget.ShortSha" xml:space="preserve">Commit Short SHA :</x:String>
|
||||||
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes :</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.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.Discard" xml:space="preserve">Discard</x:String>
|
||||||
|
@ -73,6 +77,7 @@
|
||||||
<x:String x:Key="Text.Close" xml:space="preserve">CLOSE</x:String>
|
<x:String x:Key="Text.Close" xml:space="preserve">CLOSE</x:String>
|
||||||
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">Cherry-Pick This Commit</x:String>
|
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">Cherry-Pick This Commit</x:String>
|
||||||
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">Copy SHA</x:String>
|
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">Copy SHA</x:String>
|
||||||
|
<x:String x:Key="Text.CommitCM.Checkout" xml:space="preserve">Checkout commit${0}</x:String>
|
||||||
<x:String x:Key="Text.CommitCM.Rebase" xml:space="preserve">Rebase${0}$to Here</x:String>
|
<x:String x:Key="Text.CommitCM.Rebase" xml:space="preserve">Rebase${0}$to Here</x:String>
|
||||||
<x:String x:Key="Text.CommitCM.Reset" xml:space="preserve">Reset${0}$to Here</x:String>
|
<x:String x:Key="Text.CommitCM.Reset" xml:space="preserve">Reset${0}$to Here</x:String>
|
||||||
<x:String x:Key="Text.CommitCM.Revert" xml:space="preserve">Revert Commit</x:String>
|
<x:String x:Key="Text.CommitCM.Revert" xml:space="preserve">Revert Commit</x:String>
|
||||||
|
|
|
@ -44,4 +44,11 @@
|
||||||
<TrimmerRootAssembly Include="SourceGit" />
|
<TrimmerRootAssembly Include="SourceGit" />
|
||||||
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
|
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Views\CheckoutCommit.axaml.cs">
|
||||||
|
<DependentUpon>CheckoutCommit.axaml</DependentUpon>
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
87
src/ViewModels/CheckoutCommit.cs
Normal file
87
src/ViewModels/CheckoutCommit.cs
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SourceGit.ViewModels
|
||||||
|
{
|
||||||
|
public class CheckoutCommit: Popup
|
||||||
|
{
|
||||||
|
public string Commit
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasLocalChanges
|
||||||
|
{
|
||||||
|
get => _repo.WorkingCopyChangesCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AutoStash
|
||||||
|
{
|
||||||
|
get => _autoStash;
|
||||||
|
set => SetProperty(ref _autoStash, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckoutCommit(Repository repo, string commit)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
Commit = commit;
|
||||||
|
View = new Views.CheckoutCommit() { DataContext = this };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<bool> Sure()
|
||||||
|
{
|
||||||
|
_repo.SetWatcherEnabled(false);
|
||||||
|
ProgressDescription = $"Checkout Commit '{Commit}' ...";
|
||||||
|
|
||||||
|
return Task.Run(() =>
|
||||||
|
{
|
||||||
|
var needPopStash = false;
|
||||||
|
if (HasLocalChanges)
|
||||||
|
{
|
||||||
|
if (AutoStash)
|
||||||
|
{
|
||||||
|
SetProgressDescription("Adding untracked changes ...");
|
||||||
|
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||||
|
if (succ)
|
||||||
|
{
|
||||||
|
SetProgressDescription("Stash local changes ...");
|
||||||
|
succ = new Commands.Stash(_repo.FullPath).Push("CHECKOUT_AUTO_STASH");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!succ)
|
||||||
|
{
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
needPopStash = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetProgressDescription("Discard local changes ...");
|
||||||
|
Commands.Discard.All(_repo.FullPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetProgressDescription("Checkout commit ...");
|
||||||
|
var rs = new Commands.Checkout(_repo.FullPath).Commit(Commit, SetProgressDescription);
|
||||||
|
|
||||||
|
if (needPopStash)
|
||||||
|
{
|
||||||
|
SetProgressDescription("Re-apply local changes...");
|
||||||
|
rs = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
||||||
|
if (rs)
|
||||||
|
{
|
||||||
|
rs = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return rs;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Repository _repo = null;
|
||||||
|
private bool _autoStash = true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
@ -234,6 +236,20 @@ namespace SourceGit.ViewModels
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(reset);
|
menu.Items.Add(reset);
|
||||||
|
|
||||||
|
var checkoutCommit = new MenuItem();
|
||||||
|
|
||||||
|
var shortSha = Converters.StringConverters.ToShortSHA
|
||||||
|
.Convert(commit.SHA, typeof(string), null, CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
|
checkoutCommit.Header = new Views.NameHighlightedTextBlock("CommitCM.Checkout", shortSha);
|
||||||
|
checkoutCommit.Icon = App.CreateMenuIcon("Icons.Check");
|
||||||
|
checkoutCommit.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
_repo.CheckoutCommit(commit.SHA);
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(checkoutCommit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -722,6 +722,14 @@ namespace SourceGit.ViewModels
|
||||||
PopupHost.ShowAndStartPopup(new Checkout(this, branch));
|
PopupHost.ShowAndStartPopup(new Checkout(this, branch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CheckoutCommit(string commit)
|
||||||
|
{
|
||||||
|
if (!PopupHost.CanCreatePopup())
|
||||||
|
return;
|
||||||
|
|
||||||
|
PopupHost.ShowPopup(new CheckoutCommit(this, commit));
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateNewTag()
|
public void CreateNewTag()
|
||||||
{
|
{
|
||||||
var current = Branches.Find(x => x.IsCurrent);
|
var current = Branches.Find(x => x.IsCurrent);
|
||||||
|
|
45
src/Views/CheckoutCommit.axaml
Normal file
45
src/Views/CheckoutCommit.axaml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<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"
|
||||||
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
|
xmlns:c="clr-namespace:SourceGit.Converters"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.CheckoutCommit"
|
||||||
|
x:DataType="vm:CheckoutCommit">
|
||||||
|
<StackPanel Orientation="Vertical" Margin="8,0">
|
||||||
|
<TextBlock FontSize="18"
|
||||||
|
Classes="bold"
|
||||||
|
Text="{DynamicResource Text.Checkout.Commit}"/>
|
||||||
|
|
||||||
|
<TextBlock FontSize="14"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Classes="italic"
|
||||||
|
Text="{DynamicResource Text.Checkout.Commit.Warning}"/>
|
||||||
|
|
||||||
|
<TextBlock TextWrapping="Wrap" Margin="0,16,0,0">
|
||||||
|
<TextBlock Classes="bold" Grid.Row="0" Grid.Column="0"
|
||||||
|
Text="{DynamicResource Text.Checkout.CommitTarget.Sha}"/>
|
||||||
|
<TextBlock TextWrapping="Wrap" Text="{Binding Commit}"/>
|
||||||
|
(<TextBlock Classes="italic" TextWrapping="Wrap" Text="{Binding Commit, Converter={x:Static c:StringConverters.ToShortSHA}}"/>)
|
||||||
|
</TextBlock>
|
||||||
|
|
||||||
|
<StackPanel Margin="0, 26, 0, 0" Grid.Row="1" Grid.Column="1" Orientation="Vertical" IsVisible="{Binding HasLocalChanges}">
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||||
|
HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
||||||
|
|
||||||
|
<StackPanel Margin="0, 13, 0, 0" Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
|
||||||
|
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
|
||||||
|
GroupName="LocalChanges"
|
||||||
|
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
||||||
|
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
|
||||||
|
GroupName="LocalChanges"
|
||||||
|
Margin="8,0,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
13
src/Views/CheckoutCommit.axaml.cs
Normal file
13
src/Views/CheckoutCommit.axaml.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class CheckoutCommit : UserControl
|
||||||
|
{
|
||||||
|
public bool HasLocalChanges;
|
||||||
|
public CheckoutCommit()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue