mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
code_style: simple window do not using DataContext
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
43fed8e04d
commit
0860245674
6 changed files with 54 additions and 65 deletions
|
@ -445,10 +445,14 @@ namespace SourceGit
|
||||||
|
|
||||||
var file = args[1];
|
var file = args[1];
|
||||||
if (!File.Exists(file))
|
if (!File.Exists(file))
|
||||||
|
{
|
||||||
desktop.Shutdown(-1);
|
desktop.Shutdown(-1);
|
||||||
else
|
return true;
|
||||||
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
|
}
|
||||||
|
|
||||||
|
var editor = new Views.StandaloneCommitMessageEditor();
|
||||||
|
editor.SetFile(file);
|
||||||
|
desktop.MainWindow = editor;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +465,9 @@ namespace SourceGit
|
||||||
var args = desktop.Args;
|
var args = desktop.Args;
|
||||||
if (args?.Length > 0)
|
if (args?.Length > 0)
|
||||||
{
|
{
|
||||||
desktop.MainWindow = new Views.Askpass(args[0]);
|
var askpass = new Views.Askpass();
|
||||||
|
askpass.TxtDescription.Text = args[0];
|
||||||
|
desktop.MainWindow = askpass;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.Askpass"
|
x:Class="SourceGit.Views.Askpass"
|
||||||
x:DataType="v:Askpass"
|
x:Name="ThisControl"
|
||||||
Icon="/App.ico"
|
Icon="/App.ico"
|
||||||
Title="{DynamicResource Text.Askpass}"
|
Title="{DynamicResource Text.Askpass}"
|
||||||
SizeToContent="WidthAndHeight"
|
SizeToContent="WidthAndHeight"
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
WindowStartupLocation="CenterScreen">
|
WindowStartupLocation="CenterScreen">
|
||||||
<Grid RowDefinitions="Auto,*">
|
<Grid RowDefinitions="Auto,*">
|
||||||
<!-- TitleBar -->
|
<!-- TitleBar -->
|
||||||
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !UseSystemWindowFrame}">
|
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||||
<Border Background="{DynamicResource Brush.TitleBar}"
|
<Border Background="{DynamicResource Brush.TitleBar}"
|
||||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||||
PointerPressed="BeginMoveWindow"/>
|
PointerPressed="BeginMoveWindow"/>
|
||||||
|
@ -36,23 +36,23 @@
|
||||||
|
|
||||||
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">
|
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">
|
||||||
<Border Margin="16,0">
|
<Border Margin="16,0">
|
||||||
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
|
<TextBlock x:Name="TxtDescription" Text="Enter passphrase:" TextWrapping="Wrap"/>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<TextBox Margin="16"
|
<TextBox x:Name="TxtPassphrase"
|
||||||
|
Margin="16"
|
||||||
MinWidth="300"
|
MinWidth="300"
|
||||||
Height="32"
|
Height="32"
|
||||||
Focusable="True"
|
Focusable="True"
|
||||||
Text="{Binding Passphrase, Mode=TwoWay}"
|
|
||||||
PasswordChar="*"
|
PasswordChar="*"
|
||||||
RevealPassword="{Binding ShowPassword, Mode=OneWay}"
|
RevealPassword="{Binding #ToggleShowPassword.IsChecked, Mode=OneWay}"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
v:AutoFocusBehaviour.IsEnabled="True">
|
v:AutoFocusBehaviour.IsEnabled="True">
|
||||||
<TextBox.InnerRightContent>
|
<TextBox.InnerRightContent>
|
||||||
<ToggleButton Grid.Column="6"
|
<ToggleButton Grid.Column="6"
|
||||||
|
x:Name="ToggleShowPassword"
|
||||||
Classes="toggle_untracked"
|
Classes="toggle_untracked"
|
||||||
Width="26" Height="14"
|
Width="26" Height="14"/>
|
||||||
IsChecked="{Binding ShowPassword, Mode=TwoWay}"/>
|
|
||||||
</TextBox.InnerRightContent>
|
</TextBox.InnerRightContent>
|
||||||
</TextBox>
|
</TextBox>
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Avalonia;
|
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public partial class Askpass : ChromelessWindow
|
public partial class Askpass : ChromelessWindow
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<bool> ShowPasswordProperty =
|
|
||||||
AvaloniaProperty.Register<Askpass, bool>(nameof(ShowPassword));
|
|
||||||
|
|
||||||
public bool ShowPassword
|
|
||||||
{
|
|
||||||
get => GetValue(ShowPasswordProperty);
|
|
||||||
set => SetValue(ShowPasswordProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
} = string.Empty;
|
|
||||||
|
|
||||||
public string Passphrase
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
} = string.Empty;
|
|
||||||
|
|
||||||
public Askpass()
|
public Askpass()
|
||||||
{
|
{
|
||||||
DataContext = this;
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Askpass(string description)
|
|
||||||
{
|
|
||||||
Description = description;
|
|
||||||
DataContext = this;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +18,8 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void EnterPassword(object _1, RoutedEventArgs _2)
|
private void EnterPassword(object _1, RoutedEventArgs _2)
|
||||||
{
|
{
|
||||||
Console.Out.Write($"{Passphrase}\n");
|
var passphrase = TxtPassphrase.Text ?? string.Empty;
|
||||||
|
Console.Out.Write($"{passphrase}\n");
|
||||||
App.Quit(0);
|
App.Quit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.ChangeViewModeSwitcher"
|
x:Class="SourceGit.Views.ChangeViewModeSwitcher"
|
||||||
x:DataType="v:ChangeViewModeSwitcher">
|
x:Name="ThisControl">
|
||||||
<Button Classes="icon_button" ToolTip.Tip="{DynamicResource Text.ChangeDisplayMode}">
|
<Button Classes="icon_button" ToolTip.Tip="{DynamicResource Text.ChangeDisplayMode}">
|
||||||
<Button.Flyout>
|
<Button.Flyout>
|
||||||
<MenuFlyout Placement="BottomEdgeAlignedLeft">
|
<MenuFlyout Placement="BottomEdgeAlignedLeft">
|
||||||
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.List}" Command="{Binding SwitchMode}" CommandParameter="{x:Static m:ChangeViewMode.List}">
|
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.List}" Click="SwitchToList">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="12" Height="12" Data="{StaticResource Icons.List}"/>
|
<Path Width="12" Height="12" Data="{StaticResource Icons.List}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.Grid}" Command="{Binding SwitchMode}" CommandParameter="{x:Static m:ChangeViewMode.Grid}">
|
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.Grid}" Click="SwitchToGrid">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Grid}"/>
|
<Path Width="12" Height="12" Data="{StaticResource Icons.Grid}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.Tree}" Command="{Binding SwitchMode}" CommandParameter="{x:Static m:ChangeViewMode.Tree}">
|
<MenuItem Header="{DynamicResource Text.ChangeDisplayMode.Tree}" Click="SwitchToTree">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Tree}"/>
|
<Path Width="12" Height="12" Data="{StaticResource Icons.Tree}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
|
@ -31,13 +31,13 @@
|
||||||
<Grid Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<Grid Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Path Width="14" Height="14"
|
<Path Width="14" Height="14"
|
||||||
Data="{StaticResource Icons.List}"
|
Data="{StaticResource Icons.List}"
|
||||||
IsVisible="{Binding ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.List}}"/>
|
IsVisible="{Binding #ThisControl.ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.List}}"/>
|
||||||
<Path Width="14" Height="14"
|
<Path Width="14" Height="14"
|
||||||
Data="{StaticResource Icons.Grid}"
|
Data="{StaticResource Icons.Grid}"
|
||||||
IsVisible="{Binding ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.Grid}}"/>
|
IsVisible="{Binding #ThisControl.ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.Grid}}"/>
|
||||||
<Path Width="14" Height="14"
|
<Path Width="14" Height="14"
|
||||||
Data="{StaticResource Icons.Tree}"
|
Data="{StaticResource Icons.Tree}"
|
||||||
IsVisible="{Binding ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.Tree}}"/>
|
IsVisible="{Binding #ThisControl.ViewMode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:ChangeViewMode.Tree}}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button>
|
</Button>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
|
@ -16,13 +17,25 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
public ChangeViewModeSwitcher()
|
public ChangeViewModeSwitcher()
|
||||||
{
|
{
|
||||||
DataContext = this;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchMode(object param)
|
private void SwitchToList(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ViewMode = (Models.ChangeViewMode)param;
|
ViewMode = Models.ChangeViewMode.List;
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToGrid(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ViewMode = Models.ChangeViewMode.Grid;
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToTree(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ViewMode = Models.ChangeViewMode.Tree;
|
||||||
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,14 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public StandaloneCommitMessageEditor()
|
public StandaloneCommitMessageEditor()
|
||||||
{
|
{
|
||||||
_file = string.Empty;
|
|
||||||
DataContext = this;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StandaloneCommitMessageEditor(string file)
|
public void SetFile(string file)
|
||||||
{
|
{
|
||||||
_file = file;
|
_file = file;
|
||||||
DataContext = this;
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
var content = File.ReadAllText(file).ReplaceLineEndings("\n");
|
var content = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
|
||||||
var firstLineEnd = content.IndexOf('\n');
|
var firstLineEnd = content.IndexOf('\n');
|
||||||
if (firstLineEnd == -1)
|
if (firstLineEnd == -1)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +25,7 @@ namespace SourceGit.Views
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd);
|
Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd);
|
||||||
Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1);
|
Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1).Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +37,16 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void SaveAndClose(object _1, RoutedEventArgs _2)
|
private void SaveAndClose(object _1, RoutedEventArgs _2)
|
||||||
{
|
{
|
||||||
File.WriteAllText(_file, Editor.Text);
|
if (!string.IsNullOrEmpty(_file))
|
||||||
_exitCode = 0;
|
{
|
||||||
|
File.WriteAllText(_file, Editor.Text);
|
||||||
|
_exitCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly string _file;
|
private string _file = string.Empty;
|
||||||
private int _exitCode = -1;
|
private int _exitCode = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue