/// <summary> /// Edits the specified object's value using the editor style indicated by the GetEditStyle method. /// </summary> /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param> /// <param name="provider">An IServiceProvider that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // Get associated items list Collection <object> associatedItems = new Collection <object>(); NuGenContextMenuCollection contextMenuCollection = value as NuGenContextMenuCollection; foreach (object item in contextMenuCollection) { associatedItems.Add(item); } // Get command switchboard NuGenCommandManagerBase UISwitchboard = contextMenuCollection.UISwitchboard; // Get available items list Collection <object> availableItems = new Collection <object>(); foreach (object item in UISwitchboard.UIItemAdapter.GetAvailableContextMenus()) { availableItems.Add(item); } // Get editor service IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { // Show form NuGenContextMenusForm formContextMenus = new NuGenContextMenusForm(UISwitchboard, associatedItems, availableItems); if (editorService.ShowDialog(formContextMenus) == DialogResult.OK) { NuGenContextMenuCollection modifiedContextMenuCollection = new NuGenContextMenuCollection(UISwitchboard); foreach (object item in associatedItems) { modifiedContextMenuCollection.Add(item); } return(modifiedContextMenuCollection); } } return(value); }
/// <summary> /// Edits the specified object's value using the editor style indicated by the GetEditStyle method. /// </summary> /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param> /// <param name="provider">An IServiceProvider that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // Get associated items list Collection<object> associatedItems = new Collection<object>(); NuGenContextMenuCollection contextMenuCollection = value as NuGenContextMenuCollection; foreach (object item in contextMenuCollection) { associatedItems.Add(item); } // Get command switchboard NuGenCommandManagerBase UISwitchboard = contextMenuCollection.UISwitchboard; // Get available items list Collection<object> availableItems = new Collection<object>(); foreach (object item in UISwitchboard.UIItemAdapter.GetAvailableContextMenus()) { availableItems.Add(item); } // Get editor service IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { // Show form NuGenContextMenusForm formContextMenus = new NuGenContextMenusForm(UISwitchboard, associatedItems, availableItems); if (editorService.ShowDialog(formContextMenus) == DialogResult.OK) { NuGenContextMenuCollection modifiedContextMenuCollection = new NuGenContextMenuCollection(UISwitchboard); foreach (object item in associatedItems) { modifiedContextMenuCollection.Add(item); } return modifiedContextMenuCollection; } } return value; }
/// <summary> /// Initializes a new instance of the <see cref="NuGenCommandManagerBase"/> class. /// </summary> /// <param name="container">Component container</param> public NuGenCommandManagerBase(IContainer container) { if (container != null) { container.Add(this); } applicationCommands = new NuGenApplicationCommandCollection(this); contextMenus = new NuGenContextMenuCollection(this); // Add handler for idle status update of ApplicationCommands Application.Idle += new EventHandler(Application_Idle); }