Example #1
0
        public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            int markerStart = base.Offset;
            int markerEnd   = base.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.SetSourceColor(background(editor));
                cr.RoundedRectangle(@from + 2.5, y + 0.5, to - @from, editor.LineHeight - 1, 2);                  // 2.5 to make space for the column guideline

                /* TODO: EditorTheme - do we need a border here ?
                 * if (background(editor).HasBorderColor) {
                 *      cr.FillPreserve ();
                 *
                 *      cr.SetSourceColor (background(editor).BorderColor);
                 *      cr.Stroke ();
                 * } else {*/
                cr.Fill();
//				}
            }
        }
Example #2
0
            public bool DrawBackground(TextEditor editor, Cairo.Context cr, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, double y, double startXPos, double endXPos, ref bool drawBg)
            {
                drawBg = false;
                if (selectionStart >= 0 || editor.CurrentMode is TextLinkEditMode)
                {
                    return(true);
                }
                foreach (ISegment usage in Usages)
                {
                    int markerStart = usage.Offset;
                    int markerEnd   = usage.EndOffset;

                    if (markerEnd < startOffset || markerStart > endOffset)
                    {
                        return(true);
                    }

                    double @from;
                    double to;

                    if (markerStart < startOffset && endOffset < markerEnd)
                    {
                        @from = startXPos;
                        to    = endXPos;
                    }
                    else
                    {
                        int start = startOffset < markerStart ? markerStart : startOffset;
                        int end   = endOffset < markerEnd ? endOffset : markerEnd;

                        uint curIndex = 0, byteIndex = 0;
                        TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                        int x_pos = layout.Layout.IndexToPos((int)byteIndex).X;

                        @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                        TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                        x_pos = layout.Layout.IndexToPos((int)byteIndex).X;

                        to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                    }

                    @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
                    to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
                    if (@from < to)
                    {
                        cr.Color = (HslColor)editor.ColorStyle.BracketHighlightRectangle.BackgroundColor;
                        cr.Rectangle(@from + 1, y + 1, to - @from - 1, editor.LineHeight - 2);
                        cr.Fill();

                        cr.Color = (HslColor)editor.ColorStyle.BracketHighlightRectangle.Color;
                        cr.Rectangle(@from, y, to - @from, editor.LineHeight - 1);
                        cr.Fill();
                    }
                }
                return(true);
            }
Example #3
0
            public bool DrawBackground(TextEditor editor, Gdk.Drawable win, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, int y, int startXPos, int endXPos, ref bool drawBg)
            {
                drawBg = false;
                if (selectionStart >= 0 || editor.CurrentMode is TextLinkEditMode)
                {
                    return(true);
                }
                foreach (ISegment usage in Usages)
                {
                    int markerStart = usage.Offset;
                    int markerEnd   = usage.EndOffset;

                    if (markerEnd < startOffset || markerStart > endOffset)
                    {
                        return(true);
                    }

                    int @from;
                    int to;

                    if (markerStart < startOffset && endOffset < markerEnd)
                    {
                        @from = startXPos;
                        to    = endXPos;
                    }
                    else
                    {
                        int start = startOffset < markerStart ? markerStart : startOffset;
                        int end   = endOffset < markerEnd ? endOffset : markerEnd;

                        uint curIndex = 0, byteIndex = 0;
                        TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                        int x_pos = layout.Layout.IndexToPos((int)byteIndex).X;

                        @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                        TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                        x_pos = layout.Layout.IndexToPos((int)byteIndex).X;

                        to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                    }

                    @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
                    to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
                    if (@from < to)
                    {
                        using (Gdk.GC gc = new Gdk.GC(win)) {
                            gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.BackgroundColor;
                            win.DrawRectangle(gc, true, @from + 1, y + 1, to - @from - 1, editor.LineHeight - 2);
                            gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.Color;
                            win.DrawRectangle(gc, false, @from, y, to - @from, editor.LineHeight - 1);
                        }
                    }
                }
                return(true);
            }
