RemoveCustomCommandFromMenu
Description
Removes a custom command from the specified menu location.
Syntax
await shellFrame.Commands.RemoveCustomCommandFromMenu(
commandId,
MFiles.MenuLocation.MenuLocation_TopPaneMenu
);
Parameters
| Name | Optionality | Type | Description |
|---|---|---|---|
| customCommand | Required | number | The custom command id. |
| location | Required | MenuLocation | Menu location where the command is removed. Possible locations are enumerated. |
MenuLocation
Possible values for the location parameter are
| Name | Value | Description |
|---|---|---|
MenuLocation_TopPaneMenu | 47 | TopPane Menu, typically used for the UI Extension applications. |
MenuLocation_ActivityContextMenu_1 | 48 | Menu location for the Activity view Context menu group 1. |
MenuLocation_ActivityContextMenu_2 | 49 | Menu location for the Activity view Context menu group 2. |
MenuLocation_ActivityContextMenu_3 | 50 | Menu location for the Activity view Context menu group 3. |
MenuLocation_ContextMenu_Open | 51 | Menu location for the context menu position for the open commands. |
MenuLocation_ContextMenu_Checkout | 52 | Menu location for the context menu position for the checkout commands. |
MenuLocation_ContextMenu_Share | 53 | Menu location for the context menu position for the share commands. |
MenuLocation_ContextMenu_ObjectOperations | 26 | Menu location for the position of object operations in the context menu. |
MenuLocation_ContextMenu_ConflictResolution | 40 | Menu location for the position of conflict resolution commands in the context menu. |
MenuLocation_ContextMenu_DocumentConversions | 41 | Menu location for the context menu position for document conversions. |
MenuLocation_ContextMenu_WorkflowActions | 54 | Menu location for the context menu position for the workflow action commands. |
MenuLocation_ContextMenu_Organize | 55 | Menu location for the context menu position for the organize commands. |
MenuLocation_ContextMenu_VersionControl | 56 | Menu location for the context menu position for the version control commands. |
MenuLocation_ContextMenu_Create | 57 | Menu location for the context menu position for the create commands. |
MenuLocation_ContextMenu_ViewOptions | 58 | Menu location for the context menu position for the view options commands. |
MenuLocation_ContextMenu_Group | 59 | Menu location for the context menu position for the grouping commands. |
MenuLocation_ContextMenu_DisplayOptions | 60 | Menu location for the context menu position for the display options commands. |
MenuLocation_ContextMenu_Edit | 37 | Menu location for the context menu position for Edit commands. |
MenuLocation_ContextMenu_Bottom | 43 | Menu location for the bottom of the context menu. |
MenuLocation_ContextMenu_More | 99 | Menu location for the context menu position for more commands. |
MenuLocation_TaskBar_First | 200 | Menu location for the first command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_Workspace | 205 | Menu location for the "Workspace" command group in the task bar. Supported in M-Files Client version 25.11 and later. |
MenuLocation_TaskBar_MainActions | 210 | Menu location for the "Main Actions" command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_Assignments | 220 | Menu location for the "Assignments" command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_DocumentCollections | 230 | Menu location for the "Document Collections" command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_CheckIn | 240 | Menu location for the "Check In" command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_WorkflowStates | 250 | Menu location for the "Workflow States" command group in the task bar. Supported in M-Files Client version 25.10 and later. |
MenuLocation_TaskBar_ConflictResolution | 260 | Menu location for the "Conflict Resolution" command group in the task bar. NOTE: Stability is experimental. Non-backward compatible changes or removal may occur in any future release. Use of this feature is not recommended for production environments. |
MenuLocation_TaskBar_Last | 399 | Menu location for the last command group in the task bar. Supported in M-Files Client version 25.10 and later. |
Return type
| Type | Description |
|---|---|
| Promise < void > | Method does not return a value |
Example
This JavaScript code is a UI Extension for M-Files, creating custom commands such as "Hello World" and providing functionality to dynamically show, hide, and remove these commands from the top menu based on user interactions within the M-Files shell.
// Called when the UI Extension starts
function OnNewShellUI(shellUI) {
// Wait for the ShellFrame to be created.
shellUI.Events.Register(
MFiles.Event.NewShellFrame,
async (shellFrame) => {
// Wait for the shellframe to start
shellFrame.Events.Register(
MFiles.Event.Started,
async () => {
// Create a new custom command and menu item for the command
const createCommand = async ( name: string ) => {
// Create a new custom command
const commandId = await shellFrame.Commands.CreateCustomCommand(name);
// Add the command to the top menu
const menuItemId = await shellFrame.Commands.AddCustomCommandToMenu(
// Command ID
commands.exampleCommand,
// Menulocation
MFiles.MenuLocation.MenuLocation_TopPaneMenu,
// Priority of the command
1
);
// Return a data structure containing essential information about the commands
return {
id: commandId, // ID of the command
menuItemId // Menu item ID, can be used to add sub menus to this menu item.
}
}
// Create an Example command and a set of sample commands to control it's visibility
const commands = {
// This is the sample command
exampleCommand : await createCommand("Hello World"),
// These commands control the state of the example command
addCommand: await createCommand("Add Command To Menu"),
deleteCustomCommand: await createCommand("Delete Command")
hideCommand: await createCommand("Hide Command"),
showCommand: await createCommand("Activate Command"),
executeCommand: await createCommand("Execute Command"),
getCommandName: await createCommand("Get Name"),
getCommandState: await createCommand("Get Command State"),
removeCommandFromMenu: await createCommand("Remove From Menu"),
removeCommand: await createCommand("Remove Command")
}
// Add the command to the top menu
const menuItemId = await shellFrame.Commands.AddCustomCommandToMenu(
commands.exampleCommand,
MFiles.MenuLocation.MenuLocation_TopPaneMenu,
1 // Priority of the command
);
// Listen for the custom commands.
shellFrame.Commands.Events.Register(
// Listen for the CustomCommand events.
MFiles.Event.CustomCommand,
// Each command has ID and optional data provided with it.
( commandId, data ) => {
// Respond to the command if custom command sent by the application
switch( commandId ) {
// Run the Example command
case commands.exampleCommand.id:
shellFrame.ShowMessage( "Hello World!" );
break;
// Add the new menuitem which runs the example command
case commands.addCommand.id:
await shellFrame.Commands.AddCustomCommandToMenu(
commands.exampleCommand,
MFiles.MenuLocation.MenuLocation_TopPaneMenu,
1 // Priority of the command
);
break;
// Removes the command from particular menu
case commands.removeCommandFromMenu.id:
await shellFrame.Commands.RemoveCustomCommandFromMenu(
commands.exampleCommand,
MFiles.MenuLocation.MenuLocation_TopPaneMenu
);
break;
// Deletes the command permanently
case commands.deleteCommand.id:
shellFrame.Commands.DeleteCustomCommand(
commandId
);
break;
// Hides command instance for the specified command ID from the main menu
case commands.hideCommand.id:
// Hide the command
shellFrame.Commands.SetCommandState(
commandId,
MFiles.CommandLocation.MainMenu,
MFiles.CommandState.CommandState_Hidden
);
break;
// Activates (makes visible) command instance for the specified command ID in the main menu
case commands.showCommand.id:
// Show the command
shellFrame.Commands.SetCommandState(
commandId,
MFiles.CommandLocation.MainMenu,
MFiles.CommandState.CommandState_Active
);
break;
// Get the command name
case commands.getCommandName.id:
const name = await shellFrame.Commands.GetCommandName(commands.exampleCommand.id);
shellFrame.ShowMessage( name );
break;
// Get the Command State
case commands.getCommandState.id:
// NOTE: the MFiles.CommandLocation.MainMenu must be used to get state of items added to the Top Menu
const commandState = await shellFrame.Commands.SetCommandState(commands.exampleCommand.id, MFiles.CommandLocation.MainMenu );
shellFrame.ShowMessage( `Command state: ${commandState}` );
break;
}
}
);
}
)
}
)
}
This code is essentially setting up a simple UI extension with custom commands that can be triggered from the top menu, and it allows dynamic control over the visibility of these commands based on user interactions.
Exceptions
ArgumentError - When customCommand or location is null or undefined, or when appGuid/dashboardId is missing for toolbar locations.
NotFoundError - When the command is not found or access is denied.