mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-30 16:44:59 +00:00
refactor: commandline parsing
* `--rebase-todo-editor` launches this app as a git `sequence.editor` * `--rebase-message-editor` launches this app as a git `core.editor` which runs on background by reading rebasing jobs * `--core-editor` launches this app as a git `core.editor` * `--askpass` launches this app as a SSH askpass program
This commit is contained in:
parent
cbe4c36525
commit
6930b51c64
14 changed files with 320 additions and 155 deletions
62
src/Views/CodeEditor.axaml
Normal file
62
src/Views/CodeEditor.axaml
Normal file
|
@ -0,0 +1,62 @@
|
|||
<v:ChromelessWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.CodeEditor"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.CodeEditor}"
|
||||
Width="800"
|
||||
SizeToContent="Height"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<!-- TitleBar -->
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30">
|
||||
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Background="{DynamicResource Brush.TitleBar}"
|
||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||
PointerPressed="BeginMoveWindow"/>
|
||||
|
||||
<Path Grid.Column="0"
|
||||
Width="14" Height="14"
|
||||
Margin="10,0,0,0"
|
||||
Data="{StaticResource Icons.Edit}"
|
||||
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||
|
||||
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}">
|
||||
<Button Classes="caption_button_macos" Click="CloseWindow">
|
||||
<Grid>
|
||||
<Ellipse Fill="{DynamicResource Brush.MacOS.Close}"/>
|
||||
<Path Height="6" Width="6" Stretch="Fill" Fill="#404040" Stroke="#404040" StrokeThickness="1" Data="{StaticResource Icons.Window.Close}"/>
|
||||
</Grid>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.CodeEditor}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Classes="caption_button"
|
||||
Click="CloseWindow"
|
||||
IsVisible="{OnPlatform True, macOS=False}">
|
||||
<Path Data="{StaticResource Icons.Window.Close}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="8">
|
||||
<v:CommitMessageTextBox x:Name="Editor" Height="400" Text=""/>
|
||||
<Button Classes="flat primary"
|
||||
Width="80"
|
||||
Margin="0,8,0,4"
|
||||
Content="{DynamicResource Text.Sure}"
|
||||
Click="SaveAndClose"
|
||||
HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</v:ChromelessWindow>
|
54
src/Views/CodeEditor.axaml.cs
Normal file
54
src/Views/CodeEditor.axaml.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class CodeEditor : ChromelessWindow
|
||||
{
|
||||
public CodeEditor()
|
||||
{
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public CodeEditor(string file)
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void CloseWindow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
private void SaveAndClose(object sender, RoutedEventArgs e)
|
||||
{
|
||||
File.WriteAllText(_file, Editor.Text);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
private string _file = string.Empty;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue