Example #1
0
 public PopUpContainer(Widget content, Mono.TextEditor.MonoTextEditor placementTarget)
     : base(content, placementTarget)
 {
     WindowTransparencyDecorator.Attach(_popup);//TODO: not sure we want this on all popus?
     _popup.Content = _popupContentContainer;
     _popup.Hidden += OnPopupClosed;
 }
Example #2
0
        /// <summary>
        /// Default constructor that configures the Completion form.
        /// </summary>
        public EditorView(ViewBase owner) : base(owner)
        {
            scroller   = new ScrolledWindow();
            textEditor = new MonoTextEditor();
            scroller.Add(textEditor);
            _mainWidget = scroller;
            Mono.TextEditor.TextEditorOptions options = new Mono.TextEditor.TextEditorOptions();
            options.EnableSyntaxHighlighting = true;
            options.ColorScheme                = "Visual Studio";
            options.HighlightCaretLine         = true;
            textEditor.Options                 = options;
            textEditor.TextArea.DoPopupMenu    = DoPopup;
            textEditor.Document.LineChanged   += OnTextHasChanged;
            textEditor.TextArea.FocusInEvent  += OnTextBoxEnter;
            textEditor.TextArea.FocusOutEvent += OnTextBoxLeave;
            textEditor.TextArea.KeyPressEvent += OnKeyPress;
            _mainWidget.Destroyed             += _mainWidget_Destroyed;

            AddContextActionWithAccel("Cut", OnCut, "Ctrl+X");
            AddContextActionWithAccel("Copy", OnCopy, "Ctrl+C");
            AddContextActionWithAccel("Paste", OnPaste, "Ctrl+V");
            AddContextActionWithAccel("Delete", OnDelete, "Delete");
            AddContextSeparator();
            AddContextActionWithAccel("Undo", OnUndo, "Ctrl+Z");
            AddContextActionWithAccel("Redo", OnRedo, "Ctrl+Y");
            AddContextActionWithAccel("Find", OnFind, "Ctrl+F");
            AddContextActionWithAccel("Replace", OnReplace, "Ctrl+H");

            IntelliSenseChars = ".";

            intellisense = new IntellisenseView();
            intellisense.ContextItemsNeeded += ContextItemsNeeded;
            intellisense.LoseFocus          += HideCompletionWindow;
        }
Example #3
0
        void IActionTextLineMarker.MouseHover(Mono.TextEditor.MonoTextEditor editor, MarginMouseEventArgs args, TextLineMarkerHoverResult result)
        {
            if (args.Button != 0)
            {
                return;
            }
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var          x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.TextStartPosition;
            var          y = editor.LineToY(line.LineNumber + 1) - editor.VAdjustment.Value;
            const double xAdditionalSpace = tagMarkerWidth;

            if (args.X - x >= -xAdditionalSpace * editor.Options.Zoom &&
                args.X - x < (tagMarkerWidth + xAdditionalSpace) * editor.Options.Zoom /*&&
                                                                                        * args.Y - y < (editor.LineHeight / 2) * editor.Options.Zoom*/)
            {
                result.Cursor = null;
                ShowPopup?.Invoke(null, null);
            }
            else
            {
                CancelPopup?.Invoke(null, null);
            }
        }
Example #4
0
//		static Menu menu;

        public override void InformMousePress(Mono.TextEditor.MonoTextEditor editor, Margin margin, MarginMouseEventArgs args)
        {
            if (!(margin is ActionMargin))
            {
                return;
            }
            host.PopupContextMenu(unitTest, (int)(args.X + margin.XOffset), (int)args.Y);
            editor.TextArea.ResetMouseState();
        }
