コード例 #1
0
        public CodePreviewWindow(
            Gdk.Window parentWindow,
            string fontName   = null,
            EditorTheme theme = null)
            : base(Gtk.WindowType.Popup)
        {
            ParentWindow = parentWindow ?? MonoDevelop.Ide.IdeApp.Workbench.RootWindow.GdkWindow;

            AppPaintable  = true;
            SkipPagerHint = SkipTaskbarHint = true;
            TypeHint      = WindowTypeHint.Menu;

            this.fontName = fontName = fontName ?? DefaultSourceEditorOptions.Instance.FontName;

            layout                 = PangoUtil.CreateLayout(this);
            fontDescription        = Pango.FontDescription.FromString(fontName);
            fontDescription.Size   = (int)(fontDescription.Size * 0.8f);
            layout.FontDescription = fontDescription;
            layout.Ellipsize       = Pango.EllipsizeMode.End;

            var geometry = Screen.GetUsableMonitorGeometry(Screen.GetMonitorAtWindow(ParentWindow));

            maxWidth  = geometry.Width * 2 / 5;
            maxHeight = geometry.Height * 2 / 5;

            layout.SetText("n");
            layout.GetPixelSize(out int _, out int lineHeight);
            MaximumLineCount = maxHeight / lineHeight;

            theme     = theme ?? DefaultSourceEditorOptions.Instance.GetEditorTheme();
            colorText = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.Foreground);
            colorBg   = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.Background);
            colorFold = SyntaxHighlightingService.GetColor(theme, EditorThemeColors.CollapsedText);
        }
コード例 #2
0
        public CodeSegmentPreviewWindow(TextEditor editor, bool hideCodeSegmentPreviewInformString, ISegment segment, int width, int height) : base(Gtk.WindowType.Popup)
        {
            this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString;
            this.editor       = editor;
            this.AppPaintable = true;
            layout            = PangoUtil.CreateLayout(this);
            informLayout      = PangoUtil.CreateLayout(this);
            informLayout.SetText(CodeSegmentPreviewInformString);

            fontDescription        = Pango.FontDescription.FromString(editor.Options.FontName);
            fontDescription.Size   = (int)(fontDescription.Size * 0.8f);
            layout.FontDescription = fontDescription;
            layout.Ellipsize       = Pango.EllipsizeMode.End;
            // setting a max size for the segment (40 lines should be enough),
            // no need to markup thousands of lines for a preview window
            int       startLine       = editor.Document.OffsetToLineNumber(segment.Offset);
            int       endLine         = editor.Document.OffsetToLineNumber(segment.EndOffset);
            const int maxLines        = 40;
            bool      pushedLineLimit = endLine - startLine > maxLines;

            if (pushedLineLimit)
            {
                segment = new Segment(segment.Offset, editor.Document.GetLine(startLine + maxLines).Offset - segment.Offset);
            }
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.SetMarkup(editor.Document.SyntaxMode.GetMarkup(editor.Document,
                                                                  editor.Options,
                                                                  editor.ColorStyle,
                                                                  segment.Offset,
                                                                  segment.Length,
                                                                  true) + (pushedLineLimit ? Environment.NewLine + "..." : ""));
            CalculateSize();
        }
