Inheritance: ICSharpCode.TextEditor.Document.AbstractSegment
Esempio n. 1
0
        void OnTextEditorKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.F9)
            {
                return;
            }

            ICSharpCode.TextEditor.TextArea area_obj = (ICSharpCode.TextEditor.TextArea)sender;

            ICSharpCode.TextEditor.Document.LineSegment l = area_obj.Document.GetLineSegment(area_obj.Caret.Line);
            string s = area_obj.Document.GetText(l);

            if (s.Trim().Length == 0)
            {
                return;
            }

            ICSharpCode.TextEditor.Document.BookmarkManager bm = this.textEditor.Document.BookmarkManager;

            if (bm.IsMarked(area_obj.Caret.Line))
            {
                bm.RemoveMark(bm.GetNextMark(area_obj.Caret.Line - 1));
            }
            else
            {
                this.textEditor.Document.BookmarkManager.AddMark(new Breakpoint(this._filename, this.textEditor.Document, area_obj.Caret.Line));
            }

            // this.textEditor.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, area_obj.Caret.Line));

            this.RedrawBreakpoints();

            // area_obj.IconBarMargin.Paint(area_obj.IconBarMargin.TextArea.CreateGraphics(), area_obj.IconBarMargin.TextArea.DisplayRectangle);
        }
Esempio n. 2
0
        public static int FindWordEnd(SD.Document.IDocument document, int offset)
        {
            SD.Document.LineSegment line = document.GetLineSegmentForOffset(offset);
            int endPos = line.Offset + line.Length;

            if (offset == endPos)
            {
                return(offset);
            }

            if (IsSelectableChar(document.GetCharAt(offset)))
            {
                while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
                {
                    ++offset;
                }
            }
            else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
            {
                if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                {
                    while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
                    {
                        ++offset;
                    }
                }
            }
            else
            {
                return(Math.Max(0, offset + 1));
            }

            return(offset);
        }
		static bool IsInMultilineCommentOrStringLiteral(LineSegment line)
		{
			if (line.HighlightSpanStack == null || line.HighlightSpanStack.IsEmpty) {
				return false;
			}
			return !line.HighlightSpanStack.Peek().StopEOL;
		}
 public DrawableLine(IDocument document, LineSegment line, Font monospacedFont, Font boldMonospacedFont)
 {
     this.monospacedFont = monospacedFont;
     this.boldMonospacedFont = boldMonospacedFont;
     if (line.Words != null)
     {
         foreach (TextWord word in line.Words)
         {
             if (word.Type == TextWordType.Space)
             {
                 words.Add(SimpleTextWord.Space);
             }
             else if (word.Type == TextWordType.Tab)
             {
                 words.Add(SimpleTextWord.Tab);
             }
             else
             {
                 words.Add(new SimpleTextWord(TextWordType.Word, word.Word, word.Bold, word.Color));
             }
         }
     }
     else
     {
         words.Add(new SimpleTextWord(TextWordType.Word, document.GetText(line), false, Color.Black));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Converts a DomRegion to an ISegment for the given document.
        /// </summary>
        public static ISegment ConvertRegionToSegment(IDocument document, DomRegion region)
        {
            // Single line region
            if (region.BeginLine == region.EndLine)
            {
                ICSharpCode.TextEditor.Document.LineSegment documentSegment = document.GetLineSegment(region.BeginLine);
                return(new WixDocumentLineSegment(documentSegment.Offset + region.BeginColumn,
                                                  region.EndColumn + 1 - region.BeginColumn));
            }

            // Multiple line region.
            int length      = 0;
            int startOffset = 0;

            for (int line = region.BeginLine; line <= region.EndLine; ++line)
            {
                ICSharpCode.TextEditor.Document.LineSegment currentSegment = document.GetLineSegment(line);
                if (line == region.BeginLine)
                {
                    length     += currentSegment.TotalLength - region.BeginColumn;
                    startOffset = currentSegment.Offset + region.BeginColumn;
                }
                else if (line < region.EndLine)
                {
                    length += currentSegment.TotalLength;
                }
                else
                {
                    length += region.EndColumn + 1;
                }
            }
            return(new WixDocumentLineSegment(startOffset, length));
        }
Esempio n. 6
0
		void BookmarkDocumentChanged(object sender, EventArgs e)
		{
			if (bookmark.Document != null) {
				line = bookmark.Document.GetLineSegment(Math.Min(bookmark.LineNumber, bookmark.Document.TotalNumberOfLines));
				Text = positionText + bookmark.Document.GetText(line);
			}
		}
 protected override int TryHighlightAddedAndDeletedLines(IDocument document, int line, LineSegment lineSegment)
 {
     ProcessLineSegment(document, ref line, lineSegment, "++", AppSettings.DiffAddedColor);
     ProcessLineSegment(document, ref line, lineSegment, "+ ", AppSettings.DiffAddedColor);
     ProcessLineSegment(document, ref line, lineSegment, " +", AppSettings.DiffAddedColor);
     ProcessLineSegment(document, ref line, lineSegment, "--", AppSettings.DiffRemovedColor);
     ProcessLineSegment(document, ref line, lineSegment, "- ", AppSettings.DiffRemovedColor);
     ProcessLineSegment(document, ref line, lineSegment, " -", AppSettings.DiffRemovedColor);
     return line;
 }
        /// <summary>
        /// Get the object, which was inserted under the keyword (line, at offset, with length length),
        /// returns null, if no such keyword was inserted.
        /// </summary>
        public object this[IDocument document, LineSegment line, int offset, int length]
        {
            get
            {
                if(length == 0)
                {
                    return null;
                }
                Node next = root;

                int wordOffset = line.Offset + offset;
                if (casesensitive)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)document.GetCharAt(wordOffset + i)) % 256;
                        next = next[index];

                        if (next == null)
                        {
                            return null;
                        }

                        if (next.color != null && TextUtility.RegionMatches(document, wordOffset, length, next.word))
                        {
                            return next.color;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256;

                        next = next[index];

                        if (next == null)
                        {
                            return null;
                        }

                        if (next.color != null && TextUtility.RegionMatches(document, casesensitive, wordOffset, length, next.word))
                        {
                            return next.color;
                        }
                    }
                }
                return null;
            }
        }
		protected override void MarkWords(int lineNumber, LineSegment currentLine, List<TextWord> words)
		{
			if (IsInMultilineCommentOrStringLiteral(currentLine)) {
				return;
			}
			ParseInformation parseInfo = ParserService.GetParseInformation(this.TextEditor.FileName);
			if (parseInfo == null) return;
			
			CSharpExpressionFinder finder = new CSharpExpressionFinder(parseInfo);
			Func<string, int, ExpressionResult> findExpressionMethod;
			IClass callingClass = parseInfo.MostRecentCompilationUnit.GetInnermostClass(lineNumber, 0);
			if (callingClass != null) {
				if (GetCurrentMember(callingClass, lineNumber, 0) != null) {
					findExpressionMethod = finder.FindFullExpressionInMethod;
				} else {
					findExpressionMethod = finder.FindFullExpressionInTypeDeclaration;
				}
			} else {
				findExpressionMethod = finder.FindFullExpression;
			}
			
			string lineText = this.Document.GetText(currentLine.Offset, currentLine.Length);
			bool changedLine = false;
			// now go through the word list:
			foreach (TextWord word in words) {
				if (word.IsWhiteSpace) continue;
				if (char.IsLetter(lineText[word.Offset]) || lineText[word.Offset] == '_') {
					ExpressionResult result = findExpressionMethod(lineText, word.Offset);
					if (result.Expression != null) {
						// result.Expression
						if (ICSharpCode.NRefactory.Parser.CSharp.Keywords.IsNonIdentifierKeyword(result.Expression))
							continue;
						// convert text editor to DOM coordinates:
						resolveCount++;
						ResolveResult rr = ParserService.Resolve(result, lineNumber + 1, word.Offset + 1, this.TextEditor.FileName, this.TextEditor.Text);
						if (rr is MixedResolveResult || rr is TypeResolveResult) {
							changedLine = true;
							word.SyntaxColor = this.Document.HighlightingStrategy.GetColorFor("TypeReference");
						} else if (rr == null) {
							changedLine = true;
							word.SyntaxColor = this.Document.HighlightingStrategy.GetColorFor("UnknownEntity");
						}
					}
				}
			}
			
			if (markingOutstanding && changedLine) {
				this.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber));
			}
		}
