コード例 #1
0
        public InfoBarModel(IEnumerable <IInfoBarTextSpan> textSpans, IEnumerable <IInfoBarActionItem> actionItems, ImageMoniker image = default, bool isCloseButtonVisible = true)
        {
            Validate.IsNotNull(textSpans, nameof(textSpans));
            Validate.IsNotNull(actionItems, nameof(actionItems));

            IsCloseButtonVisible = isCloseButtonVisible;
            TextSpans            = new TextSpanCollection(textSpans);
            ActionItems          = new ActionItemCollection(actionItems);
            Image = image;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Block" /> class.
        /// </summary>
        /// <param name="blocks">The ownerCollection.</param>
        /// <param name="initialBlockType">Initial type of the block.</param>
        /// <param name="text">The text.</param>
        public Block(
			ProjectBlockCollection blocks,
			BlockType initialBlockType,
			string text = "")
        {
            BlockKey = BlockKey.GetNext();
            Blocks = blocks;
            blockType = initialBlockType;
            this.text = text;
            Properties = new PropertiesDictionary();
            TextSpans = new TextSpanCollection();
            accessLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
            previouslyAnalyzedPlugins = new HashSet<IBlockAnalyzerProjectPlugin>();
        }
コード例 #3
0
        /// <summary>
        /// Formats the text using the spans, adding in error formatting if there
        /// is a text span.
        /// </summary>
        /// <param name="text">The text to format.</param>
        /// <param name="spans">The spans we need to use to format.</param>
        /// <returns>A Pango-formatted string.</returns>
        private string FormatText(
            string text,
            TextSpanCollection spans)
        {
            // Create a string builder and go through the text, one character at a time.
            var  buffer = new StringBuilder();
            bool inSpan = false;

            for (int index = 0;
                 index < text.Length;
                 index++)
            {
                // Grab the character at this position in the text.
                char c       = text[index];
                bool hasSpan = spans.Contains(index);

                // If the inSpan and hasSpan is different, we need to either
                // open or close the span.
                if (hasSpan != inSpan)
                {
                    // Add in the tag depending on if we are opening or close the tag.
                    string tag = inSpan
                                                ? "</span>"
                                                : "<span underline='error' underline_color='red' color='red'>";

                    buffer.Append(tag);

                    // Update the current inSpan state.
                    inSpan = hasSpan;
                }

                // Add in the character we've been processing.
                buffer.Append(c);
            }

            // Check to see if we were in a tag, if we are, we need to close it.
            if (inSpan)
            {
                buffer.Append("</span>");
            }

            // Return the resulting buffer.
            string markup = buffer.ToString();

            return(markup);
        }
コード例 #4
0
        public override string GetLineMarkup(
            int lineIndex,
            LineContexts lineContexts)
        {
            // We need to get a read-only lock on the block.
            Block block;

            using (blocks.AcquireBlockLock(RequestLock.Read, lineIndex, out block))
            {
                // Now that we have a block, grab the text and text spans and
                // format them. If we don't have any text spans, we can return
                // a simple formatted string.
                string             text   = block.Text;
                TextSpanCollection spans  = block.TextSpans;
                string             markup = spans.Count == 0
                                        ? PangoUtility.Escape(text)
                                        : FormatText(text, spans);

                // Return the resulting markup.
                return(markup);
            }
        }
コード例 #5
0
        /// <summary>
        /// Formats the text using the spans, adding in error formatting if there
        /// is a text span.
        /// </summary>
        /// <param name="text">The text to format.</param>
        /// <param name="spans">The spans we need to use to format.</param>
        /// <returns>A Pango-formatted string.</returns>
        private string FormatText(
			string text,
			TextSpanCollection spans)
        {
            // Create a string builder and go through the text, one character at a time.
            var buffer = new StringBuilder();
            bool inSpan = false;

            for (int index = 0;
                index < text.Length;
                index++)
            {
                // Grab the character at this position in the text.
                char c = text[index];
                bool hasSpan = spans.Contains(index);

                // If the inSpan and hasSpan is different, we need to either
                // open or close the span.
                if (hasSpan != inSpan)
                {
                    // Add in the tag depending on if we are opening or close the tag.
                    string tag = inSpan
                        ? "</span>"
                        : "<span underline='error' underline_color='red' color='red'>";

                    buffer.Append(tag);

                    // Update the current inSpan state.
                    inSpan = hasSpan;
                }

                // Add in the character we've been processing.
                buffer.Append(c);
            }

            // Check to see if we were in a tag, if we are, we need to close it.
            if (inSpan)
            {
                buffer.Append("</span>");
            }

            // Return the resulting buffer.
            string markup = buffer.ToString();
            return markup;
        }
コード例 #6
0
        public void AnalyzeBlock(
			Block block,
			int blockVersion)
        {
            // Grab the information about the block.
            string text;
            var originalMispelledWords = new TextSpanCollection();

            using (block.AcquireBlockLock(RequestLock.Read))
            {
                // If we are stale, then break out.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Grab the information from the block. We need the text and
                // alow the current spelling areas.
                text = block.Text;

                originalMispelledWords.AddRange(
                    block.TextSpans.Where(span => span.Controller == this));
            }

            // Split the word and perform spell-checking.
            var misspelledWords = new List<TextSpan>();
            IList<TextSpan> words = Splitter.SplitAndNormalize(text);
            IEnumerable<TextSpan> misspelledSpans =
                words.Where(span => !IsCorrect(span.GetText(text)));

            foreach (TextSpan span in misspelledSpans)
            {
                // We aren't correct, so add it to the list.
                span.Controller = this;

                misspelledWords.Add(span);
            }

            // Look to see if we have any change from the original spelling
            // errors and this one. This will only happen if the count is
            // identical and every one in the original list is in the new list.
            if (originalMispelledWords.Count == misspelledWords.Count)
            {
                bool isMatch = originalMispelledWords.All(misspelledWords.Contains);

                if (isMatch)
                {
                    // There are no new changes, so we don't have anything to
                    // update.
                    return;
                }
            }

            // Inside a write lock, we need to make modifications to the block's list.
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                // Check one last time to see if the block is stale.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Make the changes to the block's contents.
                block.TextSpans.Remove(this);
                block.TextSpans.AddRange(misspelledWords);

                // Raise that we changed the spelling on the block.
                block.RaiseTextSpansChanged();
            }
        }
