Skip to content

Commit

Permalink
View Extension API for ViewModel Delegate Commands (#9944)
Browse files Browse the repository at this point in the history
* Add IDynamoViewModelDelegateCommands interface

* Add ViewModelDelegateCommands to ViewLoadedParams

* Add ViewModelDelegateCommands to ViewLoadedParams

* Rename ViewModelCommandExecutive

* Add FitViewCommand to ViewExtensionCommandExecutive

* Remove IDynamoViewModelDelegateCommands

* Move FItViewCommand to new DynamoViewModelCommandExecutive class

* Add FindById and ForceRunExpression commands to VM Command Executive

* Rename DynamoViewModelCommandExecutive -> ViewModelCommandExecutive

* Update parameter name

* Update model X and Y on CenterViewOnElement
  • Loading branch information
scottmitchell authored Sep 2, 2019
1 parent 7758ff2 commit 3fc290e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
</Compile>
<Compile Include="Controls\UseLevelPopup.cs" />
<Compile Include="Controls\UseLevelSpinner.cs" />
<Compile Include="Extensions\ViewModelCommandExecutive.cs" />
<Compile Include="Extensions\IViewExtension.cs" />
<Compile Include="Extensions\IViewExtensionLoader.cs" />
<Compile Include="Extensions\IViewExtensionManager.cs" />
Expand Down
10 changes: 10 additions & 0 deletions src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Visualization;
using Dynamo.Wpf.ViewModels;
using Dynamo.Wpf.ViewModels.Watch3D;

namespace Dynamo.Wpf.Extensions
Expand Down Expand Up @@ -54,6 +55,15 @@ public IPackageInstaller PackageInstaller
get { return dynamoViewModel.PackageManagerClientViewModel; }
}

private ViewModelCommandExecutive viewModelCommandExecutive;
/// <summary>
/// Class used for executing commands on the DynamoViewModel and current WorkspaceViewModel
/// </summary>
public ViewModelCommandExecutive ViewModelCommandExecutive
{
get { return viewModelCommandExecutive ?? (viewModelCommandExecutive = new ViewModelCommandExecutive(dynamoViewModel)); }
}

/// <summary>
/// A reference to the Dynamo Window object. Useful for correctly setting the parent of a
/// newly created window.
Expand Down
52 changes: 52 additions & 0 deletions src/DynamoCoreWpf/Extensions/ViewModelCommandExecutive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dynamo.ViewModels;

namespace Dynamo.Wpf.Extensions
{
/// <summary>
/// The ViewModelCommandExecutive provides access to DynamoViewModel and WorkspaceViewModel commands
/// </summary>
public class ViewModelCommandExecutive
{
private DynamoViewModel dynamoViewModel;

/// <summary>
/// Create a Command Executive for a DynamoViewModel
/// </summary>
/// <param name="viewModel"></param>
internal ViewModelCommandExecutive(DynamoViewModel viewModel)
{
dynamoViewModel = viewModel;
}

/// <summary>
/// Fit the current workspace view to the current selection
/// </summary>
public void FitViewCommand()
{
dynamoViewModel.FitViewCommand.Execute(null);
}

/// <summary>
/// Search for an element by its ID and focus the view on it
/// </summary>
/// <param name="objectID"></param>
public void FindByIdCommand(string objectID)
{
dynamoViewModel.CurrentSpaceViewModel.FindByIdCommand.Execute(objectID);
}

/// <summary>
/// Force re-execute all nodes in the current workspace
/// </summary>
/// <param name="showErrors">Should errors be shown?</param>
public void ForceRunExpressionCommand(bool showErrors = true)
{
dynamoViewModel.ForceRunExpressionCommand.Execute(showErrors);
}
}
}
9 changes: 4 additions & 5 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,11 @@ internal void CenterViewOnElement(object sender, EventArgs e)

double deltaX = nodeCenterInOverlay.X - outerCenter.X;
double deltaY = nodeCenterInOverlay.Y - outerCenter.Y;

vm.Model.X -= deltaX;
vm.Model.Y -= deltaY;

//var offset = new Point(vm.CurrentOffset.X - deltaX, vm.CurrentOffset.Y - deltaY);

//vm.CurrentOffset = offset;

zoomBorder.SetTranslateTransformOrigin(new Point2D(vm.Model.X - deltaX, vm.Model.Y - deltaY));
zoomBorder.SetTranslateTransformOrigin(new Point2D(vm.Model.X, vm.Model.Y));
}
});
}
Expand Down

0 comments on commit 3fc290e

Please sign in to comment.