Example #4
0
        public int Replace(int offset, int count, string value)
        {
            StringBuilder sb = new StringBuilder();

            if (value != null)
            {
                bool             convertTabs = Options.TabsToSpaces;
                DocumentLocation loc         = Document.OffsetToLocation(offset);
                for (int i = 0; i < value.Length; i++)
                {
                    char ch = value[i];
                    switch (ch)
                    {
                    case '\u00A0':                     // convert non breaking spaces to standard spaces.
                        sb.Append(' ');
                        break;

                    case '\t':
                        if (convertTabs)
                        {
                            int tabWidth = TextViewMargin.GetNextTabstop(this, loc.Column) - loc.Column;
                            sb.Append(new string (' ', tabWidth));
                            loc.Column += tabWidth;
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case '\r':
                        if (i + 1 < value.Length && value[i + 1] == '\n')
                        {
                            i++;
                        }
                        goto case '\n';

                    case '\n':
                        sb.Append(EolMarker);
                        loc.Line++;
                        loc.Column = 0;
                        break;

                    default:
                        sb.Append(ch);
                        loc.Column++;
                        break;
                    }
                }
            }

            ((IBuffer)document).Replace(offset, count, sb.ToString());
            return(sb.Length);
        }
        public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = base.Offset;
            int markerEnd   = base.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.SetSourceColor(background.Color);
                cr.RoundedRectangle(@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
                cr.FillPreserve();

                if (background.HasBorderColor)
                {
                    cr.SetSourceColor(background.BorderColor);
                    cr.Stroke();
                }
            }
        }
Example #6
0
        public string FormatString(DocumentLocation loc, string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return("");
            }
            StringBuilder sb          = new StringBuilder();
            bool          convertTabs = Options.TabsToSpaces;

            for (int i = 0; i < str.Length; i++)
            {
                char ch = str [i];
                switch (ch)
                {
                case '\u00A0':                 // convert non breaking spaces to standard spaces.
                    sb.Append(' ');
                    break;

                case '\t':
                    if (convertTabs)
                    {
                        int tabWidth = TextViewMargin.GetNextTabstop(this, loc.Column) - loc.Column;
                        sb.Append(new string (' ', tabWidth));
                        loc.Column += tabWidth;
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case '\r':
                    if (i + 1 < str.Length && str [i + 1] == '\n')
                    {
                        i++;
                    }
                    goto case '\n';

                case '\n':
                    sb.Append(EolMarker);
                    loc.Line++;
                    loc.Column = 0;
                    break;

                default:
                    sb.Append(ch);
                    loc.Column++;
                    break;
                }
            }
            return(sb.ToString());
        }
Example #7
0
        public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = Offset;
            int markerEnd   = EndOffset;

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.Text, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.Text, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from <= to)
            {
                if (metrics.TextEndOffset < markerEnd)
                {
                    to = metrics.WholeLineWidth + metrics.TextRenderStartPosition;
                }

                var c1 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background);
                var c2 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Selection);
                cr.SetSourceRGB((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2);
                cr.Rectangle(@from, y, to - @from, metrics.LineHeight);
                cr.Fill();
            }
        }
Example #8
0
        public static void InsertTab(TextEditorData data)
        {
            if (!data.CanEditSelection)
            {
                return;
            }
            if (data.IsMultiLineSelection && data.MainSelection.SelectionMode != SelectionMode.Block)
            {
                IndentSelection(data);
                return;
            }
            using (var undo = data.OpenUndoGroup()) {
                string indentationString  = "\t";
                bool   convertTabToSpaces = data.Options.TabsToSpaces;

                if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs)
                {
                    for (int i = 1; i < data.Caret.Column; i++)
                    {
                        if (data.Document.GetCharAt(data.Caret.Offset - i) != '\t')
                        {
                            convertTabToSpaces = true;
                            break;
                        }
                    }
                }

                if (convertTabToSpaces)
                {
                    DocumentLocation visualLocation = data.LogicalToVisualLocation(data.Caret.Location);
                    int tabWidth = TextViewMargin.GetNextTabstop(data, visualLocation.Column) - visualLocation.Column;
                    indentationString = new string (' ', tabWidth);
                }
                if (data.IsMultiLineSelection && data.MainSelection.SelectionMode == SelectionMode.Block)
                {
                    data.InsertAtCaret(indentationString);
                }
                else
                {
                    if (data.IsSomethingSelected)
                    {
                        data.DeleteSelectedText();
                    }
                    int length = data.Insert(data.Caret.Offset, indentationString);
                    data.Caret.Column += length;
                }
            }
        }
        public int GetVisualColumn(TextEditorData editor, int logicalColumn)
        {
            int result = 0;

            for (int i = 0; i < logicalColumn; i++)
            {
                if (i < EditableLength && editor.Document.GetCharAt(Offset + i) == '\t')
                {
                    result = TextViewMargin.GetNextTabstop(editor, result);
                }
                else
                {
                    result++;
                }
            }
            return(result);
        }
Example #10
0
        public int GetLogicalColumn(TextEditorData editor, int visualColumn)
        {
            int curVisualColumn = 0;

            for (int i = 0; i < EditableLength; i++)
            {
                int curOffset = Offset + i;
                if (curOffset < editor.Document.Length && editor.Document.GetCharAt(curOffset) == '\t')
                {
                    curVisualColumn = TextViewMargin.GetNextTabstop(editor, curVisualColumn);
                }
                else
                {
                    curVisualColumn++;
                }
                if (curVisualColumn > visualColumn)
                {
                    return(i);
                }
            }
            return(EditableLength + (visualColumn - curVisualColumn));
        }
Example #11
0
        public int GetLogicalColumn(TextEditorData editor, int visualColumn)
        {
            int curVisualColumn = 1;
            int offset          = Offset;
            int max             = offset + Length;

            for (int i = offset; i < max; i++)
            {
                if (i < editor.Document.TextLength && editor.Document.GetCharAt(i) == '\t')
                {
                    curVisualColumn = TextViewMargin.GetNextTabstop(editor, curVisualColumn);
                }
                else
                {
                    curVisualColumn++;
                }
                if (curVisualColumn > visualColumn)
                {
                    return(i - offset + 1);
                }
            }
            return(Length + (visualColumn - curVisualColumn) + 1);
        }
Example #12
0
        public TextArea(TextEditor editor)
        {
            this.editor = editor;

            CanGetFocus = true;

            lineNumberMargin = new LineNumberMargin(editor);
            paddingMargin    = new PaddingMargin(5);
            textViewMargin   = new TextViewMargin(editor);

            margins.Add(lineNumberMargin);
            margins.Add(paddingMargin);
            margins.Add(textViewMargin);

            contextMenu = new Menu();

            cutMenuItem          = new MenuItem("Cut");
            cutMenuItem.Clicked += (sender, e) => Cut();
            contextMenu.Items.Add(cutMenuItem);

            copyMenuItem          = new MenuItem("Copy");
            copyMenuItem.Clicked += (sender, e) => Copy();
            contextMenu.Items.Add(copyMenuItem);

            pasteMenuItem          = new MenuItem("Paste");
            pasteMenuItem.Clicked += (sender, e) => Paste();
            contextMenu.Items.Add(pasteMenuItem);

            contextMenu.Items.Add(new SeparatorMenuItem());

            selectallMenuItem          = new MenuItem("Select All");
            selectallMenuItem.Clicked += (sender, e) => SelectAll();
            contextMenu.Items.Add(selectallMenuItem);

            ButtonPressed += HandleButtonPressed;
        }
        public QuickTaskOverviewMode(QuickTaskStrip parent)
        {
            this.parentStrip = parent;
            Events          |= EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.ButtonMotionMask |
                               EventMask.PointerMotionMask | EventMask.LeaveNotifyMask | EventMask.EnterNotifyMask;
            vadjustment = this.parentStrip.VAdjustment;

            vadjustment.ValueChanged        += RedrawOnVAdjustmentChange;
            vadjustment.Changed             += RedrawOnVAdjustmentChange;
            parentStrip.TaskProviderUpdated += RedrawOnUpdate;
            TextEditor = parent.TextEditor;
            caret      = TextEditor.Caret;
            //			caret.PositionChanged += CaretPositionChanged;
            TextEditor.HighlightSearchPatternChanged += RedrawOnUpdate;
            textViewMargin = TextEditor.TextViewMargin;
            textViewMargin.SearchRegionsUpdated    += RedrawOnUpdate;
            textViewMargin.MainSearchResultChanged += RedrawOnUpdate;
            heightTree = TextEditor.GetTextEditorData().HeightTree;
            heightTree.LineUpdateFrom += HandleLineUpdateFrom;
            TextEditor.HighlightSearchPatternChanged += HandleHighlightSearchPatternChanged;
            HasTooltip = true;

            fadeInStage.ActorStep += delegate(Actor <QuickTaskOverviewMode> actor) {
                barColorValue = actor.Percent;
                return(true);
            };
            fadeInStage.Iteration += (sender, e) => QueueDraw();

            fadeOutStage.ActorStep += delegate(Actor <QuickTaskOverviewMode> actor) {
                barColorValue = 1 - actor.Percent;
                return(true);
            };
            fadeOutStage.Iteration += (sender, e) => QueueDraw();

            fadeInStage.UpdateFrequency = fadeOutStage.UpdateFrequency = 10;
        }
