Skip to content

Commit

Permalink
Graph properties view extension (#11675)
Browse files Browse the repository at this point in the history
* initial commit

* TestCommit

* Basic adding/editing of custom properties implemented. Removing custom properties not implemented yet.

* CustomPropertyControl element removal implemented.

* Revert "TestCommit"

* Various style (xaml) fixes.

* PR comments SHK picked up largely.

* Additional cleanup.

* Corrected changes from latest PR.

* Added validation logic to Uri textbox.

-Validation Rule
-ValidationErrorTemplate
-Fixed empty textbox error.

* Commented code cleanup.

* Dispose methods added to  ViewModel and to Extension.

* Quick correction to override Loaded method.

* Removed redundant  interface.

* Update .gitignore

* Various edits around handling Custom Property behaviour correctly.

* Update .gitignore

* Styling updates

* Update GraphMetadataView.xaml

* add extension tests

* Clean up

* Update PackageManagerExtensionLoadingTests.cs

* comment updates

* fix margin and add new icons

* add summaries

* Dont show extension in CustomNode ws + add CustomProp name textbox highlight

* Mark graph dirty on props changed

* use absolute URI

Co-authored-by: Marco Juliani <[email protected]>
Co-authored-by: Craig Long <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2021
1 parent 8aff378 commit 3c861d2
Show file tree
Hide file tree
Showing 27 changed files with 2,001 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Dynamo.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeAutoCompleteViewExtensi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Md2Html", "Tools\Md2Html\Md2Html.csproj", "{0893F745-CB1A-427A-8E87-CA927273039A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphMetadataViewExtension", "GraphMetadataViewExtension\GraphMetadataViewExtension.csproj", "{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LintingViewExtension", "LintingViewExtension\LintingViewExtension.csproj", "{C86F9058-229D-40A9-95D5-D6F081AA9230}"
EndProject
Global
Expand Down Expand Up @@ -871,6 +873,14 @@ Global
{0893F745-CB1A-427A-8E87-CA927273039A}.Release|Any CPU.Build.0 = Release|Any CPU
{0893F745-CB1A-427A-8E87-CA927273039A}.Release|x64.ActiveCfg = Release|Any CPU
{0893F745-CB1A-427A-8E87-CA927273039A}.Release|x64.Build.0 = Release|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Debug|x64.ActiveCfg = Debug|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Debug|x64.Build.0 = Debug|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Release|Any CPU.Build.0 = Release|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Release|x64.ActiveCfg = Release|Any CPU
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00}.Release|x64.Build.0 = Release|Any CPU
{C86F9058-229D-40A9-95D5-D6F081AA9230}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C86F9058-229D-40A9-95D5-D6F081AA9230}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C86F9058-229D-40A9-95D5-D6F081AA9230}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -956,6 +966,7 @@ Global
{10AF430D-0D3A-49CE-A63D-848912959745} = {88D45B00-E564-41DB-B57C-9509646CAA49}
{51511AFD-F326-4995-8E27-5D711419EF6F} = {88D45B00-E564-41DB-B57C-9509646CAA49}
{0893F745-CB1A-427A-8E87-CA927273039A} = {D114C59C-CF66-4CC2-980F-9301FB4EA4E1}
{A42563F1-2B8B-4C4D-BFAD-2CA981524E00} = {88D45B00-E564-41DB-B57C-9509646CAA49}
{C86F9058-229D-40A9-95D5-D6F081AA9230} = {88D45B00-E564-41DB-B57C-9509646CAA49}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
78 changes: 78 additions & 0 deletions src/GraphMetadataViewExtension/Controls/CustomPropertyControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<UserControl x:Class="Dynamo.GraphMetadata.Controls.CustomPropertyControl"
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"
xmlns:local="clr-namespace:Dynamo.GraphMetadata.Controls"
xmlns:fa="http://schemas.fontawesome.io/icons/"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="200">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CustomPropertyControl}}}"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBox x:Name="propertyNameText"
Grid.Column="0"
Background="Transparent"
BorderBrush="Transparent"
Foreground="{StaticResource NodeNameForeground}"
Text="{Binding PropertyName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
IsEnabled="False"
BorderThickness="1"
Padding="-3,0"
Margin="0"
CaretBrush="White">
</TextBox>
<Button Grid.Column="1"
Background="Transparent"
BorderThickness="0"
Command="{Binding EditPropertyNameCmd}">
<Button.Template>
<ControlTemplate>
<fa:ImageAwesome Icon="Pencil"
Height="16px"
Grid.Column="1"
Foreground="{StaticResource FilterIconColor}" />
</ControlTemplate>
</Button.Template>
</Button>

<Button Grid.Column="2"
Background="Transparent"
BorderThickness="0"
Command="{Binding DeletePropertyNameCmd}">
<Button.Template>
<ControlTemplate>
<Image Width="16px"
Source="/GraphMetadataViewExtension;component/Resources/close-thick-grey-16px.png" />
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
<TextBox Grid.Row="1" BorderBrush="{StaticResource BorderBrushWhite}"
Background="{StaticResource SearchBoxBackgroundColor}"
Foreground="{StaticResource NestedMemberTextColor}"
Margin="0,5"
Padding="0,5"
Text="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Windows;
using System.Windows.Controls;
using Dynamo.UI.Commands;

