Exemple #1
0
        // Retrieves token settings as defined by user in Tools -> Options -> Environment -> Task List.
        private void RefreshTokens()
        {
            var taskInfo = (IVsCommentTaskInfo)_serviceProvider.GetService(typeof(SVsTaskList));

            if (taskInfo == null)
            {
                _tokens = new Dictionary <string, VSTASKPRIORITY>();
                return;
            }

            IVsEnumCommentTaskTokens enumTokens;

            ErrorHandler.ThrowOnFailure(taskInfo.EnumTokens(out enumTokens));

            var newTokens = new Dictionary <string, VSTASKPRIORITY>();

            var    token = new IVsCommentTaskToken[1];
            uint   fetched;
            string text;
            var    priority = new VSTASKPRIORITY[1];

            // DevDiv bug 1135485: EnumCommentTaskTokens.Next returns E_FAIL instead of S_FALSE
            while (enumTokens.Next(1, token, out fetched) == VSConstants.S_OK && fetched > 0)
            {
                ErrorHandler.ThrowOnFailure(token[0].Text(out text));
                ErrorHandler.ThrowOnFailure(token[0].Priority(priority));
                newTokens[text] = priority[0];
            }

            _tokens = newTokens;

            TokensChanged?.Invoke(this, EventArgs.Empty);
        }
        public static string GetTaskTokenList(IVsCommentTaskInfo tokenInfo)
        {
            int tokenCount;
            if (Succeeded(tokenInfo.TokenCount(out tokenCount)) && tokenCount > 0)
            {
                var tokens = new IVsCommentTaskToken[tokenCount];
                var tokensEnum = default(IVsEnumCommentTaskTokens);
                if (Succeeded(tokenInfo.EnumTokens(out tokensEnum)))
                {
                    uint count;
                    if (Succeeded(tokensEnum.Next((uint)tokenCount, tokens, out count)))
                    {
                        Contract.Requires(tokenCount == count);

                        string text;
                        var priority = new VSTASKPRIORITY[1];
                        var result = new List<string>();
                        foreach (var token in tokens)
                        {
                            if (Succeeded(token.Text(out text)) &&
                                Succeeded(token.Priority(priority)) &&
                                !string.IsNullOrWhiteSpace(text))
                            {
                                result.Add(string.Format("{0}:{1}", text, (int)priority[0]));
                            }
                        }

                        return string.Join("|", result);
                    }
                }
            }

            return string.Empty;
        }
        public static string GetTaskTokenList(IVsCommentTaskInfo tokenInfo)
        {
            int tokenCount;

            if (Succeeded(tokenInfo.TokenCount(out tokenCount)) && tokenCount > 0)
            {
                var tokens     = new IVsCommentTaskToken[tokenCount];
                var tokensEnum = default(IVsEnumCommentTaskTokens);
                if (Succeeded(tokenInfo.EnumTokens(out tokensEnum)))
                {
                    uint count;
                    if (Succeeded(tokensEnum.Next((uint)tokenCount, tokens, out count)))
                    {
                        Contract.Requires(tokenCount == count);

                        string text;
                        var    priority = new VSTASKPRIORITY[1];
                        var    result   = new List <string>();
                        foreach (var token in tokens)
                        {
                            if (Succeeded(token.Text(out text)) &&
                                Succeeded(token.Priority(priority)) &&
                                !string.IsNullOrWhiteSpace(text))
                            {
                                result.Add(string.Format("{0}:{1}", text, (int)priority[0]));
                            }
                        }

                        return(string.Join("|", result));
                    }
                }
            }

            return(string.Empty);
        }
