optimize<Converters>: move converter resources to app scope

This commit is contained in:
leo 2023-09-20 21:47:11 +08:00
parent fcad602144
commit 9a9a0601ed
23 changed files with 97 additions and 113 deletions

View file

@ -5,6 +5,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Resources/Icons.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Resources/Converters.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Resources/Controls.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Resources/Themes/Light.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Resources/Locales/en_US.xaml"/>

View file

@ -0,0 +1,14 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SourceGit.Views.Converters">
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
<converters:BranchToName x:Key="BranchToName"/>
<converters:FontFamiliesToName x:Key="FontFamiliesToName"/>
<converters:IntToBookmarkBrush x:Key="IntToBookmarkBrush"/>
<converters:IntToBookmarkStrokeBrush x:Key="IntToBookmarkStrokeBrush"/>
<converters:InverseBool x:Key="InverseBool"/>
<converters:PureFileName x:Key="PureFileName"/>
<converters:PureFolderName x:Key="PureFolderName"/>
<converters:WindowStateToTitleBarHeight x:Key="WindowStateToTitleBarHeight"/>
</ResourceDictionary>

View file

@ -68,6 +68,7 @@
<StreamGeometry x:Key="Icon.Tag">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</StreamGeometry>
<StreamGeometry x:Key="Icon.Tag.Add">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</StreamGeometry>
<StreamGeometry x:Key="Icon.Bookmark">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</StreamGeometry>
<StreamGeometry x:Key="Icon.VSCode">M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z</StreamGeometry>
<StreamGeometry x:Key="Icon.Sort">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</StreamGeometry>
<StreamGeometry x:Key="Icon.Ignores">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</StreamGeometry>

View file

@ -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();
}
}
}

View file

@ -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"
@ -17,10 +16,6 @@
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">
<Window.Resources>
<converters:WindowStateToTitleBarHeight x:Key="WindowStateToTitleBarHeight"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding ElementName=me, Path=WindowState, Converter={StaticResource WindowStateToTitleBarHeight}}"/>

View file

@ -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">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>

View file

@ -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">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>

View file

@ -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">
<Grid>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>

View file

@ -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">
<UserControl.Resources>
<converters:BranchToName x:Key="BranchToName"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>

View file

@ -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">
<UserControl.Resources>
<converters:BranchToName x:Key="BranchToName"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>

View file

@ -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">
<Grid>
<Grid.Resources>
<converters:FontFamiliesToName x:Key="FontFamiliesToName"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="1"/>

View file

@ -0,0 +1,13 @@
<UserControl x:Class="SourceGit.Views.Widgets.Bookmark"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Path
Data="{StaticResource Icon.Bookmark}"
Stroke="{Binding Color, ElementName=me, Converter={StaticResource IntToBookmarkStrokeBrush}}"
Fill="{Binding Color, ElementName=me, Converter={StaticResource IntToBookmarkBrush}}"/>
</UserControl>

View file