Esempio n. 10
0
 // TAB
 public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
 {
     if (document == null || line == null || color == null)
         throw new Exception();
     /*Debug.Assert(document != null);
     Debug.Assert(line != null);
     Debug.Assert(color != null);
     */
     this.document = document;
     this.line  = line;
     this.offset = offset;
     this.length = length;
     this.color = color;
     this.hasDefaultColor = hasDefaultColor;
 }
        /// <summary>
        /// Replaces the text in a line.
        /// If only whitespace at the beginning and end of the line was changed, this method
        /// only adjusts the whitespace and doesn't replace the other text.
        /// </summary>
        public static void SmartReplaceLine(IDocument document, LineSegment line, string newLineText)
        {
            if (document == null)
                throw new ArgumentNullException("document");
            if (line == null)
                throw new ArgumentNullException("line");
            if (newLineText == null)
                throw new ArgumentNullException("newLineText");
            string newLineTextTrim = newLineText.Trim(whitespaceChars);
            string oldLineText = document.GetText(line);
            if (oldLineText == newLineText)
                return;
            int pos = oldLineText.IndexOf(newLineTextTrim);
            if (newLineTextTrim.Length > 0 && pos >= 0)
            {
                document.UndoStack.StartUndoGroup();
                try
                {
                    // find whitespace at beginning
                    int startWhitespaceLength = 0;
                    while (startWhitespaceLength < newLineText.Length)
                    {
                        char c = newLineText[startWhitespaceLength];
                        if (c != ' ' && c != '\t')
                            break;
                        startWhitespaceLength++;
                    }
                    // find whitespace at end
                    int endWhitespaceLength = newLineText.Length - newLineTextTrim.Length - startWhitespaceLength;

                    // replace whitespace sections
                    int lineOffset = line.Offset;
                    document.Replace(lineOffset + pos + newLineTextTrim.Length, line.Length - pos - newLineTextTrim.Length, newLineText.Substring(newLineText.Length - endWhitespaceLength));
                    document.Replace(lineOffset, pos, newLineText.Substring(0, startWhitespaceLength));
                }
                finally
                {
                    document.UndoStack.EndUndoGroup();
                }
            }
            else
            {
                document.Replace(line.Offset, line.Length, newLineText);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Checks whether the caret is inside a set of quotes (" or ').
        /// </summary>
        bool IsInsideQuotes(TextArea textArea)
        {
            bool inside = false;

            ICSharpCode.TextEditor.Document.LineSegment line = textArea.Document.GetLineSegment(textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset));
            if (line != null)
            {
                if ((line.Offset + line.Length > textArea.Caret.Offset) &&
                    (line.Offset < textArea.Caret.Offset))
                {
                    char charAfter  = textArea.Document.GetCharAt(textArea.Caret.Offset);
                    char charBefore = textArea.Document.GetCharAt(textArea.Caret.Offset - 1);

                    if (((charBefore == '\'') && (charAfter == '\'')) ||
                        ((charBefore == '\"') && (charAfter == '\"')))
                    {
                        inside = true;
                    }
                }
            }

            return(inside);
        }
		/// <remarks>
		/// Returns true, if the line lineNumber is empty or filled with whitespaces.
		/// </remarks>
		public static bool IsEmptyLine(IDocument document, LineSegment line)
		{
			for (int i = line.Offset; i < line.Offset + line.Length; ++i) {
				char ch = document.GetCharAt(i);
				if (!Char.IsWhiteSpace(ch)) {
					return false;
				}
			}
			return true;
		}
		public LineLengthChangeEventArgs(IDocument document, LineSegment lineSegment, int moved)
			: base(document, lineSegment)
		{
			this.lengthDelta = moved;
		}
Esempio n. 15
0
		public void MarkTokens(IDocument document, List<LineSegment> inputLines)
		{
			if (Rules.Count == 0) {
				return;
			}
			
			Dictionary<LineSegment, bool> processedLines = new Dictionary<LineSegment, bool>();
			
			bool spanChanged = false;
			
			foreach (LineSegment lineToProcess in inputLines) {
				if (!processedLines.ContainsKey(lineToProcess)) {
					int lineNumber = document.GetLineNumberForOffset(lineToProcess.Offset);
					bool processNextLine = true;
					
					if (lineNumber != -1) {
						while (processNextLine && lineNumber < document.TotalNumberOfLines) {
							if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
								break;                                                // then the last line is not in the collection :)
							}
							
							processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
 							processedLines[currentLine] = true;
							++lineNumber;
						}
					}
				} 
			}
			
			if (spanChanged) {
				document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
			} else {
//				document.Caret.ValidateCaretPos();
//				document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
//				
				foreach (LineSegment lineToProcess in inputLines) {
					document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(lineToProcess.Offset)));
				}
				
			}
			document.CommitUpdate();
			currentLine = null;
		}