Example #14
0
 public double GetLineHeight(int logicalLineNumber)
 {
     return(TextViewMargin.GetLineHeight(logicalLineNumber));
 }
Example #15
0
 public double GetLineHeight(DocumentLine line)
 {
     return(TextViewMargin.GetLineHeight(line));
 }
Example #16
0
 public double LineToY(int logicalLine)
 {
     return(TextViewMargin.LineToY(logicalLine));
 }
Example #17
0
 /// <summary>
 /// Calculates the line number at line start (in one visual line could be several logical lines be displayed).
 /// </summary>
 public int YToLine(double yPos)
 {
     return(TextViewMargin.YToLine(yPos));
 }
Example #18
0
 public Cairo.Point LocationToPoint(DocumentLocation loc, bool useAbsoluteCoordinates)
 {
     return(TextViewMargin.LocationToPoint(loc, useAbsoluteCoordinates));
 }
        public override void DrawBackground(Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = usage.Offset;
            int markerEnd   = usage.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                HslColor colorStyle;
                if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write ||
                    (usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton)
                {
                    colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.ChangingUsagesRectangle);
                    if (colorStyle.Alpha == 0.0)
                    {
                        colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle);
                    }
                }
                else
                {
                    colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle);
                }

                using (var lg = new LinearGradient(@from + 1, y + 1.5, to, y + editor.LineHeight - 1)) {
                    lg.AddColorStop(0, colorStyle);
                    lg.AddColorStop(1, colorStyle);
                    cr.SetSource(lg);
                    cr.RoundedRectangle(@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2);
                    cr.FillPreserve();
                }
                // TODO: EditorTheme : do we need the border ?!
                cr.SetSourceColor(colorStyle);
                cr.Stroke();
            }
        }
Example #20
0
 public Cairo.Point LocationToPoint(DocumentLocation loc)
 {
     return(TextViewMargin.LocationToPoint(loc));
 }
