diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-08-15 16:55:05 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-09-07 11:38:49 +0000 |
commit | 6aa1775e46aa8d9733925ce841a26eb112baa0b2 (patch) | |
tree | b8efc1e911dcff69d4acf638d66aeac4d41a21bc | |
parent | 061da79c0ee26c7c5f7ab8a8cd1e10910b80339b (diff) |
Use known monikers for Add|Remove|Open Folder images
* Refactor common TextBox properties into TextBoxStyle
* Add design time data and styles (only visible in VS2022)
Fixes: QTVSADDINBUG-1005
Change-Id: Icb83a4d9460da565630f5e4db3762959e951ee66
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r-- | QtVsTools.Core/Common/NativeAPI.cs | 78 | ||||
-rw-r--r-- | QtVsTools.Package/Options/QtVersionsTable.cs | 29 | ||||
-rw-r--r-- | QtVsTools.Package/Options/QtVersionsTable.xaml | 217 |
3 files changed, 122 insertions, 202 deletions
diff --git a/QtVsTools.Core/Common/NativeAPI.cs b/QtVsTools.Core/Common/NativeAPI.cs index cbaae3d7..dcbfa38e 100644 --- a/QtVsTools.Core/Common/NativeAPI.cs +++ b/QtVsTools.Core/Common/NativeAPI.cs @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt VS Tools. @@ -101,81 +101,5 @@ namespace QtVsTools.Core [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); - - [DllImport("shell32.dll", CharSet = CharSet.Auto)] - public static extern int SHGetFileInfo( - string pszPath, - int dwFileAttributes, - ref SHFILEINFO psfi, - int cbfileInfo, - SHGFI uFlags); - - [DllImport("user32.dll", SetLastError = true)] - public static extern bool DestroyIcon(IntPtr hIcon); - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] - public struct SHFILEINFO - { - /// <summary>Maximal Length of unmanaged Windows-Path-strings</summary> - public const int MAX_PATH = 260; - /// <summary>Maximal Length of unmanaged Typename</summary> - public const int MAX_TYPE = 80; - public SHFILEINFO(bool dummy = true) - { - hIcon = IntPtr.Zero; - iIcon = 0; - dwAttributes = 0; - szDisplayName = ""; - szTypeName = ""; - } - public IntPtr hIcon; - private readonly int iIcon; - private readonly uint dwAttributes; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] - private readonly string szDisplayName; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_TYPE)] - private readonly string szTypeName; - }; - - [Flags] - public enum SHGFI : int - { - /// <summary>get icon</summary> - Icon = 0x000000100, - /// <summary>get display name</summary> - DisplayName = 0x000000200, - /// <summary>get type name</summary> - TypeName = 0x000000400, - /// <summary>get attributes</summary> - Attributes = 0x000000800, - /// <summary>get icon location</summary> - IconLocation = 0x000001000, - /// <summary>return exe type</summary> - ExeType = 0x000002000, - /// <summary>get system icon index</summary> - SysIconIndex = 0x000004000, - /// <summary>put a link overlay on icon</summary> - LinkOverlay = 0x000008000, - /// <summary>show icon in selected state</summary> - Selected = 0x000010000, - /// <summary>get only specified attributes</summary> - Attr_Specified = 0x000020000, - /// <summary>get large icon</summary> - LargeIcon = 0x000000000, - /// <summary>get small icon</summary> - SmallIcon = 0x000000001, - /// <summary>get open icon</summary> - OpenIcon = 0x000000002, - /// <summary>get shell size icon</summary> - ShellIconSize = 0x000000004, - /// <summary>pszPath is a pidl</summary> - PIDL = 0x000000008, - /// <summary>use passed dwFileAttribute</summary> - UseFileAttributes = 0x000000010, - /// <summary>apply the appropriate overlays</summary> - AddOverlays = 0x000000020, - /// <summary>Get the index of the overlay in the upper 8 bits of the iIcon</summary> - OverlayIndex = 0x000000040, - } } } diff --git a/QtVsTools.Package/Options/QtVersionsTable.cs b/QtVsTools.Package/Options/QtVersionsTable.cs index e23f8339..fb8a7e3c 100644 --- a/QtVsTools.Package/Options/QtVersionsTable.cs +++ b/QtVsTools.Package/Options/QtVersionsTable.cs @@ -30,12 +30,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; -using System.Windows.Interop; using System.Windows.Media; -using System.Windows.Media.Imaging; using Microsoft.Win32; namespace QtVsTools.Options @@ -99,7 +96,6 @@ namespace QtVsTools.Options public class Row { - static LazyFactory StaticLazy { get; } = new LazyFactory(); LazyFactory Lazy { get; } = new LazyFactory(); public Dictionary<Column, Field> Fields => Lazy.Get(() => @@ -160,13 +156,10 @@ namespace QtVsTools.Options public Visibility ButtonBrowseVisibility => (!LastRow && Host == BuildHost.Windows) ? Visibility.Visible : Visibility.Hidden; public Thickness PathMargin - => new Thickness(((Host == BuildHost.Windows) ? 22 : 2), 0, 2, 0); + => new Thickness(((Host == BuildHost.Windows) ? 24 : 2), 4, 4, 4); public FontWeight FontWeight => IsDefault ? FontWeights.Bold : FontWeights.Normal; - public static ImageSource ExplorerIcon => StaticLazy.Get(() => - ExplorerIcon, () => GetExplorerIcon()); - public State State { get; set; } = State.Unknown; public bool RowVisible => State != State.Removed; } @@ -536,26 +529,6 @@ namespace QtVsTools.Options } } - static ImageSource GetExplorerIcon() - { - var pathWindowsExplorer = string.Format(@"{0}\explorer.exe", - Environment.GetFolderPath(Environment.SpecialFolder.Windows)); - - NativeAPI.SHFILEINFO shellFileInfo = new NativeAPI.SHFILEINFO(); - NativeAPI.SHGetFileInfo(pathWindowsExplorer, - 0, ref shellFileInfo, Marshal.SizeOf(shellFileInfo), - NativeAPI.SHGFI.Icon | NativeAPI.SHGFI.SmallIcon); - if (shellFileInfo.hIcon == IntPtr.Zero) - return null; - - var iconImageSource = Imaging.CreateBitmapSourceFromHIcon( - shellFileInfo.hIcon, Int32Rect.Empty, - BitmapSizeOptions.FromEmptyOptions()); - - NativeAPI.DestroyIcon(shellFileInfo.hIcon); - return iconImageSource; - } - static object GetBinding(FrameworkElement control) { if (control == null diff --git a/QtVsTools.Package/Options/QtVersionsTable.xaml b/QtVsTools.Package/Options/QtVersionsTable.xaml index d273a8d9..27749b9b 100644 --- a/QtVsTools.Package/Options/QtVersionsTable.xaml +++ b/QtVsTools.Package/Options/QtVersionsTable.xaml @@ -32,9 +32,42 @@ 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:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging" + xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog" + xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0" + xmlns:scm="clr-namespace:System.ComponentModel;assembly=PresentationFramework" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> + <UserControl.Resources> + <Style x:Key="DesignTimeStyle" + TargetType="{x:Type FrameworkElement}"> + <Style.Triggers> + <Trigger Property="scm:DesignerProperties.IsInDesignMode" + Value="True"> + <Setter Property="Visibility" + Value="Visible" /> + </Trigger> + </Style.Triggers> + </Style> + + <Style x:Key="DesignTimeRectangle" + TargetType="{x:Type Rectangle}" + BasedOn="{StaticResource DesignTimeStyle}"> + <Setter Property="Height" + Value="16" /> + <Setter Property="Width" + Value="16" /> + <Setter Property="Stroke" + Value="Red" /> + <Setter Property="Visibility" + Value="Hidden" /> + </Style> + + <BooleanToVisibilityConverter x:Key="b2v" /> + <vsui:BrushToColorConverter x:Key="BrushToColorConverter" /> + </UserControl.Resources> + <DataGrid Margin="0,0,0,0" Name="DataGrid" AutoGenerateColumns="False" @@ -49,21 +82,56 @@ CanUserResizeRows="False" RowHeaderWidth="0" FrozenColumnCount="0" - Grid.Row="0"> + Grid.Row="0" + d:ItemsSource="{d:SampleData ItemCount=3}"> <DataGrid.Resources> + <Style x:Key="TextBoxStyle" + TargetType="{x:Type TextBox}"> + <Setter Property="BorderThickness" + Value="0" /> + <Setter Property="Background" + Value="Transparent" /> + <Setter Property="HorizontalAlignment" + Value="Stretch" /> + <Setter Property="VerticalAlignment" + Value="Center" /> + <Setter Property="Visibility" + Value="{Binding RowContentVisibility}" /> + + <EventSetter Event="Loaded" + Handler="Control_Loaded" /> + <EventSetter Event="GotFocus" + Handler="Control_GotFocus" /> + <EventSetter Event="LostFocus" + Handler="Control_LostFocus" /> + <EventSetter Event="TextChanged" + Handler="TextBox_TextChanged" /> + <EventSetter Event="SelectionChanged" + Handler="TextBox_SelectionChanged" /> + <Style.Resources> + <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" + Color="LimeGreen" /> + </Style.Resources> + </Style> + <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" /> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /> - <BooleanToVisibilityConverter x:Key="b2v" /> </DataGrid.Resources> + <DataGrid.RowStyle> - <Style TargetType="{x:Type DataGridRow}"> - <Setter Property="Visibility" Value="{Binding RowVisible, Converter={StaticResource b2v}}"/> + <Style TargetType="{x:Type DataGridRow}" + BasedOn="{StaticResource DesignTimeStyle}"> + <Style.Setters> + <Setter Property="Visibility" + Value="{Binding RowVisible, Converter={StaticResource b2v}}" /> + </Style.Setters> </Style> </DataGrid.RowStyle> + <DataGrid.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="BorderThickness" @@ -72,17 +140,17 @@ Value="{x:Null}" /> </Style> </DataGrid.CellStyle> + <DataGrid.Columns> + <!--//// Default ////--> <DataGridTemplateColumn Header="Default" CanUserResize="False"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> - <!--//// Default ////--> <CheckBox x:Name="IsDefault" IsChecked="{Binding IsDefault}" Focusable="{Binding DefaultEnabled}" Visibility="{Binding RowContentVisibility}" - BorderThickness="1" Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center" @@ -92,10 +160,11 @@ </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> + + <!--//// Version ////--> <DataGridTemplateColumn Header="Version"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> - <!--//// Name ////--> <Grid> <Button Cursor="Hand" Visibility="{Binding RowContentVisibility}" @@ -106,16 +175,15 @@ <ControlTemplate TargetType="Button"> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" - Margin="4,0"> - <Ellipse Fill="White" - Width="15" - Height="15" /> - <Ellipse Fill="Red" - Width="13" - Height="13" /> - <Rectangle Width="8" - Height="2" - Fill="White" /> + Margin="4" + ToolTip="Remove Qt version" + vsui:ImageThemingUtilities.ImageBackgroundColor="{Binding Background, + RelativeSource={RelativeSource Self}, + Converter={StaticResource BrushToColorConverter}}"> + <Rectangle Style="{StaticResource DesignTimeRectangle}" /> + <imaging:CrispImage Width="16" + Height="16" + Moniker="{x:Static catalog:KnownMonikers.Remove}" /> </Grid> </ControlTemplate> </Button.Template> @@ -129,68 +197,49 @@ <ControlTemplate TargetType="Button"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" - Margin="4,0" - Background="Transparent"> + Margin="4"> <Grid HorizontalAlignment="Left" - VerticalAlignment="Center"> - <Ellipse Fill="White" - Width="15" - Height="15" /> - <Ellipse Fill="#FF36B31A" - Width="13" - Height="13" /> - <Rectangle Width="8" - Height="2" - Fill="White" /> - <Rectangle Width="2" - Height="8" - Fill="White" /> + vsui:ImageThemingUtilities.ImageBackgroundColor="{Binding Background, + RelativeSource={RelativeSource Self}, + Converter={StaticResource BrushToColorConverter}}"> + <Rectangle Style="{StaticResource DesignTimeRectangle}" /> + <imaging:CrispImage Width="16" + Height="16" + Moniker="{x:Static catalog:KnownMonikers.Add}" /> </Grid> <TextBlock Text="<add new Qt version>" Foreground="SlateGray" - Margin="20,4,2,4" + Margin="20,4,0,4" HorizontalAlignment="Stretch" VerticalAlignment="Center" /> </Grid> </ControlTemplate> </Button.Template> </Button> - <TextBox x:Name="VersionName" + <TextBox Style="{StaticResource TextBoxStyle}" + x:Name="VersionName" Text="{Binding VersionName}" - Visibility="{Binding RowContentVisibility}" + Margin="24,4,4,4" IsEnabled="{Binding NameEnabled}" FontWeight="{Binding FontWeight}" - Margin="20,4,2,4" - Background="Transparent" - BorderThickness="0" - HorizontalAlignment="Stretch" - VerticalAlignment="Center" - Loaded="Control_Loaded" - GotFocus="Control_GotFocus" - LostFocus="Control_LostFocus" - TextChanged="TextBox_TextChanged" - SelectionChanged="TextBox_SelectionChanged" ToolTip="{Binding FieldVersionName.ToolTip}"> - <TextBox.Resources> - <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" - Color="LimeGreen" /> - </TextBox.Resources> </TextBox> </Grid> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> + + <!--//// Host ////--> <DataGridTemplateColumn Header="Host"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> - <!--//// Host ////--> <ComboBox x:Name="Host" Visibility="{Binding RowContentVisibility}" IsEditable="True" IsReadOnly="True" BorderThickness="0" Background="Transparent" - Margin="2,0" + Margin="4" HorizontalAlignment="Stretch" VerticalAlignment="Center" FrameworkElement.Loaded="ComboBox_Loaded" @@ -206,81 +255,55 @@ </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> + + <!--//// Path ////--> <DataGridTemplateColumn Header="Path"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid> - <!--//// Path ////--> <Button Cursor="Hand" Visibility="{Binding ButtonBrowseVisibility}" HorizontalAlignment="Left" VerticalAlignment="Center" - Margin="2,0" - Width="18" - Height="18" - Click="Explorer_Click" - Background="White"> + Click="Explorer_Click"> <Button.Template> <ControlTemplate TargetType="Button"> <Grid HorizontalAlignment="Center" - VerticalAlignment="Center"> - <Rectangle Fill="White" - RadiusX="5" - RadiusY="5" - HorizontalAlignment="Stretch" - VerticalAlignment="Stretch" /> - <Image Source="{Binding ExplorerIcon}" - Margin="2" /> + VerticalAlignment="Center" + Margin="4" + vsui:ImageThemingUtilities.ImageBackgroundColor="{Binding Background, + RelativeSource={RelativeSource Self}, + Converter={StaticResource BrushToColorConverter}}"> + <Rectangle Style="{StaticResource DesignTimeRectangle}" /> + <imaging:CrispImage Width="16" + Height="16" + Moniker="{x:Static catalog:KnownMonikers.OpenFolder}" /> </Grid> </ControlTemplate> </Button.Template> </Button> - <TextBox x:Name="Path" + <TextBox Style="{StaticResource TextBoxStyle}" + x:Name="Path" + d:Margin="24,4,4,4" Text="{Binding Path}" - Visibility="{Binding RowContentVisibility}" - BorderThickness="0" - Background="Transparent" Margin="{Binding PathMargin}" - HorizontalAlignment="Stretch" - VerticalAlignment="Center" - Loaded="Control_Loaded" - GotFocus="Control_GotFocus" - LostFocus="Control_LostFocus" - TextChanged="TextBox_TextChanged" - SelectionChanged="TextBox_SelectionChanged" ToolTip="{Binding FieldPath.ToolTip}"> - <TextBox.Resources> - <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" - Color="LimeGreen" /> - </TextBox.Resources> </TextBox> </Grid> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> + + <!--//// Compiler ////--> <DataGridTemplateColumn Header="Compiler"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> - <!--//// Compiler ////--> - <TextBox x:Name="Compiler" + <TextBox Style="{StaticResource TextBoxStyle}" + x:Name="Compiler" Text="{Binding Compiler}" - Visibility="{Binding RowContentVisibility}" + Margin="4" IsEnabled="{Binding CompilerEnabled}" - BorderThickness="0" - Background="Transparent" - Margin="2,0" - HorizontalAlignment="Stretch" - VerticalAlignment="Center" - Loaded="Control_Loaded" - GotFocus="Control_GotFocus" - LostFocus="Control_LostFocus" - TextChanged="TextBox_TextChanged" - SelectionChanged="TextBox_SelectionChanged" ToolTip="{Binding FieldCompiler.ToolTip}"> - <TextBox.Resources> - <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" - Color="LimeGreen" /> - </TextBox.Resources> </TextBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate> |