Esempio n. 16
0
		public void MarkTokens(IDocument document)
		{
			if (Rules.Count == 0) {
				return;
			}
			
			int lineNumber = 0;
			
			while (lineNumber < document.TotalNumberOfLines) {
				LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);
				if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
					break;                                                // then the last line is not in the collection :)
				}
				
				currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? new Stack<Span>(previousLine.HighlightSpanStack.ToArray()) : null);
				
				if (currentSpanStack != null) {
					while (currentSpanStack.Count > 0 && ((Span)currentSpanStack.Peek()).StopEOL)
					{
						currentSpanStack.Pop();
					}
					if (currentSpanStack.Count == 0) currentSpanStack = null;
				}
				
				currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];
				
				if (currentLine.Length == -1) { // happens when buffer is empty !
					return;
				}
				
				List<TextWord> words = ParseLine(document);
				// Alex: clear old words
				if (currentLine.Words != null) {
					currentLine.Words.Clear();
				}
				currentLine.Words = words;
				currentLine.HighlightSpanStack = (currentSpanStack==null || currentSpanStack.Count==0) ? null : currentSpanStack;
				
				++lineNumber;
			}
			document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
			document.CommitUpdate();
			currentLine = null;
		}
Esempio n. 17
0
		public HighlightColor GetColor(IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
		{
			return GetColor(defaultRuleSet, document, currentSegment, currentOffset, currentLength);
		}
		/// <summary>
		/// get the string, which matches the regular expression expr,
		/// in string s2 at index
		/// </summary>
		static string GetRegString(LineSegment lineSegment, char[] expr, int index, IDocument document)
		{
			int j = 0;
			StringBuilder regexpr = new StringBuilder();
			
			for (int i = 0; i < expr.Length; ++i, ++j) {
				if (index + j >= lineSegment.Length)
					break;
				
				switch (expr[i]) {
					case '@': // "special" meaning
						++i;
						switch (expr[i]) {
							case '!': // don't match the following expression
								StringBuilder whatmatch = new StringBuilder();
								++i;
								while (i < expr.Length && expr[i] != '@') {
									whatmatch.Append(expr[i++]);
								}
								break;
							case '@': // matches @
								regexpr.Append(document.GetCharAt(lineSegment.Offset + index + j));
								break;
						}
						break;
					default:
						if (expr[i] != document.GetCharAt(lineSegment.Offset + index + j)) {
							return regexpr.ToString();
						}
						regexpr.Append(document.GetCharAt(lineSegment.Offset + index + j));
						break;
				}
			}
			return regexpr.ToString();
		}
Esempio n. 19
0
 internal void Delete(ref DeferredEventList deferredEventList)
 {
     this.lineSegment = null;
     deferredEventList.AddDeletedAnchor(this);
 }
        bool MarkTokensInLine(IDocument document, int lineNumber, ref bool spanChanged)
        {
            currentLineNumber = lineNumber;
            bool        processNextLine = false;
            LineSegment previousLine    = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);

            currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? previousLine.HighlightSpanStack.Clone() : null);
            if (currentSpanStack != null)
            {
                while (!currentSpanStack.IsEmpty && currentSpanStack.Peek().StopEOL)
                {
                    currentSpanStack.Pop();
                }
                if (currentSpanStack.IsEmpty)
                {
                    currentSpanStack = null;
                }
            }

            currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];

            if (currentLine.Length == -1)               // happens when buffer is empty !
            {
                return(false);
            }

            List <TextWord> words = ParseLine(document);

            if (currentSpanStack != null && currentSpanStack.IsEmpty)
            {
                currentSpanStack = null;
            }

            // Check if the span state has changed, if so we must re-render the next line
            // This check may seem utterly complicated but I didn't want to introduce any function calls
            // or allocations here for perf reasons.
            if (currentLine.HighlightSpanStack != currentSpanStack)
            {
                if (currentLine.HighlightSpanStack == null)
                {
                    processNextLine = false;
                    foreach (Span sp in currentSpanStack)
                    {
                        if (!sp.StopEOL)
                        {
                            spanChanged     = true;
                            processNextLine = true;
                            break;
                        }
                    }
                }
                else if (currentSpanStack == null)
                {
                    processNextLine = false;
                    foreach (Span sp in currentLine.HighlightSpanStack)
                    {
                        if (!sp.StopEOL)
                        {
                            spanChanged     = true;
                            processNextLine = true;
                            break;
                        }
                    }
                }
                else
                {
                    SpanStack.Enumerator e1 = currentSpanStack.GetEnumerator();
                    SpanStack.Enumerator e2 = currentLine.HighlightSpanStack.GetEnumerator();
                    bool done = false;
                    while (!done)
                    {
                        bool blockSpanIn1 = false;
                        while (e1.MoveNext())
                        {
                            if (!((Span)e1.Current).StopEOL)
                            {
                                blockSpanIn1 = true;
                                break;
                            }
                        }
                        bool blockSpanIn2 = false;
                        while (e2.MoveNext())
                        {
                            if (!((Span)e2.Current).StopEOL)
                            {
                                blockSpanIn2 = true;
                                break;
                            }
                        }
                        if (blockSpanIn1 || blockSpanIn2)
                        {
                            if (blockSpanIn1 && blockSpanIn2)
                            {
                                if (e1.Current != e2.Current)
                                {
                                    done            = true;
                                    processNextLine = true;
                                    spanChanged     = true;
                                }
                            }
                            else
                            {
                                spanChanged     = true;
                                done            = true;
                                processNextLine = true;
                            }
                        }
                        else
                        {
                            done            = true;
                            processNextLine = false;
                        }
                    }
                }
            }
            else
            {
                processNextLine = false;
            }

            //// Alex: remove old words
            if (currentLine.Words != null)
            {
                currentLine.Words.Clear();
            }
            currentLine.Words = words;
            currentLine.HighlightSpanStack = (currentSpanStack != null && !currentSpanStack.IsEmpty) ? currentSpanStack : null;

            return(processNextLine);
        }
        protected virtual HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
        {
            HighlightColor color = null;

            if (ruleSet != null)
            {
                if (ruleSet.Reference != null)
                {
                    color = ruleSet.Highlighter.GetColor(document, currentSegment, currentOffset, currentLength);
                }
                else
                {
                    color = (HighlightColor)ruleSet.KeyWords[document, currentSegment, currentOffset, currentLength];
                }
            }
            // highlight procedures name
            if (color == null && document.ExtraWordList != null)
            {
                if (activeSpan != null && activeSpan.Rule != null)
                {
                    return(color);
                }
                int    wordOffset = currentSegment.Offset + currentOffset;
                string word       = document.GetText(wordOffset, currentLength).ToLower();
                if (word.Length > 0 && document.ExtraWordList.WordExist(word))
                {
                    color = document.ExtraWordList.WordColor;
                }
            }
            return(color);
        }
 public HighlightColor GetColor(IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
 {
     return(GetColor(defaultRuleSet, document, currentSegment, currentOffset, currentLength));
 }
        /// <summary>
        /// returns true, if the get the string s2 at index matches the expression expr
        /// </summary>
        static bool MatchExpr(LineSegment lineSegment, char[] expr, int index, IDocument document, bool ignoreCase)
        {
            for (int i = 0, j = 0; i < expr.Length; ++i, ++j)
            {
                switch (expr[i])
                {
                case '@':                         // "special" meaning
                    ++i;
                    if (i == expr.Length)
                    {
                        throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @.");
                    }
                    switch (expr[i])
                    {
                    case 'C':                                     // match whitespace or punctuation
                        if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length)
                        {
                            // nothing (EOL or SOL)
                        }
                        else
                        {
                            char ch = document.GetCharAt(lineSegment.Offset + index + j);
                            if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch))
                            {
                                return(false);
                            }
                        }
                        break;

                    case '!':                                     // don't match the following expression
                    {
                        StringBuilder whatmatch = new StringBuilder();
                        ++i;
                        while (i < expr.Length && expr[i] != '@')
                        {
                            whatmatch.Append(expr[i++]);
                        }
                        if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength)
                        {
                            int k = 0;
                            for (; k < whatmatch.Length; ++k)
                            {
                                char docChar  = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k);
                                char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
                                if (docChar != spanChar)
                                {
                                    break;
                                }
                            }
                            if (k >= whatmatch.Length)
                            {
                                return(false);
                            }
                        }
//									--j;
                        break;
                    }

                    case '-':                                     // don't match the  expression before
                    {
                        StringBuilder whatmatch = new StringBuilder();
                        ++i;
                        while (i < expr.Length && expr[i] != '@')
                        {
                            whatmatch.Append(expr[i++]);
                        }
                        if (index - whatmatch.Length >= 0)
                        {
                            int k = 0;
                            for (; k < whatmatch.Length; ++k)
                            {
                                char docChar  = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k);
                                char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
                                if (docChar != spanChar)
                                {
                                    break;
                                }
                            }
                            if (k >= whatmatch.Length)
                            {
                                return(false);
                            }
                        }
