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-1897 API to add extensions to right side bar. #9786

Merged
merged 14 commits into from
Jun 14, 2019
7 changes: 6 additions & 1 deletion src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ internal ViewLoadedParams(DynamoView dynamoV, DynamoViewModel dynamoVM) :
dynamoMenu = dynamoView.titleBar.ChildOfType<Menu>();
viewStartupParams = new ViewStartupParams(dynamoVM);
DynamoSelection.Instance.Selection.CollectionChanged += OnSelectionCollectionChanged;

}

public void AddMenuItem(MenuBarType type, MenuItem menuItem, int index = -1)
{
AddItemToMenu(type, menuItem, index);
}

// Adds the extension window to a new tab in the right side bar.
public void AddToExtensionsSideBar(Window w)
{
dynamoView.AddTabItem(w);
}

public void AddSeparator(MenuBarType type, Separator separatorObj, int index = -1)
{
AddItemToMenu(type, separatorObj, index);
Expand Down
100 changes: 100 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@
</StackPanel>
</Grid>
</Button>

</Grid>

<StackPanel.RenderTransform>
Expand Down Expand Up @@ -1676,6 +1677,105 @@
Grid.Row="2"
Grid.Column="4"
Grid.RowSpan="2">
<TabControl Name="tabDynamic" ItemsSource="{Binding}">
<TabControl.Resources>
<Style TargetType="{x:Type Button}"
x:Key="CloseButtonStyle">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="SnapsToDevicePixels"
Value="true" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="HorizontalAlignment"
Value="Right" />
<Setter Property="Margin"
Value="8,2,0,0" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Padding"
Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border"
Background="Transparent"
BorderThickness="0 0 0 0">
<ContentPresenter Margin="0 0 0 0" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="TabHeader" DataType="TabItem">
<DockPanel>
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Header}" HorizontalAlignment="Left"/>
<Button Name="CloseButton" Style="{StaticResource CloseButtonStyle}" DockPanel.Dock="Right" Click="CloseTab"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Name}">
<Image Width="14" Height="14" HorizontalAlignment="Right" VerticalAlignment="Center">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Source"
Value="/DynamoCoreWpf;component/UI/Images/closetab_normal.png" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source"
Value="/DynamoCoreWpf;component/UI/Images/closetab_hover.png" />
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Button>
</DockPanel>
</DataTemplate>
<Style TargetType="{x:Type TabItem}">
<!-- <Setter Property="MaxWidth" Value="{Binding Source={x:Static configuration:Configurations.TabDefaultWidth}}" />
<Setter Property="Width">
<Setter.Value>
<MultiBinding Converter="{StaticResource TabSizeConverter}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}"
Path="ActualWidth" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}"
Path="Items.Count" />
</MultiBinding>
</Setter.Value>
</Setter> -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border Name="Border" Margin="0,0,0,0" BorderThickness="0 0 0 0" BorderBrush="Black">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header" Margin="6,0,0,2"
RecognizesAccessKey="True">
</ContentPresenter>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="TextBlock.Foreground"
Value="{StaticResource WorkspaceTabHeaderActiveTextBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="false">
<Setter Property="Foreground"
Value="{StaticResource WorkspaceTabHeaderInactiveTextBrush}" />
<Setter TargetName="Border" Property="Background"
Value="{StaticResource HighlightedBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
</TabControl>
</Grid>

<!--Bottom Panel including RunMode etc-->
Expand Down
77 changes: 76 additions & 1 deletion src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public partial class DynamoView : Window, IDisposable
private ShortcutToolbar shortcutBar;
private bool loaded = false;

// list of items in the right side bar.
private List<TabItem> _tabItems = new List<TabItem>();

// This is to identify whether the PerformShutdownSequenceOnViewModel() method has been
// called on the view model and the process is not cancelled
private bool isPSSCalledOnViewModelNoCancel = false;
Expand Down Expand Up @@ -186,11 +189,70 @@ public DynamoView(DynamoViewModel dynamoViewModel)
}
};

this.HideOrShowRightSideBar();

this.dynamoViewModel.RequestPaste += OnRequestPaste;
this.dynamoViewModel.RequestReturnFocusToView += OnRequestReturnFocusToView;
FocusableGrid.InputBindings.Clear();
}

// This method adds a tab item to the right side bar and
// sets the extension window as the tab content.
internal TabItem AddTabItem(Window window)
{
int count = _tabItems.Count;

tabDynamic.DataContext = null;

// creates a new tab item
TabItem tab = new TabItem();
tab.Header = window.Title;
tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate;

// setting the extension window to the current tab content
tab.Content = window.Content;

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

tabDynamic.DataContext = _tabItems;
tabDynamic.SelectedItem = tab;

this.HideOrShowRightSideBar();

return tab;
}

// This method triggers the close operation on the selected tab.
private void CloseTab(object sender, RoutedEventArgs e)
{
string tabName = (sender as Button).CommandParameter.ToString();

TabItem tab = tabDynamic.SelectedItem as TabItem;

if (tab != null)
{
// get the selected tab
TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

// clear tab control binding and bind to the new tab-list.
tabDynamic.DataContext = null;
_tabItems.Remove(tab);
tabDynamic.DataContext = _tabItems;

// Highlight previously selected tab. if that is removed then Highlight the first tab
if (selectedTab == null || selectedTab.Equals(tab))
{
if (_tabItems.Count > 0) {
selectedTab = _tabItems[0];
}
}
tabDynamic.SelectedItem = selectedTab;
}

this.HideOrShowRightSideBar();
}

private void OnRequestReturnFocusToView()
{
// focusing grid allows to remove focus from current textbox
Expand Down Expand Up @@ -1693,8 +1755,21 @@ private void updateCollapseIcon()
collapsedLibrarySidebar.Visibility = Visibility.Collapsed;
}

collapsedExtensionSidebar.Visibility = Visibility.Visible;
}

// Show the extensions right side bar when there is atleast one extension
private void HideOrShowRightSideBar()
{
if (_tabItems.Count < 1)
{
RightExtensionsViewColumn.Width = new GridLength(0, GridUnitType.Star);
collapsedExtensionSidebar.Visibility = Visibility.Collapsed;
}
else
{
RightExtensionsViewColumn.Width = new GridLength(defaultSideBarWidth, GridUnitType.Star);
collapsedExtensionSidebar.Visibility = Visibility.Visible;
}
}

private void OnCollapsedLeftSidebarClick(object sender, EventArgs e)
Expand Down