Example #21
0
//		void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
//		{
//			if (TreeIter.Zero.Equals (iter))
//				return;
//			var lineRenderer = (CellRendererText)cell;
//			var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
//			if (searchResult == null)
//				return;
//
//			Document doc = GetDocument (searchResult);
//			int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
//			bool didRead = (bool)store.GetValue (iter, DidReadColumn);
//			lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead);
//		}
//
        void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            if (TreeIter.Zero.Equals(iter))
            {
                return;
            }
            var textRenderer = (CellRendererText)cell;
            var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn);

            if (searchResult == null || searchResult.Offset < 0)
            {
                textRenderer.Markup = "Invalid search result";
                return;
            }

            var doc = GetDocument(searchResult);

            if (doc == null)
            {
                textRenderer.Markup = "Can't create document for:" + searchResult.FileName;
                return;
            }
            bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter);

            if (searchResult.Markup == null)
            {
                if (searchResult.LineNumber <= 0)
                {
                    searchResult.LineNumber = doc.OffsetToLineNumber(searchResult.Offset);
                }
                DocumentLine line = doc.GetLine(searchResult.LineNumber);
                if (line == null)
                {
                    textRenderer.Markup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset;
                    return;
                }
                int indent = line.GetIndentation(doc).Length;
                var data   = new Mono.TextEditor.TextEditorData(doc);
                data.ColorStyle = highlightStyle;
                var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent);
                int col      = searchResult.Offset - line.Offset - indent;
                // search result contained part of the indent.
                if (col + searchResult.Length < lineText.Length)
                {
                    lineText = doc.GetTextAt(line.Offset, line.Length);
                }

                var markup = doc.SyntaxMode != null?
                             data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) :
                                 GLib.Markup.EscapeText(lineText);

                searchResult.Markup = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize)));

                uint start;
                uint end;
                try {
                    start = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col);
                    end   = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col + searchResult.Length);
                } catch (Exception e) {
                    LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e);
                    return;
                }
                searchResult.StartIndex = start;
                searchResult.EndIndex   = end;
            }


            try {
                textRenderer.Markup = searchResult.Markup;

                if (!isSelected)
                {
                    var    searchColor = highlightStyle.SearchResult.Color;
                    double b1          = Mono.TextEditor.HslColor.Brightness(searchColor);
                    double b2          = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground));
                    double delta       = Math.Abs(b1 - b2);
                    if (delta < 0.1)
                    {
                        Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color;
                        if (color1.L + 0.5 > 1.0)
                        {
                            color1.L -= 0.5;
                        }
                        else
                        {
                            color1.L += 0.5;
                        }
                        searchColor = color1;
                    }
                    var attr = new Pango.AttrBackground((ushort)(searchColor.R * ushort.MaxValue), (ushort)(searchColor.G * ushort.MaxValue), (ushort)(searchColor.B * ushort.MaxValue));
                    attr.StartIndex = searchResult.StartIndex;
                    attr.EndIndex   = searchResult.EndIndex;

                    using (var list = textRenderer.Attributes.Copy()) {
                        list.Insert(attr);
                        textRenderer.Attributes = list;
                    }
                }
            } catch (Exception e) {
                LoggingService.LogError("Error whil setting the text renderer markup to: " + searchResult.Markup, e);
            }
        }
Example #22
0
        public string GetMarkup(Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent, bool useColors, bool replaceTabs)
        {
            int indentLength = GetIndentLength(doc, offset, length, false);
            int curOffset    = offset;

            StringBuilder result = new StringBuilder();

            while (curOffset < offset + length && curOffset < doc.Length)
            {
                LineSegment        line       = doc.GetLineByOffset(curOffset);
                int                toOffset   = System.Math.Min(line.Offset + line.EditableLength, offset + length);
                Stack <ChunkStyle> styleStack = new Stack <ChunkStyle> ();
                for (Chunk chunk = GetChunks(doc, style, line, curOffset, toOffset - curOffset); chunk != null; chunk = chunk.Next)
                {
                    ChunkStyle chunkStyle = chunk.GetChunkStyle(style);
                    bool       setBold    = chunkStyle.Bold && (styleStack.Count == 0 || !styleStack.Peek().Bold) ||
                                            !chunkStyle.Bold && (styleStack.Count == 0 || styleStack.Peek().Bold);
                    bool setItalic = chunkStyle.Italic && (styleStack.Count == 0 || !styleStack.Peek().Italic) ||
                                     !chunkStyle.Italic && (styleStack.Count == 0 || styleStack.Peek().Italic);
                    bool setUnderline = chunkStyle.Underline && (styleStack.Count == 0 || !styleStack.Peek().Underline) ||
                                        !chunkStyle.Underline && (styleStack.Count == 0 || styleStack.Peek().Underline);
                    bool setColor = styleStack.Count == 0 || TextViewMargin.GetPixel(styleStack.Peek().Color) != TextViewMargin.GetPixel(chunkStyle.Color);
                    if (setColor || setBold || setItalic || setUnderline)
                    {
                        if (styleStack.Count > 0)
                        {
                            result.Append("</span>");
                            styleStack.Pop();
                        }
                        result.Append("<span");
                        if (useColors)
                        {
                            result.Append(" foreground=\"");
                            result.Append(ColorToPangoMarkup(chunkStyle.Color));
                            result.Append("\"");
                        }
                        if (chunkStyle.Bold)
                        {
                            result.Append(" weight=\"bold\"");
                        }
                        if (chunkStyle.Italic)
                        {
                            result.Append(" style=\"italic\"");
                        }
                        if (chunkStyle.Underline)
                        {
                            result.Append(" underline=\"single\"");
                        }
                        result.Append(">");
                        styleStack.Push(chunkStyle);
                    }

                    for (int i = 0; i < chunk.Length && chunk.Offset + i < doc.Length; i++)
                    {
                        char ch = chunk.GetCharAt(doc, chunk.Offset + i);
                        switch (ch)
                        {
                        case '&':
                            result.Append("&amp;");
                            break;

                        case '<':
                            result.Append("&lt;");
                            break;

                        case '>':
                            result.Append("&gt;");
                            break;

                        case '\t':
                            if (replaceTabs)
                            {
                                result.Append(new string (' ', options.TabSize));
                            }
                            else
                            {
                                result.Append('\t');
                            }
                            break;

                        default:
                            result.Append(ch);
                            break;
                        }
                    }
                }
                while (styleStack.Count > 0)
                {
                    result.Append("</span>");
                    styleStack.Pop();
                }

                curOffset = line.EndOffset;
                if (removeIndent)
                {
                    curOffset += indentLength;
                }
                if (result.Length > 0 && curOffset < offset + length)
                {
                    result.AppendLine();
                }
            }
            return(result.ToString());
        }