//									--j;
                        break;
                    }

                    case '@':                                     // matches @
                        if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j))
                        {
                            return(false);
                        }
                        break;
                    }
                    break;

                default:
                {
                    if (index + j >= lineSegment.Length)
                    {
                        return(false);
                    }
                    char docChar  = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j)) : document.GetCharAt(lineSegment.Offset + index + j);
                    char spanChar = ignoreCase ? Char.ToUpperInvariant(expr[i]) : expr[i];
                    if (docChar != spanChar)
                    {
                        return(false);
                    }
                    break;
                }
                }
            }
            return(true);
        }
 public LineEventArgs(Document document, LineSegment lineSegment)
 {
     this.document    = document;
     this.lineSegment = lineSegment;
 }
 public LineLengthChangeEventArgs(Document document, LineSegment lineSegment, int moved)
     : base(document, lineSegment)
 {
     this.lengthDelta = moved;
 }
Esempio n. 26
0
		void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin)
		{
			float xPos = 0;
			float fontHeight = Font.GetHeight(g);
//			bool  gotNonWhitespace = false;
			curTabIndent = 0 ;
			
			FontContainer fontContainer = TextEditorProperties.FontContainer;
			foreach (TextWord word in line.Words) {
				switch (word.Type) {
					case TextWordType.Space:
						Advance(ref xPos, ref yPos, margin.Width, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
						break;
					case TextWordType.Tab:
						Advance(ref xPos, ref yPos, margin.Width, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
						break;
					case TextWordType.Word:
//						if (!gotNonWhitespace) {
//							gotNonWhitespace = true;
//							curTabIndent    += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' ');
//						}
						g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), xPos + margin.X, yPos);
						SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, fontHeight * 100), printingStringFormat);
						Advance(ref xPos, ref yPos, margin.Width, drawingSize.Width, fontHeight);
						break;
				}
			}
		}
		public int GetVisualColumnFast(LineSegment line, int logicalColumn)
		{
			int lineOffset = line.Offset;
			int tabIndent = Document.TextEditorProperties.TabIndent;
			int guessedColumn = 0;
			for (int i = 0; i < logicalColumn; ++i) {
				char ch;
				if (i >= line.Length) {
					ch = ' ';
				} else {
					ch = Document.GetCharAt(lineOffset + i);
				}
				switch (ch) {
					case '\t':
						guessedColumn += tabIndent;
						guessedColumn = (guessedColumn / tabIndent) * tabIndent;
						break;
					default:
						++guessedColumn;
						break;
				}
			}
			return guessedColumn;
		}
 protected virtual void OnParsedLine(IDocument document, LineSegment currentLine, List <TextWord> words)
 {
 }
		protected virtual void OnParsedLine(IDocument document, LineSegment currentLine, List<TextWord> words)
		{
		}
 internal TextAnchor(LineSegment lineSegment, int columnNumber)
 {
     Line         = lineSegment;
     ColumnNumber = columnNumber;
 }
		/// <summary>
		/// returns true, if the get the string s2 at index matches the expression expr
		/// </summary>
		static bool MatchExpr(LineSegment lineSegment, char[] expr, int index, IDocument document, bool ignoreCase)
		{
			for (int i = 0, j = 0; i < expr.Length; ++i, ++j) {
				switch (expr[i]) {
					case '@': // "special" meaning
						++i;
						if (i < expr.Length) {
							switch (expr[i]) {
								case 'C': // match whitespace or punctuation
									if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length) {
										// nothing (EOL or SOL)
									} else {
										char ch = document.GetCharAt(lineSegment.Offset + index + j);
										if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch)) {
											return false;
										}
									}
									break;
								case '!': // don't match the following expression
									{
										StringBuilder whatmatch = new StringBuilder();
										++i;
										while (i < expr.Length && expr[i] != '@') {
											whatmatch.Append(expr[i++]);
										}
										if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength) {
											int k = 0;
											for (; k < whatmatch.Length; ++k) {
												char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k);
												char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
												if (docChar != spanChar) {
													break;
												}
											}
											if (k >= whatmatch.Length) {
												return false;
											}
										}
//									--j;
										break;
									}
								case '-': // don't match the  expression before
									{
										StringBuilder whatmatch = new StringBuilder();
										++i;
										while (i < expr.Length && expr[i] != '@') {
											whatmatch.Append(expr[i++]);
										}
										if (index - whatmatch.Length >= 0) {
											int k = 0;
											for (; k < whatmatch.Length; ++k) {
												char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k);
												char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
												if (docChar != spanChar)
													break;
											}
											if (k >= whatmatch.Length) {
												return false;
											}
										}
//									--j;
										break;
									}
								case '@': // matches @
									if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j)) {
										return false;
									}
									break;
							}
						}
						break;
					default:
						{
							if (index + j >= lineSegment.Length) {
								return false;
							}
							char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j)) : document.GetCharAt(lineSegment.Offset + index + j);
							char spanChar = ignoreCase ? Char.ToUpperInvariant(expr[i]) : expr[i];
							if (docChar != spanChar) {
								return false;
							}
							break;
						}
				}
			}
			return true;
		}
Esempio n. 32
0
 public RBNode(LineSegment lineSegment)
 {
     this.lineSegment = lineSegment;
     this.count       = 1;
     this.totalLength = lineSegment.TotalLength;
 }
Esempio n. 33
0
		HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
		{
			if (ruleSet != null) {
				if (ruleSet.Reference != null) {
					return ruleSet.Highlighter.GetColor(document, currentSegment, currentOffset, currentLength);
				} else {
					return (HighlightColor)ruleSet.KeyWords[document,  currentSegment, currentOffset, currentLength];
				}				
			}
			return null;
		}
 protected virtual HighlightColor GetColor(HighlightRuleSet ruleSet, IDocument document, LineSegment currentSegment, int currentOffset, int currentLength)
 {
     if (ruleSet != null)
     {
         if (ruleSet.Reference != null)
         {
             return(ruleSet.Highlighter.GetColor(document, currentSegment, currentOffset, currentLength));
         }
         else
         {
             return((HighlightColor)ruleSet.KeyWords[document, currentSegment, currentOffset, currentLength]);
         }
     }
     return(null);
 }
