Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <savagesoftware@gmail.com>2018-08-29 15:58:44 +0300
committerGitHub <noreply@github.com>2018-08-29 15:58:44 +0300
commit738949a696525c3166ef8da269f522b525fdcc19 (patch)
treef38ff62182070ca0d52b8e436a172c6cc61f2a4d
parentfe6fdb7313633078d3721b226763625c8ffddfd5 (diff)
parent8ff08a5cbbf49ec1395df17e47cbf1df7d184d50 (diff)
Merge pull request #371 from xamarin/ermau-type-icon-provider
[Core/Win] Add type icon support
-rw-r--r--Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs26
-rw-r--r--Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml4
-rw-r--r--Xamarin.PropertyEditing/IIconProvider.cs18
-rw-r--r--Xamarin.PropertyEditing/TargetPlatform.cs6
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs14
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj1
6 files changed, 65 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs
index 813f644..ee7fb84 100644
--- a/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs
+++ b/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs
@@ -3,10 +3,12 @@ using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
+using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
+using System.Windows.Media.Imaging;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
@@ -82,6 +84,7 @@ namespace Xamarin.PropertyEditing.Windows
base.OnApplyTemplate ();
this.root = (FrameworkElement) GetTemplateChild ("root");
+ this.typeIcon = (Image) GetTemplateChild ("typeIcon");
this.items = (ItemsControl) GetTemplateChild ("propertyItems");
this.propertiesPane = (FrameworkElement) GetTemplateChild ("propertiesPane");
this.eventsPane = (FrameworkElement) GetTemplateChild ("eventsPane");
@@ -99,6 +102,7 @@ namespace Xamarin.PropertyEditing.Windows
private ItemsControl items;
private ChoiceControl paneSelector;
private FrameworkElement propertiesPane, eventsPane;
+ private Image typeIcon;
private void OnPaneChanged (object sender, EventArgs e)
{
@@ -142,6 +146,28 @@ namespace Xamarin.PropertyEditing.Windows
if (ArrangeMode == PropertyArrangeMode.Name)
OnArrangeModeChanged (ArrangeMode);
+
+ UpdateIcon ();
+ }
+
+ private async void UpdateIcon ()
+ {
+ if (this.typeIcon == null)
+ return;
+
+ Stream icon = await this.vm.GetIconAsync ();
+ if (icon == null) {
+ this.typeIcon.Source = null;
+ this.typeIcon.Visibility = Visibility.Collapsed;
+ } else {
+ var source = new BitmapImage();
+ source.BeginInit();
+ source.StreamSource = icon;
+ source.EndInit();
+
+ this.typeIcon.Source = source;
+ this.typeIcon.Visibility = Visibility.Visible;
+ }
}
private void OnTargetPlatformChanged ()
diff --git a/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml b/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml
index 3fe3c53..29f7db0 100644
--- a/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml
+++ b/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml
@@ -112,8 +112,8 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
- <Border Visibility="Collapsed" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Height="32" Width="32" Margin="1,6,5,2" Background="{DynamicResource PropertiesPanelIconBackgroundBrush}" VerticalAlignment="Center">
- <!-- type icon -->
+ <Border Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Margin="1,6,5,2" Background="{DynamicResource PropertiesPanelIconBackgroundBrush}" VerticalAlignment="Center">
+ <Image Name="typeIcon" Height="32" Width="32" Visibility="Collapsed" />
</Border>
<TextBlock Visibility="{Binding IsObjectNameable, Converter={StaticResource BoolToVisibilityConverter}}" Name="nameLabel" Grid.Row="0" Grid.Column="1" Margin="0,2,0,2" Text="{x:Static prop:Resources.Name}" />
diff --git a/Xamarin.PropertyEditing/IIconProvider.cs b/Xamarin.PropertyEditing/IIconProvider.cs
new file mode 100644
index 0000000..6081cb0
--- /dev/null
+++ b/Xamarin.PropertyEditing/IIconProvider.cs
@@ -0,0 +1,18 @@
+using System.IO;
+using System.Threading.Tasks;
+
+namespace Xamarin.PropertyEditing
+{
+ public interface IIconProvider
+ {
+ /// <summary>
+ /// Gets an icon for the given <paramref name="types"/>.
+ /// </summary>
+ /// <param name="types">The types to get an icon for.</param>
+ /// <remarks>
+ /// The types provided in <paramref name="type"/> may not be the same.
+ /// If they aren't, you should return a generic icon (VS uses an XML Tag).
+ /// </remarks>
+ Task<Stream> GetTypeIconAsync (ITypeInfo[] types);
+ }
+} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/TargetPlatform.cs b/Xamarin.PropertyEditing/TargetPlatform.cs
index 49a39fa..6fa3d3c 100644
--- a/Xamarin.PropertyEditing/TargetPlatform.cs
+++ b/Xamarin.PropertyEditing/TargetPlatform.cs
@@ -63,6 +63,12 @@ namespace Xamarin.PropertyEditing
private set;
}
+ public IIconProvider IconProvider
+ {
+ get;
+ set;
+ }
+
/// <summary>
/// Gets or sets whether the platform supports custom expressions (default false).
/// </summary>
diff --git a/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs
index c871f0b..b494bee 100644
--- a/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs
@@ -1,6 +1,8 @@
-using System;
+using System;
using System.Collections.Generic;
-using System.Linq;
+ using System.IO;
+ using System.Linq;
+ using System.Threading.Tasks;
namespace Xamarin.PropertyEditing.ViewModels
{
@@ -88,6 +90,14 @@ namespace Xamarin.PropertyEditing.ViewModels
SetIsExpanded (ArrangeMode, group, isExpanded);
}
+ public Task<Stream> GetIconAsync ()
+ {
+ if (TargetPlatform.IconProvider == null)
+ return Task.FromResult<Stream> (null);
+
+ return TargetPlatform.IconProvider.GetTypeIconAsync (ObjectEditors.Select (oe => oe.TargetType).ToArray ());
+ }
+
protected override void OnAddEditors (IEnumerable<EditorViewModel> editors)
{
IEnumerable<EditorViewModel> props = Properties;
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index af46062..45486a8 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -91,6 +91,7 @@
<Compile Include="IProvidePath.cs" />
<Compile Include="IResourceProvider.cs" />
<Compile Include="ISelfConstrainedPropertyInfo.cs" />
+ <Compile Include="IIconProvider.cs" />
<Compile Include="ITypeInfo.cs" />
<Compile Include="IValidator.cs" />
<Compile Include="KnownProperty.cs" />