Skip to content

Commit

Permalink
DYN-2375 - Event to handle the close operation of the workspace refer…
Browse files Browse the repository at this point in the history
…ences extension (#10280)

* First commit

* new changes

* Renaming the event

* Adding test
  • Loading branch information
reddyashish authored Jan 10, 2020
1 parent 3cd2087 commit 201748a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/DynamoCore/Graph/Workspaces/HomeWorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class HomeWorkspaceModel : WorkspaceModel
private readonly bool verboseLogging;
private bool graphExecuted;

// Event to handle closing of the workspace references extension when the workspace is closed.
internal static event Action WorkspaceClosed;

// To check whether task is completed or not.
private bool executingTask;

Expand Down Expand Up @@ -419,6 +422,7 @@ private void NodeOnRequestSilenceNodeModifiedEvents(NodeModel node, bool value)
/// </summary>
public override void Clear()
{
WorkspaceClosed?.Invoke();
base.Clear();
PreloadedTraceData = null;
RunSettings.Reset();
Expand Down
25 changes: 13 additions & 12 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ public DynamoView(DynamoViewModel dynamoViewModel)
FocusableGrid.InputBindings.Clear();
}

/// <summary>
/// This method will close a tab item in the right side bar based on passed extension
/// </summary>
/// <param name="viewExtension">Extension to be closed</param>
/// <returns></returns>
internal void CloseExtensionTabItem(IViewExtension viewExtension)
{
string tabName = viewExtension.Name;
TabItem tabitem = ExtensionTabItems.OfType<TabItem>().SingleOrDefault(n => n.Header.ToString() == tabName);
CloseExtensionTab(tabitem);
}

// This method adds a tab item to the right side bar and
// sets the extension window as the tab content.
internal TabItem AddExtensionTabItem(IViewExtension viewExtension, ContentControl contentControl)
Expand Down Expand Up @@ -259,6 +247,19 @@ internal TabItem AddExtensionTabItem(IViewExtension viewExtension, ContentContro
return null;
}

/// <summary>
/// This method will close a tab item in the right side bar based on passed extension
/// </summary>
/// <param name="viewExtension">Extension to be closed</param>
/// <returns></returns>
internal void CloseExtensionTabItem(IViewExtension viewExtension)
{
string tabName = viewExtension.Name;
TabItem tabitem = ExtensionTabItems.OfType<TabItem>().SingleOrDefault(n => n.Header.ToString() == tabName);
CloseExtension?.Invoke(tabName);
CloseExtensionTab(tabitem);
}

/// <summary>
/// Event handler for the CloseButton.
/// This method triggers the close operation on the selected tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal void DependencyRegen(WorkspaceModel ws)
internal void TriggerDependencyRegen()
{
DependencyRegen(currentWorkspace);
}
}

/// <summary>
/// Constructor
Expand All @@ -173,6 +173,15 @@ public WorkspaceDependencyView(WorkspaceDependencyViewExtension viewExtension, V
dependencyViewExtension = viewExtension;
DependencyRegen(currentWorkspace);
DynamoView.CloseExtension += this.OnExtensionTabClosedHandler;
HomeWorkspaceModel.WorkspaceClosed += this.CloseExtensionTab;
}

/// <summary>
/// This method will call the close API on the workspace references extension.
/// </summary>
internal void CloseExtensionTab()
{
loadedParams.CloseExtensioninInSideBar(dependencyViewExtension);
}

/// <summary>
Expand Down Expand Up @@ -268,6 +277,7 @@ public void Dispose()
loadedParams.CurrentWorkspaceCleared -= OnWorkspaceCleared;
WorkspaceModel.DummyNodesReloaded -= TriggerDependencyRegen;
DynamoView.CloseExtension -= this.OnExtensionTabClosedHandler;
HomeWorkspaceModel.WorkspaceClosed -= this.CloseExtensionTab;
}

private void Refresh_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ public void APItoCloseViewExtensionTabTest()
Assert.AreEqual(0, View.ExtensionTabItems.Count);
}

/// <summary>
/// This test will make sure that the extension tab is closed upon closing the home workspace.
/// </summary>
[Test]
public void CloseViewExtensionTabOnClosingWorkspace()
{
RaiseLoadedEvent(this.View);
var extensionManager = View.viewExtensionManager;
extensionManager.Add(viewExtension);
// Open a graph which should bring up the Workspace References view extension window with one tab
Open(@"pkgs\Dynamo Samples\extra\CustomRenderExample.dyn");
Assert.AreEqual(1, View.ExtensionTabItems.Count);
var homeSpace = Model.Workspaces.First(ws => ws is HomeWorkspaceModel) as HomeWorkspaceModel;
homeSpace.Clear();
Assert.AreEqual(0, View.ExtensionTabItems.Count);
}

/// <summary>
/// This test is created to guard a crash happened that while dep viewer is loaded,
/// opening a dyf directly and closing it to switch to an empty homeworkspace causing a crash
Expand Down

0 comments on commit 201748a

Please sign in to comment.