Skip to content

Commit

Permalink
keywords tags
Browse files Browse the repository at this point in the history
 - added keywords tags
- TODO: should we replace Kewords with KewordsCollection when submitting a package?
  • Loading branch information
dnenov committed Nov 7, 2023
1 parent 578c2c2 commit 4ffda43
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ namespace Dynamo.PackageManager
{
public delegate void PublishSuccessHandler(PublishPackageViewModel sender);


/// <summary>
/// Keyword tag displaying under the keyword input text box
/// </summary>
public class KeywordTag : NotificationObject
{
/// <summary>
/// Name of the host
/// </summary>
public string Name { get; set; }

private bool _onChecked;
/// <summary>
/// Triggers the remove action
/// </summary>
public bool OnChecked
{
get { return _onChecked; }
set
{
_onChecked = value;

RaisePropertyChanged(nameof(OnChecked));
}
}

/// <summary>
/// Constructor
/// </summary>
/// <param Name="name">Keyword name</param>
public KeywordTag(string name)
{
Name = name;
}
}

/// <summary>
/// The ViewModel for Package publishing </summary>
public class PublishPackageViewModel : NotificationObject
Expand Down Expand Up @@ -269,6 +305,22 @@ public string Keywords
}
}

private ObservableCollection<KeywordTag> keywordsCollection = new ObservableCollection<KeywordTag>();

/// <summary>
/// A collection of dynamic non-hosted filters
/// such as New, Updated, Deprecated, Has/HasNoDependencies
/// </summary>
public ObservableCollection<KeywordTag> KeywordsCollection
{
get { return keywordsCollection; }
set
{
keywordsCollection = value;
RaisePropertyChanged(nameof(KeywordsCollection));
}
}

/// <summary>
/// KeywordList property </summary>
/// <value>
Expand Down Expand Up @@ -635,6 +687,11 @@ public string MarkdownFilesDirectory
/// A command which, when executed, submits the current package</value>
public DelegateCommand ToggleMoreCommand { get; private set; }

/// <summary>
/// Sets the keywords tags based on the current KeywordList items
/// </summary>
public DelegateCommand SetKeywordsCommand { get; private set; }

/// <summary>
/// The package used for this submission
/// </summary>
Expand Down Expand Up @@ -838,6 +895,7 @@ internal PublishPackageViewModel()
CancelCommand = new DelegateCommand(Cancel);
RemoveItemCommand = new Dynamo.UI.Commands.DelegateCommand(RemoveItem);
ToggleMoreCommand = new DelegateCommand(() => MoreExpanded = !MoreExpanded, () => true);
SetKeywordsCommand = new DelegateCommand(SetKeywords, CanSetKeywords);
Dependencies.CollectionChanged += DependenciesOnCollectionChanged;
Assemblies = new List<PackageAssembly>();
MarkdownFiles = new List<string>();
Expand Down Expand Up @@ -948,19 +1006,6 @@ private List<PackageItemRootViewModel> BindParentToChild(Dictionary<string, Pack
return updatedItems;
}

private bool IsSubPathOf(string path1, string path2)
{
var di1 = new DirectoryInfo(path1);
var di2 = new DirectoryInfo(path2);

if (di2.Parent == null) return false;
if (di2.Parent.FullName == di1.FullName)
{
return true;
}
return false;
}

/// <summary>
/// Test if path2 is subpath of path1
/// If it is, make sure all the intermediate file paths are created as separte PackageItemRootViewModel
Expand Down Expand Up @@ -1034,7 +1079,7 @@ private void ClearAllEntries()
// Clearing the UploadHandle when using Submit currently throws - check trheading
try
{
this._uploadHandle.PropertyChanged += UploadHandleOnPropertyChanged;
this._uploadHandle.PropertyChanged -= UploadHandleOnPropertyChanged;
this.UploadHandle = null;
}
catch { Exception ex; }
Expand Down Expand Up @@ -1113,6 +1158,29 @@ private void ThisPropertyChanged(object sender, PropertyChangedEventArgs e)
}
}

