-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathCommitMessageEditor.axaml.cs
More file actions
83 lines (69 loc) · 2.29 KB
/
CommitMessageEditor.axaml.cs
File metadata and controls
83 lines (69 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.IO;
using System.Text.Json;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class CommitMessageEditor : ChromelessWindow
{
public string ConventionalTypesOverride
{
get;
private set;
} = string.Empty;
public CommitMessageEditor()
{
InitializeComponent();
}
public void AsStandalone(string file)
{
var gitDir = new Commands.QueryGitDir(Path.GetDirectoryName(file)).GetResult();
if (!string.IsNullOrEmpty(gitDir))
{
var settingsFile = Path.Combine(gitDir, "sourcegit.settings");
if (File.Exists(settingsFile))
{
try
{
using var stream = File.OpenRead(settingsFile);
var settings = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.RepositorySettings);
ConventionalTypesOverride = settings.ConventionalTypesOverride;
}
catch
{
// Ignore errors
}
}
}
_onSave = msg => File.WriteAllText(file, msg);
_shouldExitApp = true;
Editor.CommitMessage = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
}
public void AsBuiltin(string conventionalTypesOverride, string msg, Action<string> onSave)
{
ConventionalTypesOverride = conventionalTypesOverride;
_onSave = onSave;
_shouldExitApp = false;
Editor.CommitMessage = msg;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (_shouldExitApp)
App.Quit(_exitCode);
}
private void SaveAndClose(object _1, RoutedEventArgs _2)
{
_onSave?.Invoke(Editor.CommitMessage);
Close();
}
private void CancelAndClose(object _1, RoutedEventArgs _2)
{
_exitCode = -1;
Close();
}
private Action<string> _onSave = null;
private bool _shouldExitApp = true;
private int _exitCode = 0;
}
}