Skip to content

Commit f102c9e

Browse files
committed
feature: add a STAGE SELECTED & COMMIT button to Confirm Empty Commit dialog
Signed-off-by: leo <longshuang@msn.cn>
1 parent fd62fbe commit f102c9e

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

src/App.axaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,14 @@ public static async Task<bool> AskConfirmAsync(string message, Models.ConfirmBut
208208
return false;
209209
}
210210

211-
public static async Task<Models.ConfirmEmptyCommitResult> AskConfirmEmptyCommitAsync(bool hasLocalChanges)
211+
public static async Task<Models.ConfirmEmptyCommitResult> AskConfirmEmptyCommitAsync(bool hasLocalChanges, bool hasSelectedUnstaged)
212212
{
213213
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
214214
{
215215
var confirm = new Views.ConfirmEmptyCommit();
216216
confirm.TxtMessage.Text = Text(hasLocalChanges ? "ConfirmEmptyCommit.WithLocalChanges" : "ConfirmEmptyCommit.NoLocalChanges");
217217
confirm.BtnStageAllAndCommit.IsVisible = hasLocalChanges;
218+
confirm.BtnStageSelectedAndCommit.IsVisible = hasSelectedUnstaged;
218219
return await confirm.ShowDialog<Models.ConfirmEmptyCommitResult>(owner);
219220
}
220221

src/Models/ConfirmEmptyCommitResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum ConfirmEmptyCommitResult
44
{
55
Cancel = 0,
6+
StageSelectedAndCommit,
67
StageAllAndCommit,
78
CreateEmptyCommit,
89
}

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@
281281
<x:String x:Key="Text.ConfirmEmptyCommit.Continue" xml:space="preserve">CONTINUE</x:String>
282282
<x:String x:Key="Text.ConfirmEmptyCommit.NoLocalChanges" xml:space="preserve">Empty commit detected! Do you want to continue (--allow-empty)?</x:String>
283283
<x:String x:Key="Text.ConfirmEmptyCommit.StageAllThenCommit" xml:space="preserve">STAGE ALL &amp; COMMIT</x:String>
284-
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">Empty commit detected! Do you want to continue (--allow-empty) or stage all then commit?</x:String>
284+
<x:String x:Key="Text.ConfirmEmptyCommit.StageSelectedThenCommit" xml:space="preserve">STAGE SELECTED &amp; COMMIT</x:String>
285+
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">Empty commit detected! Do you want to continue (--allow-empty) or auto-stage then commit?</x:String>
285286
<x:String x:Key="Text.ConfirmRestart.Title" xml:space="preserve">Restart Required</x:String>
286287
<x:String x:Key="Text.ConfirmRestart.Message" xml:space="preserve">You need to restart this app to apply changes.</x:String>
287288
<x:String x:Key="Text.ConventionalCommit" xml:space="preserve">Conventional Commit Helper</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@
284284
<x:String x:Key="Text.ConfigureWorkspace.Restore" xml:space="preserve">启动时恢复打开的仓库</x:String>
285285
<x:String x:Key="Text.ConfirmEmptyCommit.Continue" xml:space="preserve">确认继续</x:String>
286286
<x:String x:Key="Text.ConfirmEmptyCommit.NoLocalChanges" xml:space="preserve">提交未包含变更文件!是否继续(--allow-empty)?</x:String>
287-
<x:String x:Key="Text.ConfirmEmptyCommit.StageAllThenCommit" xml:space="preserve">自动暂存并提交</x:String>
288-
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">提交未包含变更文件!是否继续(--allow-empty)或是自动暂存所有变更并提交?</x:String>
287+
<x:String x:Key="Text.ConfirmEmptyCommit.StageAllThenCommit" xml:space="preserve">暂存所有变更并提交</x:String>
288+
<x:String x:Key="Text.ConfirmEmptyCommit.StageSelectedThenCommit" xml:space="preserve">仅暂存所选变更并提交</x:String>
289+
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">提交未包含变更文件!是否继续(--allow-empty)或是自动暂存变更并提交?</x:String>
289290
<x:String x:Key="Text.ConfirmRestart.Title" xml:space="preserve">系统提示</x:String>
290291
<x:String x:Key="Text.ConfirmRestart.Message" xml:space="preserve">程序需要重新启动,以便修改生效!</x:String>
291292
<x:String x:Key="Text.ConventionalCommit" xml:space="preserve">规范化提交信息生成</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@
284284
<x:String x:Key="Text.ConfigureWorkspace.Restore" xml:space="preserve">啟動時還原上次開啟的存放庫</x:String>
285285
<x:String x:Key="Text.ConfirmEmptyCommit.Continue" xml:space="preserve">確認繼續</x:String>
286286
<x:String x:Key="Text.ConfirmEmptyCommit.NoLocalChanges" xml:space="preserve">未包含任何檔案變更! 您是否仍要提交 (--allow-empty)?</x:String>
287-
<x:String x:Key="Text.ConfirmEmptyCommit.StageAllThenCommit" xml:space="preserve">自動暫存並提交</x:String>
288-
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">未包含任何檔案變更! 您是否仍要提交 (--allow-empty) 或者自動暫存全部變更並提交?</x:String>
287+
<x:String x:Key="Text.ConfirmEmptyCommit.StageAllThenCommit" xml:space="preserve">暫存全部變更並提交</x:String>
288+
<x:String x:Key="Text.ConfirmEmptyCommit.StageSelectedThenCommit" xml:space="preserve">僅暫存所選變更并提交</x:String>
289+
<x:String x:Key="Text.ConfirmEmptyCommit.WithLocalChanges" xml:space="preserve">未包含任何檔案變更! 您是否仍要提交 (--allow-empty) 或者自動暫存變更並提交?</x:String>
289290
<x:String x:Key="Text.ConfirmRestart.Title" xml:space="preserve">系統提示</x:String>
290291
<x:String x:Key="Text.ConfirmRestart.Message" xml:space="preserve">您需要重新啟動此應用程式才能套用變更!</x:String>
291292
<x:String x:Key="Text.ConventionalCommit" xml:space="preserve">產生約定式提交訊息</x:String>

src/ViewModels/WorkingCopy.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,14 @@ public async Task CommitAsync(bool autoStage, bool autoPush)
643643
{
644644
if ((!autoStage && _staged.Count == 0) || (autoStage && _cached.Count == 0))
645645
{
646-
var rs = await App.AskConfirmEmptyCommitAsync(_cached.Count > 0);
646+
var rs = await App.AskConfirmEmptyCommitAsync(_cached.Count > 0, _selectedUnstaged is { Count: > 0 });
647647
if (rs == Models.ConfirmEmptyCommitResult.Cancel)
648648
return;
649649

650650
if (rs == Models.ConfirmEmptyCommitResult.StageAllAndCommit)
651651
autoStage = true;
652+
else if (rs == Models.ConfirmEmptyCommitResult.StageSelectedAndCommit)
653+
await StageChangesAsync(_selectedUnstaged, null);
652654
}
653655
}
654656

src/Views/ConfirmEmptyCommit.axaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737

3838
<!-- Body -->
3939
<Border Grid.Row="1" Margin="16">
40-
<TextBlock x:Name="TxtMessage" MaxWidth="520" TextWrapping="Wrap"/>
40+
<TextBlock x:Name="TxtMessage" TextWrapping="NoWrap"/>
4141
</Border>
4242

4343
<!-- Buttons -->
44-
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
44+
<StackPanel Grid.Row="2" Margin="32,0,32,16" Orientation="Horizontal" HorizontalAlignment="Center">
45+
<Button Classes="flat"
46+
x:Name="BtnStageSelectedAndCommit"
47+
Height="30"
48+
Margin="4,0"
49+
Click="StageSelectedThenCommit"
50+
Content="{DynamicResource Text.ConfirmEmptyCommit.StageSelectedThenCommit}"
51+
HorizontalContentAlignment="Center"
52+
VerticalContentAlignment="Center"/>
53+
4554
<Button Classes="flat"
4655
x:Name="BtnStageAllAndCommit"
4756
Height="30"

src/Views/ConfirmEmptyCommit.axaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public ConfirmEmptyCommit()
99
InitializeComponent();
1010
}
1111

12+
private void StageSelectedThenCommit(object _1, RoutedEventArgs _2)
13+
{
14+
Close(Models.ConfirmEmptyCommitResult.StageSelectedAndCommit);
15+
}
16+
1217
private void StageAllThenCommit(object _1, RoutedEventArgs _2)
1318
{
1419
Close(Models.ConfirmEmptyCommitResult.StageAllAndCommit);

0 commit comments

Comments
 (0)