Example #5
0
        bool IActionTextLineMarker.MousePressed(Mono.TextEditor.MonoTextEditor editor, MarginMouseEventArgs args)
        {
            var handler = MousePressed;

            if (handler != null)
            {
                handler(this, new TextEventArgsWrapper(args));
            }
            return(false);
        }
		public override void Draw (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			this.editor = editor;
			var line = editor.GetLine (loc.Line);
			if (line == null)
				return;
			var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

			cr.Rectangle (Math.Floor (x), Math.Floor (metrics.LineYRenderStartPosition) + (line == editor.GetLineByOffset (startOffset) ? editor.LineHeight - tagMarkerHeight : 0), tagMarkerWidth, tagMarkerHeight);
			cr.SetSourceColor ((HslColor.Brightness (editor.ColorStyle.PlainText.Background) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor ());
			cr.Fill ();
		}
Example #7
0
        public override void InformMouseHover(Mono.TextEditor.MonoTextEditor editor, Margin margin, MarginMouseEventArgs args)
        {
            if (!(margin is ActionMargin))
            {
                return;
            }
            string toolTip;

            if (unitTest.IsFixture)
            {
                if (isFailed)
                {
                    toolTip = GettextCatalog.GetString("NUnit Fixture failed (click to run)");
                    if (!string.IsNullOrEmpty(failMessage))
                    {
                        toolTip += Environment.NewLine + failMessage.TrimEnd();
                    }
                }
                else
                {
                    toolTip = GettextCatalog.GetString("NUnit Fixture (click to run)");
                }
            }
            else
            {
                if (isFailed)
                {
                    toolTip = GettextCatalog.GetString("NUnit Test failed (click to run)");
                    if (!string.IsNullOrEmpty(failMessage))
                    {
                        toolTip += Environment.NewLine + failMessage.TrimEnd();
                    }
                    foreach (var id in unitTest.TestCases)
                    {
                        if (host.IsFailure(unitTest.UnitTestIdentifier, id))
                        {
                            var msg = host.GetMessage(unitTest.UnitTestIdentifier, id);
                            if (!string.IsNullOrEmpty(msg))
                            {
                                toolTip += Environment.NewLine + "Test" + id + ":";
                                toolTip += Environment.NewLine + msg.TrimEnd();
                            }
                        }
                    }
                }
                else
                {
                    toolTip = GettextCatalog.GetString("NUnit Test (click to run)");
                }
            }
            editor.TooltipText = toolTip;
        }
 protected override void OnDestroyed()
 {
     adj = null;
     if (textEditor != null)
     {
         textEditor.EditorOptionsChanged -= TextEditor_EditorOptionsChanged;
     }
     textEditor    = null;
     providerTasks = null;
     PropertyService.RemovePropertyHandler("ScrollBar.Mode", ScrollBarModeChanged);
     EnableFancyFeatures.Changed -= HandleChanged;
     base.OnDestroyed();
 }
Example #9
0
        private void _mainWidget_Destroyed(object sender, EventArgs e)
        {
            textEditor.Document.LineChanged   -= OnTextHasChanged;
            textEditor.TextArea.FocusInEvent  -= OnTextBoxEnter;
            textEditor.TextArea.FocusOutEvent -= OnTextBoxLeave;
            _mainWidget.Destroyed             -= _mainWidget_Destroyed;
            textEditor.TextArea.KeyPressEvent -= OnKeyPress;
            CompletionForm.FocusOutEvent      -= OnLeaveCompletion;
            CompletionView.ButtonPressEvent   -= OnContextListMouseDoubleClick;
            CompletionView.KeyReleaseEvent    -= CompletionView_KeyReleaseEvent;
            if (CompletionForm.IsRealized)
            {
                CompletionForm.Destroy();
            }
            // It's good practice to disconnect all event handlers, as it makes memory leaks
            // less likely. However, we may not "own" the event handlers, so how do we
            // know what to disconnect?
            // We can do this via reflection. Here's how it currently can be done in Gtk#.
            // Windows.Forms would do it differently.
            // This may break if Gtk# changes the way they implement event handlers.
            foreach (Widget w in Popup)
            {
                if (w is MenuItem)
                {
                    PropertyInfo pi = w.GetType().GetProperty("AfterSignals", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (pi != null)
                    {
                        System.Collections.Hashtable handlers = (System.Collections.Hashtable)pi.GetValue(w);
                        if (handlers != null && handlers.ContainsKey("activate"))
                        {
                            EventHandler handler = (EventHandler)handlers["activate"];
                            (w as MenuItem).Activated -= handler;
                        }
                    }
                }
            }

            Popup.Destroy();
            accel.Dispose();
            completionModel.Dispose();
            functionPixbuf.Dispose();
            propertyPixbuf.Dispose();
            CompletionView.Dispose();
            CompletionForm.Destroy();
            CompletionForm = null;
            textEditor.Destroy();
            textEditor = null;
            _findForm.Destroy();
            _owner = null;
        }
Example #10
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x), Math.Floor(metrics.LineYRenderStartPosition) + editor.LineHeight - tagMarkerHeight, tagMarkerWidth, tagMarkerHeight);
            cr.SetSourceColor((HslColor.Brightness(SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background)) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor());
            cr.Fill();
        }