Esempio n. 35
0
		bool MarkTokensInLine(IDocument document, int lineNumber, ref bool spanChanged)
		{
			bool processNextLine = false;
			LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);
			
			currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? new Stack<Span>(previousLine.HighlightSpanStack.ToArray()) : null);
			if (currentSpanStack != null) {
				while (currentSpanStack.Count > 0 && currentSpanStack.Peek().StopEOL) {
					currentSpanStack.Pop();
				}
				if (currentSpanStack.Count == 0) {
					currentSpanStack = null;
				}
			}
			
			currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];
			
			if (currentLine.Length == -1) { // happens when buffer is empty !
				return false;
			}
			
			List<TextWord> words = ParseLine(document);
			
			if (currentSpanStack != null && currentSpanStack.Count == 0) {
				currentSpanStack = null;
			}
			
			// Check if the span state has changed, if so we must re-render the next line
			// This check may seem utterly complicated but I didn't want to introduce any function calls
			// or alllocations here for perf reasons.
			if(currentLine.HighlightSpanStack != currentSpanStack) {
				if (currentLine.HighlightSpanStack == null) {
					processNextLine = false;
					foreach (Span sp in currentSpanStack) {
						if (!sp.StopEOL) {
							spanChanged = true;
							processNextLine = true;
							break;
						}
					}
				} else if (currentSpanStack == null) {
					processNextLine = false;
					foreach (Span sp in currentLine.HighlightSpanStack) {
						if (!sp.StopEOL) {
							spanChanged = true;
							processNextLine = true;
							break;
						}
					}
				} else {
					IEnumerator<Span> e1 = currentSpanStack.GetEnumerator();
					IEnumerator<Span> e2 = currentLine.HighlightSpanStack.GetEnumerator();
					bool done = false;
					while (!done) {
						bool blockSpanIn1 = false;
						while (e1.MoveNext()) {
							if (!((Span)e1.Current).StopEOL) {
								blockSpanIn1 = true;
								break;
							}
						}
						bool blockSpanIn2 = false;
						while (e2.MoveNext()) {
							if (!((Span)e2.Current).StopEOL) {
								blockSpanIn2 = true;
								break;
							}
						}
						if (blockSpanIn1 || blockSpanIn2) {
							if (blockSpanIn1 && blockSpanIn2) {
								if (e1.Current != e2.Current) {
									done = true;
									processNextLine = true;
									spanChanged = true;
								}											
							} else {
								spanChanged = true;
								done = true;
								processNextLine = true;
							}
						} else {
							done = true;
							processNextLine = false;
						}
					}
				}
			} else {
				processNextLine = false;
			}
			