@ -0,0 +1,33 @@
using System.Windows;
using System.Windows.Controls;
namespace SourceGit.Views.Widgets {
/// <summary>
/// 仓库书签
/// </summary>
public partial class Bookmark : UserControl {
/// <summary>
/// 颜色属性
/// </summary>
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
"Color",
typeof(int),
typeof(Bookmark),
new PropertyMetadata(0));
/// <summary>
/// 颜色
/// </summary>
public int Color {
get { return (int)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
/// <summary>
/// 构造函数
/// </summary>
public Bookmark() {
InitializeComponent();
}
}
}

View file

@ -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">
<UserControl.Resources>
<converters:PureFileName x:Key="PureFileName"/>
<converters:PureFolderName x:Key="PureFolderName"/>
<Style x:Key="Style.DataGridRow.Changes" TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
<EventSetter Event="ContextMenuOpening" Handler="OnDataGridContextMenuOpening"/>

View file

@ -6,7 +6,6 @@
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:models="clr-namespace:SourceGit.Models"
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
xmlns:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
@ -15,11 +14,6 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
</Grid.Resources>
<!-- Toolbar -->
<Border Grid.Row="0" BorderBrush="{DynamicResource Brush.Border0}" BorderThickness="0,0,0,1" Background="{DynamicResource Brush.ToolBar}">
<Grid>
@ -157,10 +151,6 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Resources>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
</Grid.Resources>
<!-- Workspace -->
<TextBlock Grid.Row="0" Style="{DynamicResource Style.TextBlock.Group}" Text="{DynamicResource Text.Dashboard.Workspace}"/>
<ListView Grid.Row="1" x:Name="workspace" SelectionMode="Single" SelectionChanged="OnPageSelectionChanged">

View file

@ -4,16 +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">
<Grid x:Name="layout">
<Grid.Resources>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
</Grid.Resources>
<Border x:Name="commitListPanel" Background="{DynamicResource Brush.Contents}">
<Grid ClipToBounds="True">
<Grid.RowDefinitions>

View file

@ -4,8 +4,8 @@
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:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d"
d:DesignHeight="32" d:DesignWidth="800">
<Grid>
@ -49,12 +49,6 @@
ItemsSource="{Binding ElementName=me, Path=Tabs}"
WindowChrome.IsHitTestVisibleInChrome="True"
SelectionChanged="SelectionChanged">
<ListBox.Resources>
<converters:IntToBookmarkBrush x:Key="IntToBookmarkBrush"/>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
</ListBox.Resources>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
@ -76,15 +70,12 @@
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Border" Background="Transparent" BorderBrush="Transparent" BorderThickness="1,1,1,0" CornerRadius="6,6,0,0">
<Grid x:Name="Contents" Width="200" VerticalAlignment="Center" Opacity=".5" ToolTip="{Binding Tooltip}">
<Path
Width="8" Margin="8,0,0,0"
<local:Bookmark
Width="14" Height="14"
Margin="8,0,0,0"
HorizontalAlignment="Left"
Fill="{Binding Bookmark, Converter={StaticResource IntToBookmarkBrush}}"
Visibility="{Binding IsRepository, Converter={StaticResource BoolToCollapsed}}">
<Path.Data>
<EllipseGeometry Center="0,0" RadiusX="14" RadiusY="14"/>
</Path.Data>
</Path>
Color="{Binding Bookmark}"
Visibility="{Binding IsRepository, Converter={StaticResource BoolToCollapsed}}"/>
<TextBlock Margin="32,0" HorizontalAlignment="Stretch" TextAlignment="Center" Text="{Binding Title}"/>

View file

@ -353,13 +353,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;

View file

@ -4,14 +4,12 @@
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:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="Style.DataGridRow.TextPreview" TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
</Style>
<converters:PureFileName x:Key="PureFileName"/>
</UserControl.Resources>
<Grid>

View file

@ -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">
<Grid AllowDrop="True" Drop="OnPageDrop">
<Grid.RowDefinitions>
<RowDefinition Height="36"/>
<RowDefinition Height="48"/>
<RowDefinition Height="56"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
@ -93,10 +93,6 @@
<!-- Repositories List -->
<Grid Grid.Row="2" Width="600" HorizontalAlignment="Center" Margin="0,0,0,8" AllowDrop="True" Drop="OnPageDrop">
<Grid.Resources>
<converters:IntToBookmarkBrush x:Key="IntToBookmarkBrush"/>
</Grid.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="repoList">
<ItemsControl.ItemsPanel>
@ -121,16 +117,11 @@
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Popup}"
UseLayoutRounding="True"
SnapsToDevicePixels="True">
<Path
Width="14" Height="14"
Data="M 1,0 L8,0 L1,7 z"
HorizontalAlignment="Left" VerticalAlignment="Top"
Fill="{Binding Bookmark, Converter={StaticResource IntToBookmarkBrush}}"/>
</Border>
SnapsToDevicePixels="True"/>
<StackPanel Grid.Column="0" Margin="8,0" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="12pt" Margin="4,0,0,0" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" />
<local:Bookmark Width="16" Height="16" Color="{Binding Bookmark}"/>
<TextBlock Text="{Binding Name}" FontSize="12pt" Margin="8,0,0,0" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}"/>
<TextBlock Text="{Binding Path}" FontSize="10pt" Margin="8,0,0,0" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>

View file

@ -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;

View file

@ -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">
<UserControl.Resources>
<converter:BoolToCollapsed x:Key="BoolToCollapsed"/>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" MinWidth="300"/>

View file

@ -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">
<UserControl.Resources>
<converters:PureFileName x:Key="PureFileName"/>
<converters:PureFolderName x:Key="PureFolderName"/>
<Style x:Key="Style.DataGridRow.Change" TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
<EventSetter Event="ContextMenuOpening" Handler="OnDataGridContextMenuOpening"/>