mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
feature<DeleteSubmodule>: add context menu to delete submodules
This commit is contained in:
parent
eaabfcf28e
commit
3edb8bf2dd
6 changed files with 115 additions and 0 deletions
|
@ -974,6 +974,27 @@ namespace SourceGit.Git {
|
|||
isWatcherDisabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete submodule
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void DeleteSubmodule(string path) {
|
||||
isWatcherDisabled = true;
|
||||
|
||||
var errs = RunCommand($"submodule deinit -f {path}", null);
|
||||
if (errs != null) {
|
||||
App.RaiseError(errs);
|
||||
} else {
|
||||
errs = RunCommand($"rm -f {path}", null);
|
||||
if (errs != null) App.RaiseError(errs);
|
||||
|
||||
OnWorkingCopyChanged?.Invoke();
|
||||
OnSubmoduleChanged?.Invoke();
|
||||
}
|
||||
|
||||
isWatcherDisabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Blame file.
|
||||
/// </summary>
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<sys:String x:Key="Text.Submodule.FetchNested">Fetch nested submodules</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.Open">Open Submodule Repository</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.CopyPath">Copy Relative Path</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.Remove">Delete Submodule</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.CherryPick">Cherry-Pick This Commit</sys:String>
|
||||
<sys:String x:Key="Text.CherryPick.Title">Cherry Pick</sys:String>
|
||||
|
@ -215,6 +216,9 @@
|
|||
<sys:String x:Key="Text.DeleteTag.Tag">Tag :</sys:String>
|
||||
<sys:String x:Key="Text.DeleteTag.WithRemote">Delete from remote repositories</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.DeleteSubmodule">Confirm To Delete Submodule</sys:String>
|
||||
<sys:String x:Key="Text.DeleteSubmodule.Path">Submodule Path :</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.Diff.Next">Next Difference</sys:String>
|
||||
<sys:String x:Key="Text.Diff.Prev">Previous Difference</sys:String>
|
||||
<sys:String x:Key="Text.Diff.Mode">Toggle One-Side/Two-Sides</sys:String>
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<sys:String x:Key="Text.Submodule.FetchNested">拉取子孙模块</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.Open">打开仓库</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.CopyPath">复制路径</sys:String>
|
||||
<sys:String x:Key="Text.Submodule.Remove">删除子模块</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.CherryPick">挑选此提交</sys:String>
|
||||
<sys:String x:Key="Text.CherryPick.Title">挑选提交</sys:String>
|
||||
|
@ -214,6 +215,9 @@
|
|||
<sys:String x:Key="Text.DeleteTag">确定要移除该标签吗?</sys:String>
|
||||
<sys:String x:Key="Text.DeleteTag.Tag">标签名 :</sys:String>
|
||||
<sys:String x:Key="Text.DeleteTag.WithRemote">同时删除远程仓库中的此标签</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.DeleteSubmodule">确定要移除该子模块吗?</sys:String>
|
||||
<sys:String x:Key="Text.DeleteSubmodule.Path">子模块路径 :</sys:String>
|
||||
|
||||
<sys:String x:Key="Text.Diff.Next">下一个差异</sys:String>
|
||||
<sys:String x:Key="Text.Diff.Prev">上一个差异</sys:String>
|
||||
|
|
|
@ -1026,9 +1026,17 @@ namespace SourceGit.UI {
|
|||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var rm = new MenuItem();
|
||||
rm.Header = App.Text("Submodule.Remove");
|
||||
rm.Click += (o, ev) => {
|
||||
DeleteSubmodule.Show(repo, path);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(open);
|
||||
menu.Items.Add(copy);
|
||||
menu.Items.Add(rm);
|
||||
menu.IsOpen = true;
|
||||
|
||||
e.Handled = true;
|
||||
|
|
42
src/UI/DeleteSubmodule.xaml
Normal file
42
src/UI/DeleteSubmodule.xaml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<UserControl x:Class="SourceGit.UI.DeleteSubmodule"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="128" d:DesignWidth="500" Height="128" Width="500">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="16"/>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="16"/>
|
||||
<RowDefinition Height="32"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.ColumnSpan="2" FontWeight="DemiBold" FontSize="18" Content="{StaticResource Text.DeleteSubmodule}"/>
|
||||
|
||||
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="{StaticResource Text.DeleteSubmodule.Path}"/>
|
||||
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
|
||||
<Path Width="12" Data="{StaticResource Icon.Submodule}" Margin="4,0"/>
|
||||
<TextBlock x:Name="targetPath" Foreground="{StaticResource Brush.FG1}" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Grid.Row="4" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="8"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="1" Click="Sure" Content="{StaticResource Text.Sure}" Style="{StaticResource Style.Button.AccentBordered}"/>
|
||||
<Button Grid.Column="3" Click="Cancel" Content="{StaticResource Text.Cancel}" Style="{StaticResource Style.Button.Bordered}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
36
src/UI/DeleteSubmodule.xaml.cs
Normal file
36
src/UI/DeleteSubmodule.xaml.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.UI {
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for DeleteSubmodule.xaml
|
||||
/// </summary>
|
||||
public partial class DeleteSubmodule : UserControl {
|
||||
private Git.Repository repo = null;
|
||||
private string submodule = null;
|
||||
|
||||
public DeleteSubmodule(Git.Repository opened, string path) {
|
||||
InitializeComponent();
|
||||
repo = opened;
|
||||
submodule = path;
|
||||
targetPath.Text = path;
|
||||
}
|
||||
|
||||
public static void Show(Git.Repository repo, string submodule) {
|
||||
repo.GetPopupManager()?.Show(new DeleteSubmodule(repo, submodule));
|
||||
}
|
||||
|
||||
private async void Sure(object sender, RoutedEventArgs e) {
|
||||
var popup = repo.GetPopupManager();
|
||||
popup?.Lock();
|
||||
await Task.Run(() => repo.DeleteSubmodule(submodule));
|
||||
popup?.Close(true);
|
||||
}
|
||||
|
||||
private void Cancel(object sender, RoutedEventArgs e) {
|
||||
repo.GetPopupManager()?.Close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue