Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if the run is the fiorst run of the paragraph
        /// </summary>
        /// <param name="run">run to check</param>
        /// <returns>true if the run is the fiorst run of the paragraph</returns>
        private static bool IsFirstRun(Run run)
        {
            Paragraph paragraph = GetParagraph(run);
            Run       firstRun  = ParagraphSearcher.GetRun(paragraph.Inlines.FirstInline);

            return(run == firstRun);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Move to the next highlight starting at the <paramref name="caretPosition"/>
        /// </summary>
        /// <param name="forward">true for next false for previous</param>
        /// <param name="caretPosition">caret position</param>
        /// <returns>the next highlight starting at the <paramref name="caretPosition"/></returns>
        internal Run MoveAndHighlightNextNextMatch(bool forward, TextPointer caretPosition)
        {
            Debug.Assert(caretPosition != null, "a caret position is allways valid");
            Debug.Assert(caretPosition.Parent != null && caretPosition.Parent is Run, "a caret PArent is allways a valid Run");
            Run caretRun = (Run)caretPosition.Parent;

            Run currentRun;

            if (this.currentHighlightedMatch != null)
            {
                // restore the curent highlighted background to plain highlighted
                this.currentHighlightedMatch.Background = ParagraphSearcher.HighlightBrush;
            }

            // If the caret is in the end of a highlight we move to the adjacent run
            // It has to be in the end because if there is a match at the begining of the file
            // and the caret has not been touched (so it is in the beginning of the file too)
            // we want to highlight this first match.
            // Considering the caller allways set the caret to the end of the highlight
            // The condition below works well for successive searchs
            // We also need to move to the adjacent run if the caret is at the first run and we
            // are moving backwards so that a search backwards when the first run is highlighted
            // and the caret is at the beginning will wrap to the end
            if ((!forward && IsFirstRun(caretRun)) ||
                ((caretPosition.GetOffsetToPosition(caretRun.ContentEnd) == 0) && ParagraphSearcher.Ishighlighted(caretRun)))
            {
                currentRun = ParagraphSearcher.GetNextRun(caretRun, forward);
            }
            else
            {
                currentRun = caretRun;
            }

            currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward);

            if (currentRun == null)
            {
                // if we could not find a next highlight wrap arround
                currentRun = ParagraphSearcher.GetFirstOrLastRun(caretRun, forward);
                currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward);
            }

            this.currentHighlightedMatch = currentRun;
            if (this.currentHighlightedMatch != null)
            {
                // restore the curent highligthed background to current highlighted
                this.currentHighlightedMatch.Background = ParagraphSearcher.CurrentHighlightBrush;
            }

            return(currentRun);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the HelpViewModel class
        /// </summary>
        /// <param name="psObj">object containing help</param>
        /// <param name="documentParagraph">paragraph in which help text is built/searched</param>
        internal HelpViewModel(PSObject psObj, Paragraph documentParagraph)
        {
            Debug.Assert(psObj != null, "ensured by caller");
            Debug.Assert(documentParagraph != null, "ensured by caller");

            this.helpBuilder = new HelpParagraphBuilder(documentParagraph, psObj);
            this.helpBuilder.BuildParagraph();
            this.searcher = new ParagraphSearcher();
            this.helpBuilder.PropertyChanged += new PropertyChangedEventHandler(this.HelpBuilder_PropertyChanged);
            this.helpTitle = string.Format(
                CultureInfo.CurrentCulture,
                HelpWindowResources.HelpTitleFormat,
                HelpParagraphBuilder.GetPropertyString(psObj, "name"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the next highlighted run starting and including <paramref name="currentRun"/>
        /// according to the direction specified in <paramref name="forward"/>
        /// </summary>
        /// <param name="currentRun">the current run</param>
        /// <param name="forward">true for next false for previous</param>
        /// <returns>
        /// the next highlighted run starting and including <paramref name="currentRun"/>
        /// according to the direction specified in <paramref name="forward"/>
        /// </returns>
        private static Run GetNextMatch(Run currentRun, bool forward)
        {
            while (currentRun != null)
            {
                if (ParagraphSearcher.Ishighlighted(currentRun))
                {
                    return(currentRun);
                }

                currentRun = ParagraphSearcher.GetNextRun(currentRun, forward);
            }

            return(currentRun);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the HelpViewModel class
        /// </summary>
        /// <param name="psObj">object containing help</param>
        /// <param name="documentParagraph">paragraph in which help text is built/searched</param>
        internal HelpViewModel(PSObject psObj, Paragraph documentParagraph)
        {
            Debug.Assert(psObj != null, "ensured by caller");
            Debug.Assert(documentParagraph != null, "ensured by caller");

            this.helpBuilder = new HelpParagraphBuilder(documentParagraph, psObj);
            this.helpBuilder.BuildParagraph();
            this.searcher = new ParagraphSearcher();
            this.helpBuilder.PropertyChanged += new PropertyChangedEventHandler(this.HelpBuilder_PropertyChanged);
            this.helpTitle = String.Format(
                CultureInfo.CurrentCulture,
                HelpWindowResources.HelpTitleFormat,
                HelpParagraphBuilder.GetPropertyString(psObj, "name"));
        }