mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24: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];
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
desktop.Shutdown(-1);
|
||||
else
|
||||
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
var editor = new Views.StandaloneCommitMessageEditor();
|
||||
editor.SetFile(file);
|
||||
desktop.MainWindow = editor;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -461,7 +465,9 @@ namespace SourceGit
|
|||
var args = desktop.Args;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:v="using:SourceGit.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.Askpass"
|
||||
x:DataType="v:Askpass"
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.Askpass}"
|
||||
SizeToContent="WidthAndHeight"
|
||||
|
@ -13,7 +13,7 @@
|
|||
WindowStartupLocation="CenterScreen">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<!-- 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}"
|
||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||
PointerPressed="BeginMoveWindow"/>
|
||||
|
@ -36,23 +36,23 @@
|
|||
|
||||
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">
|
||||
<Border Margin="16,0">
|
||||
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
|
||||
<TextBlock x:Name="TxtDescription" Text="Enter passphrase:" TextWrapping="Wrap"/>
|
||||
</Border>
|
||||
|
||||
<TextBox Margin="16"
|
||||
<TextBox x:Name="TxtPassphrase"
|
||||
Margin="16"
|
||||
MinWidth="300"
|
||||
Height="32"
|
||||
Focusable="True"
|
||||
Text="{Binding Passphrase, Mode=TwoWay}"
|
||||
PasswordChar="*"
|
||||
RevealPassword="{Binding ShowPassword, Mode=OneWay}"
|
||||
RevealPassword="{Binding #ToggleShowPassword.IsChecked, Mode=OneWay}"
|
||||
HorizontalAlignment="Stretch"
|
||||
v:AutoFocusBehaviour.IsEnabled="True">
|
||||
<TextBox.InnerRightContent>
|
||||
<ToggleButton Grid.Column="6"
|
||||
x:Name="ToggleShowPassword"
|
||||
Classes="toggle_untracked"
|
||||
Width="26" Height="14"
|
||||
IsChecked="{Binding ShowPassword, Mode=TwoWay}"/>
|
||||
Width="26" Height="14"/>
|
||||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
|
|
|
@ -1,43 +1,12 @@
|
|||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
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()
|
||||
{
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public Askpass(string description)
|
||||
{
|
||||
Description = description;
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
@ -49,7 +18,8 @@ namespace SourceGit.Views
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,21 @@
|
|||
xmlns:v="using:SourceGit.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.ChangeViewModeSwitcher"
|
||||
x:DataType="v:ChangeViewModeSwitcher">
|
||||
x:Name="ThisControl">
|
||||
<Button Classes="icon_button" ToolTip.Tip="{DynamicResource Text.ChangeDisplayMode}">
|
||||
<Button.Flyout>
|
||||
<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>
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.List}"/>
|
||||
</MenuItem.Icon>
|
||||
</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>
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Grid}"/>
|
||||
</MenuItem.Icon>
|
||||
</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>
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Tree}"/>
|
||||
</MenuItem.Icon>
|
||||
|
@ -31,13 +31,13 @@
|
|||
<Grid Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14"
|
||||
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"
|
||||
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"
|
||||
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>
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
|
@ -16,13 +17,25 @@ namespace SourceGit.Views
|
|||
|
||||
public ChangeViewModeSwitcher()
|
||||
{
|
||||
DataContext = this;
|
||||
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()
|
||||
{
|
||||
_file = string.Empty;
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public StandaloneCommitMessageEditor(string file)
|
||||
public void SetFile(string 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');
|
||||
if (firstLineEnd == -1)
|
||||
{
|
||||
|
@ -29,7 +25,7 @@ namespace SourceGit.Views
|
|||
else
|
||||
{
|
||||
Editor.SubjectEditor.Text = content.Substring(0, firstLineEnd);
|
||||
Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1);
|
||||
Editor.DescriptionEditor.Text = content.Substring(firstLineEnd + 1).Trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,13 +36,17 @@ namespace SourceGit.Views
|
|||
}
|
||||
|
||||
private void SaveAndClose(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_file))
|
||||
{
|
||||
File.WriteAllText(_file, Editor.Text);
|
||||
_exitCode = 0;
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private readonly string _file;
|
||||
private string _file = string.Empty;
|
||||
private int _exitCode = -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue