/// <summary> /// Called when an item's checked state has changed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> that contains no event data.</param> void toolStripItem_CheckedChanged(object sender, EventArgs e) { if (inCheckedChanged) { return; } try { inCheckedChanged = true; bool value = false; ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; if (toolStripMenuItem != null) { value = toolStripMenuItem.Checked; } ToolStripButton toolStripButton = sender as ToolStripButton; if (toolStripButton != null) { value = toolStripButton.Checked; } NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(sender); if (applicationCommand != null) { applicationCommand.Visible = value; } } finally { inCheckedChanged = false; } }
/// <summary> /// Updates the specified command. /// </summary> /// <param name="sender">The source of the update.</param> /// <param name="applicationCommand">The command to update</param> /// <param name="item">The item that should be updated (can be null).</param> internal void UpdateApplicationCommand(object sender, NuGenApplicationCommand applicationCommand, object item) { NuGenApplicationCommandEventArgs e = new NuGenApplicationCommandEventArgs(applicationCommand, item); if (ApplicationCommandUpdate != null) { ApplicationCommandUpdate(sender, e); } }
/// <summary> /// Called when the trackbar value changes. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains no data.</param> void toolStripTrackBarItem_ValueChanged(object sender, EventArgs e) { NuGenToolStripTrackBar item = sender as NuGenToolStripTrackBar; NuGenApplicationCommand applicationCommand = CommandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(sender); applicationCommand.Execute(ownerControl, item); } }
/// <summary> /// Called when an item is clicked. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="ToolBarButtonClickEventArgs"/> that contains event data.</param> void Parent_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { ToolBarButton item = e.Button; NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(sender); _owner = null; applicationCommand.Execute(ownerControl, item); } }
/// <summary> /// Called when an item is clicked. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains no data.</param> void menuItem_Click(object sender, EventArgs e) { MenuItem item = sender as MenuItem; NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(sender); _owner = null; applicationCommand.Execute(ownerControl, item); } }
/// <summary> /// Called when an item is added to the <see cref="NuGenUIItemCollection"/> collection. /// </summary> /// <remarks> /// The adapter should normally add an event handler to the Click event of this item. /// </remarks> /// <param name="command">The command that has an item added.</param> /// <param name="item">The item that has been added.</param> public override void UIItemAdded(NuGenApplicationCommand command, object item) { NuGenToolStripTrackBar toolStripTrackBarItem = item as NuGenToolStripTrackBar; if (toolStripTrackBarItem != null) { toolStripTrackBarItem.EnabledChanged += new EventHandler(toolStripItem_EnabledChanged); toolStripTrackBarItem.VisibleChanged += new EventHandler(toolStripItem_VisibleChanged); toolStripTrackBarItem.ValueChanged += new EventHandler(toolStripTrackBarItem_ValueChanged); } else { base.UIItemAdded(command, item); } }
/// <summary> /// Called when an item is added to the <see cref="NuGenUIItemCollection"/> collection. /// </summary> /// <remarks> /// The adapter should normally add an event handler to the Click event of this item. /// </remarks> /// <param name="applicationCommand">The <see cref="NuGenApplicationCommand"/> that has an item added.</param> /// <param name="item">The item that has been added.</param> public virtual void UIItemAdded(NuGenApplicationCommand applicationCommand, object item) { // Add common handlers ToolStripItem toolStripItem = item as ToolStripItem; if (toolStripItem != null) { toolStripItem.EnabledChanged += new EventHandler(toolStripItem_EnabledChanged); toolStripItem.VisibleChanged += new EventHandler(toolStripItem_VisibleChanged); } // Add check handler ToolStripMenuItem toolStripMenuItem = item as ToolStripMenuItem; if (toolStripMenuItem != null) { toolStripMenuItem.CheckedChanged += new EventHandler(toolStripItem_CheckedChanged); } ToolStripButton toolStripButton = item as ToolStripButton; if (toolStripButton != null) { toolStripButton.CheckedChanged += new EventHandler(toolStripItem_CheckedChanged); } // Add specific combobox click handler ToolStripComboBox toolStripCombobox = item as ToolStripComboBox; if (toolStripCombobox != null) { toolStripCombobox.SelectedIndexChanged += new EventHandler(toolStripItem_Click); return; } // Add specific textbox click handler ToolStripTextBox toolStripTextbox = item as ToolStripTextBox; if (toolStripTextbox != null) { toolStripTextbox.TextChanged += new EventHandler(toolStripItem_Click); return; } // Add generic click handler if (toolStripItem != null) { toolStripItem.Click += new EventHandler(toolStripItem_Click); } }
/// <summary> /// Updates the state of a tool strip item. /// </summary> /// <param name="item">The item to update.</param> void UpdateItem(MenuItem item) { NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(item); applicationCommand.Update(ownerControl, item); foreach (MenuItem childItem in item.MenuItems) { UpdateItem(childItem); } } }
/// <summary> /// </summary> /// <param name="item">The item to be associated with the command.</param> /// <param name="applicationCommand">The command to be associated with the item.</param> public void SetApplicationCommand(object item, NuGenApplicationCommand applicationCommand) { if (applicationCommand != null) { applicationCommand.CommandManager = this; applicationCommand.UIItems.Add(item); } else { NuGenApplicationCommand oldUICommand = GetApplicationCommandByItem(item); if (oldUICommand != null) { oldUICommand.UIItems.Remove(item); } } }
/// <summary> /// Called when an item is clicked. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains no data.</param> void toolStripItem_Click(object sender, EventArgs e) { ToolStripItem item = sender as ToolStripItem; NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(sender); if ((ownerControl == null) && (cachedOwnerControl != null)) { ownerControl = cachedOwnerControl; } cachedOwnerControl = null; applicationCommand.Execute(ownerControl, item); } }
/// <summary> /// Called when an item is added to the <see cref="NuGenUIItemCollection"/> collection. /// </summary> /// <remarks> /// The adapter should normally add an event handler to the Click event of this item. /// </remarks> /// <param name="applicationCommand">The command that has an item added.</param> /// <param name="item">The item that has been added.</param> public virtual void UIItemAdded(NuGenApplicationCommand applicationCommand, object item) { MenuItem menuItem = item as MenuItem; if (menuItem != null) { menuItem.Click += new EventHandler(menuItem_Click); return; } ToolBarButton toolBarButtonItem = item as ToolBarButton; if (toolBarButtonItem != null) { toolBarButtonItem.Parent.ButtonClick -= new ToolBarButtonClickEventHandler(Parent_ButtonClick); toolBarButtonItem.Parent.ButtonClick += new ToolBarButtonClickEventHandler(Parent_ButtonClick); return; } }
/// <summary> /// Updates the state of a tool strip item. /// </summary> /// <param name="item">The item to update.</param> void UpdateItem(ToolStripItem item) { NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(item); if (applicationCommand != null) { Control ownerControl = GetOwnerControl(item); applicationCommand.Update(ownerControl, item); ToolStripDropDownItem dropDownItem = item as ToolStripDropDownItem; if (dropDownItem != null) { foreach (ToolStripItem childItem in dropDownItem.DropDownItems) { UpdateItem(childItem); } } } }
/// <summary> /// Called when an item's visible state has changed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> that contains no event data.</param> void toolStripItem_VisibleChanged(object sender, EventArgs e) { if (inVisibleChanged) { return; } try { inVisibleChanged = true; NuGenApplicationCommand applicationCommand = _commandManager.GetApplicationCommandByItem(sender); if (applicationCommand != null) { ToolStripItem item = sender as ToolStripItem; applicationCommand.Visible = item.Visible; } } finally { inVisibleChanged = false; } }
/// <summary> /// Initializes a new instance of the UICommandEventArgs class. /// </summary> /// <param name="applicationCommand">The ApplicationCommand causing the event.</param> /// <param name="item">The item causing the event.</param> public NuGenApplicationCommandEventArgs(NuGenApplicationCommand applicationCommand, object item) { _applicationCommand = applicationCommand; _item = item; }
/// <summary> /// Initializes a new instance of the <see cref="NuGenUIItemCollection"/> class. /// </summary> /// <param name="applicationCommand">The <see cref="ApplicationCommand"/> that owns the collection.</param> internal NuGenUIItemCollection(NuGenApplicationCommand applicationCommand) { this.applicationCommand = applicationCommand; }