Skip to content

Commit

Permalink
[DYN-3486] Extensions menu (#11541)
Browse files Browse the repository at this point in the history
* Removal of unused code

* Revert "Removal of unused code"

This reverts commit c78dfe9.

* Added Obsolete Tag

* Message change

* Tests1

* Tests changes

* WorkspaceModel Tests

* Fix merge issue

* GitHub Action For Issue Content

* Refactor

* Update checkIssueInfo.yaml

* Add github action

* Template/Issue parser and comparator improvements

* Update infromation analyzer

* Delete checkIssueInfo.yaml

* ux changes

* Disable preferences in debug mode

* fix

* visibility change

* UX fixes

* Update DynamoView.xaml

* Extension menu and api changes

* Comment spelling

* Update DocumentationBrowserViewExtensionTests.cs

* fix
  • Loading branch information
Astul-Betizagasti authored Mar 12, 2021
1 parent b9416cc commit 8e040f6
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void Loaded(ViewLoadedParams viewLoadedParams)
this.documentationBrowserMenuItem = new MenuItem { Header = Resources.MenuItemText, IsCheckable = true };
this.documentationBrowserMenuItem.Checked += MenuItemCheckHandler;
this.documentationBrowserMenuItem.Unchecked += MenuItemUnCheckedHandler;
this.viewLoadedParamsReference.AddMenuItem(MenuBarType.View, this.documentationBrowserMenuItem);
this.viewLoadedParamsReference.AddExtensionMenuItem(this.documentationBrowserMenuItem);

// subscribe to the documentation open request event from Dynamo
this.viewLoadedParamsReference.RequestOpenDocumentationLink += HandleRequestOpenDocumentationLink;
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/Extensions/MenuBarTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static class MenuBarTypeExtensions
/// </summary>
/// <param name="type"></param>
/// <returns>A localized string used as the menu header</returns>
/// TODO: Remove in Dynamo 3.0
internal static string ToDisplayString(this MenuBarType type)
{
switch (type)
Expand Down
23 changes: 23 additions & 0 deletions src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -85,11 +86,32 @@ internal ViewLoadedParams(DynamoView dynamoV, DynamoViewModel dynamoVM) :
DynamoSelection.Instance.Selection.CollectionChanged += OnSelectionCollectionChanged;
}

[Obsolete("Method will be deprecated in Dynamo 3.0, please use AddExtensionMenuItem")]
public void AddMenuItem(MenuBarType type, MenuItem menuItem, int index = -1)
{
AddItemToMenu(type, menuItem, index);
}

/// <summary>
/// Adds a menu item to the extensions menu
/// Items will be ordered alphabetically
/// </summary>
/// <param name="menuItem">Menu item for the extension to be added</param>
public void AddExtensionMenuItem(MenuItem menuItem)
{
if (dynamoMenu == null) return;

var dynamoMenuItems = dynamoMenu.Items.OfType<MenuItem>();
var dynamoItem = dynamoMenuItems.First(item => item.Header.ToString() == Properties.Resources.DynamoViewExtensionsMenu);

if (dynamoItem == null) return;
if (!dynamoItem.IsEnabled) dynamoItem.IsEnabled = true;

dynamoItem.Items.Add(menuItem);
//Orders the menu items alphabetically
dynamoItem.Items.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));
}

/// <summary>
/// Adds the extension UI control element to a new tab in the extensions side bar.
/// </summary>
Expand Down Expand Up @@ -198,6 +220,7 @@ public event RequestOpenDocumentationLinkHandler RequestOpenDocumentationLink
/// An enum that represents the different possible
/// MenuBars which ViewExtensions may add items to.
/// </summary>
/// TODO: Remove in Dynamo 3.0
public enum MenuBarType
{
File,
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2309,4 +2309,8 @@ Uninstall the following packages: {0}?</value>
<data name="PreferencesViewVisualSettingsTab" xml:space="preserve">
<value>Visual Settings</value>
</data>
<data name="DynamoViewExtensionsMenu" xml:space="preserve">
<value>_Extensions</value>
<comment>Extensions menu</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2311,4 +2311,8 @@ Uninstall the following packages: {0}?</value>
<data name="PreferencesViewVisualSettingsTab" xml:space="preserve">
<value>Visual Settings</value>
</data>
<data name="DynamoViewExtensionsMenu" xml:space="preserve">
<value>_Extensions</value>
<comment>Extensions menu</comment>
</data>
</root>
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@
Command="{Binding Path=BackgroundPreviewViewModel.ToggleCanNavigateBackgroundCommand}" />
</MenuItem>
</MenuItem>

<!--The menu will be enabled when at least one MenuItem is added-->
<MenuItem Header="{x:Static p:Resources.DynamoViewExtensionsMenu}"
Name="ExtensionsMenu"
Focusable="False"
IsEnabled="False"/>

<MenuItem Header="{x:Static p:Resources.DynamoViewPackageMenu}"
Name="PackageManagerMenu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override void Loaded(ViewLoadedParams viewLoadedParams)
workspaceReferencesMenuItem.IsChecked = false;
}
};
viewLoadedParams.AddMenuItem(MenuBarType.View, workspaceReferencesMenuItem);
viewLoadedParams.AddExtensionMenuItem(workspaceReferencesMenuItem);
}

public override void Closed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ private List<MenuItem> GetDocsMenuItems()
// get menu items that match the extension's menu item
return loadedParams.dynamoMenu.Items
.Cast<MenuItem>()
.Where(x => ((string)x.Header).Contains("View"))
.Where(x => ((string)x.Header).Contains("Extensions"))
.Select(x => x.Items)
.FirstOrDefault()
.Cast<MenuItem>()
Expand Down

0 comments on commit 8e040f6

Please sign in to comment.