示例#1
0
        private void ActionChangeToolStripItem(ToolStripItem item, object sender, bool checkDefaults)
        {
            if (sender is TCustomAction)
            {
                TCustomAction action = (TCustomAction)sender;
                if (!checkDefaults ||
                    string.IsNullOrEmpty(item.Text) || item.Text == item.Name)
                {
                    item.Text = action.Caption;
                }
                if (!checkDefaults || item.Enabled)
                {
                    item.Enabled = action.Enabled;
                }
                if (!checkDefaults || string.IsNullOrEmpty(item.ToolTipText))
                {
                    item.ToolTipText = action.Hint;
                }
                if (!checkDefaults || item.Visible)
                {
                    item.Visible = action.Visible;
                }
                if (!checkDefaults || item.ImageIndex == -1)
                {
                    item.ImageIndex = action.ImageIndex;
                }
                if (!checkDefaults || item.GetClickEvent() == null)
                {
                    item.Click += action.ExecuteDelegate;
                    //TBasicActionLink link = compToActionLinks[item];
                    //item.Click += (s, e) => link.OnExecute(item, e);
                }

                DelphiHelpProvider helpext = HelpExtender as DelphiHelpProvider;
                if (helpext != null)
                {
                    string        helpkey     = helpext.GetHelpKeyword(item);
                    int           helpcontext = helpext.GetHelpContext(item);
                    HelpNavigator helpnav     = helpext.GetHelpNavigator(item);
                    int           helpkeyctxt;
                    if (helpcontext != -1 && int.TryParse(helpkey, out helpkeyctxt) &&
                        helpkeyctxt == helpcontext)
                    {
                        helpkey = null;
                    }

                    if (!checkDefaults || helpcontext == -1)
                    {
                        helpext.SetHelpContext(item, action.HelpContext);
                    }
                    if (!checkDefaults || helpkey == null)
                    {
                        helpext.SetHelpKeyword(item, action.HelpKeyword);
                    }
                    if (!checkDefaults || helpnav == HelpNavigator.AssociateIndex)
                    {
                        helpext.SetHelpNavigator(item, action.HelpType);
                    }
                }
            }
        }