Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamo Package Dependency View Extension #9787

Merged
merged 27 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1126ba5
Initial Commit
QilongTang Jun 10, 2019
4d9303a
Update csproj to use project config imports
QilongTang Jun 10, 2019
6428ad8
Add Data bind
QilongTang Jun 11, 2019
226dd31
Workspace Open with package info
QilongTang Jun 11, 2019
01ca109
adjust styling and make cells read only
QilongTang Jun 13, 2019
57a91f9
adjust styling
QilongTang Jun 13, 2019
1379d94
reduce package cell width
QilongTang Jun 13, 2019
4dbdcc5
Code clean Up
QilongTang Jun 13, 2019
22992d0
Add Property watch for Package Dependencies
QilongTang Jun 13, 2019
abcce1f
use name of
QilongTang Jun 14, 2019
7a270ad
Some UI tunning
QilongTang Jun 14, 2019
7357094
Merge branch 'master' into PackageDependencyViewExtension
QilongTang Jun 14, 2019
e8c3667
Styling changes
QilongTang Jun 14, 2019
d4c5a0b
Merge branch 'master' into PackageDependencyViewExtension
QilongTang Jun 14, 2019
5679bfe
Using View injection API
QilongTang Jun 14, 2019
dc748c7
grid styling
QilongTang Jun 14, 2019
27c05fc
Highlight packages not installed
QilongTang Jun 14, 2019
63c6bd9
Add Download Button and view injection Menu Item
QilongTang Jun 17, 2019
48346eb
Some comments missing
QilongTang Jun 17, 2019
4904b89
code clean up
QilongTang Jun 17, 2019
0bebfcc
Merge branch 'master' into PackageDependencyViewExtension
QilongTang Jun 17, 2019
23b06bb
Address Comments
QilongTang Jun 18, 2019
5d483b1
UI Adjustment
QilongTang Jun 18, 2019
6c4ede7
Update unsubscribe logic
QilongTang Jun 18, 2019
c4d57ef
More comments
QilongTang Jun 18, 2019
924dca9
Merge branch 'master' into PackageDependencyViewExtension
QilongTang Jun 18, 2019
befc36a
Fix Unit Tests
QilongTang Jun 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 304 additions & 0 deletions src/Dynamo.All.sln

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/DynamoCore/Extensions/ReadyParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal ReadyParams(DynamoModel dynamoM)
{
dynamoModel = dynamoM;
dynamoModel.PropertyChanged += OnDynamoModelPropertyChanged;
dynamoModel.WorkspaceCleared += OnCurrentWorkspaceModelCleared;
dynamoM.Logger.NotificationLogged += OnNotificationRecieved;
startupParams = new StartupParams(dynamoModel.AuthenticationManager.AuthProvider,
dynamoModel.PathManager, new ExtensionLibraryLoader(dynamoModel), dynamoModel.CustomNodeManager,
Expand Down Expand Up @@ -93,6 +94,16 @@ private void OnCurrentWorkspaceModelChanged(IWorkspaceModel ws)
CurrentWorkspaceChanged(ws);
}

/// <summary>
/// Occurs when current workspace is cleared
/// </summary>
public event Action<IWorkspaceModel> CurrentWorkspaceCleared;
private void OnCurrentWorkspaceModelCleared(IWorkspaceModel ws)
{
if (CurrentWorkspaceCleared != null)
CurrentWorkspaceCleared(ws);
}

private void OnDynamoModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "CurrentWorkspace")
Expand Down
4 changes: 0 additions & 4 deletions src/DynamoCore/Graph/Workspaces/PackageDependencyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Dynamo.Graph.Workspaces
{
Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
// For workspace package dependency collection
[assembly: InternalsVisibleTo("DynamoPackages")]

// Internals are visible to the Package Manager extension
// For workspace package dependency collection
[assembly: InternalsVisibleTo("PackageDependencyViewExtension")]

namespace Dynamo.Graph.Workspaces
{
/// <summary>
Expand Down Expand Up @@ -649,6 +653,7 @@ internal List<PackageDependencyInfo> PackageDependencies
set
{
packageDependencies = value;
RaisePropertyChanged("PackageDependencies");
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DynamoManipulation/DynamoManipulation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<Reference Include="PresentationFramework" />
<Reference Include="ProtoGeometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(DynamoExternPath)\ProtoGeometry\ProtoGeometry.dll</HintPath>
<HintPath>..\..\extern\ProtoGeometry\ProtoGeometry.dll</HintPath>
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand Down
16 changes: 8 additions & 8 deletions src/DynamoManipulation/NodeManipulator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Geometry;
using CoreNodeModels.Input;
using Dynamo.Extensions;
using Dynamo.Graph.Nodes;
Expand All @@ -15,6 +8,13 @@
using Dynamo.Wpf.ViewModels.Watch3D;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.Mirror;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using Point = Autodesk.DesignScript.Geometry.Point;
using Vector = Autodesk.DesignScript.Geometry.Vector;

Expand Down
5 changes: 0 additions & 5 deletions src/LibraryViewExtension/Views/LibraryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
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:ui="clr-namespace:Dynamo.UI"
xmlns:controls="clr-namespace:Dynamo.Controls"
xmlns:uicontrols="clr-namespace:Dynamo.UI.Controls"
xmlns:vms="clr-namespace:Dynamo.Wpf.ViewModels"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
xmlns:local="clr-namespace:Dynamo.LibraryUI.Views"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Expand Down
72 changes: 72 additions & 0 deletions src/PackageDependencyViewExtension/PackageDependencyView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<UserControl x:Class="Dynamo.PackageDependency.PackageDependencyView"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="300"
VerticalAlignment="Top">
<Grid Width="300" Height="800" Background= "#353535">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid
Name="PackageDependencyTable"
HorizontalAlignment="Left"
Height="400"
Width="300"
Margin="5,5,0,0"
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
VerticalAlignment="Top"
AutoGenerateColumns="False"
ItemsSource="{Binding Columns}"
CanUserAddRows="False"
IsReadOnly="True"
ColumnWidth="*"
Background= "#353535">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.Headers}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Margin="2" Width="{Binding Width}" Foreground="{Binding Color}" Text="{Binding Data}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ColumnsData}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Margin="2" Width="{Binding Width}" Foreground="{Binding Color}" Text="{Binding Data}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
</UserControl>
196 changes: 196 additions & 0 deletions src/PackageDependencyViewExtension/PackageDependencyView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using Dynamo.Graph.Workspaces;
using Dynamo.Wpf.Extensions;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;

namespace Dynamo.PackageDependency
{
/// <summary>
/// Interaction logic for PackageDependencyView.xaml
/// </summary>
public partial class PackageDependencyView : UserControl
{
private DependencyTable table = new DependencyTable();

private WorkspaceModel currentWorkspace;

/// <summary>
/// Event handler for workspaceAdded event
/// </summary>
/// <param name="obj"></param>
internal void OnWorkspaceChanged(IWorkspaceModel obj)
{
if (obj is WorkspaceModel)
{
DepdencyRegen(obj as WorkspaceModel);
}
}

/// <summary>
/// Event handler for workspaceRemoved event
/// </summary>
/// <param name="obj"></param>
internal void OnWorkspaceCleared(IWorkspaceModel obj)
{
if (obj is WorkspaceModel)
{
currentWorkspace.PropertyChanged -= OnWorkspacePropertyChanged;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like an odd place to do this -couldn't the workspace be cleared for some other reason... and if you clear the workspace but then don't add the the subscription back then you're not watching the workspace any longer...

I would have imagined this would be done in the onCurrentWorkspaceChanged handler - you cache the current workspace, unsubscribe the handler, then get the new current workspace and then subscribe?

Does that not work?

// Clear the dependency table.
table.Columns.Clear();
}
}

private void OnWorkspacePropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == "PackageDependencies")
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
DepdencyRegen(currentWorkspace);
}

/// <summary>
/// Regenerate dependency table
/// </summary>
/// <param name="ws"></param>
private void DepdencyRegen(WorkspaceModel ws)
{
// Clear the dependency table.
table.Columns.Clear();
foreach (var package in ws.PackageDependencies)
{
table.Columns.Add(new Column()
{
ColumnsData = new ObservableCollection<ColumnData>()
{
new ColumnData(package.Name),
new ColumnData(package.Version.ToString(), 100)
}
});
}
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="dynamoModel"></param>
public PackageDependencyView(ViewLoadedParams p)
{
InitializeComponent();
DataContext = table;
currentWorkspace = p.CurrentWorkspaceModel as WorkspaceModel;
p.CurrentWorkspaceChanged += OnWorkspaceChanged;
p.CurrentWorkspaceCleared += OnWorkspaceCleared;
currentWorkspace.PropertyChanged += OnWorkspacePropertyChanged;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to unsubscribe this event handler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see how this could always be the same workspace - but I think for safety's sake we should unsub this when the workspace changes and re sub it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I removed because this is causing crashes sometimes (I think I showed you).. Let me add it back and test

}
}

/// <summary>
///
/// </summary>
public class Column
{
public ObservableCollection<ColumnData> ColumnsData
{
get; set;
}
}

/// <summary>
/// Class defining data for each column
/// </summary>
public class ColumnData
{
static int DefaultWidth = 150;
static Brush DefaultColor = Brushes.Red;

/// <summary>
/// Constructor
/// </summary>
/// <param name="data"></param>
public ColumnData(string data)
{
Data = data;
Width = DefaultWidth;
Color = DefaultColor;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="data"></param>
/// <param name="width"></param>
public ColumnData(string data, int width)
{
Data = data;
Width = width;
Color = DefaultColor;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="data"></param>
/// <param name="width"></param>
/// <param name="brush"></param>
public ColumnData(string data, int width, Brush brush)
{
Data = data;
Width = width;
Color = brush;
}

/// <summary>
/// Data in each cell
/// </summary>
public string Data
{
get; set;
}

/// <summary>
/// Width of each cell
/// </summary>
public int Width
{
get; set;
}

/// <summary>
/// Foreground color of each cell
/// </summary>
public Brush Color
{
get; set;
}
}

/// <summary>
/// The data binding table holding all the dependency info
/// </summary>
public class DependencyTable
{
public ObservableCollection<Column> Columns
{ get; set; }

public ObservableCollection<ColumnData> Headers
{ get; set; }

public DependencyTable()
{
Columns = new ObservableCollection<Column>();
Headers = new ObservableCollection<ColumnData>();

Columns.Add(new Column()
{
ColumnsData = new ObservableCollection<ColumnData>()
{
new ColumnData("DummyPackage"),
new ColumnData("1.0.0")
}
});

Headers.Add(new ColumnData("Package Name"));
Headers.Add(new ColumnData("Version"));
}
}
}
Loading