feature: add Update Submodule context menu entry for selected submodule

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-07-04 11:37:08 +08:00
parent c54b6c235e
commit 937ad0c708
6 changed files with 64 additions and 21 deletions

View File

@@ -753,6 +753,7 @@
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">not initialized</x:String>
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">revision changed</x:String>
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">unmerged</x:String>
<x:String x:Key="Text.Submodule.Update" xml:space="preserve">Update Submodule</x:String>
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">URL</x:String>
<x:String x:Key="Text.Sure" xml:space="preserve">OK</x:String>
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">Copy Tag Name</x:String>

View File

@@ -757,6 +757,7 @@
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA变更</x:String>
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解决冲突</x:String>
<x:String x:Key="Text.Submodule.Update" xml:space="preserve">更新子模块</x:String>
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">仓库</x:String>
<x:String x:Key="Text.Sure" xml:space="preserve">确 定</x:String>
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">复制标签名</x:String>

View File

@@ -757,6 +757,7 @@
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA 變更</x:String>
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解決的衝突</x:String>
<x:String x:Key="Text.Submodule.Update" xml:space="preserve">更新子模組</x:String>
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">存放庫</x:String>
<x:String x:Key="Text.Sure" xml:space="preserve">確 定</x:String>
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">複製標籤名稱</x:String>

View File

@@ -1440,7 +1440,7 @@ namespace SourceGit.ViewModels
public void UpdateSubmodules()
{
if (CanCreatePopup())
ShowPopup(new UpdateSubmodules(this));
ShowPopup(new UpdateSubmodules(this, null));
}
public void OpenSubmodule(string submodule)
@@ -2556,6 +2556,16 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
var update = new MenuItem();
update.Header = App.Text("Submodule.Update");
update.Icon = App.CreateMenuIcon("Icons.Loading");
update.Click += (_, ev) =>
{
if (CanCreatePopup())
ShowPopup(new UpdateSubmodules(this, submodule));
ev.Handled = true;
};
var move = new MenuItem();
move.Header = App.Text("Submodule.Move");
move.Icon = App.CreateMenuIcon("Icons.MoveTo");
@@ -2599,6 +2609,7 @@ namespace SourceGit.ViewModels
var menu = new ContextMenu();
menu.Items.Add(open);
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(update);
menu.Items.Add(move);
menu.Items.Add(deinit);
menu.Items.Add(rm);

View File

@@ -5,12 +5,17 @@ namespace SourceGit.ViewModels
{
public class UpdateSubmodules : Popup
{
public List<string> Submodules
public bool HasPreSelectedSubmodule
{
get;
} = [];
}
public string SelectedSubmodule
public List<Models.Submodule> Submodules
{
get => _repo.Submodules;
}
public Models.Submodule SelectedSubmodule
{
get;
set;
@@ -40,27 +45,42 @@ namespace SourceGit.ViewModels
set;
} = false;
public UpdateSubmodules(Repository repo)
public UpdateSubmodules(Repository repo, Models.Submodule selected)
{
_repo = repo;
foreach (var submodule in _repo.Submodules)
Submodules.Add(submodule.Path);
SelectedSubmodule = Submodules.Count > 0 ? Submodules[0] : string.Empty;
if (selected != null)
{
_updateAll = false;
SelectedSubmodule = selected;
EnableInit = selected.Status == Models.SubmoduleStatus.NotInited;
HasPreSelectedSubmodule = true;
}
else if (repo.Submodules.Count > 0)
{
SelectedSubmodule = repo.Submodules[0];
HasPreSelectedSubmodule = false;
}
}
public override async Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
List<string> targets;
var targets = new List<string>();
if (_updateAll)
targets = Submodules;
else
targets = [SelectedSubmodule];
{
foreach (var submodule in Submodules)
targets.Add(submodule.Path);
}
else if (SelectedSubmodule != null)
{
targets.Add(SelectedSubmodule.Path);
}
if (targets.Count == 0)
return true;
var log = _repo.CreateLog("Update Submodule");
_repo.SetWatcherEnabled(false);
Use(log);
await new Commands.Submodule(_repo.FullPath)

View File

@@ -2,6 +2,7 @@
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.UpdateSubmodules"
@@ -10,7 +11,7 @@
<TextBlock FontSize="18"
Classes="bold"
Text="{DynamicResource Text.UpdateSubmodules}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32,32" ColumnDefinitions="120,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,Auto,32,32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@@ -19,21 +20,29 @@
Height="28" Padding="8,0"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
ItemsSource="{Binding Submodules}"
SelectedItem="{Binding SelectedSubmodule, Mode=TwoWay}"
IsEnabled="{Binding !UpdateAll}">
SelectedItem="{Binding SelectedSubmodule, Mode=TwoWay}">
<ComboBox.IsEnabled>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="UpdateAll" Converter="{x:Static BoolConverters.Not}"/>
<Binding Path="HasPreSelectedSubmodule" Converter="{x:Static BoolConverters.Not}"/>
</MultiBinding>
</ComboBox.IsEnabled>
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="x:String">
<DataTemplate x:DataType="m:Submodule">
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
<Path Margin="0,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Submodule}"/>
<TextBlock Text="{Binding}"/>
<TextBlock Text="{Binding Path, Mode=OneWay}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Grid.Row="1" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.UpdateSubmodules.All}"
IsChecked="{Binding UpdateAll, Mode=TwoWay}"/>
IsChecked="{Binding UpdateAll, Mode=TwoWay}"
IsVisible="{Binding !HasPreSelectedSubmodule, Mode=OneWay}"/>
<CheckBox Grid.Row="2" Grid.Column="1"
Content="{DynamicResource Text.UpdateSubmodules.Init}"