|
class MenuCommandService : System.ComponentModel.Design.IMenuCommandService
{
// List of services od DesignSurface
IServiceProvider serviceProvider;
// Basic MenuCommmand
System.ComponentModel.Design.MenuCommandService menuCommandService = null;
public MenuCommandService(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
menuCommandService = new System.ComponentModel.Design.MenuCommandService(serviceProvider);
}
// Show the contexteMenu
// Show the command Delete
public void ShowContextMenu(System.ComponentModel.Design.CommandID menuID, int x, int y)
{
// Creation of the contextMenu
ContextMenu contextMenu = new ContextMenu();
// Add the command Delete
System.ComponentModel.Design.MenuCommand command = FindCommand(System.ComponentModel.Design.StandardCommands.Delete);
if (command != null)
{
MenuItem menuItem = new MenuItem("Supprimer", new EventHandler(OnMenuClicked));
menuItem.Tag = command;
contextMenu.MenuItems.Add(menuItem);
}
// Select the service of view
ViewService viewService = (ViewService)this.serviceProvider.GetService(typeof(ViewService));
// Show the contexteMenu
if (viewService.View != null)
{
contextMenu.Show(viewService.View, viewService.View.PointToClient(new Point(x, y)));
}
}
// Management of the selections of the contexteMenu
private void OnMenuClicked(object sender, EventArgs e)
{
MenuItem menuItem = sender as MenuItem;
if (menuItem != null && menuItem.Tag is System.ComponentModel.Design.MenuCommand)
{
System.ComponentModel.Design.MenuCommand command = menuItem.Tag as System.ComponentModel.Design.MenuCommand;
command.Invoke();
}
}
// Add of standard command to the service
public void AddCommand(System.ComponentModel.Design.MenuCommand command)
{
menuCommandService.AddCommand(command);
}
// Add the verb at the service
public void AddVerb(System.ComponentModel.Design.DesignerVerb verb)
{
menuCommandService.AddVerb(verb);
}
// Search a standard command starting from its id
public System.ComponentModel.Design.MenuCommand FindCommand(System.ComponentModel.Design.CommandID commandID)
{
return menuCommandService.FindCommand(commandID);
}
// Execute the standard command
public bool GlobalInvoke(System.ComponentModel.Design.CommandID commandID)
{
return menuCommandService.GlobalInvoke(commandID);
}
// Remove a standard command at the service
public void RemoveCommand(System.ComponentModel.Design.MenuCommand command)
{
menuCommandService.RemoveCommand(command);
}
// Remove a verb from service
public void RemoveVerb(System.ComponentModel.Design.DesignerVerb verb)
{
menuCommandService.RemoveVerb(verb);
}
// Obtain the list of verbs of the service
public System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
return menuCommandService.Verbs;
}
}
} |