1
+ using System ;
2
+ using System . Collections . Generic ;
1
3
using System . Threading ;
2
4
using System . Threading . Tasks ;
3
5
@@ -13,28 +15,36 @@ public AIAssistant()
13
15
{
14
16
_cancel = new CancellationTokenSource ( ) ;
15
17
InitializeComponent ( ) ;
16
- ProgressMessage . Text = "Generating commit message... Please wait!" ;
17
18
}
18
19
19
- public void GenerateCommitMessage ( )
20
+ public AIAssistant ( string repo , List < Models . Change > changes , Action < string > onDone )
20
21
{
21
- if ( DataContext is ViewModels . WorkingCopy vm )
22
+ _repo = repo ;
23
+ _changes = changes ;
24
+ _onDone = onDone ;
25
+ _cancel = new CancellationTokenSource ( ) ;
26
+ InitializeComponent ( ) ;
27
+ }
28
+
29
+ protected override void OnOpened ( EventArgs e )
30
+ {
31
+ base . OnOpened ( e ) ;
32
+
33
+ if ( string . IsNullOrEmpty ( _repo ) )
34
+ return ;
35
+
36
+ Task . Run ( ( ) =>
22
37
{
23
- Task . Run ( ( ) =>
38
+ var message = new Commands . GenerateCommitMessage ( _repo , _changes , _cancel . Token , SetDescription ) . Result ( ) ;
39
+ if ( _cancel . IsCancellationRequested )
40
+ return ;
41
+
42
+ Dispatcher . UIThread . Invoke ( ( ) =>
24
43
{
25
- var message = new Commands . GenerateCommitMessage ( vm . RepoPath , vm . Staged , _cancel . Token , SetDescription ) . Result ( ) ;
26
- if ( _cancel . IsCancellationRequested )
27
- return ;
28
-
29
- Dispatcher . UIThread . Invoke ( ( ) =>
30
- {
31
- if ( DataContext is ViewModels . WorkingCopy wc )
32
- wc . CommitMessage = message ;
33
-
34
- Close ( ) ;
35
- } ) ;
36
- } , _cancel . Token ) ;
37
- }
44
+ _onDone ? . Invoke ( message ) ;
45
+ Close ( ) ;
46
+ } ) ;
47
+ } , _cancel . Token ) ;
38
48
}
39
49
40
50
protected override void OnClosing ( WindowClosingEventArgs e )
@@ -50,12 +60,12 @@ private void BeginMoveWindow(object _, PointerPressedEventArgs e)
50
60
51
61
private void SetDescription ( string message )
52
62
{
53
- Dispatcher . UIThread . Invoke ( ( ) =>
54
- {
55
- ProgressMessage . Text = message ;
56
- } ) ;
63
+ Dispatcher . UIThread . Invoke ( ( ) => ProgressMessage . Text = message ) ;
57
64
}
58
65
66
+ private string _repo ;
67
+ private List < Models . Change > _changes ;
68
+ private Action < string > _onDone ;
59
69
private CancellationTokenSource _cancel ;
60
70
}
61
71
}
0 commit comments