mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
e3c0f7d496
* use system chrome instead of custom caption button on macOS * move `BeginMoveWindow` and `MaximizeOrRestoreWindow` to `ChromelessWindow` * better supports for fullscreen mode on macOS * redesign the layout of title bar for all windows Signed-off-by: leo <longshuang@msn.cn>
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
using Avalonia.Controls;
|
|
using Avalonia.Threading;
|
|
|
|
namespace SourceGit.Views
|
|
{
|
|
public partial class AIAssistant : ChromelessWindow
|
|
{
|
|
public AIAssistant()
|
|
{
|
|
_cancel = new CancellationTokenSource();
|
|
InitializeComponent();
|
|
}
|
|
|
|
public AIAssistant(Models.OpenAIService service, string repo, List<Models.Change> changes, Action<string> onDone)
|
|
{
|
|
_service = service;
|
|
_repo = repo;
|
|
_changes = changes;
|
|
_onDone = onDone;
|
|
_cancel = new CancellationTokenSource();
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnOpened(EventArgs e)
|
|
{
|
|
base.OnOpened(e);
|
|
|
|
if (string.IsNullOrEmpty(_repo))
|
|
return;
|
|
|
|
Task.Run(() =>
|
|
{
|
|
var message = new Commands.GenerateCommitMessage(_service, _repo, _changes, _cancel.Token, SetDescription).Result();
|
|
if (_cancel.IsCancellationRequested)
|
|
return;
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
{
|
|
_onDone?.Invoke(message);
|
|
Close();
|
|
});
|
|
}, _cancel.Token);
|
|
}
|
|
|
|
protected override void OnClosing(WindowClosingEventArgs e)
|
|
{
|
|
base.OnClosing(e);
|
|
_cancel.Cancel();
|
|
}
|
|
|
|
private void SetDescription(string message)
|
|
{
|
|
Dispatcher.UIThread.Invoke(() => ProgressMessage.Text = message);
|
|
}
|
|
|
|
private Models.OpenAIService _service;
|
|
private string _repo;
|
|
private List<Models.Change> _changes;
|
|
private Action<string> _onDone;
|
|
private CancellationTokenSource _cancel;
|
|
}
|
|
}
|