-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Using builtin file & folder icons #1744
Changes from all commits
2f4da26
8cf9a26
054d10c
49e46af
be54a16
203f329
b2945cb
79ced6e
2fbc919
debe368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Globalization; | ||
| using System.Windows.Data; | ||
| using Microsoft.VisualStudio.Imaging; | ||
|
|
||
| namespace GitHub.VisualStudio.Views.GitHubPane | ||
| { | ||
| [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")] | ||
| internal sealed class DirectoryIsExpandedToImageMonikerConverter : IValueConverter | ||
| { | ||
| public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
| { | ||
| return (bool)value ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed; | ||
| } | ||
|
|
||
| public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Globalization; | ||
| using System.Windows; | ||
| using System.Windows.Data; | ||
| using Microsoft.VisualStudio.Imaging.Interop; | ||
| using Microsoft.VisualStudio.Shell; | ||
| using Microsoft.VisualStudio.Shell.Interop; | ||
|
|
||
| namespace GitHub.VisualStudio.Views.GitHubPane | ||
| { | ||
| [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")] | ||
| internal sealed class FileNameToImageMonikerConverter : IValueConverter | ||
| { | ||
| private readonly IVsImageService2 imageService; | ||
|
|
||
| public FileNameToImageMonikerConverter() | ||
| { | ||
| imageService = (IVsImageService2)Package.GetGlobalService(typeof(SVsImageService)); | ||
| } | ||
|
|
||
| public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
| { | ||
| // In design mode, imageService will be null | ||
| if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) | ||
| return default(ImageMoniker); | ||
|
|
||
| return imageService.GetImageMonikerForFile((string)value); | ||
| } | ||
|
|
||
| public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,10 @@ | |
| xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI" | ||
| xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf" | ||
| xmlns:vsui="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0" | ||
| xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging" | ||
| Background="{DynamicResource GitHubVsToolWindowBackground}" | ||
| Foreground="{DynamicResource GitHubVsWindowText}" | ||
| theming:ImageThemingUtilities.ImageBackgroundColor="{Binding RelativeSource={RelativeSource Self}, Path=Background.Color}" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is important to ensure that the icons have the right background in all themes. If this was set to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ignore me, you're right. |
||
| DataContext="{Binding ViewModel}" | ||
| d:DesignWidth="356" | ||
| d:DesignHeight="800" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:ghfvs="https://github.com/github/VisualStudio" | ||
| xmlns:local="clr-namespace:GitHub.VisualStudio.Views.GitHubPane" | ||
| xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI" | ||
| xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging" | ||
| mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" | ||
| Name="root"> | ||
|
|
||
|
|
@@ -47,10 +49,14 @@ | |
| </Style> | ||
| </TreeView.ItemContainerStyle> | ||
| <TreeView.Resources> | ||
| <local:DirectoryIsExpandedToImageMonikerConverter x:Key="DirectoryIsExpandedToImageMonikerConverter" /> | ||
| <local:FileNameToImageMonikerConverter x:Key="FileNameToImageMonikerConverter" /> | ||
|
|
||
| <HierarchicalDataTemplate DataType="{x:Type ghfvs:PullRequestDirectoryNode}" | ||
| ItemsSource="{Binding Children}"> | ||
| <StackPanel Orientation="Horizontal"> | ||
| <ghfvs:OcticonImage Icon="file_directory" Foreground="{DynamicResource GitHubDirectoryIconForeground}" Margin="0,0,0,2"/> | ||
| <imaging:CrispImage Moniker="{Binding Converter={StaticResource DirectoryIsExpandedToImageMonikerConverter}, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}" | ||
| Width="16" Height="16" Margin="0,0,0,2"/> | ||
| <TextBlock Text="{Binding DirectoryName}" Margin="4 2" VerticalAlignment="Center"/> | ||
| </StackPanel> | ||
| </HierarchicalDataTemplate> | ||
|
|
@@ -60,27 +66,8 @@ | |
| Tag="{Binding DataContext, ElementName=root}" | ||
| KeyboardNavigation.DirectionalNavigation="None"> | ||
|
|
||
| <!-- | ||
| We need to change the color of the file icon when the file is deleted, but applying the style | ||
| to OcticonImage directly borks the designer (see #1410). Work around this by applying the color | ||
| to a parent control and let the foreground be inherited by the icon. | ||
| --> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this used to gray out the icon if the item was deleted. This can't really be done with arbitrary colored icons. I tried replacing the color change with reduced opacity, but it didn't look very good in my opinion. And the built-in team explorer view doesn't do anything like that either (it's only the text that is grayed out, not the icon). Is it OK to remove this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's fine with me! |
||
| <Decorator> | ||
| <Decorator.Style> | ||
| <Style TargetType="Decorator"> | ||
| <Style.Triggers> | ||
| <MultiDataTrigger> | ||
| <MultiDataTrigger.Conditions> | ||
| <Condition Binding="{Binding Status}" Value="Removed"/> | ||
| <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/> | ||
| </MultiDataTrigger.Conditions> | ||
| <Setter Property="TextBlock.Foreground" Value="{DynamicResource GitHubDeletedFileIconBrush}"/> | ||
| </MultiDataTrigger> | ||
| </Style.Triggers> | ||
| </Style> | ||
| </Decorator.Style> | ||
| <ghfvs:OcticonImage Icon="file_code" Margin="0,0,0,2"/> | ||
| </Decorator> | ||
| <imaging:CrispImage Moniker="{Binding Converter={StaticResource FileNameToImageMonikerConverter}, Path=FileName}" | ||
| Width="16" Height="16" Margin="0,0,0,2"/> | ||
|
|
||
| <TextBlock Text="{Binding FileName}" Margin="4 2" VerticalAlignment="Center"> | ||
| <TextBlock.Style> | ||
|
|
||




Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would be an appropriate place for these converters? I noticed there is a folder with some converters in GitHub.UI but that project doesn't have a lot of dependencies on VS itself (which these do). Also these aren't really general purpose converters like the other ones seem to be, they're made specifically for one view. But this isn't a good place either (I assume). Where should I put them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think that where you've put them is the best place for them: as you say they're tied to a particular view, so it makes sense to put the converters alongside. Not sure if anyone else things differently though?