From 9a9a0601edad02f310bd7f053fd4b0b283027dbe Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 20 Sep 2023 21:47:11 +0800 Subject: [PATCH] optimize: move converter resources to app scope --- src/App.xaml | 1 + src/Resources/Converters.xaml | 14 +++++++++ src/Resources/Icons.xaml | 1 + src/Views/Converters/IntToBookmarkBrush.cs | 17 +++++++++-- src/Views/Launcher.xaml | 7 +---- src/Views/Popups/Apply.xaml | 7 +---- src/Views/Popups/CreateBranch.xaml | 7 +---- src/Views/Popups/Fetch.xaml | 7 +---- src/Views/Popups/Pull.xaml | 7 +---- src/Views/Popups/Push.xaml | 4 --- src/Views/Preference.xaml | 4 --- src/Views/Widgets/Bookmark.xaml | 13 +++++++++ src/Views/Widgets/Bookmark.xaml.cs | 33 ++++++++++++++++++++++ src/Views/Widgets/CommitChanges.xaml | 4 --- src/Views/Widgets/Dashboard.xaml | 10 ------- src/Views/Widgets/Histories.xaml | 5 ---- src/Views/Widgets/PageTabBar.xaml | 25 ++++++---------- src/Views/Widgets/PageTabBar.xaml.cs | 7 +---- src/Views/Widgets/RevisionFiles.xaml | 2 -- src/Views/Widgets/Welcome.xaml | 21 ++++---------- src/Views/Widgets/Welcome.xaml.cs | 7 +---- src/Views/Widgets/WorkingCopy.xaml | 4 --- src/Views/Widgets/WorkingCopyChanges.xaml | 3 -- 23 files changed, 97 insertions(+), 113 deletions(-) create mode 100644 src/Resources/Converters.xaml create mode 100644 src/Views/Widgets/Bookmark.xaml create mode 100644 src/Views/Widgets/Bookmark.xaml.cs diff --git a/src/App.xaml b/src/App.xaml index bd7132ed..1f48956b 100644 --- a/src/App.xaml +++ b/src/App.xaml @@ -5,6 +5,7 @@ + diff --git a/src/Resources/Converters.xaml b/src/Resources/Converters.xaml new file mode 100644 index 00000000..ef9b7eeb --- /dev/null +++ b/src/Resources/Converters.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index 0ff07d04..1c6470cc 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -68,6 +68,7 @@ M177 156c-22 5-33 17-36 37c-10 57-33 258-13 278l445 445c23 23 61 23 84 0l246-246c23-23 23-61 0-84l-445-445C437 120 231 145 177 156zM331 344c-26 26-69 26-95 0c-26-26-26-69 0-95s69-26 95 0C357 276 357 318 331 344z M683 537h-144v-142h-142V283H239a44 44 0 00-41 41v171a56 56 0 0014 34l321 321a41 41 0 0058 0l174-174a41 41 0 000-58zm-341-109a41 41 0 110-58a41 41 0 010 58zM649 284V142h-69v142h-142v68h142v142h69v-142h142v-68h-142z + M800 928l-512 0 0-704 224 0 0 292 113-86 111 86 0-292 128 0 0 640c0 35-29 64-64 64zM625 388l-81 64 0-260 160 0 0 260-79-64zM192 160l0 32c0 18 14 32 32 32l32 0 0 704-32 0c-35 0-64-29-64-64l0-704c0-35 29-64 64-64l576 0c24 0 44 13 55 32l-631 0c-18 0-32 14-32 32z M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z M426.7 554.7v-85.3h341.3v85.3h-341.3m0 256v-85.3h170.7v85.3h-170.7m0-512V213.3h512v85.3H426.7M256 725.3h106.7L213.3 874.7 64 725.3H170.7V298.7H64L213.3 149.3 362.7 298.7H256v426.7z M854 170c-189-189-495-189-684 0s-189 495 0 684 495 189 684 0 187-495 0-684zM213 706c-89-137-74-325 48-444 122-122 307-137 444-48L213 706zm106 105 493-493c89 137 74 325-48 444-120 122-307 137-444 48z diff --git a/src/Views/Converters/IntToBookmarkBrush.cs b/src/Views/Converters/IntToBookmarkBrush.cs index 114e5eb0..9ad6590f 100644 --- a/src/Views/Converters/IntToBookmarkBrush.cs +++ b/src/Views/Converters/IntToBookmarkBrush.cs @@ -10,11 +10,11 @@ namespace SourceGit.Views.Converters { Brushes.Transparent, Brushes.Red, Brushes.Orange, - Brushes.Yellow, + Brushes.Gold, Brushes.ForestGreen, - Brushes.Purple, + Brushes.DarkCyan, Brushes.DeepSkyBlue, - Brushes.Magenta, + Brushes.Purple, }; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -26,4 +26,15 @@ namespace SourceGit.Views.Converters { throw new NotImplementedException(); } } + + public class IntToBookmarkStrokeBrush : IValueConverter { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + var index = (int)value; + return index == 0 ? App.Current.FindResource("Brush.FG1") : Brushes.Transparent; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml index f47212b9..ae2a8d4d 100644 --- a/src/Views/Launcher.xaml +++ b/src/Views/Launcher.xaml @@ -8,7 +8,6 @@ xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" xmlns:models="clr-namespace:SourceGit.Models" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" mc:Ignorable="d" WindowStartupLocation="CenterScreen" MinWidth="1024" MinHeight="768" @@ -16,11 +15,7 @@ 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}" WindowState="{Binding Source={x:Static models:Preference.Instance}, Path=Window.State, Mode=TwoWay}" - Closing="OnClosing"> - - - - + Closing="OnClosing"> diff --git a/src/Views/Popups/Apply.xaml b/src/Views/Popups/Apply.xaml index 22cf973e..55218d87 100644 --- a/src/Views/Popups/Apply.xaml +++ b/src/Views/Popups/Apply.xaml @@ -5,17 +5,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:models="clr-namespace:SourceGit.Models" xmlns:validations="clr-namespace:SourceGit.Views.Validations" mc:Ignorable="d" d:DesignWidth="800"> - - - - - + diff --git a/src/Views/Popups/CreateBranch.xaml b/src/Views/Popups/CreateBranch.xaml index 611305c2..1fad3fa6 100644 --- a/src/Views/Popups/CreateBranch.xaml +++ b/src/Views/Popups/CreateBranch.xaml @@ -6,15 +6,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:validations="clr-namespace:SourceGit.Views.Validations" mc:Ignorable="d" d:DesignWidth="500"> - - - - - + diff --git a/src/Views/Popups/Fetch.xaml b/src/Views/Popups/Fetch.xaml index cfbaa8a6..f70b5b04 100644 --- a/src/Views/Popups/Fetch.xaml +++ b/src/Views/Popups/Fetch.xaml @@ -3,15 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:controls="clr-namespace:SourceGit.Views.Controls" mc:Ignorable="d" d:DesignWidth="500"> - - - - - + diff --git a/src/Views/Popups/Pull.xaml b/src/Views/Popups/Pull.xaml index 1aef1141..0a867590 100644 --- a/src/Views/Popups/Pull.xaml +++ b/src/Views/Popups/Pull.xaml @@ -5,14 +5,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:models="clr-namespace:SourceGit.Models" mc:Ignorable="d" - d:DesignWidth="500"> - - - - + d:DesignWidth="500"> diff --git a/src/Views/Popups/Push.xaml b/src/Views/Popups/Push.xaml index a8cff331..f7f2a2bd 100644 --- a/src/Views/Popups/Push.xaml +++ b/src/Views/Popups/Push.xaml @@ -5,12 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" mc:Ignorable="d" d:DesignWidth="500"> - - - diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml index eb4e075b..ff615c6c 100644 --- a/src/Views/Preference.xaml +++ b/src/Views/Preference.xaml @@ -7,16 +7,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:models="clr-namespace:SourceGit.Models" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" mc:Ignorable="d" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" Title="{DynamicResource Text.Preference}" Width="500" Height="312"> - - - diff --git a/src/Views/Widgets/Bookmark.xaml b/src/Views/Widgets/Bookmark.xaml new file mode 100644 index 00000000..7a8aa295 --- /dev/null +++ b/src/Views/Widgets/Bookmark.xaml @@ -0,0 +1,13 @@ + + + diff --git a/src/Views/Widgets/Bookmark.xaml.cs b/src/Views/Widgets/Bookmark.xaml.cs new file mode 100644 index 00000000..41c0547d --- /dev/null +++ b/src/Views/Widgets/Bookmark.xaml.cs @@ -0,0 +1,33 @@ +using System.Windows; +using System.Windows.Controls; + +namespace SourceGit.Views.Widgets { + /// + /// 仓库书签 + /// + public partial class Bookmark : UserControl { + /// + /// 颜色属性 + /// + public static readonly DependencyProperty ColorProperty = DependencyProperty.Register( + "Color", + typeof(int), + typeof(Bookmark), + new PropertyMetadata(0)); + + /// + /// 颜色 + /// + public int Color { + get { return (int)GetValue(ColorProperty); } + set { SetValue(ColorProperty, value); } + } + + /// + /// 构造函数 + /// + public Bookmark() { + InitializeComponent(); + } + } +} diff --git a/src/Views/Widgets/CommitChanges.xaml b/src/Views/Widgets/CommitChanges.xaml index 80a9dc29..f5684b09 100644 --- a/src/Views/Widgets/CommitChanges.xaml +++ b/src/Views/Widgets/CommitChanges.xaml @@ -4,15 +4,11 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:models="clr-namespace:SourceGit.Models" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - - - - diff --git a/src/Views/Widgets/Welcome.xaml b/src/Views/Widgets/Welcome.xaml index d69edfda..47df5ee8 100644 --- a/src/Views/Widgets/Welcome.xaml +++ b/src/Views/Widgets/Welcome.xaml @@ -3,16 +3,16 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:SourceGit.Views.Widgets" xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:models="clr-namespace:SourceGit.Models" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="800" UseLayoutRounding="True"> - + @@ -92,11 +92,7 @@ - - - - - + @@ -121,16 +117,11 @@ BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" Background="{DynamicResource Brush.Popup}" UseLayoutRounding="True" - SnapsToDevicePixels="True"> - - + SnapsToDevicePixels="True"/> - + + diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs index f1fc72a1..c65d5c23 100644 --- a/src/Views/Widgets/Welcome.xaml.cs +++ b/src/Views/Widgets/Welcome.xaml.cs @@ -131,13 +131,8 @@ namespace SourceGit.Views.Widgets { var bookmark = new MenuItem(); bookmark.Header = App.Text("PageTabBar.Tab.Bookmark"); for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) { - var icon = new System.Windows.Shapes.Path(); - icon.Data = new EllipseGeometry(new Point(0, 0), 12, 12); - icon.Fill = Converters.IntToBookmarkBrush.COLORS[i]; - icon.Width = 12; - var mark = new MenuItem(); - mark.Icon = icon; + mark.Icon = new Bookmark() { Color = i, Width = 14, Height = 14 }; mark.Header = $"{i}"; var refIdx = i; diff --git a/src/Views/Widgets/WorkingCopy.xaml b/src/Views/Widgets/WorkingCopy.xaml index 70bc5407..f95b6fb0 100644 --- a/src/Views/Widgets/WorkingCopy.xaml +++ b/src/Views/Widgets/WorkingCopy.xaml @@ -5,15 +5,11 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converter="clr-namespace:SourceGit.Views.Converters" xmlns:models="clr-namespace:SourceGit.Models" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" xmlns:validations="clr-namespace:SourceGit.Views.Validations" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - - - diff --git a/src/Views/Widgets/WorkingCopyChanges.xaml b/src/Views/Widgets/WorkingCopyChanges.xaml index 05a986f2..8b5e1f98 100644 --- a/src/Views/Widgets/WorkingCopyChanges.xaml +++ b/src/Views/Widgets/WorkingCopyChanges.xaml @@ -5,13 +5,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:controls="clr-namespace:SourceGit.Views.Controls" - xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:models="clr-namespace:SourceGit.Models" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - -