-
Notifications
You must be signed in to change notification settings - Fork 654
[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
Changes from 2 commits
93491b7
cd27f31
71a5002
079d128
95fa75b
7fcf02e
8da6ee8
bdc6ee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>(); | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when the button is constructed you can actually use the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
reddyashish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.