Example #11
0
        public override void DrawForeground(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            if (statusIcon == null)
            {
                UpdateStatusIcon();
            }

            if (statusIcon != null)
            {
                if (statusIcon.Width > metrics.Width || statusIcon.Height > metrics.Height)
                {
                    statusIcon = statusIcon.WithBoxSize(metrics.Width, metrics.Height);
                }
                cr.DrawImage(editor, statusIcon, Math.Truncate(metrics.X + metrics.Width / 2 - statusIcon.Width / 2), Math.Truncate(metrics.Y + metrics.Height / 2 - statusIcon.Height / 2));
            }
        }
Example #12
0
        public override void DrawForeground(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            isFailed = false;
            bool searchCases = false;

            Xwt.Drawing.Image icon = host.GetStatusIcon(unitTest.UnitTestIdentifier);
            if (icon != null)
            {
                if (host.HasResult(unitTest.UnitTestIdentifier))
                {
                    searchCases = true;
                }
                else if (host.IsFailure(unitTest.UnitTestIdentifier))
                {
                    failMessage = host.GetMessage(unitTest.UnitTestIdentifier);
                    isFailed    = true;
                }
            }
            else
            {
                searchCases = true;
            }

            if (searchCases)
            {
                foreach (var caseId in unitTest.TestCases)
                {
                    icon = host.GetStatusIcon(unitTest.UnitTestIdentifier, caseId);
                    if (host.IsFailure(unitTest.UnitTestIdentifier, caseId))
                    {
                        failMessage = host.GetMessage(unitTest.UnitTestIdentifier, caseId);
                        isFailed    = true;
                        break;
                    }
                }
            }

            if (icon != null)
            {
                if (icon.Width > metrics.Width || icon.Height > metrics.Height)
                {
                    icon = icon.WithBoxSize(metrics.Width, metrics.Height);
                }
                cr.DrawImage(editor, icon, Math.Truncate(metrics.X + metrics.Width / 2 - icon.Width / 2), Math.Truncate(metrics.Y + metrics.Height / 2 - icon.Height / 2));
            }
        }
Example #13
0
        public PopupAgent(Mono.TextEditor.MonoTextEditor textView, IMDSpaceReservationManager manager, ITrackingSpan visualSpan, PopupStyles style, Widget content)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (visualSpan == null)
            {
                throw new ArgumentNullException("visualSpan");
            }
            if (((int)style & ~(0xff)) != 0)        //Union of all the legal style bits.
            {
                throw new ArgumentOutOfRangeException("style");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if ((style & PopupStyles.DismissOnMouseLeaveText) != 0 && (style & PopupStyles.DismissOnMouseLeaveTextOrContent) != 0)
            {
                throw new ArgumentException("Can't specify both PopupStyles.DismissOnMouseLeaveText and PopupStyles.DismissOnMouseLeaveTextOrContent", "style");
            }

            _textView   = textView;
            _manager    = manager;
            _visualSpan = visualSpan;
            _style      = style;

            var popupCache = textView.Properties.GetOrCreateSingletonProperty <Dictionary <WeakReferenceForDictionaryKey, PopupOrWindowContainer> >(
                () => new Dictionary <WeakReferenceForDictionaryKey, PopupOrWindowContainer>(MaxPopupCacheSize));

            if (!popupCache.TryGetValue(new WeakReferenceForDictionaryKey(content), out _popup))
            {
                _popup = PopupOrWindowContainer.Create(content, _textView.VisualElement);

                if (popupCache.Count == MaxPopupCacheSize)
                {
                    popupCache.Clear();
                }
                popupCache.Add(new WeakReferenceForDictionaryKey(content), _popup);
            }
        }
