mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 05:10:25 +08:00
enhance: AI-based commit message generator (#2255)
- Make `AI Assistant` window resizable - Make `AI Assistant` window non-modal dialog - Clean up code Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -4,16 +4,16 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="120"
|
||||
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="400"
|
||||
x:Class="SourceGit.Views.AIAssistant"
|
||||
x:DataType="vm:AIAssistant"
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.AIAssistant}"
|
||||
Width="520" SizeToContent="Height"
|
||||
CanResize="False"
|
||||
Width="520" Height="400"
|
||||
CanResize="True"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto">
|
||||
<Grid RowDefinitions="Auto,*,Auto">
|
||||
<!-- TitleBar -->
|
||||
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||
<Border Background="{DynamicResource Brush.TitleBar}"
|
||||
@@ -39,7 +39,6 @@
|
||||
<!-- AI response -->
|
||||
<v:AIResponseView Grid.Row="1"
|
||||
Margin="8"
|
||||
Height="320"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource Brush.Border2}"
|
||||
Background="{DynamicResource Brush.Contents}"
|
||||
|
||||
@@ -565,7 +565,7 @@ namespace SourceGit.Views
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void OnOpenOpenAIHelper(object sender, RoutedEventArgs e)
|
||||
private void OnOpenOpenAIHelper(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.WorkingCopy vm && sender is Button button && ShowAdvancedOptions)
|
||||
{
|
||||
@@ -588,7 +588,7 @@ namespace SourceGit.Views
|
||||
|
||||
if (services.Count == 1)
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.AIAssistant(repo, services[0], vm.Staged));
|
||||
DoOpenAIAssistant(repo, services[0], vm.Staged);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
@@ -599,9 +599,9 @@ namespace SourceGit.Views
|
||||
var dup = service;
|
||||
var item = new MenuItem();
|
||||
item.Header = service.Name;
|
||||
item.Click += async (_, ev) =>
|
||||
item.Click += (_, ev) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.AIAssistant(repo, dup, vm.Staged));
|
||||
DoOpenAIAssistant(repo, dup, vm.Staged);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -637,5 +637,16 @@ namespace SourceGit.Views
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void DoOpenAIAssistant(ViewModels.Repository repo, AI.Service service, List<Models.Change> changes)
|
||||
{
|
||||
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||
if (owner == null)
|
||||
return;
|
||||
|
||||
var assistant = new ViewModels.AIAssistant(repo, service, changes);
|
||||
var view = new AIAssistant() { DataContext = assistant };
|
||||
view.Show(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Avalonia.Controls;
|
||||
@@ -927,9 +928,9 @@ namespace SourceGit.Views
|
||||
|
||||
if (services.Count == 1)
|
||||
{
|
||||
ai.Click += async (_, e) =>
|
||||
ai.Click += (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.AIAssistant(repo, services[0], selectedStaged));
|
||||
DoOpenAIAssistant(repo, services[0], selectedStaged);
|
||||
e.Handled = true;
|
||||
};
|
||||
}
|
||||
@@ -941,9 +942,9 @@ namespace SourceGit.Views
|
||||
|
||||
var item = new MenuItem();
|
||||
item.Header = service.Name;
|
||||
item.Click += async (_, e) =>
|
||||
item.Click += (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.AIAssistant(repo, dup, selectedStaged));
|
||||
DoOpenAIAssistant(repo, dup, selectedStaged);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1369,5 +1370,16 @@ namespace SourceGit.Views
|
||||
menu.Items.Add(custom);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
private void DoOpenAIAssistant(ViewModels.Repository repo, AI.Service serivce, List<Models.Change> changes)
|
||||
{
|
||||
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||
if (owner == null)
|
||||
return;
|
||||
|
||||
var assistant = new ViewModels.AIAssistant(repo, serivce, changes);
|
||||
var view = new AIAssistant() { DataContext = assistant };
|
||||
view.Show(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user