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

[DYN-2349] Close workspace references extension tab by user action and API #10230

Merged
merged 8 commits into from
Dec 19, 2019
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Visualization;
using Dynamo.Wpf.ViewModels;
using Dynamo.Wpf.ViewModels.Watch3D;

namespace Dynamo.Wpf.Extensions
Expand Down
35 changes: 21 additions & 14 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public partial class DynamoView : Window, IDisposable
internal ViewExtensionManager viewExtensionManager;
private ShortcutToolbar shortcutBar;
private bool loaded = false;
// This event is raised on the dynamo view when an extension tab is closed.
internal static event Action<String> CloseExtension;

internal ObservableCollection<TabItem> TabItems { set; get; } = new ObservableCollection<TabItem>();

Expand Down Expand Up @@ -203,14 +205,15 @@ public DynamoView(DynamoViewModel dynamoViewModel)
}

/// <summary>
/// This method close a tab item in the right side bar based on passed extension
/// 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 CloseTabItem(IViewExtension viewExtension)
{
string tabName = viewExtension.Name;
CloseTab(tabName);
TabItem tabitem = TabItems.OfType<TabItem>().SingleOrDefault(n => n.Header.ToString() == tabName);
CloseTab(tabitem);
}

// This method adds a tab item to the right side bar and
Expand All @@ -227,6 +230,7 @@ internal TabItem AddTabItem(IViewExtension viewExtension, ContentControl content
TabItem tab = new TabItem();
tab.Header = viewExtension.Name;
tab.Tag = viewExtension.GetType();
tab.Uid = viewExtension.UniqueId;
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate;

// setting the extension UI to the current tab content
Expand All @@ -242,7 +246,6 @@ internal TabItem AddTabItem(IViewExtension viewExtension, ContentControl content

//Insert the tab at the end
TabItems.Insert(count, tab);
TabItems = TabItems;

tabDynamic.DataContext = TabItems;
tabDynamic.SelectedItem = tab;
Expand All @@ -255,31 +258,35 @@ internal TabItem AddTabItem(IViewExtension viewExtension, ContentControl content
// This method triggers the close operation on the selected tab.
private void CloseTab(object sender, RoutedEventArgs e)
{
string tabName = (sender as Button).CommandParameter.ToString();
CloseTab(tabName);
string tabName = (sender as Button).DataContext.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

when the button is constructed you can actually use the tag property to add the name of the tab instead of getting it this way - I think that makes it more explicit.

Copy link
Member

Choose a reason for hiding this comment

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

hmm, maybe this is not possible - am I understanding correctly the tabitems close buttons are already present from the existing control?

Copy link
Contributor Author

@reddyashish reddyashish Dec 19, 2019

Choose a reason for hiding this comment

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

The close button is present in the dynamoview.xaml and all the buttons have the same name.
https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/Views/Core/DynamoView.xaml#L1721.

Copy link
Member

Choose a reason for hiding this comment

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

theres probably some way to tag them with the header property of their dataContext instead of the name which was never set in the tabItem constructor.


CloseExtension?.Invoke(tabName);

TabItem tabitem = TabItems.OfType<TabItem>().SingleOrDefault(n => n.Header.ToString() == tabName);
CloseTab(tabitem);
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Close tab by its name
/// </summary>
/// <param name="tabName">tab name</param>
private void CloseTab(string tabName)
/// <param name="tabitem">tab item</param>
private void CloseTab(TabItem tabitem)
{
TabItem tab = tabDynamic.SelectedItem as TabItem;
TabItem tabToBeRemoved = tabitem;

if (tab != null)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
// get the selected tab
TabItem selectedTab = tabDynamic.SelectedItem as TabItem;
// get the selected tab
TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

if (tabToBeRemoved != null)
{
// clear tab control binding and bind to the new tab-list.
tabDynamic.DataContext = null;
TabItems.Remove(tab);
TabItems.Remove(tabToBeRemoved);
TabItems = TabItems;
tabDynamic.DataContext = TabItems;

// Highlight previously selected tab. if that is removed then Highlight the first tab
if (selectedTab == null || selectedTab.Equals(tab))
if (selectedTab.Equals(tabToBeRemoved))
{
if (TabItems.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Dynamo.Controls;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Utilities;
Expand Down Expand Up @@ -53,6 +54,10 @@ private Boolean HasDependencyIssue
if (hasDependencyIssue)
{
loadedParams.AddToExtensionsSideBar(dependencyViewExtension, this);
if (dependencyViewExtension.workspaceReferencesMenuItem != null && !dependencyViewExtension.workspaceReferencesMenuItem.IsChecked)
{
dependencyViewExtension.workspaceReferencesMenuItem.IsChecked = true;
}
}
}
}
Expand Down Expand Up @@ -167,6 +172,21 @@ public WorkspaceDependencyView(WorkspaceDependencyViewExtension viewExtension, V
packageInstaller = p.PackageInstaller;
dependencyViewExtension = viewExtension;
DependencyRegen(currentWorkspace);
DynamoView.CloseExtension += this.OnExtensionTabClosedHandler;
}

/// <summary>
/// This event is raised when an extension tab is closed and this event
/// is subscribed by the Workspace dependency view extension.
/// <param name="extensionTabName"></param>
/// </summary>
internal event Action<String> OnExtensionTabClosed;
private void OnExtensionTabClosedHandler(String extensionTabName)
{
if (OnExtensionTabClosed != null)
{
OnExtensionTabClosed(extensionTabName);
}
}

/// <summary>
Expand Down Expand Up @@ -247,6 +267,7 @@ public void Dispose()
loadedParams.CurrentWorkspaceChanged -= OnWorkspaceChanged;
loadedParams.CurrentWorkspaceCleared -= OnWorkspaceCleared;
WorkspaceModel.DummyNodesReloaded -= TriggerDependencyRegen;
DynamoView.CloseExtension -= this.OnExtensionTabClosedHandler;
}

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 @@ -17,7 +17,8 @@ namespace Dynamo.WorkspaceDependency
/// </summary>
public class WorkspaceDependencyViewExtension : IViewExtension, ILogSource
{
private MenuItem packageDependencyMenuItem;
internal MenuItem workspaceReferencesMenuItem;
private const String extensionName = "Workspace References";

internal WorkspaceDependencyView DependencyView
{
Expand All @@ -34,7 +35,7 @@ public string Name
{
get
{
return "Workspace References";
return extensionName;
}
}

Expand All @@ -54,6 +55,7 @@ public string UniqueId
/// </summary>
public void Dispose()
{
DependencyView.OnExtensionTabClosed -= OnCloseExtension;
}


Expand All @@ -74,11 +76,20 @@ public void Startup(ViewStartupParams viewLoadedParams)
}

public event Action<ILogMessage> MessageLogged;

internal void OnMessageLogged(ILogMessage msg)
{
this.MessageLogged?.Invoke(msg);
}

internal void OnCloseExtension(String extensionTabName)
{
if (extensionTabName.Equals(extensionName))
{
this.workspaceReferencesMenuItem.IsChecked = false;
}
}

public void Loaded(ViewLoadedParams viewLoadedParams)
{
DependencyView = new WorkspaceDependencyView(this, viewLoadedParams);
Expand All @@ -90,23 +101,27 @@ public void Loaded(ViewLoadedParams viewLoadedParams)
DependencyView.DependencyRegen(viewLoadedParams.CurrentWorkspaceModel as WorkspaceModel);
};

DependencyView.OnExtensionTabClosed += OnCloseExtension;

// Adding a button in view menu to refresh and show manually
packageDependencyMenuItem = new MenuItem { Header = Resources.MenuItemString, IsCheckable = true, IsChecked = false };
packageDependencyMenuItem.Click += (sender, args) =>
workspaceReferencesMenuItem = new MenuItem { Header = Resources.MenuItemString, IsCheckable = true, IsChecked = false };
workspaceReferencesMenuItem.Click += (sender, args) =>
{
if (packageDependencyMenuItem.IsChecked)
if (workspaceReferencesMenuItem.IsChecked)
{
// Refresh dependency data
DependencyView.DependencyRegen(viewLoadedParams.CurrentWorkspaceModel as WorkspaceModel);
viewLoadedParams.AddToExtensionsSideBar(this, DependencyView);
workspaceReferencesMenuItem.IsChecked = true;
}
else
{
viewLoadedParams.CloseExtensioninInSideBar(this);
workspaceReferencesMenuItem.IsChecked = false;
}

};
viewLoadedParams.AddMenuItem(MenuBarType.View, packageDependencyMenuItem);
viewLoadedParams.AddMenuItem(MenuBarType.View, workspaceReferencesMenuItem);
}

}
Expand Down