Example #14
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            double y           = metrics.LineYRenderStartPosition;
            var    layout      = metrics.Layout.Layout;
            int    markerStart = line.Offset + startColumn;
            int    markerEnd   = line.Offset + endColumn;

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

            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;
                int  x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index((uint)(start - startOffset), ref curIndex, ref byteIndex)).X;

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

                x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index((uint)(end - startOffset), ref curIndex, ref 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.DrawLine(editor.EditorTheme.GetForeground(editor.EditorTheme.GetChunkStyle(new ScopeStack(style))), @from + 0.5, y + editor.LineHeight - 1.5, to + 0.5, y + editor.LineHeight - 1.5);
            }
        }
		public override void Draw (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			this.editor = editor;
			var line = editor.GetLine (loc.Line);
			if (line == null)
				return;
			var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

			cr.Rectangle (Math.Floor (x) + 0.5, Math.Floor (metrics.LineYRenderStartPosition) + 0.5 + (line == editor.GetLineByOffset (startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

			if (HslColor.Brightness (editor.ColorStyle.PlainText.Background) < 0.5) {
				cr.SetSourceRGBA (0.8, 0.8, 1, 0.9);
			} else {
				cr.SetSourceRGBA (0.2, 0.2, 1, 0.9);
			}
			cr.Stroke ();
		}
 protected override void OnDestroyed()
 {
     layout          = layout.Kill();
     informLayout    = informLayout.Kill();
     fontDescription = fontDescription.Kill();
     fontInform      = fontInform.Kill();
     if (textGC != null)
     {
         textGC.Dispose();
         textBgGC.Dispose();
         foldGC.Dispose();
         foldBgGC.Dispose();
         textGC = textBgGC = foldGC = foldBgGC = null;
     }
     editor = null;
     base.OnDestroyed();
 }
Example #17
0
        public CodeSegmentEditorWindow(MonoTextEditor editor) : base(Gtk.WindowType.Toplevel)
        {
            Gtk.ScrolledWindow scrolledWindow = new Gtk.ScrolledWindow();
            scrolledWindow.Child      = codeSegmentEditor;
            scrolledWindow.ShadowType = Gtk.ShadowType.In;
            Child = scrolledWindow;
            codeSegmentEditor.Realize();
            ((SimpleEditMode)codeSegmentEditor.CurrentMode).AddBinding(Gdk.Key.Escape, Close);
            TextEditorOptions options = new TextEditorOptions();

            options.FontName             = editor.Options.FontName;
            options.ColorScheme          = editor.Options.ColorScheme;
            options.ShowRuler            = false;
            options.ShowLineNumberMargin = false;
            options.ShowFoldMargin       = false;
            options.ShowIconMargin       = false;
            options.Zoom = 0.8;
            codeSegmentEditor.Document.MimeType = editor.MimeType;
            codeSegmentEditor.Document.ReadOnly = true;
            codeSegmentEditor.Options           = options;

            codeSegmentEditor.KeyPressEvent += delegate(object o, Gtk.KeyPressEventArgs args) {
                if (args.Event.Key == Gdk.Key.Escape)
                {
                    Destroy();
                }
            };
            Gtk.Widget parent = editor.Parent;
            while (parent != null && !(parent is Gtk.Window))
            {
                parent = parent.Parent;
            }
            if (parent is Gtk.Window)
            {
                this.TransientFor = (Gtk.Window)parent;
            }
            this.SkipTaskbarHint = true;
            this.Decorated       = false;
            Gdk.Pointer.Grab(this.GdkWindow, true, Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask, null, null, Gtk.Global.CurrentEventTime);
            Gtk.Grab.Add(this);
            GrabBrokenEvent += delegate {
                Destroy();
            };
            codeSegmentEditor.GrabFocus();
        }
Example #18
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            double y           = metrics.LineYRenderStartPosition;
            var    layout      = metrics.Layout.Layout;

            int markerStart = LineSegment.Offset + System.Math.Max(StartCol - 1, 0);
            int markerEnd   = LineSegment.Offset + (EndCol < 1 ? LineSegment.Length : EndCol - 1);

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

            if (editor.IsSomethingSelected)
            {
                var range = editor.SelectionRange;
                if (range.Contains(markerStart))
                {
                    int end = System.Math.Min(markerEnd, range.EndOffset);
                    InternalDraw(markerStart, end, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
                if (range.Contains(markerEnd))
                {
                    InternalDraw(markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.Offset, markerEnd, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
                if (markerStart <= range.Offset && range.EndOffset <= markerEnd)
                {
                    InternalDraw(markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.Offset, range.EndOffset, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
            }

            InternalDraw(markerStart, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
        }
Example #19
0
        internal static void ShowAndPositionTooltip(MonoTextEditor editor, Xwt.WindowFrame tipWindow, int mouseX, int mouseY, int width, double xalign)
        {
            int ox = 0, oy = 0;

            if (editor.GdkWindow != null)
            {
                editor.GdkWindow.GetOrigin(out ox, out oy);
            }

            width += 10;

            int x = mouseX + ox + editor.Allocation.X;
            int y = mouseY + oy + editor.Allocation.Y;

            Gdk.Rectangle geometry = editor.Screen.GetUsableMonitorGeometry(editor.Screen.GetMonitorAtPoint(x, y));

            x -= (int)((double)width * xalign);
            y += 10;

            if (x + width >= geometry.X + geometry.Width)
            {
                x = geometry.X + geometry.Width - width;
            }
            if (x < geometry.Left)
            {
                x = geometry.Left;
            }

            int h = (int)tipWindow.Height;

            if (y + h >= geometry.Y + geometry.Height)
            {
                y = geometry.Y + geometry.Height - h;
            }
            if (y < geometry.Top)
            {
                y = geometry.Top;
            }

            tipWindow.Location = new Xwt.Point(x, y);

            tipWindow.Show();
        }
        public override void Update(MonoTextEditor editor)
        {
            var startLine = editor.GetLine(start);

            if (start == end)
            {
                editor.TextViewMargin.RemoveCachedLine(startLine);
                editor.RedrawLine(start);
            }
            else
            {
                for (int i = 0; startLine != null && i < end - start; i++)
                {
                    editor.TextViewMargin.RemoveCachedLine(startLine);
                    startLine = startLine.NextLine;
                }
                editor.RedrawLines(start, end);
            }
        }
Example #21
0
        private void _mainWidget_Destroyed(object sender, EventArgs e)
        {
            textEditor.Document.LineChanged   -= OnTextHasChanged;
            textEditor.TextArea.FocusInEvent  -= OnTextBoxEnter;
            textEditor.TextArea.FocusOutEvent -= OnTextBoxLeave;
            _mainWidget.Destroyed             -= _mainWidget_Destroyed;
            textEditor.TextArea.KeyPressEvent -= OnKeyPress;

            intellisense.ContextItemsNeeded -= ContextItemsNeeded;
            intellisense.ItemSelected       -= InsertCompletionItemIntoTextBox;
            intellisense.LoseFocus          -= HideCompletionWindow;
            intellisense.Cleanup();

            // It's good practice to disconnect all event handlers, as it makes memory leaks
            // less likely. However, we may not "own" the event handlers, so how do we
            // know what to disconnect?
            // We can do this via reflection. Here's how it currently can be done in Gtk#.
            // Windows.Forms would do it differently.
            // This may break if Gtk# changes the way they implement event handlers.
            foreach (Widget w in Popup)
            {
                if (w is MenuItem)
                {
                    PropertyInfo pi = w.GetType().GetProperty("AfterSignals", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (pi != null)
                    {
                        System.Collections.Hashtable handlers = (System.Collections.Hashtable)pi.GetValue(w);
                        if (handlers != null && handlers.ContainsKey("activate"))
                        {
                            EventHandler handler = (EventHandler)handlers["activate"];
                            (w as MenuItem).Activated -= handler;
                        }
                    }
                }
            }

            Popup.Destroy();
            accel.Dispose();
            textEditor.Destroy();
            textEditor = null;
            _findForm.Destroy();
            _owner = null;
        }
Example #22
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;
     if (PlatformService.AccessibilityInUse)
     {
         drawer = new VSNetFoldMarkerMarginDrawer(this);
     }
     else
     {
         drawer = new VSCodeFoldMarkerMarginDrawer(this);
     }
     UpdateAccessibility();
     animationStage.ActorStep += AnimationStage_ActorStep;
 }
Example #23
0
        protected override void OnDestroyed()
        {
            adj = null;
            if (textEditor != null)
            {
                textEditor.EditorOptionsChanged -= TextEditor_EditorOptionsChanged;
            }
            textEditor    = null;
            providerTasks = null;
            PropertyService.RemovePropertyHandler("ScrollBar.Mode", ScrollBarModeChanged);
            EnableFancyFeatures.Changed -= HandleChanged;

            if (updateAccessibilityId != 0)
            {
                GLib.Source.Remove(updateAccessibilityId);
                updateAccessibilityId = 0;
            }

            base.OnDestroyed();
        }
Example #24
0
        public CodeSegmentPreviewWindow(MonoTextEditor 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;
            this.SkipPagerHint = this.SkipTaskbarHint = true;
            this.TypeHint      = WindowTypeHint.Menu;
            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);
        }
Example #25
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            if (editor is null)
            {
                throw new ArgumentNullException(nameof(editor));
            }
            if (cr is null)
            {
                throw new ArgumentNullException(nameof(cr));
            }
            if (metrics is null)
            {
                throw new ArgumentNullException(nameof(metrics));
            }

            var    startOffset   = metrics.TextStartOffset;
            int    endOffset     = metrics.TextEndOffset;
            double startXPos     = metrics.TextRenderStartPosition;
            double endXPos       = metrics.TextRenderEndPosition;
            double y             = metrics.LineYRenderStartPosition;
            var    layoutWrapper = metrics.Layout;
            var    layout        = layoutWrapper?.Layout;

            if (layout == null || LineSegment == null)
            {
                return;
            }
            var lineOffset  = LineSegment.Offset;
            int markerStart = lineOffset + startColumn;
            int markerEnd   = lineOffset + endColumn;

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

            var(x1, x2) = CalculateXPositions(startOffset, endOffset, startXPos, endXPos, layoutWrapper, layout, markerStart, markerEnd);
            DrawUnderline(editor, cr, y, layoutWrapper, markerStart, x1, x2);
        }
            public double GetLineIndentationStart()
            {
                MonoTextEditor editor = mode.editor;

                var lineAbove = editor.Document.GetLine(mode.CurrentInsertionPoint.Line - 1);
                var lineBelow = editor.Document.GetLine(mode.CurrentInsertionPoint.Line);

                double aboveStart = 0 /*, aboveEnd = editor.TextViewMargin.XOffset*/;
                double belowStart = 0 /*, belowEnd = editor.TextViewMargin.XOffset*/;
                int    l = 0, tmp;

                if (lineAbove != null)
                {
                    var wrapper = editor.TextViewMargin.GetLayout(lineAbove);
                    wrapper.Layout.IndexToLineX(lineAbove.GetIndentation(editor.Document).Length, true, out l, out tmp);
                    aboveStart = tmp / Pango.Scale.PangoScale;
                    //aboveEnd = wrapper.PangoWidth / Pango.Scale.PangoScale;

                    if (wrapper.IsUncached)
                    {
                        wrapper.Dispose();
                    }
                }
                if (lineBelow != null)
                {
                    var wrapper = editor.TextViewMargin.GetLayout(lineBelow);
                    wrapper.Layout.IndexToLineX(lineBelow.GetIndentation(editor.Document).Length, true, out l, out tmp);

                    belowStart = tmp / Pango.Scale.PangoScale;
                    //belowEnd = wrapper.PangoWidth / Pango.Scale.PangoScale;
                    if (wrapper.IsUncached)
                    {
                        wrapper.Dispose();
                    }
                }
                var x1 = editor.TextViewMargin.XOffset - editor.HAdjustment.Value;

                return(x1 + System.Math.Max(aboveStart, belowStart));
            }
Example #27
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();
                }
            }
        }
        static void DrawIcon(MonoTextEditor editor, Cairo.Context cr, DocumentLine lineSegment, double x, double y, double width, double height)
        {
            if (lineSegment.IsBookmarked)
            {
                var color1 = editor.ColorStyle.Bookmarks.Color;
                var color2 = editor.ColorStyle.Bookmarks.SecondColor;

                DrawRoundRectangle(cr, x + 1, y + 1, 8, width - 4, height - 4);
                using (var pat = new Cairo.LinearGradient(x + width / 4, y, x + width / 2, y + height - 4)) {
                    pat.AddColorStop(0, color1);
                    pat.AddColorStop(1, color2);
                    cr.SetSource(pat);
                    cr.FillPreserve();
                }

                using (var pat = new Cairo.LinearGradient(x, y + height, x + width, y)) {
                    pat.AddColorStop(0, color2);
                    //pat.AddColorStop (1, color1);
                    cr.SetSource(pat);
                    cr.Stroke();
                }
            }
        }
Example #29
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x) + 0.5, Math.Floor(metrics.LineYRenderStartPosition) + 0.5 + (line == editor.GetLineByOffset(startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

            if (HslColor.Brightness(editor.ColorStyle.PlainText.Background) < 0.5)
            {
                cr.SetSourceRGBA(0.8, 0.8, 1, 0.9);
            }
            else
            {
                cr.SetSourceRGBA(0.2, 0.2, 1, 0.9);
            }
            cr.Stroke();
        }
Example #30
0
        void DrawUnderline(MonoTextEditor editor, Cairo.Context cr, double y, TextViewMargin.LayoutWrapper layoutWrapper, int markerStart, double x1, double x2)
        {
            if (editor is null)
            {
                throw new ArgumentNullException(nameof(editor));
            }
            if (cr is null)
            {
                throw new ArgumentNullException(nameof(cr));
            }
            if (layoutWrapper is null)
            {
                throw new ArgumentNullException(nameof(layoutWrapper));
            }

            x1 = System.Math.Max(x1, editor.TextViewMargin.XOffset);
            x2 = System.Math.Max(x2, editor.TextViewMargin.XOffset);
            if (x1 < x2)
            {
                if (color == null)
                {
                    foreach (var chunk in layoutWrapper.Chunks)
                    {
                        if (chunk.Contains(markerStart))
                        {
                            color = editor.EditorTheme.GetForeground(editor.EditorTheme.GetChunkStyle(chunk.ScopeStack));
                            break;
                        }
                    }
                    if (color == null)
                    {
                        color = editor.EditorTheme.GetForeground(editor.EditorTheme.GetChunkStyle(new ScopeStack(style)));
                    }
                }
                cr.DrawLine(color.Value, x1 + 0.5, y + editor.LineHeight - 1.5, x2 + 0.5, y + editor.LineHeight - 1.5);
            }
        }
Example #31
0
 public IconMargin(MonoTextEditor editor)
 {
     this.editor = editor;
 }
Example #32
0
 public virtual void DrawBackground(MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
 }
Example #33
0
 public HighlightGroup(Mono.TextEditor.MonoTextEditor editor)
 {
     _editor = editor;
     _document = editor.Document;
 }
		protected override void OnDestroyed ()
		{
			adj = null;
			if (textEditor != null)
				textEditor.EditorOptionsChanged -= TextEditor_EditorOptionsChanged;
			textEditor = null;
			providerTasks = null;
			PropertyService.RemovePropertyHandler ("ScrollBar.Mode", ScrollBarModeChanged);
			EnableFancyFeatures.Changed -= HandleChanged;
			base.OnDestroyed ();
		}
Example #35
0
        /// <summary>
        /// Default constructor that configures the Completion form.
        /// </summary>
        public EditorView(ViewBase owner)
            : base(owner)
        {
            scroller = new ScrolledWindow();
            textEditor = new MonoTextEditor();
            scroller.Add(textEditor);
            _mainWidget = scroller;
            TextEditorOptions options = new TextEditorOptions();
            options.EnableSyntaxHighlighting = true;
            options.ColorScheme = "Visual Studio";
            options.HighlightCaretLine = true;
            textEditor.Options = options;
            textEditor.Document.LineChanged += OnTextHasChanged;
            textEditor.LeaveNotifyEvent += OnTextBoxLeave;
            _mainWidget.Destroyed += _mainWidget_Destroyed;

            CompletionForm = new Window(WindowType.Toplevel);
            CompletionForm.Decorated = false;
            CompletionForm.SkipPagerHint = true;
            CompletionForm.SkipTaskbarHint = true;
            Frame completionFrame = new Frame();
            CompletionForm.Add(completionFrame);
            ScrolledWindow completionScroller = new ScrolledWindow();
            completionFrame.Add(completionScroller);
            completionModel = new ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));
            CompletionView = new TreeView(completionModel);
            completionScroller.Add(CompletionView);
            TreeViewColumn column = new TreeViewColumn();
            CellRendererPixbuf iconRender = new Gtk.CellRendererPixbuf();
            column.PackStart(iconRender, false);
            CellRendererText textRender = new Gtk.CellRendererText();
            textRender.Editable = false;
            column.PackStart(textRender, true);
            column.SetAttributes(iconRender, "pixbuf", 0);
            column.SetAttributes(textRender, "text", 1);
            column.Title = "Item";
            column.Resizable = true;
            CompletionView.AppendColumn(column);
            textRender = new CellRendererText();
            column = new TreeViewColumn("Units", textRender, "text", 2);
            column.Resizable = true;
            CompletionView.AppendColumn(column);
            textRender = new CellRendererText();
            column = new TreeViewColumn("Type", textRender, "text", 3);
            column.Resizable = true;
            CompletionView.AppendColumn(column);
            textRender = new CellRendererText();
            column = new TreeViewColumn("Descr", textRender, "text", 4);
            column.Resizable = true;
            CompletionView.AppendColumn(column);
            functionPixbuf = new Gdk.Pixbuf(null, "ApsimNG.Resources.Function.png", 16, 16);
            propertyPixbuf = new Gdk.Pixbuf(null, "ApsimNG.Resources.Property.png", 16, 16);
            textEditor.TextArea.KeyPressEvent += OnKeyPress;
            CompletionView.HasTooltip = true;
            CompletionView.TooltipColumn = 5;
            CompletionForm.FocusOutEvent += OnLeaveCompletion;
            CompletionView.ButtonPressEvent += OnContextListMouseDoubleClick;
            CompletionView.KeyPressEvent += OnContextListKeyDown;
            CompletionView.KeyReleaseEvent += CompletionView_KeyReleaseEvent;
            IntelliSenseChars = ".";
        }