Example #23
0
        void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            if (TreeIter.Zero.Equals(iter))
            {
                return;
            }
            var textRenderer = (CellRendererText)cell;
            var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn);

            if (searchResult == null || searchResult.Offset < 0)
            {
                textRenderer.Markup = "Invalid search result";
                return;
            }
            string textMarkup = searchResult.TextMarkup;

            if (textMarkup == null)
            {
                var doc = GetDocument(searchResult);
                if (doc == null)
                {
                    textMarkup = "Can't create document for:" + searchResult.FileName;
                    goto end;
                }
                bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter);

                if (searchResult.Markup == null)
                {
                    if (searchResult.LineNumber <= 0)
                    {
                        searchResult.LineNumber = doc.OffsetToLineNumber(searchResult.Offset);
                    }
                    DocumentLine line = doc.GetLine(searchResult.LineNumber);
                    if (line == null)
                    {
                        textMarkup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset;
                        goto end;
                    }
                    int indent = line.GetIndentation(doc).Length;
                    var data   = new Mono.TextEditor.TextEditorData(doc);
                    data.ColorStyle = highlightStyle;
                    var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent);
                    int col      = searchResult.Offset - line.Offset - indent;
                    // search result contained part of the indent.
                    if (col + searchResult.Length < lineText.Length)
                    {
                        lineText = doc.GetTextAt(line.Offset, line.Length);
                    }

                    var markup = doc.SyntaxMode != null?
                                 data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) :
                                     GLib.Markup.EscapeText(lineText);

                    searchResult.Markup = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize)));

                    if (col >= 0)
                    {
                        uint start;
                        uint end;
                        try {
                            start = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col);
                            end   = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col + searchResult.Length));
                        } catch (Exception e) {
                            LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e);
                            return;
                        }
                        searchResult.StartIndex = start;
                        searchResult.EndIndex   = end;
                    }
                }


                try {
                    textMarkup = searchResult.Markup;

                    if (!isSelected)
                    {
                        var    searchColor = searchResult.GetBackgroundMarkerColor(highlightStyle).Color;
                        double b1          = Mono.TextEditor.HslColor.Brightness(searchColor);
                        double b2          = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground));
                        double delta       = Math.Abs(b1 - b2);
                        if (delta < 0.1)
                        {
                            Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color;
                            if (color1.L + 0.5 > 1.0)
                            {
                                color1.L -= 0.5;
                            }
                            else
                            {
                                color1.L += 0.5;
                            }
                            searchColor = color1;
                        }
                        if (searchResult.StartIndex != searchResult.EndIndex)
                        {
                            var  markupBuilder = new StringBuilder();
                            bool inMarkup = false, inEntity = false, closed = false;
                            int  i = 0;
                            for (int j = 0; j < textMarkup.Length; j++)
                            {
                                var ch = textMarkup [j];
                                if (inEntity)
                                {
                                    if (ch == ';')
                                    {
                                        inEntity = false;
                                    }
                                    markupBuilder.Append(ch);
                                    continue;
                                }
                                if (inMarkup)
                                {
                                    if (ch == '>')
                                    {
                                        inMarkup = false;
                                    }
                                    markupBuilder.Append(ch);
                                    continue;
                                }
                                if (i == searchResult.EndIndex)
                                {
                                    markupBuilder.Append("</span>");
                                    markupBuilder.Append(textMarkup.Substring(j));
                                    closed = true;
                                    break;
                                }
                                if (ch == '&')
                                {
                                    inEntity = true;
                                    markupBuilder.Append(ch);
                                    continue;
                                }
                                if (ch == '<')
                                {
                                    inMarkup = true;
                                    markupBuilder.Append(ch);
                                    continue;
                                }
                                if (i == searchResult.StartIndex)
                                {
                                    markupBuilder.Append("<span background=\"" + ColorToPangoMarkup((HslColor)searchColor) + "\">");
                                }
                                markupBuilder.Append(ch);
                                i++;
                            }
                            if (!closed)
                            {
                                markupBuilder.Append("</span>");
                            }
                            textMarkup = markupBuilder.ToString();
                        }
                    }
                } catch (Exception e) {
                    LoggingService.LogError("Error whil setting the text renderer markup to: " + searchResult.Markup, e);
                }