コード例 #3
0
        public void DrawLineNumber(TextEditor editor, double width, Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var lineNumberBgGC = editor.ColorStyle.LineNumbers.Background;
            var lineNumberGC   = editor.ColorStyle.LineNumbers.Foreground;

            cr.Rectangle(x, y, width, lineHeight);
            cr.Color = editor.Caret.Line == line?editor.ColorStyle.LineMarker.GetColor("color") : lineNumberGC;

            cr.Fill();

            if (line <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = editor.Options.Font;
                    layout.Width           = (int)width;
                    layout.Alignment       = Pango.Alignment.Right;
                    layout.SetText(line.ToString());
                    cr.Save();
                    cr.Translate(x + (int)width + (editor.Options.ShowFoldMargin ? 0 : -2), y);
                    cr.Color = lineNumberBgGC;
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
コード例 #4
0
 public FoldMarkerMargin(TextEditor editor)
 {
     this.editor = editor;
     layout      = PangoUtil.CreateLayout(editor);
     editor.Caret.PositionChanged    += HandleEditorCaretPositionChanged;
     editor.Document.FoldTreeUpdated += HandleEditorDocumentFoldTreeUpdated;
 }
コード例 #5
0
 public LayoutProxy RequestLayout()
 {
     if (layoutQueue.Count == 0)
     {
         layoutQueue.Enqueue(new LayoutProxy(this, PangoUtil.CreateLayout(widget)));
     }
     return(layoutQueue.Dequeue());
 }
コード例 #6
0
 public FoldMarkerMargin(TextEditor editor)
 {
     this.editor                   = editor;
     layout                        = PangoUtil.CreateLayout(editor);
     delayTimer                    = new Timer(150);
     delayTimer.AutoReset          = false;
     delayTimer.Elapsed           += DelayTimerElapsed;
     editor.Caret.PositionChanged += HandleEditorCaretPositionChanged;
 }
コード例 #7
0
 public GutterMargin(TextEditor editor)
 {
     this.editor = editor;
     layout      = PangoUtil.CreateLayout(editor, null);
     base.cursor = new Gdk.Cursor(Gdk.CursorType.RightPtr);
     this.editor.Document.LineChanged  += UpdateWidth;
     this.editor.Document.TextSet      += HandleEditorDocumenthandleTextSet;
     this.editor.Caret.PositionChanged += EditorCarethandlePositionChanged;
 }
コード例 #8
0
ファイル: GutterMargin.cs プロジェクト: thild/monodevelop
 void CalculateWidth()
 {
     using (var layout = PangoUtil.CreateLayout(editor)) {
         layout.FontDescription = editor.Options.Font;
         layout.SetText(editor.Document.LineCount.ToString());
         layout.Alignment = Pango.Alignment.Left;
         layout.Width     = -1;
         int height;
         layout.GetPixelSize(out this.width, out height);
         this.width += 4;
     }
 }
コード例 #9
0
 public FoldMarkerMargin(MonoTextEditor editor)
 {
     this.editor = editor;
     layout      = PangoUtil.CreateLayout(editor);
     editor.Caret.PositionChanged    += HandleEditorCaretPositionChanged;
     editor.Document.FoldTreeUpdated += HandleEditorDocumentFoldTreeUpdated;
     editor.Caret.PositionChanged    += EditorCarethandlePositionChanged;
     editor.TextArea.MouseHover      += TextArea_MouseHover;
     editor.TextArea.MouseLeft       += TextArea_MouseLeft;
     drawer = new VSCodeFoldMarkerMarginDrawer(this);
     UpdateAccessibility();
     animationStage.ActorStep += AnimationStage_ActorStep;
 }
コード例 #10
0
        public SegmentCanvas(TextEditor editor, TextSegment segment, bool removeIndent = true)
        {
            this.editor       = editor;
            layout            = PangoUtil.CreateLayout(this);
            informLayout      = PangoUtil.CreateLayout(this);
            informLayout.Text = CodeSegmentPreviewWindow.CodeSegmentPreviewInformString;

            fontDescription = Font.FromName(editor.Options.FontName).WithSize(Font.Size * 0.8f);
            layout.Font     = fontDescription;
            layout.Trimming = TextTrimming.WordElipsis;
            // setting a max size for the segment (40 lines should be enough),
            // no need to markup thousands of lines for a preview window
            SetSegment(segment, removeIndent);
        }
コード例 #11
0
        public CodeSegmentPreviewWindow(TextEditor editor, bool hideCodeSegmentPreviewInformString, TextSegment segment, int width, int height, bool removeIndent = true) : base(Gtk.WindowType.Popup)
        {
            this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString;
            this.Segment      = segment;
            this.editor       = editor;
            this.AppPaintable = true;
            layout            = PangoUtil.CreateLayout(this);
            informLayout      = PangoUtil.CreateLayout(this);
            informLayout.SetText(CodeSegmentPreviewInformString);

            fontDescription        = Pango.FontDescription.FromString(editor.Options.FontName);
            fontDescription.Size   = (int)(fontDescription.Size * 0.8f);
            layout.FontDescription = fontDescription;
            layout.Ellipsize       = Pango.EllipsizeMode.End;
            // setting a max size for the segment (40 lines should be enough),
            // no need to markup thousands of lines for a preview window
            SetSegment(segment, removeIndent);
            CalculateSize(width);
        }
コード例 #12
0
        void CalculateWidth()
        {
            using (var layout = PangoUtil.CreateLayout(editor)) {
                layout.FontDescription = gutterFont;
                layout.SetText(LineCountMax.ToString());
                layout.Alignment = Pango.Alignment.Left;
                layout.Width     = -1;
                int height;
                layout.GetPixelSize(out this.width, out height);
                this.width += 4;
                if (!editor.Options.ShowFoldMargin)
                {
                    this.width += 2;
                }

                using (var metrics = editor.PangoContext.GetMetrics(layout.FontDescription, editor.PangoContext.Language)) {
                    fontHeight = System.Math.Ceiling(0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale);
                }
            }
        }
コード例 #13
0
        internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var gutterMarker = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(marker => marker is MarginMarker && ((MarginMarker)marker).CanDraw(this)) : null;

            if (gutterMarker != null && gutterMarker.CanDrawBackground(this))
            {
                bool hasDrawn = gutterMarker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                if (!hasDrawn)
                {
                    DrawGutterBackground(cr, line, x, y, lineHeight);
                }
            }
            else
            {
                DrawGutterBackground(cr, line, x, y, lineHeight);
            }

            if (gutterMarker != null && gutterMarker.CanDrawForeground(this))
            {
                gutterMarker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                return;
            }

            if (line <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = gutterFont;
                    layout.Width           = (int)Width;
                    layout.Alignment       = Pango.Alignment.Right;
                    layout.SetText(line.ToString());
                    cr.Save();
                    cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y);
                    cr.SetSourceColor(lineNumberGC);
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
コード例 #14
0
        public override void DrawForeground(MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            var width          = metrics.Width;
            var lineNumberBgGC = editor.ColorStyle.LineNumbers.Background;

            if (metrics.LineNumber <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = editor.Options.Font;
                    layout.Width           = (int)width;
                    layout.Alignment       = Pango.Alignment.Right;
                    layout.SetText(metrics.LineNumber.ToString());
                    cr.Save();
                    cr.Translate(metrics.X + (int)width + (editor.Options.ShowFoldMargin ? 0 : -2), metrics.Y);
                    cr.SetSourceColor(lineNumberBgGC);
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
コード例 #15
0
        internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var gutterMarker = lineSegment != null ? (IGutterMarker)lineSegment.Markers.FirstOrDefault(marker => marker is IGutterMarker) : null;

            if (gutterMarker != null)
            {
                gutterMarker.DrawLineNumber(editor, Width, cr, area, lineSegment, line, x, y, lineHeight);
                return;
            }
            if (editor.Caret.Line == line)
            {
                editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight);
            }
            else
            {
                cr.Rectangle(x, y, Width, lineHeight);
                cr.Color = lineNumberBgGC;
                cr.Fill();
            }

            if (line <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = gutterFont;

                    layout.Width     = (int)Width;
                    layout.Alignment = Pango.Alignment.Right;
                    layout.SetText(line.ToString());
                    cr.Save();
                    cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y + (lineHeight - fontHeight) / 2);
                    cr.Color = lineNumberGC;
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
コード例 #16
0
        internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            cr.Rectangle(x, y, Width, lineHeight);
            cr.Color = lineNumberBgGC;
            cr.Fill();

            if (line <= editor.Document.LineCount)
            {
                // Due to a mac? gtk bug I need to re-create the layout here
                // otherwise I get pango exceptions.
                using (var layout = PangoUtil.CreateLayout(editor)) {
                    layout.FontDescription = editor.Options.Font;
                    layout.Width           = (int)Width;
                    layout.Alignment       = Pango.Alignment.Right;
                    layout.SetText(line.ToString());
                    cr.Save();
                    cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y);
                    cr.Color = editor.Caret.Line == line ? lineNumberHighlightGC : lineNumberGC;
                    cr.ShowLayout(layout);
                    cr.Restore();
                }
            }
        }
コード例 #17
0
 public IconMargin(TextEditor editor)
 {
     this.editor = editor;
     layout      = PangoUtil.CreateLayout(editor);
 }