refactor<*>: add Controls.Window to replace System.Windows.Window

This commit is contained in:
leo 2021-06-18 09:26:19 +08:00
parent 31dd0eb832
commit 4b9923b84c
15 changed files with 842 additions and 879 deletions

View file

@ -4,7 +4,7 @@
<SolidColorBrush x:Key="Brush.Logo" Color="#FFF05133"/> <SolidColorBrush x:Key="Brush.Logo" Color="#FFF05133"/>
<SolidColorBrush x:Key="Brush.Window" Color="#FFF8F8F8"/> <SolidColorBrush x:Key="Brush.Window" Color="#FFF8F8F8"/>
<SolidColorBrush x:Key="Brush.WindowBorder" Color="#FF505050"/> <SolidColorBrush x:Key="Brush.WindowBorder" Color="#FF4295FF"/>
<SolidColorBrush x:Key="Brush.TitleBar" Color="White"/> <SolidColorBrush x:Key="Brush.TitleBar" Color="White"/>
<SolidColorBrush x:Key="Brush.NewPageHover" Color="#1D000000"/> <SolidColorBrush x:Key="Brush.NewPageHover" Color="#1D000000"/>

View file

@ -1,20 +1,15 @@
<Window x:Class="SourceGit.Views.About" <controls:Window
x:Class="SourceGit.Views.About"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d" mc:Ignorable="d"
UseLayoutRounding="True"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
Title="{StaticResource Text.About}" Title="{StaticResource Text.About}"
Height="280" Width="400" Height="280" Width="400"
ResizeMode="NoResize"> ResizeMode="NoResize">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -93,5 +88,4 @@
HorizontalAlignment="Center"/> HorizontalAlignment="Center"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -8,7 +8,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 关于对话框 /// 关于对话框
/// </summary> /// </summary>
public partial class About : Window { public partial class About : Controls.Window {
public About() { public About() {
InitializeComponent(); InitializeComponent();

View file

@ -1,4 +1,5 @@
<Window x:Class="SourceGit.Views.Blame" <controls:Window
x:Class="SourceGit.Views.Blame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -6,17 +7,8 @@
xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d" mc:Ignorable="d"
Title="{StaticResource Text.Blame}" Title="{StaticResource Text.Blame}"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
RenderOptions.ClearTypeHint="Enabled"
UseLayoutRounding="True"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
Height="600" Width="800"> Height="600" Width="800">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -144,5 +136,4 @@
</Border> </Border>
</Popup> </Popup>
</Grid> </Grid>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -11,7 +11,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 逐行追溯 /// 逐行追溯
/// </summary> /// </summary>
public partial class Blame : Window { public partial class Blame : Controls.Window {
private static readonly Brush[] BG = new Brush[] { private static readonly Brush[] BG = new Brush[] {
Brushes.Transparent, Brushes.Transparent,
new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) new SolidColorBrush(Color.FromArgb(128, 0, 0, 0))

View file

@ -0,0 +1,41 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Shell;
namespace SourceGit.Views.Controls {
/// <summary>
/// 项目使用的窗体基类
/// </summary>
public class Window : System.Windows.Window {
public Window() {
Background = FindResource("Brush.Window") as Brush;
BorderBrush = FindResource("Brush.WindowBorder") as Brush;
BorderThickness = new Thickness(1);
SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
SetValue(TextOptions.TextRenderingModeProperty, TextRenderingMode.ClearType);
SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Animated);
UseLayoutRounding = true;
var chrome = new WindowChrome();
chrome.ResizeBorderThickness = new Thickness(4);
chrome.UseAeroCaptionButtons = false;
chrome.CornerRadius = new CornerRadius(0);
chrome.CaptionHeight = 28;
WindowChrome.SetWindowChrome(this, chrome);
StateChanged += (_, __) => {
var content = Content as FrameworkElement;
if (WindowState == WindowState.Maximized) {
BorderThickness = new Thickness(0);
content.Margin = new Thickness((SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2);
} else {
BorderThickness = new Thickness(1);
content.Margin = new Thickness(0);
}
};
}
}
}

View file

@ -1,36 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.Views.Controls {
/// <summary>
/// 主窗体Border
/// </summary>
public class WindowBorder : Border {
public WindowBorder() {
Background = FindResource("Brush.Window") as Brush;
BorderBrush = FindResource("Brush.WindowBorder") as Brush;
BorderThickness = new Thickness(1);
Margin = new Thickness(0);
Loaded += (o, e) => {
var owner = Parent as Window;
if (owner != null) {
owner.StateChanged += (o1, e1) => {
if (owner.WindowState == WindowState.Maximized) {
BorderThickness = new Thickness(0);
Margin = new Thickness(
(SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2
);
} else {
BorderThickness = new Thickness(1);
Margin = new Thickness(0);
}
};
}
};
}
}
}

View file

@ -1,4 +1,5 @@
<Window x:Class="SourceGit.Views.Histories" <controls:Window
x:Class="SourceGit.Views.Histories"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -8,17 +9,8 @@
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
mc:Ignorable="d" mc:Ignorable="d"
Title="{StaticResource Text.FileHistory}" Title="{StaticResource Text.FileHistory}"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
RenderOptions.ClearTypeHint="Enabled"
UseLayoutRounding="True"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
MinHeight="600" MinWidth="800"> MinHeight="600" MinWidth="800">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -143,5 +135,4 @@
<widgets:DiffViewer Grid.Column="2" x:Name="diffViewer" Padding="4"/> <widgets:DiffViewer Grid.Column="2" x:Name="diffViewer" Padding="4"/>
</Grid> </Grid>
</Grid> </Grid>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -8,7 +8,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 文件历史 /// 文件历史
/// </summary> /// </summary>
public partial class Histories : Window { public partial class Histories : Controls.Window {
private string repo = null; private string repo = null;
private string file = null; private string file = null;
private bool isLFSEnabled = false; private bool isLFSEnabled = false;

View file

@ -1,4 +1,5 @@
<Window x:Class="SourceGit.Views.Launcher" <controls:Window
x:Class="SourceGit.Views.Launcher"
x:Name="me" x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -8,20 +9,11 @@
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
xmlns:models="clr-namespace:SourceGit.Models" xmlns:models="clr-namespace:SourceGit.Models"
mc:Ignorable="d" mc:Ignorable="d"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
RenderOptions.ClearTypeHint="Enabled"
UseLayoutRounding="True"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
MinWidth="1280" MinHeight="720" MinWidth="1280" MinHeight="720"
Title="{StaticResource Text.About.Title}" Title="{StaticResource Text.About.Title}"
Width="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Width, Mode=TwoWay}" Width="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Width, Mode=TwoWay}"
Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}"> Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<controls:DragDropAdornerLayer> <controls:DragDropAdornerLayer>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -65,5 +57,4 @@
HorizontalAlignment="Right" VerticalAlignment="Top" HorizontalAlignment="Right" VerticalAlignment="Top"
Width="330" Height="Auto"/> Width="330" Height="Auto"/>
</controls:DragDropAdornerLayer> </controls:DragDropAdornerLayer>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -8,7 +8,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 主窗体 /// 主窗体
/// </summary> /// </summary>
public partial class Launcher : Window { public partial class Launcher : Controls.Window {
public Launcher() { public Launcher() {
Models.Watcher.Opened += OpenRepository; Models.Watcher.Opened += OpenRepository;

View file

@ -1,4 +1,5 @@
<Window x:Class="SourceGit.Views.Preference" <controls:Window
x:Class="SourceGit.Views.Preference"
x:Name="me" x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -9,14 +10,8 @@
mc:Ignorable="d" mc:Ignorable="d"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
ResizeMode="NoResize" ResizeMode="NoResize"
UseLayoutRounding="True"
Title="{StaticResource Text.Preference}" Title="{StaticResource Text.Preference}"
Width="500" SizeToContent="Height"> Width="500" SizeToContent="Height">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -310,5 +305,4 @@
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>
</Grid> </Grid>
</Grid> </Grid>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -8,7 +8,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 设置面板 /// 设置面板
/// </summary> /// </summary>
public partial class Preference : Window { public partial class Preference : Controls.Window {
public string User { get; set; } public string User { get; set; }
public string Email { get; set; } public string Email { get; set; }

View file

@ -1,4 +1,5 @@
<Window x:Class="SourceGit.Views.Upgrade" <controls:Window
x:Class="SourceGit.Views.Upgrade"
x:Name="me" x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -6,19 +7,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d" mc:Ignorable="d"
UseLayoutRounding="True"
Title="{StaticResource Text.UpdateAvailable}" Title="{StaticResource Text.UpdateAvailable}"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
Height="400" Width="500" Height="400" Width="500"
ResizeMode="NoResize"> ResizeMode="NoResize">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="False" CornerRadius="0" CaptionHeight="28" ResizeBorderThickness="1"/>
</WindowChrome.WindowChrome>
<controls:WindowBorder>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="1"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
@ -49,8 +45,10 @@
WindowChrome.IsHitTestVisibleInChrome="True"/> WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid> </Grid>
<Rectangle Grid.Row="1" Fill="{StaticResource Brush.Border0}" HorizontalAlignment="Stretch" Height="1"/>
<!-- Body --> <!-- Body -->
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="8,16,8,0"> <StackPanel Grid.Row="2" Orientation="Vertical" Margin="8,16,8,0">
<!-- Title --> <!-- Title -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Path Width="20" Height="20" Data="{StaticResource Icon.Git}" Fill="{StaticResource Brush.Logo}"/> <Path Width="20" Height="20" Data="{StaticResource Icon.Git}" Fill="{StaticResource Brush.Logo}"/>
@ -82,7 +80,7 @@
</StackPanel> </StackPanel>
<!-- CHANGELOG --> <!-- CHANGELOG -->
<Border Grid.Row="2" Margin="8" Background="{StaticResource Brush.Contents}" BorderBrush="{StaticResource Brush.Border1}" BorderThickness="1"> <Border Grid.Row="3" Margin="8" Background="{StaticResource Brush.Contents}" BorderBrush="{StaticResource Brush.Border1}" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock <TextBlock
FontSize="10pt" FontSize="10pt"
@ -111,5 +109,4 @@
Content="{StaticResource Text.Cancel}"/> Content="{StaticResource Text.Cancel}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</controls:WindowBorder> </controls:Window>
</Window>

View file

@ -5,7 +5,7 @@ namespace SourceGit.Views {
/// <summary> /// <summary>
/// 新版本提示窗口 /// 新版本提示窗口
/// </summary> /// </summary>
public partial class Upgrade : Window { public partial class Upgrade : Controls.Window {
public Models.Version Version { get; set; } = new Models.Version(); public Models.Version Version { get; set; } = new Models.Version();
public Upgrade(Models.Version ver) { public Upgrade(Models.Version ver) {