상속: System.Attribute
예제 #1
0
        public override bool Equals(object other)
        {
            if (other == null)
            {
                return(false);
            }

            HelpKeywordAttribute o = other as HelpKeywordAttribute;

            if (o == null)
            {
                return(false);
            }

            return(o.contextKeyword == contextKeyword);
        }
        private void UpdateHelpKeyword(bool tryLater)
        {
            IHelpService service = this.GetService(typeof(IHelpService)) as IHelpService;

            if (service == null)
            {
                if (tryLater)
                {
                    Application.Idle += new EventHandler(this.ApplicationIdle);
                }
            }
            else
            {
                if (this._contextAttributes != null)
                {
                    foreach (string str in this._contextAttributes)
                    {
                        service.RemoveContextAttribute("Keyword", str);
                    }
                    this._contextAttributes = null;
                }
                service.RemoveContextAttribute("Selection", SelectionKeywords[this._contextKeyword]);
                bool flag = false;
                if (this._selection.Count == 0)
                {
                    flag = true;
                }
                else if (this._selection.Count == 1)
                {
                    IDesignerHost host = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
                    if ((host != null) && this._selection.Contains(host.RootComponent))
                    {
                        flag = true;
                    }
                }
                this._contextAttributes = new string[this._selection.Count];
                for (int i = 0; i < this._selection.Count; i++)
                {
                    object component = this._selection[i];
                    string className = TypeDescriptor.GetClassName(component);
                    HelpKeywordAttribute attribute = (HelpKeywordAttribute)TypeDescriptor.GetAttributes(component)[typeof(HelpKeywordAttribute)];
                    if ((attribute != null) && !attribute.IsDefaultAttribute())
                    {
                        className = attribute.HelpKeyword;
                    }
                    this._contextAttributes[i] = className;
                }
                HelpKeywordType keywordType = flag ? HelpKeywordType.GeneralKeyword : HelpKeywordType.F1Keyword;
                foreach (string str3 in this._contextAttributes)
                {
                    service.AddContextAttribute("Keyword", str3, keywordType);
                }
                int count = this._selection.Count;
                if ((count == 1) && flag)
                {
                    count--;
                }
                this._contextKeyword = (short)Math.Min(count, SelectionKeywords.Length - 1);
                service.AddContextAttribute("Selection", SelectionKeywords[this._contextKeyword], HelpKeywordType.FilterKeyword);
            }
        }
예제 #3
0
        /// <summary>
        /// Pushes the help context into the help service for the current set of selected objects.
        /// </summary>
        private void UpdateHelpKeyword(bool tryLater)
        {
            if (!(GetService(typeof(IHelpService)) is IHelpService helpService))
            {
                if (tryLater)
                {
                    // we don't have an help service YET, we need to wait for it...
                    // hook up to the application.idle event
                    // yes this is UGLY but we don't have a choice, vs is always returning a UserContext, so even if we manage to instanciate the HelpService beforehand and class pushcontext on it (trying to stack up help context in the helpservice to be flushed when we get the documentactivation event we just don't know if that's going to work or not... so we just wait...) :(((
                    Windows.Forms.Application.Idle += new EventHandler(ApplicationIdle);
                }
                return;
            }

            // If there is an old set of context attributes, remove them.
            if (_contextAttributes != null)
            {
                foreach (string s in _contextAttributes)
                {
                    helpService.RemoveContextAttribute("Keyword", s);
                }
                _contextAttributes = null;
            }

            // Clear the selection keyword
            helpService.RemoveContextAttribute("Selection", s_selectionKeywords[_contextKeyword]);
            // Get a list of unique class names.
            Debug.Assert(_selection != null, "Should be impossible to update the help context before configuring the selection hash");
            bool baseComponentSelected = false;

            if (_selection.Count == 0)
            {
                baseComponentSelected = true;
            }
            else if (_selection.Count == 1)
            {
                if (GetService(typeof(IDesignerHost)) is IDesignerHost host && _selection.Contains(host.RootComponent))
                {
                    baseComponentSelected = true;
                }
            }
            _contextAttributes = new string[_selection.Count];

            for (int i = 0; i < _selection.Count; i++)
            {
                object s           = _selection[i];
                string helpContext = TypeDescriptor.GetClassName(s);
                HelpKeywordAttribute contextAttr = (HelpKeywordAttribute)TypeDescriptor.GetAttributes(s)[typeof(HelpKeywordAttribute)];
                if (contextAttr != null && !contextAttr.IsDefaultAttribute())
                {
                    helpContext = contextAttr.HelpKeyword;
                }
                _contextAttributes[i] = helpContext;
            }

            // And push them into the help context as keywords.
            HelpKeywordType selectionType = baseComponentSelected ? HelpKeywordType.GeneralKeyword : HelpKeywordType.F1Keyword;

            foreach (string helpContext in _contextAttributes)
            {
                helpService.AddContextAttribute("Keyword", helpContext, selectionType);
            }

            // Now add the appropriate selection keyword.  Note that we do not count the base component as being selected if it is the only thing selected.
            int count = _selection.Count;

            if (count == 1 && baseComponentSelected)
            {
                count--;
            }
            _contextKeyword = (short)Math.Min(count, s_selectionKeywords.Length - 1);
            helpService.AddContextAttribute("Selection", s_selectionKeywords[_contextKeyword], HelpKeywordType.FilterKeyword);
        }