namespace Dynamo.GraphMetadata.Controls
{
/// <summary>
/// Interaction logic for CustomPropertyControl.xaml
/// </summary>
public partial class CustomPropertyControl : UserControl
{
/// <summary>
/// This command corresponds to an edit of a CustomProperty name.
/// </summary>
public DelegateCommand EditPropertyNameCmd { get; set; }
/// <summary>
/// This command corresponds to a deletion of a CustomProperty from a collection of CustomProperties in the ViewModel.
/// </summary>
public DelegateCommand DeletePropertyNameCmd { get; set; }
public bool PropertyNameEnabled { get; set; }

/// <summary>
/// This event fires when the 'Delete' command is triggered. It signals to the ViewModel that the corresponding CustomProperty ought to be removed.
/// </summary>
public event EventHandler RequestDelete;

private void OnRequestDelete(EventArgs e)
{
RequestDelete?.Invoke(this, e);
}

public CustomPropertyControl()
{
InitializeComponent();
InitializeCommands();
PropertyNameEnabled = false;
}

private void InitializeCommands()
{
this.EditPropertyNameCmd = new DelegateCommand(EditPropertyNameCmdExecute);
this.DeletePropertyNameCmd = new DelegateCommand(DeletePropertyNameCmdExecute);
}

private void EditPropertyNameCmdExecute(object obj)
{
PropertyNameEnabled = !PropertyNameEnabled;
propertyNameText.IsEnabled = PropertyNameEnabled;
propertyNameText.Focus();
propertyNameText.CaretIndex = PropertyName.Length;

propertyNameText.LostFocus += DisableEditable;
}

private void DisableEditable(object sender, RoutedEventArgs e)
{
propertyNameText.IsEnabled = false;
propertyNameText.LostFocus -= DisableEditable;
}

private void DeletePropertyNameCmdExecute(object obj)
{
if (string.IsNullOrEmpty(this.PropertyName)) return;

OnRequestDelete(EventArgs.Empty);
}

#region DependencyProperties

public string PropertyName
{
get { return (string)GetValue(PropertyNameProperty); }
set { SetValue(PropertyNameProperty, value); }
}

public static readonly DependencyProperty PropertyNameProperty = DependencyProperty.Register(
nameof(PropertyName),
typeof(string),
typeof(CustomPropertyControl)
);

public string PropertyValue
{
get { return (string)GetValue(PropertyValueProperty); }
set { SetValue(PropertyValueProperty, value); }
}

public static readonly DependencyProperty PropertyValueProperty = DependencyProperty.Register(
nameof(PropertyValue),
typeof(string),
typeof(CustomPropertyControl)
);

#endregion
}
}
81 changes: 81 additions & 0 deletions src/GraphMetadataViewExtension/Controls/ImageSelector.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<UserControl x:Class="Dynamo.GraphMetadata.Controls.ImageSelector"
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"
xmlns:local="clr-namespace:Dynamo.GraphMetadata.Controls"
xmlns:properties="clr-namespace:Dynamo.GraphMetadata.Properties"
xmlns:convertes="clr-namespace:Dynamo.GraphMetadata.Converters"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"
mc:Ignorable="d"
d:DesignHeight="198" d:DesignWidth="314">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<convertes:BooleanInverseConverter x:Key="BooleanInverseConverter" />
<convertes:BooleansToVisibilityConverter x:Key="BooleansToVisibilityConverter" />

<SolidColorBrush x:Key="ButtonOverlayBrush" Color="Black" Opacity="0.5" />
<SolidColorBrush x:Key="ButtonOverlayPressedBrush" Color="Black" Opacity="0.3" />

<Style x:Key="OverlayButton" TargetType="Button">
<Setter Property="Background" Value="{StaticResource ButtonOverlayBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageSelector}}}"
Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ButtonOverlayBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource ButtonOverlayPressedBrush}" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>

<Border
DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageSelector}}}"
BorderThickness="1"
BorderBrush="#FF3F4040">
<Grid
Background="{StaticResource SearchBoxBackgroundColor}">
<Image
Source="{Binding Image}"
Stretch="Uniform" />
<TextBlock
Text="{x:Static properties:Resources.ImageSelector_Message_NoImageSelected}"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource BooleansToVisibilityConverter}">
<Binding Path="IsMouseOver" Converter="{StaticResource BooleanInverseConverter}" />
<Binding Path="HasImage" Converter="{StaticResource BooleanInverseConverter}" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>

<Button
x:Name="btn_ImageSelection"
Style="{StaticResource OverlayButton}"
Content="{Binding UserFeedback}">
</Button>
</Grid>
</Border>
</UserControl>
Loading

0 comments on commit 3c861d2

Please sign in to comment.