end:
                searchResult.TextMarkup = textMarkup;
            }
            textRenderer.Markup = textMarkup;
        }
Example #24
0
            public override bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics)
            {
                if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
                {
                    return(false);
                }
                foreach (var usage in Usages)
                {
                    int markerStart = usage.TextSegment.Offset;
                    int markerEnd   = usage.TextSegment.EndOffset;

                    if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset)
                    {
                        return(false);
                    }

                    double @from;
                    double to;

                    if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd)
                    {
                        @from = metrics.TextRenderStartPosition;
                        to    = metrics.TextRenderEndPosition;
                    }
                    else
                    {
                        int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
                        int end   = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;

                        uint curIndex = 0, byteIndex = 0;
                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);

                        int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        @from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);

                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
                        x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
                    }

                    @from = Math.Max(@from, editor.TextViewMargin.XOffset);
                    to    = Math.Max(to, editor.TextViewMargin.XOffset);
                    if (@from < to)
                    {
                        Mono.TextEditor.Highlighting.AmbientColor colorStyle;
                        if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write)
                        {
                            colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
                        }
                        else
                        {
                            colorStyle = editor.ColorStyle.UsagesRectangle;
                        }

                        using (var lg = new LinearGradient(@from + 1, y + 1, to, y + editor.LineHeight)) {
                            lg.AddColorStop(0, colorStyle.Color);
                            lg.AddColorStop(1, colorStyle.SecondColor);
                            cr.SetSource(lg);
                            cr.RoundedRectangle(@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2);
                            cr.FillPreserve();
                        }

                        cr.SetSourceColor(colorStyle.BorderColor);
                        cr.Stroke();
                    }
                }
                return(true);
            }
Example #25
0
 public Cairo.Point LocationToPoint(int line, int column)
 {
     return(TextViewMargin.LocationToPoint(line, column));
 }
Example #26
0
 public Cairo.Point LocationToPoint(int line, int column, bool useAbsoluteCoordinates)
 {
     return(TextViewMargin.LocationToPoint(line, column, useAbsoluteCoordinates));
 }
Example #27
0
 public DocumentLocation PointToLocation(double xp, double yp)
 {
     return(TextViewMargin.PointToLocation(xp, yp));
 }
Example #28
0
 public double ColumnToX(DocumentLine line, int column)
 {
     return(TextViewMargin.ColumnToX(line, column));
 }