//// Alex: remove old words
			if (currentLine.Words!=null) currentLine.Words.Clear();
			currentLine.Words = words;
			currentLine.HighlightSpanStack = (currentSpanStack != null && currentSpanStack.Count > 0) ? currentSpanStack : null;
			
			return processNextLine;
		}
		public bool Next()
		{
			if (lineDirty) {
				DefaultFormattingStrategy.SmartReplaceLine(doc, line, text);
				lineDirty = false;
				++changedLines;
			}
			++num;
			if (num > maxLine) return false;
			line = doc.GetLineSegment(num);
			text = doc.GetText(line);
			return true;
		}
		public LineEventArgs(IDocument document, LineSegment lineSegment)
		{
			this.document = document;
			this.lineSegment = lineSegment;
		}
 public LineLengthChangeEventArgs(IDocument document, LineSegment lineSegment, int moved, bool editLineState)
     : base(document, lineSegment)
 {
     this.lengthDelta   = moved;
     this.editLineState = editLineState;
 }
Esempio n. 39
0
		void PrintWords(LineSegment lineSegment, StringBuilder b)
		{
			string currentSpan = null;
			foreach (TextWord word in lineSegment.Words) {
				if (word.Type == TextWordType.Space) {
					b.Append(' ');
				} else if (word.Type == TextWordType.Tab) {
					b.Append('\t');
				} else {
					string newSpan = GetStyle(word);
					if (currentSpan != newSpan) {
						if (currentSpan != null) b.Append("</span>");
						if (newSpan != null) {
							b.Append("<span");
							WriteStyle(newSpan, b);
							b.Append('>');
						}
						currentSpan = newSpan;
					}
					b.Append(HtmlEncode(word.Word));
				}
			}
			if (currentSpan != null) b.Append("</span>");
		}
        public static string GetLineAsString(Document document, int lineNumber)
        {
            LineSegment line = document.GetLineSegment(lineNumber);

            return(document.GetText(line.Offset, line.Length));
        }
Esempio n. 41
0
		// btw. I hate source code duplication ... but this time I don't care !!!!
		float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
		{
			float xPos = 0;
			float yPos = 0;
			float fontHeight = Font.GetHeight(g);
//			bool  gotNonWhitespace = false;
			curTabIndent = 0;
			FontContainer fontContainer = TextEditorProperties.FontContainer;
			foreach (TextWord word in line.Words) {
				switch (word.Type) {
					case TextWordType.Space:
						Advance(ref xPos, ref yPos, maxWidth, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
						break;
					case TextWordType.Tab:
						Advance(ref xPos, ref yPos, maxWidth, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
						break;
					case TextWordType.Word:
//						if (!gotNonWhitespace) {
//							gotNonWhitespace = true;
//							curTabIndent    += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' ');
//						}
						SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, fontHeight * 100), printingStringFormat);
						Advance(ref xPos, ref yPos, maxWidth, drawingSize.Width, fontHeight);
						break;
				}
			}
			return yPos + fontHeight;
		}
 public HighlightColor GetColor(IDocument document, LineSegment keyWord, int index, int length)
 {
     return baseStrategy.GetColor(document, keyWord, index, length);
 }
