2024-09-01 01:54:20 -07:00
|
|
|
using System;
|
2024-07-08 19:16:15 -07:00
|
|
|
using System.IO;
|
2024-07-14 00:55:15 -07:00
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
using Avalonia.Input;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
public partial class StandaloneCommitMessageEditor : ChromelessWindow
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
public StandaloneCommitMessageEditor()
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
_file = string.Empty;
|
2024-07-08 19:16:15 -07:00
|
|
|
DataContext = this;
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
public StandaloneCommitMessageEditor(string file)
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
|
|
|
_file = file;
|
|
|
|
DataContext = this;
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
var content = File.ReadAllText(file).ReplaceLineEndings("\n");
|
|
|
|
var firstLineEnd = content.IndexOf('\n');
|
|
|
|
if (firstLineEnd == -1)
|
|
|
|
{
|
|
|
|
Editor.SubjectEditor.Text = content;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd);
|
|
|
|
Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-01 01:54:20 -07:00
|
|
|
protected override void OnClosed(EventArgs e)
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
2024-09-01 01:54:20 -07:00
|
|
|
base.OnClosed(e);
|
|
|
|
App.Quit(_exitCode);
|
2024-07-08 19:16:15 -07:00
|
|
|
}
|
|
|
|
|
2024-09-01 01:54:20 -07:00
|
|
|
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
2024-09-01 01:54:20 -07:00
|
|
|
BeginMoveDrag(e);
|
2024-07-08 19:16:15 -07:00
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private void SaveAndClose(object _1, RoutedEventArgs _2)
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
|
|
|
File.WriteAllText(_file, Editor.Text);
|
2024-09-01 01:54:20 -07:00
|
|
|
_exitCode = 0;
|
|
|
|
Close();
|
2024-07-08 19:16:15 -07:00
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private readonly string _file;
|
2024-09-01 01:54:20 -07:00
|
|
|
private int _exitCode = -1;
|
2024-07-08 19:16:15 -07:00
|
|
|
}
|
|
|
|
}
|