コード例 #7
0
        public void AnalyzeBlock(
            Block block,
            int blockVersion)
        {
            // Grab the information about the block.
            string text;
            var    originalMispelledWords = new TextSpanCollection();

            using (block.AcquireBlockLock(RequestLock.Read))
            {
                // If we are stale, then break out.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Grab the information from the block. We need the text and
                // alow the current spelling areas.
                text = block.Text;

                originalMispelledWords.AddRange(
                    block.TextSpans.Where(span => span.Controller == this));
            }

            // Split the word and perform spell-checking.
            var misspelledWords                    = new List <TextSpan>();
            IList <TextSpan>       words           = Splitter.SplitAndNormalize(text);
            IEnumerable <TextSpan> misspelledSpans =
                words.Where(span => !IsCorrect(span.GetText(text)));

            foreach (TextSpan span in misspelledSpans)
            {
                // We aren't correct, so add it to the list.
                span.Controller = this;

                misspelledWords.Add(span);
            }

            // Look to see if we have any change from the original spelling
            // errors and this one. This will only happen if the count is
            // identical and every one in the original list is in the new list.
            if (originalMispelledWords.Count == misspelledWords.Count)
            {
                bool isMatch = originalMispelledWords.All(misspelledWords.Contains);

                if (isMatch)
                {
                    // There are no new changes, so we don't have anything to
                    // update.
                    return;
                }
            }

            // Inside a write lock, we need to make modifications to the block's list.
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                // Check one last time to see if the block is stale.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Make the changes to the block's contents.
                block.TextSpans.Remove(this);
                block.TextSpans.AddRange(misspelledWords);

                // Raise that we changed the spelling on the block.
                block.RaiseTextSpansChanged();
            }
        }