Skip to content

Commit c9f2c7f

Browse files
authored
Merge pull request mendix#10176 from mendix/qt-csharp
Review C# Extension docs
2 parents 6abae42 + bc9ef90 commit c9f2c7f

11 files changed

Lines changed: 456 additions & 308 deletions

File tree

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/add-menu.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ weight: 15
77

88
## Introduction
99

10-
This how-to describes how you can add a menu that contains submenus, some of which also contain submenus of their own. Before you start this how-to, it is recommended to [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) first.
10+
This how-to describes how to add a menu that contains sub-menus, some of which also contain sub-menus of their own.
1111

1212
You can download the example in this how-to in [this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
1313

14+
## Prerequisites
15+
16+
This how-to uses the results of [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/). Complete that how-to before starting this one.
17+
1418
## Creating Menu Extension Class
1519

16-
1. Open the project that you previously created when you followed [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
20+
1. Open the project you created when following [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
1721
2. Add a new class to the project and name it `MyMenuExtension.cs`.
18-
3. Replace the code in the file with the following code:
22+
3. Replace the code in the file with the following:
1923

2024
```csharp
2125
using Mendix.StudioPro.ExtensionsAPI.UI.Menu;
@@ -57,10 +61,41 @@ You can download the example in this how-to in [this GitHub repository](https://
5761
}
5862
```
5963

60-
The code above creates a single menu, `Beverages`, which contains the submenus `Hot` and `Cold`, both of which contain some submenus. Note that when you are creating this menu structure, you only return the main parent menu (in this example, the `Beverages` menu) from the `GetMenus` method. You should only return the topmost parents in your list, so only the ones that do not have a parent should be returned. In the example above, there is only one.
64+
### Menu Structure Overview
65+
66+
The code above creates a single menu, `Beverages`. This menu contains the following:
67+
68+
* `Beverages` contain two sub-menus: `Hot` and `Cold`
69+
* `Hot` contains `Coffee` and `Tea`
70+
* `Coffee` contains `Black Coffee`, `Decaf`, and `Espresso`
71+
* `Espresso` contains `Regular Espresso` and `Ristretto`
72+
* `Cold` contains `Soda`
73+
74+
Only the top-most parent menu (`Beverages`) is returned from the `GetMenus` method. You should only return menus that do not have a parent.
75+
76+
### Menu Placement
77+
78+
If an app contains one or more extensions, a top-level menu named `Extensions` will appear in the main menu bar of Studio Pro.
79+
80+
Menus that are created from `MenuExtension` implementations are grouped by their extension entry point name (in this example, `MyCompany`), and are placed under a dedicated sub-menu. For example, `MyMenuExtension` will be placed as follows: **Extensions** > **MyCompany** > **MyMenuExtension**.
81+
82+
### Menu Properties
83+
84+
A menu can either:
85+
86+
* Be a parent (a menu that contains sub-menus), or
87+
* Have an action
88+
89+
You cannot create a menu that both contains sub-menus and has an action.
90+
91+
#### Separators
92+
93+
You can add a `MenuSeparator` to a menu using the `Separator` property. The options include:
6194

62-
If an app contains one or more extensions, a top-level menu named `Extensions` will appear in the main menu bar of Studio Pro. Menus that are created from `MenuExtension` implementations will be grouped by their extension entry point name (in this example, `MyCompany`), and then placed under their own dedicated submenu under the main `Extensions` top-level menu. For example, the `MyMenuExtension` above will be placed as follows: **Extensions** > **MyCompany** > **MyMenuExtension**.
95+
* `After`
96+
* `Before`
97+
* `None` (default).
6398

64-
A menu can only be a parent (namely, a menu that contains submenus) or have an action. You cannot create a menu with an action which also contains submenus.
99+
#### Enabling and Disabling Menus
65100

66-
You can add a `MenuSeparator` to a menu, via the `Separator` property. Options are `After`, `Before` or `None`. The default value is `None`. You can also disable a menu by setting its `IsEnabled` property to `false`. Menus are enabled by default.
101+
Menus are enabled by default. To disable a menu, set its `IsEnabled` property to `false`.

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/build-todo-example-extension.md

Lines changed: 172 additions & 146 deletions
Large diffs are not rendered by default.

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/create-context-menu.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ weight: 6
77

88
## Introduction
99

10-
It is possible to add a context menu to an `IEntity` in Studio Pro or to a `IDocument`, such as microflows and pages, etc. Context menus will be placed under a menu named after the extension that contains them (e.g. `MyExtension`) and context menus can modify those items they relate to. You can achieve this simple by specifying the type when creating the extension.
11-
12-
This how-to describes how you can add a context menu to an entity. Before you start this how-to, it is recommended to [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) first.
10+
You can add a context menu to an `IEntity` in Studio Pro or to a `IDocument`, such as microflows and pages. These context menus will appear under a menu named after the extension that contains them (for example, `MyExtension`) and can modify the items they relate to. This is achieved by specifying the type when creating the extension.
1311

1412
You can download the example in this how-to in [this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
1513

14+
## Prerequisites
15+
16+
Before you start this how-to, it is recommended to [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) first.
17+
1618
## Creating an Entity Context Menu Extension Class
1719

18-
1. Open the project that you previously created when you followed [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
19-
2. Add a new class to the project and name it `MyEntityContextMenuExtension.cs`.
20-
3. Replace the code in the file with the following code:
20+
1. Open the project you previously created by following [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
21+
2. Add a new class to the project named *MyEntityContextMenuExtension.cs*.
22+
3. Replace the code in the file with the following:
2123

2224
```csharp
2325
namespace MyCompany.MyProject.MendixExtension;
@@ -90,15 +92,20 @@ You can download the example in this how-to in [this GitHub repository](https://
9092
}
9193
```
9294

93-
The code above creates a series of context menu items for any entity. It is important to note the type `IEntity` is passed in so that the context menu will only apply to entities. It adds menus using the same logic as `MenuExtension.cs`. For more examples, see [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
95+
The code above creates a series of context menu items for any entity. The menus allow you to:
9496

95-
In the code above, you can see a few context menus that can perform changes on the entity they belong to. In The entity's location on the canvas can be changed, it can be renamed, and some of its information is shown in a message box.
97+
* Rename the entity
98+
* Change the entity's location on the canvas
99+
* Display entity information in a message box
100+
* Enable a previously disabled menu item
96101

97-
It is also possible to add menus that are disabled until some action is performed.
102+
{{% alert type="info" %}}
103+
The type `IEntity` is passed so the context menu will only apply to entities. It adds menus using the same logic as `MenuExtension.cs`. For more examples, see [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
104+
{{% /alert %}}
98105

99106
## Adding a Context Menu to a Document
100107

101-
You can also add a context menu to a document. All you have to do is specify the type `IDocument` in the context menu extension.
108+
You can also add a context menu to a document. To do this, specify the type `IDocument` in your context menu extension.
102109

103110
```csharp
104111
namespace MyCompany.MyProject.MendixExtension;

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/create-dockable-pane.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ weight: 5
77

88
## Introduction
99

10-
This how-to describes how you can add a custom dockable web pane window to Studio Pro. Before you start this how-to, it is recommended to [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) first.
10+
This how-to describes how to add a custom dockable web pane window to Studio Pro.
1111

1212
You can download the example in this how-to in [this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
1313

14+
## Prerequisites
15+
16+
Before you start this how-to, it is recommended to [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) first.
17+
1418
## Creating a Dockable Pane Extension Class
1519

16-
1. Open the project that you previously created when you followed [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17-
2. Add a new class to the project and name it `MyDockablePaneExtension.cs`.
18-
3. Replace the code in the file with the following code:
20+
1. Open the project you previously created by following [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
21+
2. Add a new class to the project named *MyDockablePaneExtension.cs*.
22+
3. Replace the code in the file with the following:
1923

2024
```csharp
2125
using System.ComponentModel.Composition;
@@ -33,13 +37,13 @@ You can download the example in this how-to in [this GitHub repository](https://
3337
}
3438
```
3539

36-
## The View Model for the Extension Tab
40+
## Creating The View Model for the Extension Tab
3741

38-
The dockable pane will have content, and this content comes in the form of a view model. The view model is an implementation of `WebViewDockablePaneViewModel`.
42+
The dockable pane has content, which is provided through a view model. The view model is an implementation of `WebViewDockablePaneViewModel`.
3943

40-
You need to override the `InitWebView` method in which you can set up the content of your web view inside the dockable pane. In this example, it will contain the home page of `http://mendix.com`.
44+
Override the `InitWebView` method, where you can set up the content of your web view inside the dockable pane. In this example, it contains the `http://mendix.com` home page.
4145
42-
Below is a small example code of the view model:
46+
Below is a code example of the view model:
4347

4448
```csharp
4549
using Mendix.StudioPro.ExtensionsAPI.UI.DockablePane;
@@ -57,7 +61,12 @@ public class MyDockablePaneExtensionWebViewModel(string homePage) : WebViewDocka
5761
{{% snippet file="/static/_includes/apidocs-mxsdk/warning-wwwroot.md" %}}
5862
{{% /alert %}}
5963

60-
The code above creates a new web-enabled tab view. You still need a way to show the new dockable pane. To do so, you need to modify the menu extension you added when you followed [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/). Simple replace the existing content of `MyMenuExtension.cs` with the following code:
64+
## Displaying the Pane Through a Menu
65+
66+
To show the new dockable pane, modify the extension you created when following [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
67+
68+
1. Open `MyMenuExtension.cs`.
69+
2. Replace its contents with the following code:
6170

6271
```csharp
6372
using System.ComponentModel.Composition;
@@ -77,17 +86,18 @@ public class MyMenuExtension(IDockingWindowService dockingWindowService, IMessag
7786
}
7887
```
7988

80-
The code above introduces a few new concepts.
89+
The code above introduces the following concepts:
8190

82-
Firstly, you inject the `IDockingWindowService` so that you can open a new dockable pane.
91+
* The `IDockingWindowService` is injected to allow opening the dockable pane
92+
* A new menu item named *Open My Dockable Pane* is added to trigger the pane using the `IDockingWindow` service
8393

84-
Secondly, you add a new menu item with the caption **Open My Dockable Pane** that you will use to open your new dockable pane using the `IDockingWindow` service that you have injected.
94+
Once you have made these changes, build your project. If you have opted to not automatically copy the output to the destination folder, manually copy the bin output from your project to your extension folder you created when you followed the [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/) process.
8595

86-
In order for the changes to reflect, you need to build your project. If you have opted to not automatically copy the output to the destination folder, then you will also need to manually copy the bin output from your project to your extension folder you created when you followed [Create a Menu Extension Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
96+
## Showing a Dockable Pane Without a Custom Menu
8797

88-
## Showing a Dockable Pane Without Adding a Custom Menu
98+
If you prefer to not add a separate menu item to open the docking pane, you can override the `ViewMenuCaption` property in the `DockablePaneExtension` implementation.
8999

90-
Instead of adding a separate menu to open the docking pane, you can override the `ViewMenuCaption` property in the implementation of the `DockablePaneExtension`. This means that the menu that opens will be placed under the `View` top-level menu in Studio Pro and will have the caption provided. There is no need for a separate `MenuExtension` in this case.
100+
This places the menu under the `View` top-level menu in Studio Pro using the caption provided. In this case, you do not need a separate `MenuExtension` class.
91101

92102
```csharp
93103
public override string? ViewMenuCaption => "My pane without custom menu";

0 commit comments

Comments
 (0)