Esempio n. 43
0
 void SetSegmentLength(LineSegment segment, int newTotalLength)
 {
     int delta = newTotalLength - segment.TotalLength;
     if (delta != 0) {
         lineCollection.SetSegmentLength(segment, newTotalLength);
         OnLineLengthChanged(new LineLengthChangeEventArgs(document, segment, delta));
     }
 }
		public virtual void MarkTokens(IDocument document, List<LineSegment> inputLines)
		{
			if (Rules.Count == 0) {
				return;
			}
			
			Dictionary<LineSegment, bool> processedLines = new Dictionary<LineSegment, bool>();
			
			bool spanChanged = false;
			int documentLineSegmentCount = document.LineSegmentCollection.Count;
			
			foreach (LineSegment lineToProcess in inputLines) {
				if (!processedLines.ContainsKey(lineToProcess)) {
					int lineNumber = lineToProcess.LineNumber;
					bool processNextLine = true;
					
					if (lineNumber != -1) {
						while (processNextLine && lineNumber < documentLineSegmentCount) {
							processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
							processedLines[currentLine] = true;
							++lineNumber;
						}
					}
				}
			}
			
			if (spanChanged || inputLines.Count > 20) {
				// if the span was changed (more than inputLines lines had to be reevaluated)
				// or if there are many lines in inputLines, it's faster to update the whole
				// text area instead of many small segments
				document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
			} else {
//				document.Caret.ValidateCaretPos();
//				document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
//
				foreach (LineSegment lineToProcess in inputLines) {
					document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineToProcess.LineNumber));
				}
				
			}
			document.CommitUpdate();
			currentLine = null;
		}
		int GetLogicalColumnInternal(Graphics g, LineSegment line, int start, int end, ref int drawingPos, int targetVisualPosX)
		{
			if (start == end)
				return end;
			Debug.Assert(start < end);
			Debug.Assert(drawingPos < targetVisualPosX);
			
			int tabIndent = Document.TextEditorProperties.TabIndent;
			
			/*float spaceWidth = SpaceWidth;
			float drawingPos = 0;
			LineSegment currentLine = Document.GetLineSegment(logicalLine);
			List<TextWord> words = currentLine.Words;
			if (words == null) return 0;
			int wordCount = words.Count;
			int wordOffset = 0;
			FontContainer fontContainer = TextEditorProperties.FontContainer;
			 */
			FontContainer fontContainer = TextEditorProperties.FontContainer;
			
			List<TextWord> words = line.Words;
			if (words == null) return 0;
			int wordOffset = 0;
			for (int i = 0; i < words.Count; i++) {
				TextWord word = words[i];
				if (wordOffset >= end) {
					return wordOffset;
				}
				if (wordOffset + word.Length >= start) {
					int newDrawingPos;
					switch (word.Type) {
						case TextWordType.Space:
							newDrawingPos = drawingPos + spaceWidth;
							if (newDrawingPos >= targetVisualPosX)
								return IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos) ? wordOffset : wordOffset+1;
							break;
						case TextWordType.Tab:
							// go to next tab position
							drawingPos = (int)((drawingPos + MinTabWidth) / tabIndent / WideSpaceWidth) * tabIndent * WideSpaceWidth;
							newDrawingPos = drawingPos + tabIndent * WideSpaceWidth;
							if (newDrawingPos >= targetVisualPosX)
								return IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos) ? wordOffset : wordOffset+1;
							break;
						case TextWordType.Word:
							int wordStart = Math.Max(wordOffset, start);
							int wordLength = Math.Min(wordOffset + word.Length, end) - wordStart;
							string text = Document.GetText(line.Offset + wordStart, wordLength);
							Font font = word.GetFont(fontContainer) ?? fontContainer.RegularFont;
							newDrawingPos = drawingPos + MeasureStringWidth(g, text, font);
							if (newDrawingPos >= targetVisualPosX) {
								for (int j = 0; j < text.Length; j++) {
									newDrawingPos = drawingPos + MeasureStringWidth(g, text[j].ToString(), font);
									if (newDrawingPos >= targetVisualPosX) {
										if (IsNearerToAThanB(targetVisualPosX, drawingPos, newDrawingPos))
											return wordStart + j;
										else
											return wordStart + j + 1;
									}
									drawingPos = newDrawingPos;
								}
								return wordStart + text.Length;
							}
							break;
						default:
							throw new NotSupportedException();
					}
					drawingPos = newDrawingPos;
				}
				wordOffset += word.Length;
			}
			return wordOffset;
		}
Esempio n. 46
0
 internal TextAnchor(LineSegment lineSegment, int columnNumber)
 {
     this.lineSegment  = lineSegment;
     this.columnNumber = columnNumber;
 }
		bool TryDeclarationTypeInference(SharpDevelopTextAreaControl editor, LineSegment curLine)
		{
			string lineText = editor.Document.GetText(curLine.Offset, curLine.Length);
			ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.CSharp, new System.IO.StringReader(lineText));
			Token typeToken = lexer.NextToken();
			if (typeToken.kind == CSTokens.Question) {
				if (lexer.NextToken().kind == CSTokens.Identifier) {
					Token t = lexer.NextToken();
					if (t.kind == CSTokens.Assign) {
						string expr = lineText.Substring(t.col);
						LoggingService.Debug("DeclarationTypeInference: >" + expr + "<");
						ResolveResult rr = ParserService.Resolve(new ExpressionResult(expr),
						                                         editor.ActiveTextAreaControl.Caret.Line + 1,
						                                         t.col, editor.FileName,
						                                         editor.Document.TextContent);
						if (rr != null && rr.ResolvedType != null) {
							ClassFinder context = new ClassFinder(editor.FileName, editor.ActiveTextAreaControl.Caret.Line, t.col);
							if (CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context))
								CSharpAmbience.Instance.ConversionFlags = ConversionFlags.None;
							else
								CSharpAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames;
							string typeName = CSharpAmbience.Instance.Convert(rr.ResolvedType);
							editor.Document.Replace(curLine.Offset + typeToken.col - 1, 1, typeName);
							editor.ActiveTextAreaControl.Caret.Column += typeName.Length - 1;
							return true;
						}
					}
				}
			}
			return false;
		}
Esempio n. 48
0
		public void AddRemovedLine(LineSegment line)
		{
			if (removedLines == null)
				removedLines = new List<LineSegment>();
			removedLines.Add(line);
		}