Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 0c5e175

Browse files
author
Meaghan Lewis
authored
Merge pull request #1744 from Neme12/icons
Using builtin file & folder icons
2 parents a83ebfe + debe368 commit 0c5e175

File tree

6 files changed

+80
-22
lines changed

6 files changed

+80
-22
lines changed

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@
142142
<HintPath>..\..\packages\Microsoft.VisualStudio.Editor.14.3.25407\lib\net45\Microsoft.VisualStudio.Editor.dll</HintPath>
143143
<Private>True</Private>
144144
</Reference>
145+
<Reference Include="Microsoft.VisualStudio.ImageCatalog, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
146+
<HintPath>..\..\packages\Microsoft.VisualStudio.ImageCatalog.14.3.25407\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll</HintPath>
147+
</Reference>
148+
<Reference Include="Microsoft.VisualStudio.Imaging, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
149+
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll</HintPath>
150+
</Reference>
145151
<Reference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
146152
<EmbedInteropTypes>True</EmbedInteropTypes>
147153
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.14.3.25407\lib\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll</HintPath>
@@ -387,6 +393,8 @@
387393
<Compile Include="Views\Dialog\RepositoryRecloneView.xaml.cs">
388394
<DependentUpon>RepositoryRecloneView.xaml</DependentUpon>
389395
</Compile>
396+
<Compile Include="Views\GitHubPane\DirectoryIsExpandedToImageMonikerConverter.cs" />
397+
<Compile Include="Views\GitHubPane\FileNameToImageMonikerConverter.cs" />
390398
<Compile Include="Views\GitHubPane\LoggedOutView.xaml.cs">
391399
<DependentUpon>LoggedOutView.xaml</DependentUpon>
392400
</Compile>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using Microsoft.VisualStudio.Imaging;
6+
7+
namespace GitHub.VisualStudio.Views.GitHubPane
8+
{
9+
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")]
10+
internal sealed class DirectoryIsExpandedToImageMonikerConverter : IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
return (bool)value ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Globalization;
5+
using System.Windows;
6+
using System.Windows.Data;
7+
using Microsoft.VisualStudio.Imaging.Interop;
8+
using Microsoft.VisualStudio.Shell;
9+
using Microsoft.VisualStudio.Shell.Interop;
10+
11+
namespace GitHub.VisualStudio.Views.GitHubPane
12+
{
13+
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")]
14+
internal sealed class FileNameToImageMonikerConverter : IValueConverter
15+
{
16+
private readonly IVsImageService2 imageService;
17+
18+
public FileNameToImageMonikerConverter()
19+
{
20+
imageService = (IVsImageService2)Package.GetGlobalService(typeof(SVsImageService));
21+
}
22+
23+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
// In design mode, imageService will be null
26+
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
27+
return default(ImageMoniker);
28+
29+
return imageService.GetImageMonikerForFile((string)value);
30+
}
31+
32+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
33+
{
34+
throw new NotImplementedException();
35+
}
36+
}
37+
}

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestDetailView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
99
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
1010
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
11+
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
1112
Background="{DynamicResource GitHubVsToolWindowBackground}"
1213
Foreground="{DynamicResource GitHubVsWindowText}"
14+
theming:ImageThemingUtilities.ImageBackgroundColor="{Binding RelativeSource={RelativeSource Self}, Path=Background.Color}"
1315
DataContext="{Binding ViewModel}"
1416
d:DesignWidth="356"
1517
d:DesignHeight="800"

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestFilesView.xaml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:ghfvs="https://github.com/github/VisualStudio"
7+
xmlns:local="clr-namespace:GitHub.VisualStudio.Views.GitHubPane"
78
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
9+
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
810
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
911
Name="root">
1012

@@ -47,10 +49,14 @@
4749
</Style>
4850
</TreeView.ItemContainerStyle>
4951
<TreeView.Resources>
52+
<local:DirectoryIsExpandedToImageMonikerConverter x:Key="DirectoryIsExpandedToImageMonikerConverter" />
53+
<local:FileNameToImageMonikerConverter x:Key="FileNameToImageMonikerConverter" />
54+
5055
<HierarchicalDataTemplate DataType="{x:Type ghfvs:PullRequestDirectoryNode}"
5156
ItemsSource="{Binding Children}">
5257
<StackPanel Orientation="Horizontal">
53-
<ghfvs:OcticonImage Icon="file_directory" Foreground="{DynamicResource GitHubDirectoryIconForeground}" Margin="0,0,0,2"/>
58+
<imaging:CrispImage Moniker="{Binding Converter={StaticResource DirectoryIsExpandedToImageMonikerConverter}, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}"
59+
Width="16" Height="16" Margin="0,0,0,2"/>
5460
<TextBlock Text="{Binding DirectoryName}" Margin="4 2" VerticalAlignment="Center"/>
5561
</StackPanel>
5662
</HierarchicalDataTemplate>
@@ -60,27 +66,8 @@
6066
Tag="{Binding DataContext, ElementName=root}"
6167
KeyboardNavigation.DirectionalNavigation="None">
6268

63-
<!--
64-
We need to change the color of the file icon when the file is deleted, but applying the style
65-
to OcticonImage directly borks the designer (see #1410). Work around this by applying the color
66-
to a parent control and let the foreground be inherited by the icon.
67-
-->
68-
<Decorator>
69-
<Decorator.Style>
70-
<Style TargetType="Decorator">
71-
<Style.Triggers>
72-
<MultiDataTrigger>
73-
<MultiDataTrigger.Conditions>
74-
<Condition Binding="{Binding Status}" Value="Removed"/>
75-
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/>
76-
</MultiDataTrigger.Conditions>
77-
<Setter Property="TextBlock.Foreground" Value="{DynamicResource GitHubDeletedFileIconBrush}"/>
78-
</MultiDataTrigger>
79-
</Style.Triggers>
80-
</Style>
81-
</Decorator.Style>
82-
<ghfvs:OcticonImage Icon="file_code" Margin="0,0,0,2"/>
83-
</Decorator>
69+
<imaging:CrispImage Moniker="{Binding Converter={StaticResource FileNameToImageMonikerConverter}, Path=FileName}"
70+
Width="16" Height="16" Margin="0,0,0,2"/>
8471

8572
<TextBlock Text="{Binding FileName}" Margin="4 2" VerticalAlignment="Center">
8673
<TextBlock.Style>

src/GitHub.VisualStudio/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<package id="Microsoft.VisualStudio.ComponentModelHost" version="14.0.25424" targetFramework="net461" />
1010
<package id="Microsoft.VisualStudio.CoreUtility" version="14.3.25407" targetFramework="net461" />
1111
<package id="Microsoft.VisualStudio.Editor" version="14.3.25407" targetFramework="net461" />
12+
<package id="Microsoft.VisualStudio.ImageCatalog" version="14.3.25407" targetFramework="net461" />
13+
<package id="Microsoft.VisualStudio.Imaging" version="14.3.25407" targetFramework="net461" />
1214
<package id="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" version="14.3.25407" targetFramework="net461" />
1315
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net461" />
1416
<package id="Microsoft.VisualStudio.Sdk.BuildTasks.14.0" version="14.0.215" targetFramework="net461" developmentDependency="true" />

0 commit comments

Comments
 (0)