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

@ -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"
@ -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">
<Window.Resources>
<converters:WindowStateToTitleBarHeight x:Key="WindowStateToTitleBarHeight"/>
</Window.Resources>
Closing="OnClosing">
<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>
<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>
<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>
<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>
d:DesignWidth="500">
<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>
@ -48,13 +48,7 @@
BorderBrush="{DynamicResource Brush.Border0}"
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>
SelectionChanged="SelectionChanged">
<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"
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>
<local:Bookmark
Width="14" Height="14"
Margin="8,0,0,0"
HorizontalAlignment="Left"
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>
@ -92,11 +92,7 @@
</Grid>
<!-- 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>
<Grid Grid.Row="2" Width="600" HorizontalAlignment="Center" Margin="0,0,0,8" AllowDrop="True" Drop="OnPageDrop">
<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"/>