private void LegacyUpdateCommand(ICommandItem item) { ICommandClient client = GetClientOrActiveClient(item.CommandTag); if (client != null) { var commandState = new CommandState { Text = item.Text, Check = item.IsChecked }; client.UpdateCommand(item.CommandTag, commandState); item.Text = commandState.Text.Trim(); item.IsChecked = commandState.Check; } }
/// <summary> /// Utility function to get the command's client and call UpdateCommand.</summary> /// <param name="commandTag">The command to update</param> /// <param name="state">Command's state</param> private void UpdatePinnableCommand(object commandTag, CommandState state) { ICommandClient client = GetClient(commandTag); if (client == null) { client = m_activeClient; } if (client != null && client.CanDoCommand(commandTag)) { client.UpdateCommand(commandTag, state); } }
/// <summary> /// Force an update on a particular command</summary> /// <param name="info">Command to update</param> public void UpdateCommand(CommandInfo info) { if (m_mainForm.InvokeRequired) { m_mainForm.BeginInvoke(new Action <CommandInfo>(UpdateCommand), info); return; } ToolStripMenuItem menuItem; ToolStripButton menuButton; info.GetMenuItemAndButton(out menuItem, out menuButton); CommandState commandState = new CommandState(); commandState.Text = info.DisplayedMenuText; commandState.Check = menuItem.Checked; ICommandClient client = GetClient(info.CommandTag); if (client == null) { client = m_activeClient; } bool enabled = false; if (client != null) { enabled = client.CanDoCommand(info.CommandTag); if (enabled) { client.UpdateCommand(info.CommandTag, commandState); } } string menuText = commandState.Text.Trim(); menuItem.Text = menuButton.Text = menuText; menuItem.Checked = menuButton.Checked = commandState.Check; menuItem.Enabled = menuButton.Enabled = enabled; }
private void UpdateCommand(CommandInfo info, ICommandClient client) { if (m_mainForm.InvokeRequired) { m_mainForm.BeginInvoke(new Action<CommandInfo>(UpdateCommand), info); return; } ToolStripMenuItem menuItem; ToolStripButton menuButton; info.GetMenuItemAndButton(out menuItem, out menuButton); CommandState commandState = new CommandState(); commandState.Text = info.DisplayedMenuText; commandState.Check = menuItem.Checked; bool enabled = false; if (client != null) { enabled = client.CanDoCommand(info.CommandTag); if (enabled) client.UpdateCommand(info.CommandTag, commandState); } string menuText = commandState.Text.Trim(); menuItem.Text = menuButton.Text = menuText; menuItem.Checked = menuButton.Checked = commandState.Check; menuItem.Enabled = menuButton.Enabled = enabled; }