mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 19:55:00 +00:00
refactor: use custom view locator to create new window/dialog (#1216)
Signed-off-by: leo <longshuang@msn.cn> (cherry picked from commit 3e6f2b25f15b263e2b84922abc5cf6d621d62a83)
This commit is contained in:
parent
86113701f3
commit
750ca8ec61
15 changed files with 158 additions and 164 deletions
|
@ -37,10 +37,10 @@ namespace SourceGit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly Command OpenPreferencesCommand = new Command(_ => OpenDialog(new Views.Preferences()));
|
public static readonly Command OpenPreferencesCommand = new Command(_ => ShowWindow(new Views.Preferences(), false));
|
||||||
public static readonly Command OpenHotkeysCommand = new Command(_ => OpenDialog(new Views.Hotkeys()));
|
public static readonly Command OpenHotkeysCommand = new Command(_ => ShowWindow(new Views.Hotkeys(), false));
|
||||||
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
|
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
|
||||||
public static readonly Command OpenAboutCommand = new Command(_ => OpenDialog(new Views.About()));
|
public static readonly Command OpenAboutCommand = new Command(_ => ShowWindow(new Views.About(), false));
|
||||||
public static readonly Command CheckForUpdateCommand = new Command(_ => (Current as App)?.Check4Update(true));
|
public static readonly Command CheckForUpdateCommand = new Command(_ => (Current as App)?.Check4Update(true));
|
||||||
public static readonly Command QuitCommand = new Command(_ => Quit(0));
|
public static readonly Command QuitCommand = new Command(_ => Quit(0));
|
||||||
public static readonly Command CopyTextBlockCommand = new Command(p =>
|
public static readonly Command CopyTextBlockCommand = new Command(p =>
|
||||||
|
|
|
@ -105,10 +105,36 @@ namespace SourceGit
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Utility Functions
|
#region Utility Functions
|
||||||
public static void OpenDialog(Window window)
|
public static void ShowWindow(object data, bool showAsDialog)
|
||||||
{
|
{
|
||||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
if (data is Views.ChromelessWindow window)
|
||||||
window.ShowDialog(owner);
|
{
|
||||||
|
if (showAsDialog && Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||||
|
window.ShowDialog(owner);
|
||||||
|
else
|
||||||
|
window.Show();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataTypeName = data.GetType().FullName;
|
||||||
|
if (string.IsNullOrEmpty(dataTypeName) || !dataTypeName.Contains(".ViewModels.", StringComparison.Ordinal))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var viewTypeName = dataTypeName.Replace(".ViewModels.", ".Views.");
|
||||||
|
var viewType = Type.GetType(viewTypeName);
|
||||||
|
if (viewType == null || !viewType.IsSubclassOf(typeof(Views.ChromelessWindow)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
window = Activator.CreateInstance(viewType) as Views.ChromelessWindow;
|
||||||
|
if (window != null)
|
||||||
|
{
|
||||||
|
window.DataContext = data;
|
||||||
|
if (showAsDialog && Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||||
|
window.ShowDialog(owner);
|
||||||
|
else
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RaiseException(string context, string message)
|
public static void RaiseException(string context, string message)
|
||||||
|
@ -598,11 +624,7 @@ namespace SourceGit
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
ShowWindow(new ViewModels.SelfUpdate() { Data = data }, true);
|
||||||
{
|
|
||||||
var dialog = new Views.SelfUpdate() { DataContext = new ViewModels.SelfUpdate() { Data = data } };
|
|
||||||
dialog.ShowDialog(owner);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
80
src/ViewModels/AIAssistant.cs
Normal file
80
src/ViewModels/AIAssistant.cs
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
namespace SourceGit.ViewModels
|
||||||
|
{
|
||||||
|
public class AIAssistant : ObservableObject
|
||||||
|
{
|
||||||
|
public bool IsGenerating
|
||||||
|
{
|
||||||
|
get => _isGenerating;
|
||||||
|
private set => SetProperty(ref _isGenerating, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get => _text;
|
||||||
|
private set => SetProperty(ref _text, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AIAssistant(Repository repo, Models.OpenAIService service, List<Models.Change> changes, Action<string> onApply)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
_service = service;
|
||||||
|
_changes = changes;
|
||||||
|
_onApply = onApply;
|
||||||
|
_cancel = new CancellationTokenSource();
|
||||||
|
|
||||||
|
Gen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Regen()
|
||||||
|
{
|
||||||
|
if (_cancel is { IsCancellationRequested: false })
|
||||||
|
_cancel.Cancel();
|
||||||
|
|
||||||
|
Gen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Apply()
|
||||||
|
{
|
||||||
|
_onApply?.Invoke(Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Cancel()
|
||||||
|
{
|
||||||
|
_cancel?.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Gen()
|
||||||
|
{
|
||||||
|
Text = string.Empty;
|
||||||
|
IsGenerating = true;
|
||||||
|
|
||||||
|
_cancel = new CancellationTokenSource();
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
new Commands.GenerateCommitMessage(_service, _repo.FullPath, _changes, _cancel.Token, message =>
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Invoke(() => Text = message);
|
||||||
|
}).Exec();
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Invoke(() => IsGenerating = false);
|
||||||
|
}, _cancel.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Repository _repo = null;
|
||||||
|
private Models.OpenAIService _service = null;
|
||||||
|
private List<Models.Change> _changes = null;
|
||||||
|
private Action<string> _onApply = null;
|
||||||
|
private CancellationTokenSource _cancel = null;
|
||||||
|
private bool _isGenerating = false;
|
||||||
|
private string _text = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
|
@ -332,8 +332,7 @@ namespace SourceGit.ViewModels
|
||||||
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
||||||
history.Click += (_, ev) =>
|
history.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path, _commit.SHA) };
|
App.ShowWindow(new FileHistories(_repo, change.Path, _commit.SHA), false);
|
||||||
window.Show();
|
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -343,8 +342,7 @@ namespace SourceGit.ViewModels
|
||||||
blame.IsEnabled = change.Index != Models.ChangeState.Deleted;
|
blame.IsEnabled = change.Index != Models.ChangeState.Deleted;
|
||||||
blame.Click += (_, ev) =>
|
blame.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, change.Path, _commit.SHA) };
|
App.ShowWindow(new Blame(_repo.FullPath, change.Path, _commit.SHA), false);
|
||||||
window.Show();
|
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -508,8 +506,7 @@ namespace SourceGit.ViewModels
|
||||||
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
||||||
history.Click += (_, ev) =>
|
history.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, file.Path, _commit.SHA) };
|
App.ShowWindow(new FileHistories(_repo, file.Path, _commit.SHA), false);
|
||||||
window.Show();
|
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -519,8 +516,7 @@ namespace SourceGit.ViewModels
|
||||||
blame.IsEnabled = file.Type == Models.ObjectType.Blob;
|
blame.IsEnabled = file.Type == Models.ObjectType.Blob;
|
||||||
blame.Click += (_, ev) =>
|
blame.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, file.Path, _commit.SHA) };
|
App.ShowWindow(new Blame(_repo.FullPath, file.Path, _commit.SHA), false);
|
||||||
window.Show();
|
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -570,11 +570,7 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.OpenDialog(new Views.InteractiveRebase()
|
App.ShowWindow(new InteractiveRebase(_repo, current, commit), true);
|
||||||
{
|
|
||||||
DataContext = new InteractiveRebase(_repo, current, commit)
|
|
||||||
});
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ namespace SourceGit.ViewModels
|
||||||
configure.Header = App.Text("Workspace.Configure");
|
configure.Header = App.Text("Workspace.Configure");
|
||||||
configure.Click += (_, e) =>
|
configure.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Views.ConfigureWorkspace() { DataContext = new ConfigureWorkspace() });
|
App.ShowWindow(new ConfigureWorkspace(), true);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(configure);
|
menu.Items.Add(configure);
|
||||||
|
|
|
@ -1405,8 +1405,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
locks.Click += (_, e) =>
|
locks.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(this, _remotes[0].Name) };
|
App.ShowWindow(new LFSLocks(this, _remotes[0].Name), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1419,8 +1418,7 @@ namespace SourceGit.ViewModels
|
||||||
lockRemote.Header = remoteName;
|
lockRemote.Header = remoteName;
|
||||||
lockRemote.Click += (_, e) =>
|
lockRemote.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(this, remoteName) };
|
App.ShowWindow(new LFSLocks(this, remoteName), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
locks.Items.Add(lockRemote);
|
locks.Items.Add(lockRemote);
|
||||||
|
@ -1706,10 +1704,7 @@ namespace SourceGit.ViewModels
|
||||||
compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare");
|
compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||||
compareWithHead.Click += (_, _) =>
|
compareWithHead.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Views.BranchCompare()
|
App.ShowWindow(new BranchCompare(_fullpath, branch, _currentBranch), false);
|
||||||
{
|
|
||||||
DataContext = new BranchCompare(_fullpath, branch, _currentBranch)
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
menu.Items.Add(compareWithHead);
|
menu.Items.Add(compareWithHead);
|
||||||
|
@ -1989,10 +1984,7 @@ namespace SourceGit.ViewModels
|
||||||
compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare");
|
compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||||
compareWithHead.Click += (_, _) =>
|
compareWithHead.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Views.BranchCompare()
|
App.ShowWindow(new BranchCompare(_fullpath, branch, _currentBranch), false);
|
||||||
{
|
|
||||||
DataContext = new BranchCompare(_fullpath, branch, _currentBranch)
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
menu.Items.Add(compareWithHead);
|
menu.Items.Add(compareWithHead);
|
||||||
|
|
||||||
|
|
|
@ -323,10 +323,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void OpenAssumeUnchanged()
|
public void OpenAssumeUnchanged()
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Views.AssumeUnchangedManager()
|
App.ShowWindow(new AssumeUnchangedManager(_repo), true);
|
||||||
{
|
|
||||||
DataContext = new AssumeUnchangedManager(_repo)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StashAll(bool autoStart)
|
public void StashAll(bool autoStart)
|
||||||
|
@ -726,8 +723,7 @@ namespace SourceGit.ViewModels
|
||||||
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
||||||
history.Click += (_, e) =>
|
history.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
|
App.ShowWindow(new FileHistories(_repo, change.Path), false);
|
||||||
window.Show();
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1093,8 +1089,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
ai.Click += (_, e) =>
|
ai.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var dialog = new Views.AIAssistant(services[0], _repo.FullPath, this, _selectedStaged);
|
App.ShowWindow(new AIAssistant(_repo, services[0], _selectedStaged, t => CommitMessage = t), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1108,8 +1103,7 @@ namespace SourceGit.ViewModels
|
||||||
item.Header = service.Name;
|
item.Header = service.Name;
|
||||||
item.Click += (_, e) =>
|
item.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var dialog = new Views.AIAssistant(dup, _repo.FullPath, this, _selectedStaged);
|
App.ShowWindow(new AIAssistant(_repo, dup, _selectedStaged, t => CommitMessage = t), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1193,8 +1187,7 @@ namespace SourceGit.ViewModels
|
||||||
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
||||||
history.Click += (_, e) =>
|
history.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
|
App.ShowWindow(new FileHistories(_repo, change.Path), false);
|
||||||
window.Show();
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1490,8 +1483,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
if (services.Count == 1)
|
if (services.Count == 1)
|
||||||
{
|
{
|
||||||
var dialog = new Views.AIAssistant(services[0], _repo.FullPath, this, _staged);
|
App.ShowWindow(new AIAssistant(_repo, services[0], _staged, t => CommitMessage = t), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1503,8 +1495,7 @@ namespace SourceGit.ViewModels
|
||||||
item.Header = service.Name;
|
item.Header = service.Name;
|
||||||
item.Click += (_, e) =>
|
item.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
var dialog = new Views.AIAssistant(dup, _repo.FullPath, this, _staged);
|
App.ShowWindow(new AIAssistant(_repo, dup, _staged, t => CommitMessage = t), true);
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1705,14 +1696,7 @@ namespace SourceGit.ViewModels
|
||||||
if (!string.IsNullOrEmpty(_filter) && _staged.Count > _visibleStaged.Count && !confirmWithFilter)
|
if (!string.IsNullOrEmpty(_filter) && _staged.Count > _visibleStaged.Count && !confirmWithFilter)
|
||||||
{
|
{
|
||||||
var confirmMessage = App.Text("WorkingCopy.ConfirmCommitWithFilter", _staged.Count, _visibleStaged.Count, _staged.Count - _visibleStaged.Count);
|
var confirmMessage = App.Text("WorkingCopy.ConfirmCommitWithFilter", _staged.Count, _visibleStaged.Count, _staged.Count - _visibleStaged.Count);
|
||||||
App.OpenDialog(new Views.ConfirmCommit()
|
App.ShowWindow(new ConfirmCommit(confirmMessage, () => DoCommit(autoStage, autoPush, allowEmpty, true)), true);
|
||||||
{
|
|
||||||
DataContext = new ConfirmCommit(confirmMessage, () =>
|
|
||||||
{
|
|
||||||
DoCommit(autoStage, autoPush, allowEmpty, true);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1720,14 +1704,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))
|
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Views.ConfirmEmptyCommit()
|
App.ShowWindow(new ConfirmEmptyCommit(_count > 0, stageAll => DoCommit(stageAll, autoPush, true, confirmWithFilter)), true);
|
||||||
{
|
|
||||||
DataContext = new ConfirmEmptyCommit(_count > 0, stageAll =>
|
|
||||||
{
|
|
||||||
DoCommit(stageAll, autoPush, true, confirmWithFilter);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
xmlns:c="using:SourceGit.Converters"
|
xmlns:c="using:SourceGit.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="120"
|
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="120"
|
||||||
x:Class="SourceGit.Views.AIAssistant"
|
x:Class="SourceGit.Views.AIAssistant"
|
||||||
|
x:DataType="vm:AIAssistant"
|
||||||
x:Name="ThisControl"
|
x:Name="ThisControl"
|
||||||
Icon="/App.ico"
|
Icon="/App.ico"
|
||||||
Title="{DynamicResource Text.AIAssistant}"
|
Title="{DynamicResource Text.AIAssistant}"
|
||||||
|
@ -48,20 +49,22 @@
|
||||||
<!-- Options -->
|
<!-- Options -->
|
||||||
<Border Grid.Row="2" Margin="0,0,0,8">
|
<Border Grid.Row="2" Margin="0,0,0,8">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
<v:LoadingIcon x:Name="IconInProgress" Width="14" Height="14" Margin="0,0,8,0"/>
|
<v:LoadingIcon Width="14" Height="14"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
IsVisible="{Binding IsGenerating}"/>
|
||||||
<Button Classes="flat"
|
<Button Classes="flat"
|
||||||
x:Name="BtnGenerateCommitMessage"
|
|
||||||
Height="28"
|
Height="28"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
Padding="12,0"
|
Padding="12,0"
|
||||||
Content="{DynamicResource Text.AIAssistant.Use}"
|
Content="{DynamicResource Text.AIAssistant.Use}"
|
||||||
Click="OnGenerateCommitMessage"/>
|
IsEnabled="{Binding !IsGenerating}"
|
||||||
|
Click="OnApply"/>
|
||||||
<Button Classes="flat"
|
<Button Classes="flat"
|
||||||
x:Name="BtnRegenerate"
|
|
||||||
Height="28"
|
Height="28"
|
||||||
Padding="12,0"
|
Padding="12,0"
|
||||||
Content="{DynamicResource Text.AIAssistant.Regen}"
|
Content="{DynamicResource Text.AIAssistant.Regen}"
|
||||||
Click="OnRegen"/>
|
IsEnabled="{Binding !IsGenerating}"
|
||||||
|
Command="{Binding Regen}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
|
||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using AvaloniaEdit.Document;
|
using AvaloniaEdit.Document;
|
||||||
using AvaloniaEdit.Editing;
|
using AvaloniaEdit.Editing;
|
||||||
|
@ -101,76 +99,16 @@ namespace SourceGit.Views
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AIAssistant(Models.OpenAIService service, string repo, ViewModels.WorkingCopy wc, List<Models.Change> changes)
|
|
||||||
{
|
|
||||||
_service = service;
|
|
||||||
_repo = repo;
|
|
||||||
_wc = wc;
|
|
||||||
_changes = changes;
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnOpened(EventArgs e)
|
|
||||||
{
|
|
||||||
base.OnOpened(e);
|
|
||||||
Generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnClosing(WindowClosingEventArgs e)
|
protected override void OnClosing(WindowClosingEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
_cancel?.Cancel();
|
(DataContext as ViewModels.AIAssistant)?.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGenerateCommitMessage(object sender, RoutedEventArgs e)
|
private void OnApply(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (_wc != null)
|
(DataContext as ViewModels.AIAssistant)?.Apply();
|
||||||
_wc.CommitMessage = TxtResponse.Text;
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRegen(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
TxtResponse.Text = string.Empty;
|
|
||||||
Generate();
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Generate()
|
|
||||||
{
|
|
||||||
if (_repo == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IconInProgress.IsVisible = true;
|
|
||||||
BtnGenerateCommitMessage.IsEnabled = false;
|
|
||||||
BtnRegenerate.IsEnabled = false;
|
|
||||||
|
|
||||||
_cancel = new CancellationTokenSource();
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
new Commands.GenerateCommitMessage(_service, _repo, _changes, _cancel.Token, message =>
|
|
||||||
{
|
|
||||||
Dispatcher.UIThread.Invoke(() => TxtResponse.Text = message);
|
|
||||||
}).Exec();
|
|
||||||
|
|
||||||
if (!_cancel.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
|
||||||
{
|
|
||||||
IconInProgress.IsVisible = false;
|
|
||||||
BtnGenerateCommitMessage.IsEnabled = true;
|
|
||||||
BtnRegenerate.IsEnabled = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, _cancel.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Models.OpenAIService _service;
|
|
||||||
private string _repo;
|
|
||||||
private ViewModels.WorkingCopy _wc;
|
|
||||||
private List<Models.Change> _changes;
|
|
||||||
private CancellationTokenSource _cancel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,12 +201,7 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnOpenConventionalCommitHelper(object _, RoutedEventArgs e)
|
private void OnOpenConventionalCommitHelper(object _, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var dialog = new ConventionalCommitMessageBuilder()
|
App.ShowWindow(new ViewModels.ConventionalCommitMessageBuilder(text => Text = text), true);
|
||||||
{
|
|
||||||
DataContext = new ViewModels.ConventionalCommitMessageBuilder(text => Text = text)
|
|
||||||
};
|
|
||||||
|
|
||||||
App.OpenDialog(dialog);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace SourceGit.Views
|
||||||
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
|
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
|
||||||
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P })
|
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P })
|
||||||
{
|
{
|
||||||
App.OpenDialog(new Preferences());
|
App.ShowWindow(new Preferences(), true);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace SourceGit.Views
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewTypeName = dataTypeName.Replace("ViewModels", "Views");
|
var viewTypeName = dataTypeName.Replace(".ViewModels.", ".Views.");
|
||||||
var viewType = Type.GetType(viewTypeName);
|
var viewType = Type.GetType(viewTypeName);
|
||||||
if (viewType == null)
|
if (viewType == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -349,9 +349,7 @@ namespace SourceGit.Views
|
||||||
if (sender is CheckBox box)
|
if (sender is CheckBox box)
|
||||||
{
|
{
|
||||||
ViewModels.Preferences.Instance.UseSystemWindowFrame = box.IsChecked == true;
|
ViewModels.Preferences.Instance.UseSystemWindowFrame = box.IsChecked == true;
|
||||||
|
App.ShowWindow(new ConfirmRestart(), true);
|
||||||
var dialog = new ConfirmRestart();
|
|
||||||
App.OpenDialog(dialog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
|
|
@ -22,22 +22,20 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenStatistics(object _, RoutedEventArgs e)
|
private void OpenStatistics(object _, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
if (DataContext is ViewModels.Repository repo)
|
||||||
{
|
{
|
||||||
var dialog = new Statistics() { DataContext = new ViewModels.Statistics(repo.FullPath) };
|
App.ShowWindow(new ViewModels.Statistics(repo.FullPath), true);
|
||||||
await dialog.ShowDialog(owner);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenConfigure(object sender, RoutedEventArgs e)
|
private void OpenConfigure(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
if (DataContext is ViewModels.Repository repo)
|
||||||
{
|
{
|
||||||
var dialog = new RepositoryConfigure() { DataContext = new ViewModels.RepositoryConfigure(repo) };
|
App.ShowWindow(new ViewModels.RepositoryConfigure(repo), true);
|
||||||
await dialog.ShowDialog(owner);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,12 +127,11 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenGitLogs(object sender, RoutedEventArgs e)
|
private void OpenGitLogs(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
if (DataContext is ViewModels.Repository repo)
|
||||||
{
|
{
|
||||||
var dialog = new ViewLogs() { DataContext = new ViewModels.ViewLogs(repo) };
|
App.ShowWindow(new ViewModels.ViewLogs(repo), true);
|
||||||
await dialog.ShowDialog(owner);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue