diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-11-18 00:22:30 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-11-18 00:22:30 +0400 |
commit | 095f2d7ec19bc4f78ed0fa54d5ca5a4e9423f4ba (patch) | |
tree | 4b8f293a7dbc3bbbe600eda7694153d090f89b22 /main/src/addins/MonoDevelop.SourceEditor2 | |
parent | ae607a1050d901ae22d95cd6023a0aed2c7601e9 (diff) | |
parent | 532138fa22ed040ed3a353d755c259163c77398f (diff) |
Merge branch 'master' into newresolver
Conflicts:
extras/GtkSourceViewEditor/MonoDevelop.SourceEditor.addin.xml
extras/MonoDevelop.Database/MonoDevelop.Database.Components/Widgets/DataGrid/DataGrid.cs
main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml
main/src/addins/NUnit/Makefile.am
main/src/addins/NUnit/MonoDevelop.NUnit.csproj
main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Dom.Serialization/ProjectCodeCompletionDatabase.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeCompletion/ListWindow.cs
Diffstat (limited to 'main/src/addins/MonoDevelop.SourceEditor2')
9 files changed, 221 insertions, 390 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/Makefile.am b/main/src/addins/MonoDevelop.SourceEditor2/Makefile.am index 650945aeca..e581850162 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/Makefile.am +++ b/main/src/addins/MonoDevelop.SourceEditor2/Makefile.am @@ -49,7 +49,6 @@ FILES = \ MonoDevelop.SourceEditor/SourceEditorPrintOperation.cs \ MonoDevelop.SourceEditor/SourceEditorView.cs \ MonoDevelop.SourceEditor/SourceEditorWidget.cs \ - MonoDevelop.SourceEditor/StatusBox.cs \ MonoDevelop.SourceEditor/StyledSourceEditorOptions.cs \ MonoDevelop.SourceEditor/SyntaxModeCodon.cs \ MonoDevelop.SourceEditor/SyntaxModeService.cs diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml index 5cf8f3d06f..929df6c653 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml @@ -115,12 +115,7 @@ _description = "Activates code focus on caret move" shortcut = "Ctrl|Shift|k" macShortcut = "Meta|Shift|k" /> - - <Command id = "MonoDevelop.SourceEditor.NavigationBarCommands.ToggleNavPanelViews" - defaultHandler = "MonoDevelop.SourceEditor.ToggleNavPanelViewsHandler" - _label = "" - type="array"/> - + <Command id = "MonoDevelop.SourceEditor.MessageBubbleCommands.HideIssues" defaultHandler = "MonoDevelop.SourceEditor.HideIssuesHandler" _label = "_Hide Issues"/> @@ -188,7 +183,6 @@ <CommandItem id = "MonoDevelop.SourceEditor.NavigationBarCommands.ToggleNavPanelViews" /> </Extension> - <Extension path = "/MonoDevelop/SourceEditor2/IconContextMenu/Editor"> <CommandItem id = "MonoDevelop.Ide.Commands.SearchCommands.ToggleBookmark" /> <CommandItem id = "MonoDevelop.Ide.Commands.SearchCommands.ClearBookmarks" /> diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj index 85d3e58248..147143cd6c 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj @@ -152,7 +152,6 @@ <Compile Include="MonoDevelop.SourceEditor\SourceEditorPrintOperation.cs" /> <Compile Include="MonoDevelop.SourceEditor\PrintSettingsWidget.cs" /> <Compile Include="gtk-gui\MonoDevelop.SourceEditor.PrintSettingsWidget.cs" /> - <Compile Include="MonoDevelop.SourceEditor\StatusBox.cs" /> <Compile Include="MonoDevelop.SourceEditor\MessageBubbleCommands.cs" /> <Compile Include="MonoDevelop.SourceEditor\MessageBubbleTextMarker.cs" /> <Compile Include="MonoDevelop.SourceEditor\MessageBubbleHighlightPopupWindow.cs" /> diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs index 792bb6b1e9..3e160d7c60 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.cs @@ -55,8 +55,6 @@ namespace MonoDevelop.SourceEditor SourceEditorView view; ExtensionContext extensionContext; - Cairo.Point menuPopupLocation; - public ITextEditorExtension Extension { get; set; @@ -108,8 +106,7 @@ namespace MonoDevelop.SourceEditor UpdateEditMode (); this.GetTextEditorData ().Paste += HandleTextPaste; - - this.ButtonPressEvent += OnPopupMenu; + this.DoPopupMenu = ShowPopup; } void HandleSkipCharsOnReplace (object sender, ReplaceEventArgs args) @@ -179,7 +176,6 @@ namespace MonoDevelop.SourceEditor { ExtensionContext = null; view = null; - this.ButtonPressEvent -= OnPopupMenu; base.OnDestroyed (); } @@ -199,22 +195,6 @@ namespace MonoDevelop.SourceEditor TooltipProviders.Remove (provider); } } - - void OnPopupMenu (object sender, Gtk.ButtonPressEventArgs args) - { - if (args.Event.Button == 3) { - int textEditorXOffset = (int)args.Event.X - (int)this.TextViewMargin.XOffset; - if (textEditorXOffset < 0) - return; - this.menuPopupLocation = new Cairo.Point ((int)args.Event.X, (int)args.Event.Y); - DocumentLocation loc= PointToLocation (textEditorXOffset, (int)args.Event.Y); - if (!this.IsSomethingSelected || !this.SelectionRange.Contains (Document.LocationToOffset (loc))) - Caret.Location = loc; - - this.ShowPopup (); - base.ResetMouseState (); - } - } public void FireOptionsChange () { @@ -230,19 +210,12 @@ namespace MonoDevelop.SourceEditor UpdateEditMode (); base.OptionsChanged (sender, args); } + bool isInKeyStroke = false; protected override bool OnKeyPressEvent (Gdk.EventKey evnt) { isInKeyStroke = true; try { - // Handle keyboard menu popup - if (evnt.Key == Gdk.Key.Menu || (evnt.Key == Gdk.Key.F10 && (evnt.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask)) { - this.menuPopupLocation = LocationToPoint (this.Caret.Location); - this.menuPopupLocation.Y += (int)LineHeight; - this.ShowPopup (); - return true; - } - // Handle keyboard toolip popup /* if ((evnt.Key == Gdk.Key.F1 && (evnt.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)) { Gdk.Point p = this.TextViewMargin.LocationToDisplayCoordinates (this.Caret.Location); @@ -588,34 +561,30 @@ namespace MonoDevelop.SourceEditor return base.OnFocusOutEvent (evnt); } - void ShowPopup () + void ShowPopup (Gdk.EventButton evt) { HideTooltip (); - CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet (ExtensionContext ?? AddinManager.AddinEngine, "/MonoDevelop/SourceEditor2/ContextMenu/Editor"); + const string menuPath = "/MonoDevelop/SourceEditor2/ContextMenu/Editor"; + var ctx = ExtensionContext ?? AddinManager.AddinEngine; + CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet (ctx, menuPath); Gtk.Menu menu = IdeApp.CommandService.CreateMenu (cset); - menu.Append (new SeparatorMenuItem ()); + var imMenu = CreateInputMethodMenuItem (GettextCatalog.GetString ("_Input Methods")); if (imMenu != null) { + menu.Append (new SeparatorMenuItem ()); menu.Append (imMenu); } + menu.Destroyed += delegate { this.QueueDraw (); }; - menu.Popup (null, null, new Gtk.MenuPositionFunc (PositionPopupMenu), 0, Gtk.Global.CurrentEventTime); - } - - void PositionPopupMenu (Menu menu, out int x, out int y, out bool pushIn) - { - this.GdkWindow.GetOrigin (out x, out y); - x += this.menuPopupLocation.X; - y += this.menuPopupLocation.Y; - Requisition request = menu.SizeRequest (); - Gdk.Rectangle geometry = DesktopService.GetUsableMonitorGeometry (Screen, Screen.GetMonitorAtPoint (x, y)); - - y = Math.Max (geometry.Top, Math.Min (y, geometry.Bottom - request.Height)); - x = Math.Max (geometry.Left, Math.Min (x, geometry.Right - request.Width)); - pushIn = true; + if (evt != null) { + GtkWorkarounds.ShowContextMenu (menu, this, evt); + } else { + var pt = LocationToPoint (this.Caret.Location); + GtkWorkarounds.ShowContextMenu (menu, this, new Gdk.Rectangle (pt.X, pt.Y, 1, (int)LineHeight)); + } } #region Templates diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs index 48bb35ccd6..449b8df33c 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleHighlightPopupWindow.cs @@ -51,12 +51,12 @@ namespace MonoDevelop.SourceEditor protected override Gdk.Rectangle CalculateInitialBounds () { - int spaceX = marker.ErrorTextBounds.Width / 2; - - return new Gdk.Rectangle (marker.ErrorTextBounds.X - spaceX, - (int)(marker.ErrorTextBounds.Y - Editor.LineHeight), - marker.ErrorTextBounds.Width + spaceX * 2, - (int)(marker.ErrorTextBounds.Height + Editor.LineHeight * 2)); + var bounds = marker.ErrorTextBounds; + int spaceX = bounds.Width / 2; + return new Gdk.Rectangle (bounds.X - spaceX, + (int)(bounds.Y - Editor.LineHeight), + bounds.Width + spaceX * 2, + (int)(bounds.Height + Editor.LineHeight * 2)); } protected override void OnAnimationCompleted () @@ -72,22 +72,23 @@ namespace MonoDevelop.SourceEditor cr.Paint (); } + var bounds = marker.ErrorTextBounds; using (var cr = Gdk.CairoHelper.Create (evnt.Window)) { cr.Translate (width / 2, height / 2); cr.Scale (1 + scale / 8, 1 + scale / 8); - int x = -(marker.ErrorTextBounds.Width) / 2; - int y = -marker.ErrorTextBounds.Height / 2; + int x = -(bounds.Width) / 2; + int y = -bounds.Height / 2; if (marker.FitsInSameLine) { cr.MoveTo (x + Editor.LineHeight / 2, y); cr.LineTo (x, 0); - cr.LineTo (x + Editor.LineHeight / 2, marker.ErrorTextBounds.Height / 2); + cr.LineTo (x + Editor.LineHeight / 2, bounds.Height / 2); } else { - cr.MoveTo (x, -marker.ErrorTextBounds.Height / 2); - cr.LineTo (x, marker.ErrorTextBounds.Height / 2); + cr.MoveTo (x, -bounds.Height / 2); + cr.LineTo (x, bounds.Height / 2); } - cr.LineTo (x + marker.ErrorTextBounds.Width, marker.ErrorTextBounds.Height / 2); - cr.LineTo (x + marker.ErrorTextBounds.Width, y); + cr.LineTo (x + bounds.Width, bounds.Height / 2); + cr.LineTo (x + bounds.Width, y); cr.ClosePath (); Mono.TextEditor.HslColor hsl = marker.colorMatrix [0, 0, 0, 0, 0]; @@ -110,7 +111,7 @@ namespace MonoDevelop.SourceEditor int ew, eh; marker.errorCountLayout.GetPixelSize (out ew, out eh); errorCounterWidth = ew + 10; - int rX = x + marker.ErrorTextBounds.Width - errorCounterWidth; + int rX = x + bounds.Width - errorCounterWidth; int rW = errorCounterWidth - 2; double rH = Editor.LineHeight * 3 / 4; @@ -134,7 +135,7 @@ namespace MonoDevelop.SourceEditor marker.Layouts [0].Layout.GetPixelSize (out layoutWidth, out layoutHeight); double ly; if (marker.CollapseExtendedErrors || marker.Errors.Count == 1) { - ly = 1 + y + (marker.ErrorTextBounds.Height - layoutHeight) / 2; + ly = 1 + y + (bounds.Height - layoutHeight) / 2; double x2 = x + MessageBubbleTextMarker.border; if (marker.FitsInSameLine) x2 += 1 + Editor.LineHeight / 2; @@ -148,7 +149,7 @@ namespace MonoDevelop.SourceEditor cr.Save (); double x2; if (i == 0) { - x2 = x + marker.ErrorTextBounds.Width - layoutWidth - errorCounterWidth; + x2 = x + bounds.Width - layoutWidth - errorCounterWidth; } else { x2 = x + MessageBubbleTextMarker.border; } diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleTextMarker.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleTextMarker.cs index 37a39a19a8..83537b5d1e 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleTextMarker.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/MessageBubbleTextMarker.cs @@ -75,7 +75,7 @@ namespace MonoDevelop.SourceEditor set { task.Completed = !value; } } - bool collapseExtendedErrors; + bool collapseExtendedErrors = true; public bool CollapseExtendedErrors { get { return collapseExtendedErrors; } set { @@ -86,10 +86,11 @@ namespace MonoDevelop.SourceEditor if (collapseExtendedErrors) { editor.Document.UnRegisterVirtualTextMarker (this); } else { - for (int i = 1; i < errors.Count; i++) - editor.Document.RegisterVirtualTextMarker (lineNumber + i, this); + var fitting = IsCurrentErrorTextFitting (); + for (int i = fitting ? 1 : 0; i < errors.Count; i++) + editor.Document.RegisterVirtualTextMarker (lineNumber + i + (fitting ? 0 : 1), this); } - editor.Document.CommitMultipleLineUpdate (lineNumber, lineNumber + errors.Count); + editor.Document.CommitMultipleLineUpdate (lineNumber, lineNumber + errors.Count + 1); } } @@ -107,6 +108,8 @@ namespace MonoDevelop.SourceEditor public double GetLineHeight (TextEditor editor) { + return editor.LineHeight; + /* if (!IsVisible || DebuggingService.IsDebugging) return editor.LineHeight; @@ -129,7 +132,7 @@ namespace MonoDevelop.SourceEditor lastLineLength = lineSegment.EditableLength; lastHeight = height; - return height; + return height;*/ } public void SetPrimaryError (string text) @@ -156,17 +159,17 @@ namespace MonoDevelop.SourceEditor layouts.Insert (0, tmplayout); } - void CalculateLineFit (TextEditor editor, LineSegment lineSegment) - { - double textWidth; - if (!cache.lineWidthDictionary.TryGetValue (lineSegment, out textWidth)) { - var textLayout = editor.TextViewMargin.GetLayout (lineSegment); - textWidth = textLayout.PangoWidth / Pango.Scale.PangoScale; - cache.lineWidthDictionary[lineSegment] = textWidth; - } - EnsureLayoutCreated (editor); - fitsInSameLine = editor.TextViewMargin.XOffset + textWidth + LayoutWidth + cache.errorPixbuf.Width + border + editor.LineHeight / 2 < editor.Allocation.Width; - } +// void CalculateLineFit (TextEditor editor, LineSegment lineSegment) +// { +// double textWidth; +// if (!cache.lineWidthDictionary.TryGetValue (lineSegment, out textWidth)) { +// var textLayout = editor.TextViewMargin.GetLayout (lineSegment); +// textWidth = textLayout.PangoWidth / Pango.Scale.PangoScale; +// cache.lineWidthDictionary[lineSegment] = textWidth; +// } +// EnsureLayoutCreated (editor); +// fitsInSameLine = editor.TextViewMargin.XOffset + textWidth + LayoutWidth + cache.errorPixbuf.Width + border + editor.LineHeight / 2 < editor.Allocation.Width; +// } string initialText; internal MessageBubbleTextMarker (MessageBubbleCache cache, Task task, LineSegment lineSegment, bool isError, string errorMessage) @@ -178,7 +181,7 @@ namespace MonoDevelop.SourceEditor this.initialText = editor.Document.GetTextAt (lineSegment); this.Flags = TextMarkerFlags.DrawsSelection; AddError (isError, errorMessage); - cache.Changed += (sender, e) => CalculateLineFit (editor, lineSegment); +// cache.Changed += (sender, e) => CalculateLineFit (editor, lineSegment); } static System.Text.RegularExpressions.Regex mcsErrorFormat = new System.Text.RegularExpressions.Regex ("(.+)\\(CS\\d+\\)\\Z"); @@ -188,7 +191,7 @@ namespace MonoDevelop.SourceEditor if (match.Success) errorMessage = match.Groups [1].Value; errors.Add (new ErrorText (isError, errorMessage)); - CollapseExtendedErrors = errors.Count > 1; + CollapseExtendedErrors = true; DisposeLayout (); } @@ -236,7 +239,6 @@ namespace MonoDevelop.SourceEditor layouts = new List<MessageBubbleCache.LayoutDescriptor> (); foreach (ErrorText errorText in errors) { - layouts.Add (cache.CreateLayoutDescriptor (errorText)); } @@ -260,7 +262,68 @@ namespace MonoDevelop.SourceEditor return 0; if (!CollapseExtendedErrors && errors.Count > 1) return layouts.Max (l => l.Width); - return layouts[0].Width; + return layouts [0].Width; + } + } + + Tuple<int, int> GetErrorCountBounds (TextViewMargin.LayoutWrapper wrapper = null) + { + EnsureLayoutCreated (editor); + var layout = wrapper ?? editor.TextViewMargin.GetLayout (lineSegment); + try { + var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout.PangoWidth / Pango.Scale.PangoScale; + if (errors.Count > 1 && errorCountLayout != null || editor.Allocation.Width < lineTextPx + layouts [0].Width) { + int ew = 0, eh = 0; + if (errorCountLayout != null) { + errorCountLayout.GetPixelSize (out ew, out eh); + } else { + ew = 10; + } + return Tuple.Create (ew + 10, eh); + } + return Tuple.Create (0, 0); + } finally { + if (wrapper == null && layout.IsUncached) + layout.Dispose (); + } + } + + void DrawMessageExtendIcon (Mono.TextEditor.TextEditor editor, Cairo.Context g, double y, int errorCounterWidth, int eh) + { + EnsureLayoutCreated (editor); + double rW = errorCounterWidth - 2; + double rH = editor.LineHeight * 3 / 4; + + double rX = editor.Allocation.Width - rW - 2; + double rY = y + (editor.LineHeight - rH) / 2; + BookmarkMarker.DrawRoundRectangle (g, rX, rY, 8, rW, rH); + + g.Color = oldIsOver ? new Cairo.Color (0.3, 0.3, 0.3) : new Cairo.Color (0.5, 0.5, 0.5); + g.Fill (); + if (CollapseExtendedErrors) { + if (errorCountLayout != null) { + g.Color = cache.gcLight; + g.Save (); + g.Translate (rX + rW / 4, rY + (rH - eh) / 2); + g.ShowLayout (errorCountLayout); + g.Restore (); + } else { + g.MoveTo (rX + rW / 2 - rW / 4, rY + rH / 4); + g.LineTo (rX + rW / 2 + rW / 4, rY + rH / 4); + g.LineTo (rX + rW / 2, rY + rH - rH / 4); + g.ClosePath (); + + g.Color = new Cairo.Color (1, 1, 1); + g.Fill (); + } + } else { + g.MoveTo (rX + rW / 2 - rW / 4, rY + rH - rH / 4); + g.LineTo (rX + rW / 2 + rW / 4, rY + rH - rH / 4); + g.LineTo (rX + rW / 2, rY + rH / 4); + g.ClosePath (); + + g.Color = new Cairo.Color (1, 1, 1); + g.Fill (); } } @@ -271,15 +334,12 @@ namespace MonoDevelop.SourceEditor EnsureLayoutCreated (editor); double x = editor.TextViewMargin.XOffset; int right = editor.Allocation.Width; - int errorCounterWidth = 0; bool isCaretInLine = startOffset <= editor.Caret.Offset && editor.Caret.Offset <= endOffset; - int ew = 0, eh = 0; - if (errors.Count > 1 && errorCountLayout != null) { - errorCountLayout.GetPixelSize (out ew, out eh); - errorCounterWidth = ew + 10; - } - + var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout2.PangoWidth / Pango.Scale.PangoScale; + int errorCounterWidth = GetErrorCountBounds (layout2).Item1; +// int eh = GetErrorCountBounds ().Item2; double x2 = System.Math.Max (right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); + bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset + lineSegment.EditableLength) : false; int active = editor.Document.GetTextAt (lineSegment) == initialText ? 0 : 1; @@ -322,7 +382,7 @@ namespace MonoDevelop.SourceEditor g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke (); } - + // draw background if (layout2.StartSet || selectionStart == endOffset) { double startX; @@ -386,10 +446,12 @@ namespace MonoDevelop.SourceEditor y += editor.LineHeight; double y2 = y + 0.5; double y2Bottom = y2 + editor.LineHeight - 1; - selected = isEolSelected && (CollapseExtendedErrors || errors.Count == 1) ? 1 : 0; - + selected = isEolSelected && (CollapseExtendedErrors) ? 1 : 0; + if (x2 < lineTextPx) + x2 = lineTextPx; + // draw message text background - if (CollapseExtendedErrors || errors.Count == 1) { + if (CollapseExtendedErrors) { if (!fitsInSameLine) { // draw box below line g.MoveTo (new Cairo.PointD (x2 + 0.5, y2 - 1)); @@ -407,24 +469,26 @@ namespace MonoDevelop.SourceEditor g.Stroke (); } else { // draw 'arrow marker' in the same line - g.MoveTo (new Cairo.PointD (x2 + 0.5, y2)); - double mid = y2 + topSize; - g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, mid)); - - g.LineTo (new Cairo.PointD (right, mid)); - g.LineTo (new Cairo.PointD (right, y2)); - g.ClosePath (); - g.Color = colorMatrix [active, TOP, DARK, highlighted, selected]; - g.Fill (); - g.MoveTo (new Cairo.PointD (x2 + 0.5, y2Bottom)); - g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, mid)); - - g.LineTo (new Cairo.PointD (right, mid)); - g.LineTo (new Cairo.PointD (right, y2Bottom)); - g.ClosePath (); - - g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; - g.Fill (); + if (errors.Count > 1) { + g.MoveTo (new Cairo.PointD (x2 + 0.5, y2)); + double mid = y2 + topSize; + g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, mid)); + + g.LineTo (new Cairo.PointD (right, mid)); + g.LineTo (new Cairo.PointD (right, y2)); + g.ClosePath (); + g.Color = colorMatrix [active, TOP, DARK, highlighted, selected]; + g.Fill (); + g.MoveTo (new Cairo.PointD (x2 + 0.5, y2Bottom)); + g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, mid)); + + g.LineTo (new Cairo.PointD (right, mid)); + g.LineTo (new Cairo.PointD (right, y2Bottom)); + g.ClosePath (); + + g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; + g.Fill (); + } // draw border g.MoveTo (new Cairo.PointD (x2 + 0.5, y2)); @@ -448,12 +512,14 @@ namespace MonoDevelop.SourceEditor g.ClosePath (); } else { // draw filled arrow box - g.MoveTo (new Cairo.PointD (x2 + 0.5, y2)); - g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2)); - g.LineTo (new Cairo.PointD (x2 + 0.5, y2Bottom)); - g.LineTo (new Cairo.PointD (right, y2Bottom)); - g.LineTo (new Cairo.PointD (right, y2)); - g.ClosePath (); + if (!(errors.Count == 1 && !CollapseExtendedErrors)) { + g.MoveTo (new Cairo.PointD (x2 + 0.5, y2)); + g.LineTo (new Cairo.PointD (x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2)); + g.LineTo (new Cairo.PointD (x2 + 0.5, y2Bottom)); + g.LineTo (new Cairo.PointD (right, y2Bottom)); + g.LineTo (new Cairo.PointD (right, y2)); + g.ClosePath (); + } } g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]; g.Fill (); @@ -494,39 +560,24 @@ namespace MonoDevelop.SourceEditor g.Stroke (); } } - - if (errors.Count > 1 && errorCountLayout != null) { - double rX = x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border + LayoutWidth; - double rY = y + editor.LineHeight / 6; - double rW = errorCounterWidth - 2; - double rH = editor.LineHeight * 3 / 4; - BookmarkMarker.DrawRoundRectangle (g, rX, rY, 8, rW, rH); - - g.Color = oldIsOver ? new Cairo.Color (0.3, 0.3, 0.3) : new Cairo.Color (0.5, 0.5, 0.5); - g.Fill (); - if (CollapseExtendedErrors) { - g.Color = cache.gcLight; - g.Save (); - g.Translate (x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border + LayoutWidth + 4, y + (editor.LineHeight - eh) / 2 + eh % 2); - g.ShowLayout (errorCountLayout); - g.Restore (); - } else { - g.MoveTo (rX + rW / 2 - rW / 4, rY + rH - rH / 4); - g.LineTo (rX + rW / 2 + rW / 4, rY + rH - rH / 4); - g.LineTo (rX + rW / 2, rY + rH / 4); - g.ClosePath (); - - g.Color = new Cairo.Color (1, 1, 1); - g.Fill (); - } - } + for (int i = 0; i < layouts.Count; i++) { + if (!IsCurrentErrorTextFitting (layout2) && !CollapseExtendedErrors) + break; + var layout = layouts [i]; x2 = right - layout.Width - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0); - if (i == 0) + if (i == 0) { x2 -= errorCounterWidth; - x2 = System.Math.Max (x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); + if (x2 < lineTextPx) { + // if (CollapseExtendedErrors) { + x2 = lineTextPx; + // } + } + } +// x2 = System.Math.Max (x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); + if (i > 0) { editor.TextViewMargin.DrawRectangleWithRuler (g, x, new Cairo.Rectangle (x, y, right, editor.LineHeight), isEolSelected ? editor.ColorStyle.Selection.CairoBackgroundColor : editor.ColorStyle.Default.CairoBackgroundColor, true); g.MoveTo (new Cairo.PointD (x2 + 0.5, y)); @@ -542,7 +593,7 @@ namespace MonoDevelop.SourceEditor g.Pattern = pat; } } else { - g.Color = colorMatrix[active, TOP, LIGHT, highlighted, selected]; + g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected]; } g.Fill (); if (editor.Options.ShowRuler) { @@ -550,7 +601,7 @@ namespace MonoDevelop.SourceEditor if (divider >= x2) { g.MoveTo (new Cairo.PointD (divider + 0.5, y)); g.LineTo (new Cairo.PointD (divider + 0.5, y + editor.LineHeight)); - g.Color = colorMatrix[active, BOTTOM, DARK, highlighted, selected]; + g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; g.Stroke (); } } @@ -622,17 +673,16 @@ namespace MonoDevelop.SourceEditor double height = editor.LineHeight * errors.Count; if (!fitsInSameLine) y += editor.LineHeight; - int errorCounterWidth = 0; - - int ew = 0, eh = 0; - if (errors.Count > 1 && errorCountLayout != null) { - errorCountLayout.GetPixelSize (out ew, out eh); - errorCounterWidth = ew + 10; - } + int errorCounterWidth = GetErrorCountBounds ().Item1; double labelWidth = LayoutWidth + border + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + errorCounterWidth; if (fitsInSameLine) labelWidth += editor.LineHeight / 2; + + var layout = editor.TextViewMargin.GetLayout (lineSegment); + var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout.PangoWidth / Pango.Scale.PangoScale; + labelWidth = Math.Min (editor.Allocation.Width - lineTextPx - editor.TextViewMargin.TextStartPosition, labelWidth); + return new Gdk.Rectangle ((int)(editor.Allocation.Width - labelWidth), (int)y, (int)labelWidth, (int)height); } } @@ -651,7 +701,6 @@ namespace MonoDevelop.SourceEditor bool MouseIsOverMarker (TextEditor editor, MarginMouseEventArgs args) { - int ew = 0, eh = 0; int lineNumber = editor.Document.OffsetToLineNumber (lineSegment.Offset); double y = editor.LineToY (lineNumber) - editor.VAdjustment.Value; if (fitsInSameLine) { @@ -662,14 +711,26 @@ namespace MonoDevelop.SourceEditor return false; } - if (errors.Count > 1 && errorCountLayout != null) { - errorCountLayout.GetPixelSize (out ew, out eh); - int errorCounterWidth = ew + 10; - if (editor.Allocation.Width - args.X - editor.TextViewMargin.XOffset <= errorCounterWidth) - return true; - } + int errorCounterWidth = GetErrorCountBounds ().Item1; + if (errorCounterWidth > 0) + return editor.Allocation.Width - editor.TextViewMargin.XOffset - 2 - errorCounterWidth <= args.X; return false; } + + bool IsCurrentErrorTextFitting (TextViewMargin.LayoutWrapper wrapper = null) + { + int errorCounterWidth = GetErrorCountBounds (wrapper).Item1; + double labelWidth = LayoutWidth + border + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + errorCounterWidth + editor.LineHeight / 2; + + var layout = wrapper ?? editor.TextViewMargin.GetLayout (lineSegment); + + var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout.PangoWidth / Pango.Scale.PangoScale; + + if (wrapper == null && layout.IsUncached) + layout.Dispose (); + + return labelWidth < editor.Allocation.Width - lineTextPx - editor.TextViewMargin.TextStartPosition; + } int MouseIsOverError (TextEditor editor, MarginMouseEventArgs args) { @@ -687,17 +748,17 @@ namespace MonoDevelop.SourceEditor // Console.WriteLine ("error:" + error); if (error >= layouts.Count) return -1; - int errorCounterWidth = 0; - - int ew = 0, eh = 0; - if (error == 0 && errors.Count > 1 && errorCountLayout != null) { - errorCountLayout.GetPixelSize (out ew, out eh); - errorCounterWidth = ew + 10; - } + int errorCounterWidth = GetErrorCountBounds ().Item1; double labelWidth = LayoutWidth + border + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + errorCounterWidth + editor.LineHeight / 2; - if (editor.Allocation.Width - editor.TextViewMargin.XOffset - args.X < labelWidth) + var layout = editor.TextViewMargin.GetLayout (lineSegment); + + var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout.PangoWidth / Pango.Scale.PangoScale; + + labelWidth = Math.Min (editor.Allocation.Width - lineTextPx - editor.TextViewMargin.TextStartPosition, labelWidth); + + if (editor.Allocation.Width - editor.TextViewMargin.XOffset - labelWidth < args.X) return error; return -1; @@ -723,8 +784,18 @@ namespace MonoDevelop.SourceEditor } } - #endregion + + public override void Draw (TextEditor editor, Cairo.Context g, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) + { + var bounds = GetErrorCountBounds (); + int errorCounterWidth = bounds.Item1; + int eh = bounds.Item2; + + if (errorCounterWidth > 0) + DrawMessageExtendIcon (editor, g, y, errorCounterWidth, eh); + + } #region IExtendingTextMarker implementation public void Draw (TextEditor editor, Cairo.Context g, int lineNr, Cairo.Rectangle lineArea) @@ -732,18 +803,17 @@ namespace MonoDevelop.SourceEditor EnsureLayoutCreated (editor); int lineNumber = editor.Document.OffsetToLineNumber (lineSegment.Offset); int errorNumber = lineNr - lineNumber; + if (!IsCurrentErrorTextFitting ()) + errorNumber--; double x = editor.TextViewMargin.XOffset; double y = lineArea.Y; double right = editor.Allocation.Width; - int errorCounterWidth = 0; - - int ew = 0, eh = 0; - if (errors.Count > 1 && errorCountLayout != null) { - errorCountLayout.GetPixelSize (out ew, out eh); - errorCounterWidth = ew + 10; - } + int errorCounterWidth = GetErrorCountBounds ().Item1; +// int eh = GetErrorCountBounds ().Item2; double x2 = System.Math.Max (right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); + if (errors.Count == 1) + x2 = editor.TextViewMargin.XOffset; // bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset + lineSegment.EditableLength) : false; int active = editor.Document.GetTextAt (lineSegment) == initialText ? 0 : 1; bool isCaretInLine = lineSegment.Offset <= editor.Caret.Offset && editor.Caret.Offset <= lineSegment.EndOffset; @@ -784,6 +854,7 @@ namespace MonoDevelop.SourceEditor g.Color = selected == 0 ? gc : cache.gcSelected; g.ShowLayout (layout.Layout); g.Restore (); + // if (ShowIconsInBubble) // win.DrawPixbuf (editor.Style.BaseGC (Gtk.StateType.Normal), errors[errorNumber].IsError ? errorPixbuf : warningPixbuf, 0, 0, x2, y + (editor.LineHeight - errorPixbuf.Height) / 2, errorPixbuf.Width, errorPixbuf.Height, Gdk.RgbDither.None, 0, 0); } diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/QuickTaskStrip.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/QuickTaskStrip.cs index 3dff32e3bf..de7ceaeccf 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/QuickTaskStrip.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/QuickTaskStrip.cs @@ -372,7 +372,7 @@ namespace MonoDevelop.SourceEditor { button |= evnt.Button; - if (evnt.Button == 1 && hoverTask != null) { + if (!evnt.TriggersContextMenu () && evnt.Button == 1 && hoverTask != null) { TextEditor.Caret.Location = new DocumentLocation (hoverTask.Location.Line, Math.Max (DocumentLocation.MinColumn, hoverTask.Location.Column)); TextEditor.CenterToCaret (); TextEditor.StartCaretPulseAnimation (); diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs index 5cdbe166b8..758a346445 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs @@ -1041,7 +1041,7 @@ namespace MonoDevelop.SourceEditor void OnIconButtonPress (object s, MarginMouseEventArgs args) { - if (args.Button == 3) { + if (args.TriggersContextMenu ()) { TextEditor.Caret.Line = args.LineNumber; TextEditor.Caret.Column = 1; IdeApp.CommandService.ShowContextMenu (WorkbenchWindow.ExtensionContext, "/MonoDevelop/SourceEditor2/IconContextMenu/Editor"); diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/StatusBox.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/StatusBox.cs deleted file mode 100644 index 0090ad42e4..0000000000 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/StatusBox.cs +++ /dev/null @@ -1,202 +0,0 @@ -// -// StatusBox.cs -// -// Author: -// Mike Krüger <mkrueger@novell.com> -// -// Copyright (c) 2010 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.ComponentModel; -using Gtk; -using Mono.TextEditor; -using MonoDevelop.Components.Commands; -using MonoDevelop.Ide.Gui; -using MonoDevelop.Core; -using MonoDevelop.Ide; - -namespace MonoDevelop.SourceEditor -{ - class StatusBox : Gtk.Button - { - Pango.Layout layout; - const int leftSpacing = 2; - const int ySpacing = 1; - - public string Text { - get { - return layout.Text; - } - set { - layout.SetText (value); - } - } - - public bool DrawRightBorder { - get; - set; - } - - public static bool ShowRealColumns { - get { - return PropertyService.Get ("CaretStatusBoxShowRealColumns", true); - } - set { - PropertyService.Set ("CaretStatusBoxShowRealColumns", value); - } - } - SourceEditorWidget Editor { - get; - set; - } - - public StatusBox (SourceEditorWidget editor) - { - this.Editor = editor; - PropertyService.AddPropertyHandler ("CaretStatusBoxShowRealColumns", PropertyHandler); - - WidgetFlags |= WidgetFlags.NoWindow; - - layout = new Pango.Layout (this.PangoContext); - measureLayout = new Pango.Layout (this.PangoContext); - } - - - void PropertyHandler (object sender, MonoDevelop.Core.PropertyChangedEventArgs e) - { - Text = GetText (false); - UpdateWidth (); - } - - protected override void OnDestroyed () - { - base.OnDestroyed (); - if (measureLayout != null) { - measureLayout.Dispose (); - measureLayout = null; - } - if (layout != null) { - layout.Dispose (); - layout = null; - } - Editor = null; - PropertyService.RemovePropertyHandler ("CaretStatusBoxShowRealColumns", PropertyHandler); - } - - int requestWidth = 200; - Pango.Layout measureLayout; - public void UpdateWidth () - { - measureLayout.SetText (GetText (true)); - int h, w; - measureLayout.GetPixelSize (out w, out h); - if (w != requestWidth) { - requestWidth = w; - QueueResize (); - } - } - - string GetText (bool showMax) - { - int line = showMax ? Editor.Document.LineCount : Editor.TextEditor.Caret.Line; - int column; - if (showMax) { - column = System.Math.Max (Editor.TextEditor.Caret.Column, 100); - } else if (ShowRealColumns) { - DocumentLocation location = Editor.TextEditor.LogicalToVisualLocation (Editor.TextEditor.Caret.Location); - column = location.Column; - } else { - column = Editor.TextEditor.Caret.Column ; - } - - return string.Format (ShowRealColumns ? GettextCatalog.GetString ("Line: {0}, Column: {1}") : "{0} : {1}", line, column); - } - - public void ShowCaretState () - { - this.Text = GetText (false); - this.QueueDraw (); - } - - protected override bool OnButtonPressEvent (Gdk.EventButton evnt) - { - if (evnt.Button == 3) { - ShowNavigationBarContextMenu (); - return true; - } - return base.OnButtonPressEvent (evnt); - } - - internal static void ShowNavigationBarContextMenu () - { - CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet ("/MonoDevelop/SourceEditor2/ContextMenu/NavigationBar"); - Gtk.Menu menu = IdeApp.CommandService.CreateMenu (cset); - IdeApp.CommandService.ShowContextMenu (menu); - } - - protected override void OnSizeRequested (ref Gtk.Requisition requisition) - { - requisition.Width = requestWidth + leftSpacing * 2; - } - protected override void OnSizeAllocated (Gdk.Rectangle allocation) - { - base.OnSizeAllocated (allocation); - } - - protected override bool OnExposeEvent (Gdk.EventExpose args) - { - Gdk.Drawable win = args.Window; - - int width, height; - layout.GetPixelSize (out width, out height); - - int arrowHeight = height / 2; - int arrowWidth = arrowHeight + 1; - int arrowXPos = this.Allocation.X + this.Allocation.Width - arrowWidth; - if (DrawRightBorder) - arrowXPos -= 2; - var state = StateType.Normal; - //HACK: don't ever draw insensitive, only active/prelight/normal, because insensitive generally looks really ugly - //this *might* cause some theme issues with the state of the text/arrows rendering on top of it - - //HACK: paint the button background as if it were bigger, but it stays clipped to the real area, - // so we get the content but not the border. This might break with crazy themes. - //FIXME: we can't use the style's actual internal padding because GTK# hasn't wrapped GtkBorder AFAICT - // (default-border, inner-border, default-outside-border, etc - see http://git.gnome.org/browse/gtk+/tree/gtk/gtkbutton.c) - const int padding = 4; - Style.PaintBox (Style, args.Window, state, ShadowType.None, args.Area, this, "button", - Allocation.X - padding, Allocation.Y - padding, Allocation.Width + padding * 2, Allocation.Height + padding * 2); - -// int xPos = Allocation.Left; - - //constrain the text area so it doesn't get rendered under the arrows -// var textArea = new Gdk.Rectangle (xPos + 2, Allocation.Y + ySpacing, arrowXPos - xPos - 2, Allocation.Height - ySpacing); - args.Window.DrawLayout (Style.TextGC (StateType.Normal), Allocation.X + 2, Allocation.Y+ ySpacing, layout); - //Style.PaintLayout (Style, win, state, true, textArea, this, "", textArea.X, textArea.Y, layout); - - if (DrawRightBorder) - win.DrawLine (this.Style.DarkGC (StateType.Normal), Allocation.X + Allocation.Width - 1, Allocation.Y, Allocation.X + Allocation.Width - 1, Allocation.Y + Allocation.Height); - return false; - } - - } -} - |