diff options
author | iain holmes <iain@xamarin.com> | 2017-03-16 19:39:56 +0300 |
---|---|---|
committer | iain holmes <iain@xamarin.com> | 2017-03-16 19:39:56 +0300 |
commit | 160024a97d0c7783302b82f8cc64778882016fbe (patch) | |
tree | 80514d92665b686dccb9cb714d1d3213581a5631 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor | |
parent | d299b02f484b6acaeca9e9ef60923105d88b9b81 (diff) | |
parent | b4c75c942570caad8ef060d04fcda1ee1417b701 (diff) |
Merge remote-tracking branch 'upstream/master' into a11y
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor')
20 files changed, 529 insertions, 89 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Caret.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Caret.cs new file mode 100644 index 0000000000..db7e5009c5 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Caret.cs @@ -0,0 +1,83 @@ +// +// Caret.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2016 Xamarin Inc. (http://xamarin.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; + +namespace MonoDevelop.Ide.Editor +{ + public abstract class Caret + { + public abstract DocumentLocation Location { + get; + set; + } + + public virtual int Line { + get { + return Location.Line; + } + set { + Location = new DocumentLocation (value, Column); + } + } + + public virtual int Column { + get { + return Location.Column; + } + set { + Location = new DocumentLocation (Line, value); + } + } + + public abstract int Offset { + get; + set; + } + + protected virtual void OnPositionChanged (CaretLocationEventArgs args) + { + if (PositionChanged != null) + PositionChanged (this, args); + } + + public event EventHandler<CaretLocationEventArgs> PositionChanged; + } + + public enum CaretChangeReason { + BufferChange, + Movement + } + + public class CaretLocationEventArgs : DocumentLocationEventArgs + { + public CaretChangeReason CaretChangeReason { get; } + + public CaretLocationEventArgs (DocumentLocation location, CaretChangeReason reason) : base (location) + { + CaretChangeReason = reason; + } + } +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/CustomEditorOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/CustomEditorOptions.cs index 736f0f7810..415b7a3afd 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/CustomEditorOptions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/CustomEditorOptions.cs @@ -115,7 +115,7 @@ namespace MonoDevelop.Ide.Editor set; } - public string ColorScheme { + public string EditorTheme { get; set; } @@ -153,7 +153,7 @@ namespace MonoDevelop.Ide.Editor public CustomEditorOptions () { - this.ColorScheme = MonoDevelop.Ide.Editor.Highlighting.ColorScheme.DefaultColorStyle; + this.EditorTheme = MonoDevelop.Ide.Editor.Highlighting.EditorTheme.DefaultThemeName; this.TabSize = this.IndentationSize = 4; this.DefaultEolMarker = "\n"; } @@ -179,7 +179,7 @@ namespace MonoDevelop.Ide.Editor WrapLines = initializeFrom.WrapLines; FontName = initializeFrom.FontName; GutterFontName = initializeFrom.GutterFontName; - ColorScheme = initializeFrom.ColorScheme; + EditorTheme = initializeFrom.EditorTheme; DefaultEolMarker = initializeFrom.DefaultEolMarker; GenerateFormattingUndoStep = initializeFrom.GenerateFormattingUndoStep; EnableSelectionWrappingKeys = initializeFrom.EnableSelectionWrappingKeys; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs index deec2b802c..5f24903839 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs @@ -200,9 +200,9 @@ namespace MonoDevelop.Ide.Editor } } - string ITextEditorOptions.ColorScheme { + string ITextEditorOptions.EditorTheme { get { - return DefaultSourceEditorOptions.Instance.ColorScheme; + return DefaultSourceEditorOptions.Instance.EditorTheme; } } @@ -464,7 +464,7 @@ namespace MonoDevelop.Ide.Editor } } - bool tabsToSpaces = false; + bool tabsToSpaces = true; public bool TabsToSpaces { get { return tabsToSpaces; @@ -592,7 +592,7 @@ namespace MonoDevelop.Ide.Editor } } - int rulerColumn = 80; + int rulerColumn = 120; public int RulerColumn { get { @@ -681,7 +681,7 @@ namespace MonoDevelop.Ide.Editor } ConfigurationProperty<string> colorScheme = IdeApp.Preferences.ColorScheme; - public string ColorScheme { + public string EditorTheme { get { return colorScheme; } @@ -695,7 +695,7 @@ namespace MonoDevelop.Ide.Editor OnChanged (EventArgs.Empty); } - ConfigurationProperty<bool> generateFormattingUndoStep = ConfigurationProperty.Create ("GenerateFormattingUndoStep", false); + ConfigurationProperty<bool> generateFormattingUndoStep = ConfigurationProperty.Create ("GenerateFormattingUndoStep", true); public bool GenerateFormattingUndoStep { get { return generateFormattingUndoStep; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs index 0cd3806f2c..d3208cdac0 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs @@ -86,7 +86,7 @@ namespace MonoDevelop.Ide.Editor /// <summary> /// Returns the roslyn document for this document. This may return <c>null</c> if it's no compileable document. - /// Even if it's a C# file. + /// Even if it's a C# file. Is always not <c>null</c> when the parser returns <c>true</c> on CanGenerateAnalysisDocument. /// </summary> public abstract Microsoft.CodeAnalysis.Document AnalysisDocument { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentLocation.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentLocation.cs index 9e0cf1cdbf..f68cb7ddae 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentLocation.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentLocation.cs @@ -233,5 +233,21 @@ namespace MonoDevelop.Ide.Editor return base.ConvertTo(context, culture, value, destinationType); } } + + public class DocumentLocationEventArgs : System.EventArgs + { + readonly DocumentLocation location; + + public DocumentLocation Location { + get { + return location; + } + } + + public DocumentLocationEventArgs (DocumentLocation location) + { + this.location = location; + } + } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/EditActions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/EditActions.cs index a72688c0e2..87082a2e55 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/EditActions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/EditActions.cs @@ -380,7 +380,7 @@ namespace MonoDevelop.Ide.Editor public static void ExpandSelectionToLine (TextEditor textEditor) { - // from Mono.TextEditor.SelectionActions.ExpandSelectionToLine + // from MonoDevelop.Ide.Editor.SelectionActions.ExpandSelectionToLine using (var undoGroup = textEditor.OpenUndoGroup ()) { var curLineSegment = textEditor.GetLine (textEditor.CaretLine).SegmentIncludingDelimiter; var range = textEditor.SelectionRange; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/IDocumentLine.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/IDocumentLine.cs index 8bd9388f83..059599d9ed 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/IDocumentLine.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/IDocumentLine.cs @@ -97,6 +97,10 @@ namespace MonoDevelop.Ide.Editor /// </returns> public static string GetIndentation (this IDocumentLine line, IReadonlyTextDocument doc) { + if (line == null) + throw new ArgumentNullException (nameof (line)); + if (doc == null) + throw new ArgumentNullException (nameof (doc)); var result = new StringBuilder (); int offset = line.Offset; int max = Math.Min (offset + line.LengthIncludingDelimiter, doc.Length); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextEditorOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextEditorOptions.cs index 17bc9f12ce..bcabd79f88 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextEditorOptions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextEditorOptions.cs @@ -91,7 +91,7 @@ namespace MonoDevelop.Ide.Editor string GutterFontName { get; } - string ColorScheme { get; } + string EditorTheme { get; } string DefaultEolMarker { get; } @@ -108,11 +108,11 @@ namespace MonoDevelop.Ide.Editor public static class TextEditorOptionsExtension { - public static ColorScheme GetColorStyle (this ITextEditorOptions options) + public static EditorTheme GetEditorTheme (this ITextEditorOptions options) { if (options == null) throw new ArgumentNullException ("options"); - return SyntaxModeService.GetColorStyle (options.ColorScheme); + return SyntaxHighlightingService.GetEditorTheme (options.EditorTheme); } /// <summary> diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorImpl.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorImpl.cs index ff5526f4df..10517742db 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorImpl.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorImpl.cs @@ -1,4 +1,4 @@ -// +// // ITextEditorImpl.cs // // Author: @@ -32,6 +32,8 @@ using MonoDevelop.Ide.Editor.Highlighting; using MonoDevelop.Components; using Xwt; using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; namespace MonoDevelop.Ide.Editor { @@ -56,14 +58,16 @@ namespace MonoDevelop.Ide.Editor IReadonlyTextDocument Document { get; } - DocumentLocation CaretLocation { get; set; } - SemanticHighlighting SemanticHighlighting { get; set; } + ISyntaxHighlighting SyntaxHighlighting { get; set; } + int CaretOffset { get; set; } bool IsSomethingSelected { get; } + IEnumerable<Selection> Selections { get; } + SelectionMode SelectionMode { get; } ISegment SelectionRange { get; set; } @@ -168,16 +172,14 @@ namespace MonoDevelop.Ide.Editor IEnumerable<IFoldSegment> GetFoldingsIn (int offset, int length); - string GetMarkup (int offset, int length, MarkupOptions options); + string GetPangoMarkup (int offset, int length, bool fitIdeStyle = false); - void SetIndentationTracker (IndentationTracker indentationTracker); - void SetSelectionSurroundingProvider (SelectionSurroundingProvider surroundingProvider); + string GetMarkup (int offset, int length, MarkupOptions options);
+
+ IndentationTracker IndentationTracker { get; set; }
+ void SetSelectionSurroundingProvider (SelectionSurroundingProvider surroundingProvider); void SetTextPasteHandler (TextPasteHandler textPasteHandler); - event EventHandler<LineEventArgs> LineChanged; - event EventHandler<LineEventArgs> LineInserted; - event EventHandler<LineEventArgs> LineRemoved; - #region Internal use only API (do not mirror in TextEditor) TextEditorExtension EditorExtension { @@ -216,6 +218,7 @@ namespace MonoDevelop.Ide.Editor void UpdateBraceMatchingResult (BraceMatchingResult? result); IEnumerable<IDocumentLine> VisibleLines { get; } + IReadOnlyList<Caret> Carets { get; } void GrabFocus (); bool HasFocus { get; } @@ -223,5 +226,9 @@ namespace MonoDevelop.Ide.Editor event EventHandler<LineEventArgs> LineShown; event EventHandler FocusLost; + void ShowTooltipWindow (Control window, TooltipWindowOptions options); + Task<ScopeStack> GetScopeStackAsync (int offset, CancellationToken cancellationToken); + + double GetLineHeight (int line); + } } -}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedCompletionExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedCompletionExtension.cs index 741fabe3c2..66e8b84e4a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedCompletionExtension.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedCompletionExtension.cs @@ -250,14 +250,6 @@ namespace MonoDevelop.Ide.Editor.Projection return projectedExtension.CanRunCompletionCommand (); } - public override Task<MonoDevelop.Ide.CodeCompletion.ICompletionDataList> CodeCompletionCommand (MonoDevelop.Ide.CodeCompletion.CodeCompletionContext completionContext) - { - var projectedExtension = GetExtensionAt (completionContext.TriggerOffset); - if (projectedExtension == null) - return null; - return projectedExtension.CodeCompletionCommand (ConvertContext (completionContext)); - } - public override bool CanRunParameterCompletionCommand () { var projectedExtension = GetCurrentExtension (); @@ -302,13 +294,13 @@ namespace MonoDevelop.Ide.Editor.Projection return projectedExtension.GuessBestMethodOverload (provider, currentOverload, token); } - public override System.Threading.Tasks.Task<MonoDevelop.Ide.CodeCompletion.ICompletionDataList> HandleCodeCompletionAsync (MonoDevelop.Ide.CodeCompletion.CodeCompletionContext completionContext, char completionChar, System.Threading.CancellationToken token) + public override System.Threading.Tasks.Task<MonoDevelop.Ide.CodeCompletion.ICompletionDataList> HandleCodeCompletionAsync (MonoDevelop.Ide.CodeCompletion.CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken token) { var projectedExtension = GetExtensionAt (completionContext.TriggerOffset); if (projectedExtension == null) return null; - return projectedExtension.HandleCodeCompletionAsync (ConvertContext (completionContext), completionChar, token); + return projectedExtension.HandleCodeCompletionAsync (ConvertContext (completionContext), triggerInfo, token); } public override Task<ParameterHintingResult> HandleParameterCompletionAsync (MonoDevelop.Ide.CodeCompletion.CodeCompletionContext completionContext, char completionChar, System.Threading.CancellationToken token) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedFilterCompletionTextEditorExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedFilterCompletionTextEditorExtension.cs index 8174b221ce..9ee715512b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedFilterCompletionTextEditorExtension.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedFilterCompletionTextEditorExtension.cs @@ -26,6 +26,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Ide.Editor.Extension; namespace MonoDevelop.Ide.Editor.Projection @@ -44,10 +45,21 @@ namespace MonoDevelop.Ide.Editor.Projection } } + internal override CodeCompletion.ICompletionWidget CompletionWidget { + get { + return completionTextEditorExtension.CompletionWidget; + } + set { + completionTextEditorExtension.CompletionWidget = value; + completionTextEditorExtension.UnsubscribeCompletionContextChanged (); + } + } + public ProjectedFilterCompletionTextEditorExtension (CompletionTextEditorExtension completionTextEditorExtension, IReadOnlyList<Projection> projections) { this.completionTextEditorExtension = completionTextEditorExtension; this.projections = projections; + completionTextEditorExtension.UnsubscribeCompletionContextChanged (); } internal protected override bool IsActiveExtension () @@ -129,9 +141,9 @@ namespace MonoDevelop.Ide.Editor.Projection return completionTextEditorExtension.CanRunParameterCompletionCommand (); } - public override System.Threading.Tasks.Task<CodeCompletion.ICompletionDataList> HandleCodeCompletionAsync (CodeCompletion.CodeCompletionContext completionContext, char completionChar, System.Threading.CancellationToken token) + public override System.Threading.Tasks.Task<CodeCompletion.ICompletionDataList> HandleCodeCompletionAsync (CodeCompletion.CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken token) { - return completionTextEditorExtension.HandleCodeCompletionAsync (completionContext, completionChar, token); + return completionTextEditorExtension.HandleCodeCompletionAsync (completionContext, triggerInfo, token); } public override System.Threading.Tasks.Task<CodeCompletion.ParameterHintingResult> HandleParameterCompletionAsync (CodeCompletion.CodeCompletionContext completionContext, char completionChar, System.Threading.CancellationToken token) @@ -160,12 +172,6 @@ namespace MonoDevelop.Ide.Editor.Projection return completionTextEditorExtension.ShowCodeTemplatesCommand (completionContext); } - public override Task<CodeCompletion.ICompletionDataList> CodeCompletionCommand (CodeCompletion.CodeCompletionContext completionContext) - { - if (!IsActiveExtension()) return null; - return completionTextEditorExtension.CodeCompletionCommand (completionContext); - } - public override Task<CodeCompletion.ParameterHintingResult> ParameterCompletionCommand (CodeCompletion.CodeCompletionContext completionContext) { if (!IsActiveExtension()) return null; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedSemanticHighlighting.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedSemanticHighlighting.cs index 93da211780..20d6872813 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedSemanticHighlighting.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedSemanticHighlighting.cs @@ -90,7 +90,7 @@ namespace MonoDevelop.Ide.Editor.Projection var originalEndOffset = seg.FromProjectedToOriginal (projectedEndOffset); foreach (var cs in p.ProjectedEditor.SemanticHighlighting.GetColoredSegments (MonoDevelop.Core.Text.TextSegment.FromBounds (projectedStartOffset, projectedEndOffset))) { - yield return new ColoredSegment (cs.Offset - projectedStartOffset + v, cs.Length, cs.ColorStyleKey); + yield return new ColoredSegment (cs.Offset - projectedStartOffset + v, cs.Length, cs.ScopeStack); } if (originalEndOffset < segment.EndOffset) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Selection.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Selection.cs new file mode 100644 index 0000000000..146b09e7ab --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Selection.cs @@ -0,0 +1,188 @@ +// +// Selection.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2016 Xamarin Inc. (http://xamarin.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 MonoDevelop.Core.Text; + +namespace MonoDevelop.Ide.Editor +{ + public struct Selection : IEquatable<Selection> + { + public static readonly Selection Empty = new Selection (true); + + public bool IsEmpty { + get { + return anchor.IsEmpty; + } + } + + readonly DocumentLocation anchor; + public DocumentLocation Anchor { + get { + return anchor; + } + } + + readonly DocumentLocation lead; + public DocumentLocation Lead { + get { + return lead; + } + } + + + public int MinLine { + get { + return System.Math.Min (Anchor.Line, Lead.Line); + } + } + + public int MaxLine { + get { + return System.Math.Max (Anchor.Line, Lead.Line); + } + } + + public DocumentLocation Start { + get { + return anchor < lead ? anchor : lead; + } + } + + public DocumentLocation End { + get { + return anchor < lead ? lead : anchor; + } + } + + readonly SelectionMode selectionMode; + public SelectionMode SelectionMode { + get { + return selectionMode; + } + } + + public bool Contains (DocumentLocation loc) + { + return anchor <= loc && loc <= lead || lead < loc && loc < anchor; + } + + public bool Contains (int line, int column) + { + return Contains (new DocumentLocation (line, column)); + } + + Selection (bool empty) + { + anchor = lead = DocumentLocation.Empty; + selectionMode = SelectionMode.Normal; + } + + public Selection (int anchorLine, int anchorColumn, int leadLine, int leadColumn, SelectionMode mode = SelectionMode.Normal) : this (new DocumentLocation (anchorLine, anchorColumn), new DocumentLocation (leadLine, leadColumn), mode) + { + } + + public Selection (DocumentLocation anchor, DocumentLocation lead, SelectionMode selectionMode = SelectionMode.Normal) + { + if (anchor.Line < DocumentLocation.MinLine || anchor.Column < DocumentLocation.MinColumn) + throw new ArgumentOutOfRangeException ("anchor", anchor + " is out of range."); + if (lead.Line < DocumentLocation.MinLine || lead.Column < DocumentLocation.MinColumn) + throw new ArgumentOutOfRangeException ("lead", lead + " is out of range."); + this.anchor = anchor; + this.lead = lead; + this.selectionMode = selectionMode; + } + + public Selection WithLead (DocumentLocation newLead) + { + return new Selection (Anchor, newLead, SelectionMode); + } + + public Selection WithAnchor (DocumentLocation newAnchor) + { + return new Selection (newAnchor, Lead, SelectionMode); + } + + public Selection WithRange (DocumentLocation newAnchor, DocumentLocation newLead) + { + return new Selection (newAnchor, newLead, SelectionMode); + } + + public Selection WithSelectionMode (SelectionMode newSelectionMode) + { + return new Selection (Anchor, Lead, newSelectionMode); + } + + public override bool Equals (object obj) + { + if (!(obj is Selection)) + return false; + return Equals ((Selection)obj); + } + + public bool Equals (Selection other) + { + return Anchor == other.Anchor && Lead == other.Lead && SelectionMode == other.SelectionMode; + } + + public bool IsSelected (DocumentLocation loc) + { + return anchor <= loc && loc <= lead || lead <= loc && loc <= anchor; + } + + public bool IsSelected (int line, int column) + { + return IsSelected (new DocumentLocation (line, column)); + } + + public bool IsSelected (DocumentLocation start, DocumentLocation end) + { + return IsSelected (start) && IsSelected (end); + } + + public bool IsSelected (int startLine, int startColumn, int endLine, int endColumn) + { + return IsSelected (new DocumentLocation (startLine, startColumn), new DocumentLocation (endLine, endColumn)); + } + + public override int GetHashCode () + { + unchecked { + return Anchor.GetHashCode () ^ Lead.GetHashCode (); + } + } + + public override string ToString () + { + return string.Format ("[Selection: Anchor={0}, Lead={1}, MinLine={2}, MaxLine={3}, SelectionMode={4}]", Anchor, Lead, MinLine, MaxLine, SelectionMode); + } + + internal bool ContainsLine (int lineNr) + { + return anchor.Line <= lineNr && lineNr <= lead.Line || lead.Line <= lineNr && lineNr <= anchor.Line; + } + } +} + diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs index 1140d15980..198126f346 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs @@ -1,4 +1,4 @@ -// +// // ITextEditor.cs // // Author: @@ -43,6 +43,7 @@ using MonoDevelop.Ide.Editor.Projection; using Xwt; using System.Collections.Immutable; using MonoDevelop.Components.Commands; +using System.Threading.Tasks; namespace MonoDevelop.Ide.Editor { @@ -50,6 +51,7 @@ namespace MonoDevelop.Ide.Editor { readonly ITextEditorImpl textEditorImpl; IReadonlyTextDocument ReadOnlyTextDocument { get { return textEditorImpl.Document; } } + ITextDocument ReadWriteTextDocument { get { return (ITextDocument)textEditorImpl.Document; } } public ITextSourceVersion Version { @@ -102,6 +104,18 @@ namespace MonoDevelop.Ide.Editor remove { textEditorImpl.VAdjustmentChanged -= value; } } + public double GetLineHeight (int line) + { + return textEditorImpl.GetLineHeight (line); + } + + public double GetLineHeight (IDocumentLine line) + { + if (line == null) + throw new ArgumentNullException (nameof (line)); + return textEditorImpl.GetLineHeight (line.LineNumber); + } + internal event EventHandler HAdjustmentChanged { add { textEditorImpl.HAdjustmentChanged += value; } remove { textEditorImpl.HAdjustmentChanged -= value; } @@ -158,53 +172,67 @@ namespace MonoDevelop.Ide.Editor } } + public SemanticHighlighting SemanticHighlighting { + get { + return textEditorImpl.SemanticHighlighting; + } + set { + textEditorImpl.SemanticHighlighting = value; + } + } + + public IReadOnlyList<Caret> Carets { + get { + return textEditorImpl.Carets; + } + } + public DocumentLocation CaretLocation { get { - return textEditorImpl.CaretLocation; + return Carets [0].Location; } set { Runtime.AssertMainThread (); - textEditorImpl.CaretLocation = value; + Carets [0].Location = value; } } - public SemanticHighlighting SemanticHighlighting { + public ISyntaxHighlighting SyntaxHighlighting { get { - return textEditorImpl.SemanticHighlighting; + return textEditorImpl.SyntaxHighlighting; } set { - textEditorImpl.SemanticHighlighting = value; + textEditorImpl.SyntaxHighlighting = value; } } public int CaretLine { get { - return CaretLocation.Line; + return Carets [0].Line; } set { - CaretLocation = new DocumentLocation (value, CaretColumn); + Carets [0].Line = value; } } public int CaretColumn { get { - return CaretLocation.Column; + return Carets [0].Column; } set { - CaretLocation = new DocumentLocation (CaretLine, value); + Carets [0].Column = value; } } public int CaretOffset { get { - return textEditorImpl.CaretOffset; + return Carets [0].Offset; } set { Runtime.AssertMainThread (); - textEditorImpl.CaretOffset = value; + Carets [0].Offset = value; } } - public bool IsReadOnly { get { return ReadOnlyTextDocument.IsReadOnly; @@ -227,6 +255,12 @@ namespace MonoDevelop.Ide.Editor } } + public IEnumerable<Selection> Selections { + get { + return textEditorImpl.Selections; + } + } + public ISegment SelectionRange { get { return textEditorImpl.SelectionRange; @@ -436,11 +470,11 @@ namespace MonoDevelop.Ide.Editor public void SetCaretLocation (DocumentLocation location, bool usePulseAnimation = false, bool centerCaret = true) { Runtime.AssertMainThread (); - CaretLocation = location; + Carets [0].Location = location; if (centerCaret) { - CenterTo (CaretLocation); + CenterTo (Carets [0].Location); } else { - ScrollTo (CaretLocation); + ScrollTo (Carets [0].Location); } if (usePulseAnimation) StartCaretPulseAnimation (); @@ -449,11 +483,11 @@ namespace MonoDevelop.Ide.Editor public void SetCaretLocation (int line, int col, bool usePulseAnimation = false, bool centerCaret = true) { Runtime.AssertMainThread (); - CaretLocation = new DocumentLocation (line, col); + Carets [0].Location = new DocumentLocation (line, col); if (centerCaret) { - CenterTo (CaretLocation); + CenterTo (Carets [0].Location); } else { - ScrollTo (CaretLocation); + ScrollTo (Carets [0].Location); } if (usePulseAnimation) StartCaretPulseAnimation (); @@ -521,18 +555,32 @@ namespace MonoDevelop.Ide.Editor textEditorImpl.StartInsertionMode (insertionModeOptions); } + TextLinkModeOptions textLinkModeOptions; public void StartTextLinkMode (TextLinkModeOptions textLinkModeOptions) { if (textLinkModeOptions == null) throw new ArgumentNullException (nameof (textLinkModeOptions)); Runtime.AssertMainThread (); textEditorImpl.StartTextLinkMode (textLinkModeOptions); + this.textLinkModeOptions = textLinkModeOptions; + } + + internal TextLinkPurpose TextLinkPurpose { + get { + if (EditMode != EditMode.TextLink || textLinkModeOptions == null) + return TextLinkPurpose.Unknown; + return textLinkModeOptions.TextLinkPurpose; + } } public void InsertAtCaret (string text) { Runtime.AssertMainThread (); - InsertText (CaretOffset, text); + foreach (var caret in Carets.OrderBy (i => -i.Offset)) { + var caretOffset = caret.Offset; + InsertText (caretOffset, text); + caret.Offset = caretOffset + text.Length; + } } public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = false) @@ -869,13 +917,6 @@ namespace MonoDevelop.Ide.Editor } [EditorBrowsable(EditorBrowsableState.Advanced)] - public void SetIndentationTracker (IndentationTracker indentationTracker) - { - Runtime.AssertMainThread (); - textEditorImpl.SetIndentationTracker (indentationTracker); - } - - [EditorBrowsable(EditorBrowsableState.Advanced)] public void SetSelectionSurroundingProvider (SelectionSurroundingProvider surroundingProvider) { Runtime.AssertMainThread (); @@ -1404,16 +1445,28 @@ namespace MonoDevelop.Ide.Editor return; if ((disabledFeatures & DisabledProjectionFeatures.Completion) != DisabledProjectionFeatures.Completion) { - TextEditorExtension lastExtension = textEditorImpl.EditorExtension; - while (lastExtension != null && lastExtension.Next != null) { - var completionTextEditorExtension = lastExtension.Next as CompletionTextEditorExtension; + TextEditorExtension curExtension = textEditorImpl.EditorExtension; + TextEditorExtension lastExtension = null; + while (curExtension != null) { + var completionTextEditorExtension = curExtension as CompletionTextEditorExtension; if (completionTextEditorExtension != null) { var projectedFilterExtension = new ProjectedFilterCompletionTextEditorExtension (completionTextEditorExtension, projections) { Next = completionTextEditorExtension.Next }; + var completionWidget = completionTextEditorExtension.CompletionWidget; completionTextEditorExtension.Deinitialize (); - lastExtension.Next = projectedFilterExtension; + projectedFilterExtension.Next = curExtension.Next; + + if (lastExtension != null) { + lastExtension.Next = projectedFilterExtension; + } else { + textEditorImpl.EditorExtension = projectedFilterExtension; + curExtension = projectedFilterExtension; + } projectedFilterExtension.Initialize (this, DocumentContext); + projectedFilterExtension.CompletionWidget = completionWidget; + break; } - lastExtension = lastExtension.Next; + lastExtension = curExtension; + curExtension = curExtension.Next; } @@ -1449,13 +1502,38 @@ namespace MonoDevelop.Ide.Editor internal ITextEditorImpl Implementation { get { return this.textEditorImpl; } } - public event EventHandler FocusLost { add { textEditorImpl.FocusLost += value; } remove { textEditorImpl.FocusLost -= value; } } + [EditorBrowsable(EditorBrowsableState.Advanced)] + public IndentationTracker IndentationTracker + { + get + { + Runtime.AssertMainThread(); + return textEditorImpl.IndentationTracker; + } + set + { + Runtime.AssertMainThread(); + textEditorImpl.IndentationTracker = value; + } + } + + public event EventHandler FocusLost { add { textEditorImpl.FocusLost += value; } remove { textEditorImpl.FocusLost -= value; } } public new void GrabFocus () { this.textEditorImpl.GrabFocus (); } + public void ShowTooltipWindow (Control window, TooltipWindowOptions options = null) + { + textEditorImpl.ShowTooltipWindow (window, options); + } + + public Task<ScopeStack> GetScopeStackAsync (int offset, CancellationToken cancellationToken) + { + return textEditorImpl.GetScopeStackAsync (offset, cancellationToken); + } + public new bool HasFocus { get { return this.textEditorImpl.HasFocus; } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs index 5c626bbdab..15d839752b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs @@ -39,7 +39,7 @@ namespace MonoDevelop.Ide.Editor public static FilePath SyntaxModePath { get { - return UserProfile.Current.UserDataRoot.Combine ("HighlightingSchemes"); + return UserProfile.Current.UserDataRoot.Combine ("ColorThemes"); } } @@ -73,7 +73,7 @@ namespace MonoDevelop.Ide.Editor } } if (success) - SyntaxModeService.LoadStylesAndModes (SyntaxModePath); + SyntaxHighlightingService.LoadStylesAndModesInPath (SyntaxModePath); } public string Name { @@ -96,6 +96,7 @@ namespace MonoDevelop.Ide.Editor public ViewContent CreateContent (FilePath fileName, string mimeType, Project ownerProject) { var editor = TextEditorFactory.CreateNewEditor (); + editor.FileName = fileName; editor.MimeType = mimeType; editor.GetViewContent ().Project = ownerProject; editor.GetViewContent ().ContentName = fileName; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs index 04c8a511d9..13b7d8c3f7 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs @@ -111,14 +111,5 @@ namespace MonoDevelop.Ide.Editor result.InitializeExtensionChain (ctx); return result; } - - public static string[] GetSyntaxProperties (string mimeType, string name) - { - if (mimeType == null) - throw new System.ArgumentNullException ("mimeType"); - if (name == null) - throw new System.ArgumentNullException ("name"); - return currentFactory.GetSyntaxProperties (mimeType, name); - } } }
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs index ee8da81f5b..552444edaa 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs @@ -77,6 +77,14 @@ namespace MonoDevelop.Ide.Editor } + protected override void OnContentNameChanged () + { + base.OnContentNameChanged (); + textEditorImpl.ContentName = this.ContentName; + if (this.WorkbenchWindow?.Document != null) + textEditor.InitializeExtensionChain (this.WorkbenchWindow.Document); + } + void ViewContent_ContentNameChanged (object sender, EventArgs e) { this.ContentName = textEditorImpl.ViewContent.ContentName; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextLinkModeOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextLinkModeOptions.cs index ef20516cf9..5be3ff5e64 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextLinkModeOptions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextLinkModeOptions.cs @@ -28,6 +28,12 @@ using System.Collections.Generic; namespace MonoDevelop.Ide.Editor { + public enum TextLinkPurpose + { + Unknown, + Rename + } + /// <summary> /// This class contains information the editor needs to initiate the text link mode. /// </summary> @@ -50,6 +56,8 @@ namespace MonoDevelop.Ide.Editor private set; } + public TextLinkPurpose TextLinkPurpose { get; set; } + /// <summary> /// Initializes a new instance of the <see cref="MonoDevelop.Ide.Editor.TextLinkModeOptions"/> class. /// </summary> diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipProvider.cs index 259bad2056..ebe77c7d70 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipProvider.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipProvider.cs @@ -125,7 +125,7 @@ namespace MonoDevelop.Ide.Editor (int)p1.X, (int)p1.Y, (int)w, - (int)editor.LineHeight + (int)editor.GetLineHeight (startLoc.Line) ); tipWindow.ShowPopup (editorWidget, caret, PopupPosition.Top); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipWindowOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipWindowOptions.cs new file mode 100644 index 0000000000..b4ff9c4174 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TooltipWindowOptions.cs @@ -0,0 +1,58 @@ +// +// TooltipWindowOptions.cs +// +// Author: +// Mike Krüger <mikkrg@microsoft.com> +// +// Copyright (c) 2016 Microsoft Corporation +// +// 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 MonoDevelop.Core.Text; +using System.Collections.Generic; +using System.Text; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Ide.Editor.Extension; +using System.IO; +using MonoDevelop.Ide.Editor.Highlighting; +using Mono.Addins; +using MonoDevelop.Core; +using MonoDevelop.Ide.Extensions; +using System.Linq; +using MonoDevelop.Components; +using System.ComponentModel; +using MonoDevelop.Ide.TypeSystem; +using System.Threading; +using MonoDevelop.Ide.Editor.Projection; +using Xwt; +using System.Collections.Immutable; +using MonoDevelop.Components.Commands; + +namespace MonoDevelop.Ide.Editor +{ + public class TooltipWindowOptions + { + /// <summary> + /// Gets or sets a value indicating whether this tooltip should close automatically on mouse hover. + /// </summary> + /// <value><c>true</c> if auto close; otherwise, <c>false</c>.</value> + public bool AutoClose { get; set; } = true; + } +}
\ No newline at end of file |