Exemple #4
0
        // called when OnCommentTaskInfoChanged is called.
        public void Refresh()
        {
            //Get token enumerator and allocate memory
            Guid guid = typeof(IVsCommentTaskInfo).GUID;
            IVsCommentTaskInfo commentTaskInfo = null;

            try {
                commentTaskInfo = (IVsCommentTaskInfo)this.site.QueryService(guid, typeof(IVsCommentTaskInfo));
                if (commentTaskInfo == null)
                {
                    return;
                }

                int count;
                commentTaskInfo.TokenCount(out count);

                IVsEnumCommentTaskTokens commentTaskTokens = null;
                commentTaskInfo.EnumTokens(out commentTaskTokens);

                Hashtable newTokens = new Hashtable();

                //Get all tokens

                int index = 0;
                for (index = 0; index < count; index++)
                {
                    uint fetched;
                    IVsCommentTaskToken[] commentTaskToken = new IVsCommentTaskToken[1];

                    commentTaskTokens.Next(1, commentTaskToken, out fetched);
                    if (fetched == 1)
                    {
                        string           token    = null;
                        VSTASKPRIORITY[] priority = new VSTASKPRIORITY[1] {
                            VSTASKPRIORITY.TP_NORMAL
                        };
                        commentTaskToken[0].Text(out token);
                        commentTaskToken[0].Priority(priority);
                        if (token != null)
                        {
                            newTokens[token] = priority[0];
                        }
                    }
                }

                //update the token information
                this.taskTokens = newTokens;
            } catch (Exception) {
                return;
            }
        }
        private void CacheCommentTokens()
        {
            // The VS options dialog allows tokens to be entered that differ only by case (e.g., todo and TODO),
            // and it allows them to each have a different priority assigned.  However, the VS comment task provider
            // doesn't match case-insensitively, so only the last token and priority are used within a case group.
            // We'll be smarter than that and detect whether case-sensitivity is required for a token.
            Dictionary <string, TaskPriority> tempTokens = new Dictionary <string, TaskPriority>();

            if (this.VsTaskList is IVsCommentTaskInfo tokenInfo &&
                ErrorHandler.Succeeded(tokenInfo.TokenCount(out int tokenCount)) && tokenCount > 0)
            {
                var tokens = new IVsCommentTaskToken[tokenCount];
                if (ErrorHandler.Succeeded(tokenInfo.EnumTokens(out IVsEnumCommentTaskTokens tokenEnum)) &&
                    ErrorHandler.Succeeded(tokenEnum.Next((uint)tokenCount, tokens, out uint count)) && count == tokenCount)
                {
                    var priority = new VSTASKPRIORITY[1];
                    foreach (var token in tokens)
                    {
                        if (ErrorHandler.Succeeded(token.Text(out string text)) &&
                            ErrorHandler.Succeeded(token.Priority(priority)) &&
                            !string.IsNullOrWhiteSpace(text))
                        {
                            tempTokens.Add(text, (TaskPriority)priority[0]);
                        }
                    }
                }
            }

            lock (this.foregroundTokens)
            {
                this.foregroundTokens.Clear();
                var groups = tempTokens.GroupBy(pair => pair.Key, StringComparer.OrdinalIgnoreCase);
                foreach (var group in groups)
                {
                    bool isCaseSensitive = group.Count() > 1;
                    foreach (var pair in group)
                    {
                        this.foregroundTokens.Add(new CommentToken(pair.Key, pair.Value, isCaseSensitive));
                    }
                }

                this.foregroundTokensChanged = true;
            }
        }
Exemple #6
0
    // called when OnCommentTaskInfoChanged is called.
    public void Refresh() {

      //Get token enumerator and allocate memory
      Guid guid = typeof(IVsCommentTaskInfo).GUID;
      IVsCommentTaskInfo commentTaskInfo = null;
      try {
        commentTaskInfo = (IVsCommentTaskInfo)this.site.QueryService(guid, typeof(IVsCommentTaskInfo));
        if (commentTaskInfo == null) return;
      
        int count;
        commentTaskInfo.TokenCount(out count );

        IVsEnumCommentTaskTokens commentTaskTokens = null;
        commentTaskInfo.EnumTokens(out commentTaskTokens );

        Hashtable newTokens = new Hashtable();

        //Get all tokens

        int index = 0;
        for (index = 0; index < count; index++) {
          uint fetched;
          IVsCommentTaskToken[] commentTaskToken = new IVsCommentTaskToken[1];

          commentTaskTokens.Next( 1, commentTaskToken, out fetched );
          if (fetched == 1) {
            string token = null;
            VSTASKPRIORITY[] priority = new VSTASKPRIORITY[1] { VSTASKPRIORITY.TP_NORMAL };
            commentTaskToken[0].Text(out token);            
            commentTaskToken[0].Priority(priority);
            if (token != null) {
              newTokens[token] = priority[0];
            }
          }
        }
        
        //update the token information
        this.taskTokens = newTokens;

      } catch (Exception) {
        return;
      }
    }