Skip to content

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

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

Merged
merged 8 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
15 changes: 14 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 Expand Up @@ -84,6 +83,7 @@ internal ViewLoadedParams(DynamoView dynamoV, DynamoViewModel dynamoVM) :
dynamoMenu = dynamoView.titleBar.ChildOfType<Menu>();
ViewStartupParams = new ViewStartupParams(dynamoVM);
DynamoSelection.Instance.Selection.CollectionChanged += OnSelectionCollectionChanged;
DynamoView.CloseExtension += this.OnExtensionTabClosedHandler;
}

public void AddMenuItem(MenuBarType type, MenuItem menuItem, int index = -1)
Expand Down Expand Up @@ -148,6 +148,19 @@ private void OnSelectionCollectionChanged(object sender, NotifyCollectionChanged
}
}

/// <summary>
/// This event is raised when an extension tab is closed and this event
/// is subscired by the Workspace dependency view extension
/// </summary>
public event Action OnExtensionTabClosed;
private void OnExtensionTabClosedHandler()
{
if (OnExtensionTabClosed != null)
{
OnExtensionTabClosed();
}
}

private void AddItemToMenu(MenuBarType type, Control itemToAdd, int index)
{
if (dynamoMenu == null) return;
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 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;
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();

TabItem tabitem = TabItems.OfType<TabItem>().SingleOrDefault(n => n.Header.ToString() == tabName);
CloseTab(tabitem);
}

/// <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)
{
// 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 @@ -50,9 +50,10 @@ private Boolean HasDependencyIssue
set
{
hasDependencyIssue = value;
if (hasDependencyIssue)
if (hasDependencyIssue && !dependencyViewExtension.packageDependencyMenuItem.IsChecked)
{
loadedParams.AddToExtensionsSideBar(dependencyViewExtension, this);
dependencyViewExtension.packageDependencyMenuItem.IsChecked = true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Dynamo.WorkspaceDependency
/// </summary>
public class WorkspaceDependencyViewExtension : IViewExtension, ILogSource
{
private MenuItem packageDependencyMenuItem;
internal MenuItem packageDependencyMenuItem;

internal WorkspaceDependencyView DependencyView
{
Expand Down Expand Up @@ -74,11 +74,17 @@ public void Startup(ViewStartupParams viewLoadedParams)
}

public event Action<ILogMessage> MessageLogged;

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

internal void OnCloseExtension()
{
this.packageDependencyMenuItem.IsChecked = false;
}

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

viewLoadedParams.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) =>
Expand All @@ -99,10 +107,12 @@ public void Loaded(ViewLoadedParams viewLoadedParams)
// Refresh dependency data
DependencyView.DependencyRegen(viewLoadedParams.CurrentWorkspaceModel as WorkspaceModel);
viewLoadedParams.AddToExtensionsSideBar(this, DependencyView);
packageDependencyMenuItem.IsChecked = true;
}
else
{
viewLoadedParams.CloseExtensioninInSideBar(this);
packageDependencyMenuItem.IsChecked = false;
}

};
Expand Down