Example #29
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle area)
        {
            TextViewMargin textViewMargin = editor.TextViewMargin;
            ISyntaxMode    mode           = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document);

            TextViewMargin.LayoutWrapper lineLayout = null;
            double brightness = HslColor.Brightness(editor.ColorStyle.PlainText.Background);

            int colorCount = foldSegments.Count + 2;

            cr.SetSourceColor(GetColor(-1, brightness, colorCount));
            cr.Rectangle(area);
            cr.Fill();
            var       rectangles         = new Cairo.Rectangle[foldSegments.Count];
            const int xPadding           = 4;
            const int yPadding           = 2;
            const int rightMarginPadding = 16;

            for (int i = foldSegments.Count - 1; i >= 0; i--)
            {
                var segment = foldSegments [i];
                if (segment.IsInvalid)
                {
                    continue;
                }
                var segmentStartLine = segment.StartLine;
                var segmentEndLine   = segment.EndLine;

                int curWidth = 0;
                var endLine  = segmentEndLine.NextLine;
                var y        = editor.LineToY(segmentStartLine.LineNumber);
                if (y < editor.VAdjustment.Value)
                {
                    segmentStartLine = editor.GetLine(editor.YToLine(editor.VAdjustment.Value));
                    y = editor.LineToY(segmentStartLine.LineNumber);
                }

                for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Allocation.Height; curLine = curLine.NextLine)
                {
                    var curLayout = textViewMargin.CreateLinePartLayout(mode, curLine, curLine.Offset, curLine.Length, -1, -1);
                    var width     = (int)(curLayout.Width);
                    curWidth = System.Math.Max(curWidth, width);
                    y       += editor.GetLineHeight(curLine);
                }

                double xPos = textViewMargin.XOffset;
                double rectangleWidth = 0, rectangleHeight = 0;

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
                var rectangleStart = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X / Pango.Scale.PangoScale) - xPadding);

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);

                var rectangleEnd = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X / Pango.Scale.PangoScale) - xPadding));

                rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2;

                if (i < foldSegments.Count - 1)
                {
                    rectangleWidth = System.Math.Max((rectangles [i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth);
                }

                y = editor.LineToY(segment.StartLine.LineNumber);
                var yEnd = editor.LineToY(segment.EndLine.LineNumber + 1) + (segment.EndLine.LineNumber == editor.LineCount ? editor.LineHeight : 0);
                if (yEnd == 0)
                {
                    yEnd = editor.VAdjustment.Upper;
                }
                rectangleHeight = yEnd - y;

                rectangles[i] = new Cairo.Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2);
            }

            for (int i = 0; i < foldSegments.Count; i++)
            {
                Cairo.Rectangle clampedRect;
                var             rect = rectangles[i];

                if (i == foldSegments.Count - 1)
                {
/*					var radius = (int)(editor.Options.Zoom * 2);
 *                                      int w = 2 * radius;
 *                                      using (var shadow = new Blur (
 *                                              System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width),
 *                                              System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height),
 *                                              radius)) {
 *                                              using (var gctx = shadow.GetContext ()) {
 *                                                      gctx.Color = new Cairo.Color (0, 0, 0, 0);
 *                                                      gctx.Fill ();
 *
 *                                                      var a = 0;
 *                                                      var b = 0;
 *                                                      DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2);
 *                                                      var bg = editor.ColorStyle.Default.CairoColor;
 *                                                      gctx.Color = new Cairo.Color (bg.R, bg.G, bg.B, 0.6);
 *                                                      gctx.Fill ();
 *                                              }
 *
 *                                              cr.Save ();
 *                                              cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w);
 *                                              shadow.Draw (cr);
 *                                              cr.Restore ();
 *                                      }*/

                    var curPadSize = 1;

                    var age   = (DateTime.Now - startTime).TotalMilliseconds;
                    var alpha = 0.1;
                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize = (int)(3 + System.Math.Sin(System.Math.PI * animationState) * 3);
                        alpha      = 0.1 + (1.0 - animationState) / 5;
                    }

                    var bg = editor.ColorStyle.PlainText.Foreground;
                    cr.SetSourceRGBA(bg.R, bg.G, bg.B, alpha);
                    clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                    DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                    cr.Fill();

                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize  = (int)(2 + System.Math.Sin(System.Math.PI * animationState) * 2);
                        clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                        DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                        cr.SetSourceColor(GetColor(i, brightness, colorCount));
                        cr.Fill();

                        continue;
                    }
                }

                clampedRect = ClampRect(rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height, area);
                DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);

                cr.SetSourceColor(GetColor(i, brightness, colorCount));
                cr.Fill();
            }
        }
Example #30
0
 public DocumentLocation PointToLocation(Cairo.PointD p)
 {
     return(TextViewMargin.PointToLocation(p));
 }