private bool CanSetKeywords()
{
return KeywordList.Count() > 0;
}
private void SetKeywords()
{
KeywordsCollection = KeywordList.Select(x => new KeywordTag(x)).ToObservableCollection();
foreach (var keyword in KeywordsCollection)
{
keyword.PropertyChanged += Keyword_PropertyChanged;
}
}

private void Keyword_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (!(sender is KeywordTag keyword)) return;
if (e.PropertyName == nameof(KeywordTag.OnChecked))
{
keyword.PropertyChanged -= Keyword_PropertyChanged;
KeywordsCollection.Remove(keyword);
}
}

public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoViewModel, Package l)
{
var defs = new List<CustomNodeDefinition>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,43 @@
ToggleDefaultBrush="{StaticResource MidBlueBrush}"
ToggleHoverBrush="{StaticResource MidDarkBlueBrush}"
TogglePressedBrush="{StaticResource MidLightBlueBrush}" />
<ControlTemplate x:Key="ToggleTemplate"
TargetType="{x:Type Button}">
<ControlTemplate x:Key="ToggleTemplate" TargetType="{x:Type Button}">
<Border x:Name="border"
Padding="4 2"
Margin="3"
CornerRadius="12"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
BorderThickness="2"
BorderBrush="#2a2a2a"
BorderBrush="Transparent"
Background="#494949">
<StackPanel Orientation="Horizontal">
<ContentPresenter />
<Image Source="/DynamoCoreWpf;component/UI/Images/close_16px.png"
Width="16"
Height="16"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
VerticalAlignment="Stretch"
Margin="2 0" />
<Border Background="Transparent">
<Viewbox Width="12"
Height="12"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
VerticalAlignment="Stretch"
Margin="0 -1 5 2">
<Path x:Name="remove"
Fill="#999999"
Data="M13.3996 3.39998L12.5996 2.59998L7.99961 7.29998L3.39961 2.59998L2.59961 3.39998L7.29961 7.99998L2.59961 12.6L3.39961 13.4L7.99961 8.69998L12.5996 13.4L13.3996 12.6L8.69961 7.99998L13.3996 3.39998Z"
StrokeThickness="0">
</Path>
</Viewbox>
</Border>
</StackPanel>
</Border>

<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="border"
Property="Background"
Value="#5D5D5D" />
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="#5D5D5D" />
</Trigger>
<Trigger Property="IsPressed"
Value="True">
<Setter TargetName="border"
Property="BorderBrush"
Value="#25576E" />
<Setter TargetName="border"
Property="Background"
Value="#494949" />
<Setter TargetName="border" Property="BorderBrush" Value="#25576E" />
<Setter TargetName="border" Property="Background" Value="#494949" />

</Trigger>
</ControlTemplate.Triggers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,33 @@
Style="{StaticResource InputStyle}"
Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Tag="{x:Static p:Resources.PublishPackageKeywordsWatermark}"
TabIndex="7" />
TabIndex="7">
<TextBox.InputBindings>
<KeyBinding Command="{Binding SetKeywordsCommand}" Key="Return" />
</TextBox.InputBindings>
</TextBox>
<!-- Bar containing all active fitlers -->
<ItemsControl x:Name="KeywordsItemControl">
<ItemsControl.Resources>
<CollectionViewSource x:Key="KeywordItems" Source="{Binding KeywordsCollection}" />
</ItemsControl.Resources>
<ItemsControl.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource KeywordItems}}" />
</CompositeCollection>
</ItemsControl.ItemsSource>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:FilterTagControl}">
<local:FilterTagControl TagName="{Binding Name}"
IsFilterOn="{Binding OnChecked, Mode=TwoWay}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

<!-- More -->
<Expander x:Name="detailsExpander"
Expand Down

0 comments on commit 4ffda43

Please sign in to comment.