From 4b9923b84c25b66f458f0a2193de63d8de044099 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Jun 2021 09:26:19 +0800 Subject: [PATCH] refactor<*>: add Controls.Window to replace System.Windows.Window --- src/Resources/Themes/Light.xaml | 2 +- src/Views/About.xaml | 176 ++++----- src/Views/About.xaml.cs | 2 +- src/Views/Blame.xaml | 255 ++++++------ src/Views/Blame.xaml.cs | 2 +- src/Views/Controls/Window.cs | 41 ++ src/Views/Controls/WindowBorder.cs | 36 -- src/Views/Histories.xaml | 251 ++++++------ src/Views/Histories.xaml.cs | 2 +- src/Views/Launcher.xaml | 119 +++--- src/Views/Launcher.xaml.cs | 2 +- src/Views/Preference.xaml | 612 ++++++++++++++--------------- src/Views/Preference.xaml.cs | 2 +- src/Views/Upgrade.xaml | 217 +++++----- src/Views/Upgrade.xaml.cs | 2 +- 15 files changed, 842 insertions(+), 879 deletions(-) create mode 100644 src/Views/Controls/Window.cs delete mode 100644 src/Views/Controls/WindowBorder.cs diff --git a/src/Resources/Themes/Light.xaml b/src/Resources/Themes/Light.xaml index 2f74d46f..a5fd12c8 100644 --- a/src/Resources/Themes/Light.xaml +++ b/src/Resources/Themes/Light.xaml @@ -4,7 +4,7 @@ - + diff --git a/src/Views/About.xaml b/src/Views/About.xaml index eebacb5f..d164a381 100644 --- a/src/Views/About.xaml +++ b/src/Views/About.xaml @@ -1,97 +1,91 @@ - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + diff --git a/src/Views/About.xaml.cs b/src/Views/About.xaml.cs index 500945ad..99c4d148 100644 --- a/src/Views/About.xaml.cs +++ b/src/Views/About.xaml.cs @@ -8,7 +8,7 @@ namespace SourceGit.Views { /// /// 关于对话框 /// - public partial class About : Window { + public partial class About : Controls.Window { public About() { InitializeComponent(); diff --git a/src/Views/Blame.xaml b/src/Views/Blame.xaml index e3550aa0..0c7f5ba3 100644 --- a/src/Views/Blame.xaml +++ b/src/Views/Blame.xaml @@ -1,148 +1,139 @@ - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/src/Views/Blame.xaml.cs b/src/Views/Blame.xaml.cs index d3af7cdd..208d8642 100644 --- a/src/Views/Blame.xaml.cs +++ b/src/Views/Blame.xaml.cs @@ -11,7 +11,7 @@ namespace SourceGit.Views { /// /// 逐行追溯 /// - public partial class Blame : Window { + public partial class Blame : Controls.Window { private static readonly Brush[] BG = new Brush[] { Brushes.Transparent, new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) diff --git a/src/Views/Controls/Window.cs b/src/Views/Controls/Window.cs new file mode 100644 index 00000000..c1224c37 --- /dev/null +++ b/src/Views/Controls/Window.cs @@ -0,0 +1,41 @@ +using System.Windows; +using System.Windows.Media; +using System.Windows.Shell; + +namespace SourceGit.Views.Controls { + /// + /// 项目使用的窗体基类 + /// + 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); + } + }; + } + } +} diff --git a/src/Views/Controls/WindowBorder.cs b/src/Views/Controls/WindowBorder.cs deleted file mode 100644 index 9b594a81..00000000 --- a/src/Views/Controls/WindowBorder.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; - -namespace SourceGit.Views.Controls { - - /// - /// 主窗体Border - /// - 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); - } - }; - } - }; - } - } -} diff --git a/src/Views/Histories.xaml b/src/Views/Histories.xaml index 5182906b..8467dbb9 100644 --- a/src/Views/Histories.xaml +++ b/src/Views/Histories.xaml @@ -1,147 +1,138 @@ - - - - + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + - - + + - - - - - - - - - - + + - + + + + + + + - - - - - - - - - - - - - - - - - - - - + - + + + + + + + - - - - - + + + + + + + + + + + + - - - - - + - + + + + + + + + + + + + + - - - - + + Grid.Column="1" + Text="{Binding Author.Time}" + FontSize="9pt" FontFamily="Consolas" + Foreground="{StaticResource Brush.FG2}" + Margin="4,0,0,0" + HorizontalAlignment="Right"/> - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + diff --git a/src/Views/Histories.xaml.cs b/src/Views/Histories.xaml.cs index 6d7e5e5b..8d8b8d5a 100644 --- a/src/Views/Histories.xaml.cs +++ b/src/Views/Histories.xaml.cs @@ -8,7 +8,7 @@ namespace SourceGit.Views { /// /// 文件历史 /// - public partial class Histories : Window { + public partial class Histories : Controls.Window { private string repo = null; private string file = null; private bool isLFSEnabled = false; diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml index 14e336b4..f6b659f7 100644 --- a/src/Views/Launcher.xaml +++ b/src/Views/Launcher.xaml @@ -1,69 +1,60 @@ - - - - + + + + + + - - - - - - - - - - - - - + + + + + + - - + + - - + + - - - - - - - - - - - - + + + + + + + + + - - - - - + + + + + + + diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index 8a960c5f..74251745 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -8,7 +8,7 @@ namespace SourceGit.Views { /// /// 主窗体 /// - public partial class Launcher : Window { + public partial class Launcher : Controls.Window { public Launcher() { Models.Watcher.Opened += OpenRepository; diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml index 148cc368..d4229300 100644 --- a/src/Views/Preference.xaml +++ b/src/Views/Preference.xaml @@ -1,314 +1,308 @@ - - - - - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index dd28ff71..f47d6d26 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -8,7 +8,7 @@ namespace SourceGit.Views { /// /// 设置面板 /// - public partial class Preference : Window { + public partial class Preference : Controls.Window { public string User { get; set; } public string Email { get; set; } diff --git a/src/Views/Upgrade.xaml b/src/Views/Upgrade.xaml index a905e699..003f4252 100644 --- a/src/Views/Upgrade.xaml +++ b/src/Views/Upgrade.xaml @@ -1,115 +1,112 @@ - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -