diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.AssemblyBrowser')
18 files changed, 732 insertions, 384 deletions
diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj index b0beb0d94c..59ea407e2e 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj @@ -46,7 +46,6 @@ <ItemGroup> <Reference Include="Mono.Posix" /> <Reference Include="System" /> - <Reference Include="System.Xml" /> <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"> <SpecificVersion>False</SpecificVersion> </Reference> @@ -64,6 +63,24 @@ </Reference> <Reference Include="System.Core" /> <Reference Include="Mono.Cairo" /> + <Reference Include="System.Collections.Immutable"> + <HintPath>..\..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="System.Reflection.Metadata"> + <HintPath>..\..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.CodeAnalysis.Desktop"> + <HintPath>..\..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.CodeAnalysis"> + <HintPath>..\..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="monodoc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" /> + <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj"> @@ -76,11 +93,6 @@ <Name>MonoDevelop.Ide</Name> <Private>False</Private> </ProjectReference> - <ProjectReference Include="..\..\core\Mono.Texteditor\Mono.TextEditor.csproj"> - <Project>{A2329308-3751-4DBD-9A75-5F7B8B024625}</Project> - <Name>Mono.TextEditor</Name> - <Private>False</Private> - </ProjectReference> <ProjectReference Include="..\MonoDevelop.Refactoring\MonoDevelop.Refactoring.csproj"> <Project>{100568FC-F4E8-439B-94AD-41D11724E45B}</Project> <Name>MonoDevelop.Refactoring</Name> @@ -96,11 +108,6 @@ <Name>ICSharpCode.Decompiler</Name> <Private>False</Private> </ProjectReference> - <ProjectReference Include="..\MonoDevelop.SourceEditor2\MonoDevelop.SourceEditor.csproj"> - <Project>{F8F92AA4-A376-4679-A9D4-60E7B7FBF477}</Project> - <Name>MonoDevelop.SourceEditor</Name> - <Private>False</Private> - </ProjectReference> <ProjectReference Include="..\..\..\external\cecil\Mono.Cecil.csproj"> <Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project> <Name>Mono.Cecil</Name> @@ -131,6 +138,11 @@ <Name>Xwt</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\core\Mono.Texteditor\Mono.TextEditor.csproj"> + <Project>{A2329308-3751-4DBD-9A75-5F7B8B024625}</Project> + <Name>Mono.TextEditor</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <ItemGroup> <Compile Include="AssemblyInfo.cs" /> @@ -169,6 +181,8 @@ <Compile Include="XmlDocIdLib\OperatorType.cs" /> <Compile Include="XmlDocIdLib\XmlDocIdGenerator.cs" /> <Compile Include="AddinInfo.cs" /> + <Compile Include="MonoDevelop.AssemblyBrowser\NRefactoryStock.cs" /> + <Compile Include="MonoDevelop.AssemblyBrowser\HelpExtensions.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="gtk-gui\gui.stetic"> @@ -183,4 +197,7 @@ <Folder Include="MonoDevelop.AssemblyBrowser\TreeNodes\" /> <Folder Include="XmlDocIdLib\" /> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> </Project> diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserViewContent.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserViewContent.cs index c6ab4132c6..5cbeeac429 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserViewContent.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserViewContent.cs @@ -72,10 +72,10 @@ namespace MonoDevelop.AssemblyBrowser IsDisposed = false; } - public override void Load (string fileName) + public override void Load (FileOpenInformation fileOpenInformation) { ContentName = GettextCatalog.GetString ("Assembly Browser"); - widget.AddReferenceByFileName (fileName); + widget.AddReferenceByFileName (fileOpenInformation.FileName); } public override bool IsFile { @@ -108,30 +108,17 @@ namespace MonoDevelop.AssemblyBrowser #region IUrlHandler implementation - public void Open (INamedElement element) + public void Open (Microsoft.CodeAnalysis.ISymbol element) { - var member = element as IUnresolvedEntity; - if (member == null) { - var entity = element as IMember; - if (entity != null) - member = entity.UnresolvedMember; + var url = element.OriginalDefinition.GetDocumentationCommentId ();//AssemblyBrowserWidget.GetIdString (member); + widget.Open (url); + } - } - if (member == null) { - var entity = element as IType; - if (entity != null) - member = entity.GetDefinition ().Parts [0]; - } - if (member == null) - return; - var url = AssemblyBrowserWidget.GetIdString (member); - try { - widget.Open (url); - } catch (Exception e) { - MessageService.ShowError (GettextCatalog.GetString ("{0} could not be opened", url), e); - } + public void Open (string documentationCommentId) + { + widget.Open (documentationCommentId); } - + #endregion [MonoDevelop.Components.Commands.CommandHandler(MonoDevelop.Refactoring.RefactoryCommands.FindReferences)] @@ -140,7 +127,7 @@ namespace MonoDevelop.AssemblyBrowser var member = widget.ActiveMember as IMember; if (member == null) return; - FindReferencesHandler.FindRefs (member); + // FindReferencesHandler.FindRefs (member); } [MonoDevelop.Components.Commands.CommandHandler(MonoDevelop.Refactoring.RefactoryCommands.FindDerivedClasses)] @@ -149,7 +136,7 @@ namespace MonoDevelop.AssemblyBrowser var type = widget.ActiveMember as ITypeDefinition; if (type == null) return; - FindDerivedClassesHandler.FindDerivedClasses (type); + //FindDerivedClassesHandler.FindDerivedClasses (type); } public void FillWidget () diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs index 3ff7e29ebc..f560573715 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs @@ -40,19 +40,17 @@ using MonoDevelop.Ide; using MonoDevelop.Ide.Commands; using MonoDevelop.Ide.Gui.Components; using System.Linq; -using Mono.TextEditor; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.Documentation; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Projects; using ICSharpCode.NRefactory.TypeSystem.Implementation; -using Mono.TextEditor.Theatrics; -using MonoDevelop.SourceEditor; using XmlDocIdLib; using MonoDevelop.Ide.Gui; using MonoDevelop.Components; using System.Threading.Tasks; using System.Threading; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -77,11 +75,6 @@ namespace MonoDevelop.AssemblyBrowser } } - Ambience ambience = AmbienceService.GetAmbience ("text/x-csharp"); - public Ambience Ambience { - get { return ambience; } - } - DocumentationPanel documentationPanel = new DocumentationPanel (); readonly TextEditor inspectEditor; @@ -111,6 +104,28 @@ namespace MonoDevelop.AssemblyBrowser } } + static string GetLink (ReferenceSegment referencedSegment) + { + if (referencedSegment == null) + return null; + if (referencedSegment.Reference is TypeDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((TypeDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is MethodDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((MethodDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is PropertyDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((PropertyDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is FieldDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is EventDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((EventDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is FieldDefinition) + return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference); + if (referencedSegment.Reference is TypeReference) { + return new XmlDocIdGenerator ().GetXmlDocPath ((TypeReference)referencedSegment.Reference); + } + return referencedSegment.Reference.ToString (); + } + public AssemblyBrowserWidget () { this.Build (); @@ -198,47 +213,15 @@ namespace MonoDevelop.AssemblyBrowser // this.documentationLabel.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (255, 255, 225)); // this.documentationLabel.Wrap = true; - var options = new MonoDevelop.Ide.Gui.CommonTextEditorOptions () { - ShowFoldMargin = false, - ShowIconMargin = false, - ShowLineNumberMargin = false, - HighlightCaretLine = true, - }; - inspectEditor = new TextEditor (new TextDocument (), options); - inspectEditor.ButtonPressEvent += HandleInspectEditorButtonPressEvent; + + inspectEditor = TextEditorFactory.CreateNewEditor (); + inspectEditor.Options = DefaultSourceEditorOptions.PlainEditor; + + //inspectEditor.ButtonPressEvent += HandleInspectEditorButtonPressEvent; - this.inspectEditor.Document.ReadOnly = true; + this.inspectEditor.IsReadOnly = true; // this.inspectEditor.Document.SyntaxMode = new Mono.TextEditor.Highlighting.MarkupSyntaxMode (); - this.inspectEditor.TextViewMargin.GetLink = delegate(Mono.TextEditor.MarginMouseEventArgs arg) { - var loc = inspectEditor.PointToLocation (arg.X, arg.Y); - int offset = inspectEditor.LocationToOffset (loc); - var referencedSegment = ReferencedSegments != null ? ReferencedSegments.FirstOrDefault (seg => seg.Segment.Contains (offset)) : null; - if (referencedSegment == null) - return null; - if (referencedSegment.Reference is TypeDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((TypeDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is MethodDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((MethodDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is PropertyDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((PropertyDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is FieldDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is EventDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((EventDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is FieldDefinition) - return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference); - - if (referencedSegment.Reference is TypeReference) { - return new XmlDocIdGenerator ().GetXmlDocPath ((TypeReference)referencedSegment.Reference); - } - return referencedSegment.Reference.ToString (); - }; - this.inspectEditor.LinkRequest += InspectEditorhandleLinkRequest; +// this.inspectEditor.LinkRequest += InspectEditorhandleLinkRequest; documentationScrolledWindow.Add (inspectEditor); this.hpaned1.ExposeEvent += HPaneExpose; @@ -299,13 +282,13 @@ namespace MonoDevelop.AssemblyBrowser [CommandHandler (EditCommands.Copy)] protected void OnCopyCommand () { - inspectEditor.RunAction (Mono.TextEditor.ClipboardActions.Copy); + EditActions.ClipboardCopy (inspectEditor); } [CommandHandler (EditCommands.SelectAll)] protected void OnSelectAllCommand () { - inspectEditor.RunAction (Mono.TextEditor.SelectionActions.SelectAll); + EditActions.SelectAll (inspectEditor); } void HandleInspectEditorButtonPressEvent (object o, ButtonPressEventArgs args) @@ -343,22 +326,7 @@ namespace MonoDevelop.AssemblyBrowser FillInspectLabel (); } - void InspectEditorhandleLinkRequest (object sender, Mono.TextEditor.LinkEventArgs args) - { - var loader = (AssemblyLoader)this.TreeView.GetSelectedNode ().GetParentDataItem (typeof(AssemblyLoader), true); - if (args.Button == 2 || (args.Button == 1 && (args.ModifierState & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask)) { - AssemblyBrowserViewContent assemblyBrowserView = new AssemblyBrowserViewContent (); - foreach (var cu in definitions) { - assemblyBrowserView.Load (cu.UnresolvedAssembly.AssemblyName); - } - IdeApp.Workbench.OpenDocument (assemblyBrowserView, true); - ((AssemblyBrowserWidget)assemblyBrowserView.Control).Open (args.Link); - } else { - this.Open (args.Link, loader); - } - } - public IEntity ActiveMember { get; set; @@ -456,7 +424,7 @@ namespace MonoDevelop.AssemblyBrowser StringBuilder sb; switch (member.SymbolKind) { - case SymbolKind.TypeDefinition: + case ICSharpCode.NRefactory.TypeSystem.SymbolKind.TypeDefinition: var type = member as IUnresolvedTypeDefinition; if (type.TypeParameters.Count == 0) return "T:" + type.FullName; @@ -1066,34 +1034,50 @@ namespace MonoDevelop.AssemblyBrowser return result.ToString (); } - + List<ReferenceSegment> ReferencedSegments = new List<ReferenceSegment>(); - List<UnderlineMarker> underlineMarkers = new List<UnderlineMarker> (); + List<ITextSegmentMarker> underlineMarkers = new List<ITextSegmentMarker> (); public void ClearReferenceSegment () { ReferencedSegments = null; - underlineMarkers.ForEach (m => inspectEditor.Document.RemoveMarker (m)); + underlineMarkers.ForEach (m => inspectEditor.RemoveMarker (m)); underlineMarkers.Clear (); } - public void SetReferencedSegments (List<ReferenceSegment> refs) + internal void SetReferencedSegments (List<ReferenceSegment> refs) { ReferencedSegments = refs; if (ReferencedSegments == null) return; - foreach (var seg in refs) { - DocumentLine line = inspectEditor.GetLineByOffset (seg.Offset); + foreach (var _seg in refs) { + var seg = _seg; + var line = inspectEditor.GetLineByOffset (seg.Offset); if (line == null) continue; // FIXME: ILSpy sometimes gives reference segments for punctuation. See http://bugzilla.xamarin.com/show_bug.cgi?id=2918 - string text = inspectEditor.GetTextAt (seg); + string text = inspectEditor.GetTextAt (seg.Offset, seg.Length); if (text != null && text.Length == 1 && !(char.IsLetter (text [0]) || text [0] == '…')) continue; - var marker = new UnderlineMarker (new Cairo.Color (0, 0, 1.0), 1 + seg.Offset - line.Offset, 1 + seg.EndOffset - line.Offset); - marker.Wave = false; + var marker = TextMarkerFactory.CreateLinkMarker (inspectEditor, seg.Offset, seg.Length, delegate (LinkRequest request) { + var link = GetLink (seg); + if (link == null) + return; + var loader = (AssemblyLoader)this.TreeView.GetSelectedNode ().GetParentDataItem (typeof(AssemblyLoader), true); + // args.Button == 2 || (args.Button == 1 && (args.ModifierState & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask) + if (request == LinkRequest.RequestNewView) { + AssemblyBrowserViewContent assemblyBrowserView = new AssemblyBrowserViewContent (); + foreach (var cu in definitions) { + assemblyBrowserView.Load (cu.UnresolvedAssembly.AssemblyName); + } + IdeApp.Workbench.OpenDocument (assemblyBrowserView, true); + ((AssemblyBrowserWidget)assemblyBrowserView.Control).Open (link); + } else { + this.Open (link, loader); + } + }); underlineMarkers.Add (marker); - inspectEditor.Document.AddMarker (line, marker); + inspectEditor.AddMarker (marker); } } @@ -1104,34 +1088,33 @@ namespace MonoDevelop.AssemblyBrowser return; IAssemblyBrowserNodeBuilder builder = nav.TypeNodeBuilder as IAssemblyBrowserNodeBuilder; if (builder == null) { - this.inspectEditor.Document.Text = ""; + this.inspectEditor.Text = ""; return; } ClearReferenceSegment (); - inspectEditor.Document.ClearFoldSegments (); + inspectEditor.SetFoldings (Enumerable.Empty<IFoldSegment> ()); switch (this.languageCombobox.Active) { case 0: - inspectEditor.Options.ShowFoldMargin = true; - this.inspectEditor.Document.MimeType = "text/x-csharp"; - SetReferencedSegments (builder.GetSummary (inspectEditor.GetTextEditorData (), nav, PublicApiOnly)); + inspectEditor.Options = DefaultSourceEditorOptions.PlainEditor; + this.inspectEditor.MimeType = "text/x-csharp"; + SetReferencedSegments (builder.GetSummary (inspectEditor, nav, PublicApiOnly)); break; case 1: - inspectEditor.Options.ShowFoldMargin = true; - this.inspectEditor.Document.MimeType = "text/x-ilasm"; - SetReferencedSegments (builder.Disassemble (inspectEditor.GetTextEditorData (), nav)); + inspectEditor.Options = DefaultSourceEditorOptions.PlainEditor; + this.inspectEditor.MimeType = "text/x-ilasm"; + SetReferencedSegments (builder.Disassemble (inspectEditor, nav)); break; case 2: - inspectEditor.Options.ShowFoldMargin = true; - this.inspectEditor.Document.MimeType = "text/x-csharp"; - SetReferencedSegments (builder.Decompile (inspectEditor.GetTextEditorData (), nav, PublicApiOnly)); + inspectEditor.Options = DefaultSourceEditorOptions.PlainEditor; + this.inspectEditor.MimeType = "text/x-csharp"; + SetReferencedSegments (builder.Decompile (inspectEditor, nav, PublicApiOnly)); break; default: - inspectEditor.Options.ShowFoldMargin = false; - this.inspectEditor.Document.Text = "Invalid combobox value: " + this.languageCombobox.Active; + inspectEditor.Options = DefaultSourceEditorOptions.PlainEditor; + this.inspectEditor.Text = "Invalid combobox value: " + this.languageCombobox.Active; break; } - this.inspectEditor.QueueDraw (); } void CreateOutput () @@ -1187,7 +1170,7 @@ namespace MonoDevelop.AssemblyBrowser this.hpaned1.Position = Math.Min (350, this.Allocation.Width * 2 / 3); } - public void Open (string url, AssemblyLoader currentAssembly = null) + internal void Open (string url, AssemblyLoader currentAssembly = null) { ITreeNavigator nav = SearchMember (url); if (definitions == null) // we've been disposed @@ -1364,11 +1347,11 @@ namespace MonoDevelop.AssemblyBrowser documentationPanel.Destroy (); documentationPanel = null; } - if (inspectEditor != null) { - inspectEditor.TextViewMargin.GetLink = null; - inspectEditor.LinkRequest -= InspectEditorhandleLinkRequest; - inspectEditor.Destroy (); - } +// if (inspectEditor != null) { +// inspectEditor.TextViewMargin.GetLink = null; +// inspectEditor.LinkRequest -= InspectEditorhandleLinkRequest; +// inspectEditor.Destroy (); +// } if (this.UIManager != null) { this.UIManager.Dispose (); @@ -1412,12 +1395,12 @@ namespace MonoDevelop.AssemblyBrowser List<AssemblyLoader> definitions = new List<AssemblyLoader> (); List<Project> projects = new List<Project> (); - public AssemblyLoader AddReferenceByAssemblyName (AssemblyNameReference reference) + internal AssemblyLoader AddReferenceByAssemblyName (AssemblyNameReference reference) { return AddReferenceByAssemblyName (reference.Name); } - public AssemblyLoader AddReferenceByAssemblyName (string assemblyFullName) + internal AssemblyLoader AddReferenceByAssemblyName (string assemblyFullName) { string assemblyFile = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyLocation (assemblyFullName, null); if (assemblyFile == null || !System.IO.File.Exists (assemblyFile)) { @@ -1433,7 +1416,7 @@ namespace MonoDevelop.AssemblyBrowser return AddReferenceByFileName (assemblyFile); } - public AssemblyLoader AddReferenceByFileName (string fileName) + internal AssemblyLoader AddReferenceByFileName (string fileName) { var result = definitions.FirstOrDefault (d => d.FileName == fileName); if (result != null) { @@ -1499,77 +1482,7 @@ namespace MonoDevelop.AssemblyBrowser builder.Selected = builder.Expanded = selectReference; } - [CommandHandler (SearchCommands.FindNext)] - public void FindNext () - { - SearchAndReplaceWidget.FindNext (this.inspectEditor); - } - - [CommandHandler (SearchCommands.FindPrevious)] - public void FindPrevious () - { - SearchAndReplaceWidget.FindPrevious (this.inspectEditor); - } - - [CommandHandler (SearchCommands.Find)] - public void ShowSearchWidget () - { - if (searchAndReplaceWidget == null) { - popupWidgetFrame = new MonoDevelop.Components.RoundedFrame (); - //searchAndReplaceWidgetFrame.SetFillColor (MonoDevelop.Components.CairoExtensions.GdkColorToCairoColor (widget.TextEditor.ColorStyle.Default.BackgroundColor)); - popupWidgetFrame.SetFillColor (MonoDevelop.Components.CairoExtensions.GdkColorToCairoColor (Style.Background (StateType.Normal))); - popupWidgetFrame.Show (); - - popupWidgetFrame.Child = searchAndReplaceWidget = new SearchAndReplaceWidget (inspectEditor, popupWidgetFrame); - searchAndReplaceWidget.Destroyed += (sender, e) => { - DestroyFrames (); - if (inspectEditor.IsRealized) - inspectEditor.GrabFocus (); - }; - searchAndReplaceWidget.UpdateSearchPattern (); - inspectEditor.AddAnimatedWidget (popupWidgetFrame, 300, Mono.TextEditor.Theatrics.Easing.ExponentialInOut, Blocking.Downstage, inspectEditor.Allocation.Width - 400, -searchAndReplaceWidget.Allocation.Height); - searchAndReplaceWidget.IsReplaceMode = false; - } - - searchAndReplaceWidget.Focus (); - } - MonoDevelop.Components.RoundedFrame popupWidgetFrame; - - GotoLineNumberWidget gotoLineNumberWidget; - SearchAndReplaceWidget searchAndReplaceWidget; - void DestroyFrames () - { - if (popupWidgetFrame != null) { - popupWidgetFrame.Destroy (); - popupWidgetFrame = null; - gotoLineNumberWidget = null; - searchAndReplaceWidget = null; - } - } - - [CommandHandler (SearchCommands.GotoLineNumber)] - public void ShowGotoLineNumberWidget () - { - if (gotoLineNumberWidget == null) { - DestroyFrames (); - popupWidgetFrame = new MonoDevelop.Components.RoundedFrame (); - //searchAndReplaceWidgetFrame.SetFillColor (MonoDevelop.Components.CairoExtensions.GdkColorToCairoColor (widget.TextEditor.ColorStyle.Default.BackgroundColor)); - popupWidgetFrame.SetFillColor (MonoDevelop.Components.CairoExtensions.GdkColorToCairoColor (Style.Background (StateType.Normal))); - popupWidgetFrame.Show (); - - popupWidgetFrame.Child = gotoLineNumberWidget = new GotoLineNumberWidget (inspectEditor, popupWidgetFrame); - gotoLineNumberWidget.Destroyed += (sender, e) => { - DestroyFrames (); - if (inspectEditor.IsRealized) - inspectEditor.GrabFocus (); - }; - inspectEditor.AddAnimatedWidget (popupWidgetFrame, 300, Mono.TextEditor.Theatrics.Easing.ExponentialInOut, Blocking.Downstage, inspectEditor.Allocation.Width - 400, -gotoLineNumberWidget.Allocation.Height); - } - - gotoLineNumberWidget.Focus (); - } - #region NavigationHistory Stack<ITreeNavigator> navigationBackwardHistory = new Stack<ITreeNavigator> (); diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyReferenceFolder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyReferenceFolder.cs index 36912b98df..d0266fe485 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyReferenceFolder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyReferenceFolder.cs @@ -34,7 +34,6 @@ using MonoDevelop.Core; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Pads; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor; using System.Collections.Generic; using ICSharpCode.NRefactory.TypeSystem; diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs index 05d9a3fbfc..e63acbb988 100755 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs @@ -28,9 +28,10 @@ using ICSharpCode.NRefactory; using System; using System.Text; using ICSharpCode.Decompiler; -using Mono.TextEditor; using System.Collections.Generic; using System.Linq; +using MonoDevelop.Core.Text; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -80,13 +81,13 @@ namespace MonoDevelop.AssemblyBrowser class ColoredCSharpFormatter : ICSharpCode.Decompiler.ITextOutput { public StringBuilder sb = new StringBuilder(); - TextDocument doc; + TextEditor doc; bool write_indent; int indent; - public List<FoldSegment> FoldSegments = new List<FoldSegment>(); + public List<IFoldSegment> FoldSegments = new List<IFoldSegment>(); public List<ReferenceSegment> ReferencedSegments = new List<ReferenceSegment>(); - public ColoredCSharpFormatter (TextDocument doc) + public ColoredCSharpFormatter (TextEditor doc) { this.doc = doc; } @@ -94,7 +95,7 @@ namespace MonoDevelop.AssemblyBrowser public void SetDocumentData () { doc.Text = sb.ToString (); - doc.UpdateFoldSegments (FoldSegments, false); + doc.SetFoldings (FoldSegments); } #region ITextOutput implementation @@ -105,9 +106,9 @@ namespace MonoDevelop.AssemblyBrowser } } - public TextLocation Location { + public ICSharpCode.NRefactory.TextLocation Location { get { - return new TextLocation (currentLine, 1); + return new ICSharpCode.NRefactory.TextLocation (currentLine, 1); } } @@ -193,9 +194,8 @@ namespace MonoDevelop.AssemblyBrowser public void MarkFoldEnd () { var curFold = foldSegmentStarts.Pop (); - FoldSegments.Add (new FoldSegment (doc, curFold.Item2 ,curFold.Item1, sb.Length - curFold.Item1, FoldingType.None) { - IsFolded = curFold.Item3 - }); + var seg = FoldSegmentFactory.CreateFoldSegment (doc, curFold.Item1, sb.Length - curFold.Item1, curFold.Item3, curFold.Item2); + FoldSegments.Add (seg); } #endregion diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/HelpExtensions.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/HelpExtensions.cs new file mode 100644 index 0000000000..ee67c390d8 --- /dev/null +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/HelpExtensions.cs @@ -0,0 +1,168 @@ +// +// HelpExtensions.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2015 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 System.Linq; +using Monodoc; +using System.Threading; +using MonoDevelop.Core; +using Mono.Addins; +using System.IO; +using System.Collections.Generic; +using MonoDevelop.Projects.Extensions; +using System.Text; +using System.Xml; +using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Projects; +using ICSharpCode.NRefactory.Documentation; + +namespace MonoDevelop.AssemblyBrowser +{ + static class HelpExtension + { + static void AppendTypeReference (StringBuilder result, ITypeReference type) + { + if (type is ArrayTypeReference) { + var array = (ArrayTypeReference)type; + AppendTypeReference (result, array.ElementType); + result.Append ("["); + result.Append (new string (',', array.Dimensions)); + result.Append ("]"); + return; + } + + if (type is PointerTypeReference) { + var ptr = (PointerTypeReference)type; + AppendTypeReference (result, ptr.ElementType); + result.Append ("*"); + return; + } + + if (type is IType) + result.Append (((IType)type).FullName); + } + + + static void AppendHelpParameterList (StringBuilder result, IList<IParameter> parameters) + { + result.Append ('('); + if (parameters != null) { + for (int i = 0; i < parameters.Count; i++) { + if (i > 0) + result.Append (','); + var p = parameters [i]; + if (p == null) + continue; + if (p.IsRef || p.IsOut) + result.Append ("&"); + AppendTypeReference (result, p.Type.ToTypeReference ()); + } + } + result.Append (')'); + } + + static void AppendHelpParameterList (StringBuilder result, IList<IUnresolvedParameter> parameters) + { + result.Append ('('); + if (parameters != null) { + for (int i = 0; i < parameters.Count; i++) { + if (i > 0) + result.Append (','); + var p = parameters [i]; + if (p == null) + continue; + if (p.IsRef || p.IsOut) + result.Append ("&"); + AppendTypeReference (result, p.Type); + } + } + result.Append (')'); + } + + static XmlNode FindMatch (IMethod method, XmlNodeList nodes) + { + foreach (XmlNode node in nodes) { + XmlNodeList paramList = node.SelectNodes ("Parameters/*"); + if (method.Parameters.Count == 0 && paramList.Count == 0) + return node; + if (method.Parameters.Count != paramList.Count) + continue; + + /* bool matched = true; + for (int i = 0; i < p.Count; i++) { + if (p [i].ReturnType.FullName != paramList [i].Attributes ["Type"].Value) { + matched = false; + break; + } + } + if (matched)*/ + return node; + } + return null; + } + + public static XmlNode GetMonodocDocumentation (this IEntity member) + { + if (member.SymbolKind == SymbolKind.TypeDefinition) { + var helpXml = HelpService.HelpTree != null ? HelpService.HelpTree.GetHelpXml (IdStringProvider.GetIdString (member)) : null; + if (helpXml == null) + return null; + return helpXml.SelectSingleNode ("/Type/Docs"); + } + + var declaringXml = HelpService.HelpTree != null && member.DeclaringTypeDefinition != null ? HelpService.HelpTree.GetHelpXml (member.DeclaringTypeDefinition.GetIdString ()) : null; + if (declaringXml == null) + return null; + + switch (member.SymbolKind) { + case SymbolKind.Method: + { + var nodes = declaringXml.SelectNodes ("/Type/Members/Member[@MemberName='" + member.Name + "']"); + XmlNode node = nodes.Count == 1 ? nodes [0] : FindMatch ((IMethod)member, nodes); + if (node != null) { + System.Xml.XmlNode result = node.SelectSingleNode ("Docs"); + return result; + } + return null; + } + case SymbolKind.Constructor: + { + var nodes = declaringXml.SelectNodes ("/Type/Members/Member[@MemberName='.ctor']"); + XmlNode node = nodes.Count == 1 ? nodes [0] : FindMatch ((IMethod)member, nodes); + if (node != null) { + System.Xml.XmlNode result = node.SelectSingleNode ("Docs"); + return result; + } + return null; + } + default: + return declaringXml.SelectSingleNode ("/Type/Members/Member[@MemberName='" + member.Name + "']/Docs"); + } + } + + } +} + diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/IAssemblyBrowserNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/IAssemblyBrowserNodeBuilder.cs index 7a13a020b6..2355c9897c 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/IAssemblyBrowserNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/IAssemblyBrowserNodeBuilder.cs @@ -29,16 +29,16 @@ using System; using MonoDevelop.Ide.Gui.Pads; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor; using System.Collections.Generic; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { interface IAssemblyBrowserNodeBuilder { string GetDocumentationMarkup (ITreeNavigator navigator); - List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator); - List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly); - List<ReferenceSegment> GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly); + List<ReferenceSegment> Disassemble (TextEditor data, ITreeNavigator navigator); + List<ReferenceSegment> Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly); + List<ReferenceSegment> GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly); } } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs new file mode 100644 index 0000000000..9d4624c339 --- /dev/null +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs @@ -0,0 +1,302 @@ +// +// NRefactoryStock.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2015 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; +using ICSharpCode.NRefactory.TypeSystem; + +namespace MonoDevelop.AssemblyBrowser +{ + static class NRefactoryStock + { + static readonly IconId Class = "md-class"; + static readonly IconId Enum = "md-enum"; + static readonly IconId Event = "md-event"; + static readonly IconId Field = "md-field"; + static readonly IconId Interface = "md-interface"; + static readonly IconId Method = "md-method"; + static readonly IconId ExtensionMethod = "md-extensionmethod"; + static readonly IconId Property = "md-property"; + static readonly IconId Struct = "md-struct"; + static readonly IconId Delegate = "md-delegate"; + public static readonly IconId Namespace = "md-name-space"; + + static readonly IconId InternalClass = "md-internal-class"; + static readonly IconId InternalDelegate = "md-internal-delegate"; + static readonly IconId InternalEnum = "md-internal-enum"; + static readonly IconId InternalEvent = "md-internal-event"; + static readonly IconId InternalField = "md-internal-field"; + static readonly IconId InternalInterface = "md-internal-interface"; + static readonly IconId InternalMethod = "md-internal-method"; + static readonly IconId InternalExtensionMethod = "md-internal-extensionmethod"; + static readonly IconId InternalProperty = "md-internal-property"; + static readonly IconId InternalStruct = "md-internal-struct"; + + static readonly IconId InternalAndProtectedClass = "md-InternalAndProtected-class"; + static readonly IconId InternalAndProtectedDelegate = "md-InternalAndProtected-delegate"; + static readonly IconId InternalAndProtectedEnum = "md-InternalAndProtected-enum"; + static readonly IconId InternalAndProtectedEvent = "md-InternalAndProtected-event"; + static readonly IconId InternalAndProtectedField = "md-InternalAndProtected-field"; + static readonly IconId InternalAndProtectedInterface = "md-InternalAndProtected-interface"; + static readonly IconId InternalAndProtectedMethod = "md-InternalAndProtected-method"; + static readonly IconId InternalAndProtectedExtensionMethod = "md-InternalAndProtected-extensionmethod"; + static readonly IconId InternalAndProtectedProperty = "md-InternalAndProtected-property"; + static readonly IconId InternalAndProtectedStruct = "md-InternalAndProtected-struct"; + + static readonly IconId PrivateClass = "md-private-class"; + static readonly IconId PrivateDelegate = "md-private-delegate"; + static readonly IconId PrivateEnum = "md-private-enum"; + static readonly IconId PrivateEvent = "md-private-event"; + static readonly IconId PrivateField = "md-private-field"; + static readonly IconId PrivateInterface = "md-private-interface"; + static readonly IconId PrivateMethod = "md-private-method"; + static readonly IconId PrivateExtensionMethod = "md-private-extensionmethod"; + static readonly IconId PrivateProperty = "md-private-property"; + static readonly IconId PrivateStruct = "md-private-struct"; + + static readonly IconId ProtectedClass = "md-protected-class"; + static readonly IconId ProtectedDelegate = "md-protected-delegate"; + static readonly IconId ProtectedEnum = "md-protected-enum"; + static readonly IconId ProtectedEvent = "md-protected-event"; + static readonly IconId ProtectedField = "md-protected-field"; + static readonly IconId ProtectedInterface = "md-protected-interface"; + static readonly IconId ProtectedMethod = "md-protected-method"; + static readonly IconId ProtectedExtensionMethod = "md-protected-extensionmethod"; + static readonly IconId ProtectedProperty = "md-protected-property"; + static readonly IconId ProtectedStruct = "md-protected-struct"; + + static readonly IconId ProtectedOrInternalClass = "md-ProtectedOrInternal-class"; + static readonly IconId ProtectedOrInternalDelegate = "md-ProtectedOrInternal-delegate"; + static readonly IconId ProtectedOrInternalEnum = "md-ProtectedOrInternal-enum"; + static readonly IconId ProtectedOrInternalEvent = "md-ProtectedOrInternal-event"; + static readonly IconId ProtectedOrInternalField = "md-ProtectedOrInternal-field"; + static readonly IconId ProtectedOrInternalInterface = "md-ProtectedOrInternal-interface"; + static readonly IconId ProtectedOrInternalMethod = "md-ProtectedOrInternal-method"; + static readonly IconId ProtectedOrInternalExtensionMethod = "md-ProtectedOrInternal-extensionmethod"; + static readonly IconId ProtectedOrInternalProperty = "md-ProtectedOrInternal-property"; + static readonly IconId ProtectedOrInternalStruct = "md-ProtectedOrInternal-struct"; + + static IconId[,] typeIconTable = new IconId[,] { + {Class, PrivateClass, Class, ProtectedClass, InternalClass, ProtectedOrInternalClass, InternalAndProtectedClass}, // class + {Enum, PrivateEnum, Enum, ProtectedEnum, InternalEnum, ProtectedOrInternalEnum, InternalAndProtectedEnum}, // enum + {Interface, PrivateInterface, Interface, ProtectedInterface, InternalInterface, ProtectedOrInternalInterface, InternalAndProtectedInterface}, // interface + {Struct, PrivateStruct, Struct, ProtectedStruct, InternalStruct, ProtectedOrInternalStruct, InternalAndProtectedStruct}, // struct + {Delegate, PrivateDelegate, Delegate, ProtectedDelegate, InternalDelegate, ProtectedOrInternalDelegate, InternalAndProtectedDelegate} // delegate + }; + static readonly IconId[] fieldIconTable = { + NRefactoryStock.Field, NRefactoryStock.PrivateField, NRefactoryStock.Field, NRefactoryStock.ProtectedField, NRefactoryStock.InternalField, NRefactoryStock.ProtectedOrInternalField, NRefactoryStock.InternalAndProtectedField + }; + static readonly IconId[] methodIconTable = { + NRefactoryStock.Method, NRefactoryStock.PrivateMethod, NRefactoryStock.Method, NRefactoryStock.ProtectedMethod, NRefactoryStock.InternalMethod, NRefactoryStock.ProtectedOrInternalMethod, NRefactoryStock.InternalAndProtectedMethod + }; + static readonly IconId[] extensionMethodIconTable = { + NRefactoryStock.ExtensionMethod, NRefactoryStock.PrivateExtensionMethod, NRefactoryStock.ExtensionMethod, NRefactoryStock.ProtectedExtensionMethod, NRefactoryStock.InternalExtensionMethod, NRefactoryStock.ProtectedOrInternalExtensionMethod, NRefactoryStock.InternalAndProtectedExtensionMethod + }; + static readonly IconId[] propertyIconTable = { + NRefactoryStock.Property, NRefactoryStock.PrivateProperty, NRefactoryStock.Property, NRefactoryStock.ProtectedProperty, NRefactoryStock.InternalProperty, NRefactoryStock.ProtectedOrInternalProperty, NRefactoryStock.InternalAndProtectedProperty + }; + static readonly IconId[] eventIconTable = { + NRefactoryStock.Event, NRefactoryStock.PrivateEvent, NRefactoryStock.Event, NRefactoryStock.ProtectedEvent, NRefactoryStock.InternalEvent, NRefactoryStock.ProtectedOrInternalEvent, NRefactoryStock.InternalAndProtectedEvent + }; + + public static IconId GetStockIcon (this INamedElement element) + { + if (element is IType) + return ((IType)element).GetStockIcon (); + if (element is ITypeParameter) + return ((ITypeParameter)element).GetStockIcon (); + if (element is IUnresolvedEntity) + return ((IUnresolvedEntity)element).GetStockIcon (); + return ((IEntity)element).GetStockIcon (); + } + + public static IconId GetStockIcon (this ITypeDefinition entity) + { + return GetStockIcon ((IType)entity); + } + + public static IconId GetStockIcon (this IType entity) + { + var def = entity.GetDefinition (); + if (def == null) + return Class; + switch (def.Kind) { + case TypeKind.Class: + return typeIconTable [0, (int)def.Accessibility]; + case TypeKind.Enum: + return typeIconTable [1, (int)def.Accessibility]; + case TypeKind.Interface: + return typeIconTable [2, (int)def.Accessibility]; + case TypeKind.Struct: + return typeIconTable [3, (int)def.Accessibility]; + case TypeKind.Delegate: + return typeIconTable [4, (int)def.Accessibility]; + default: + return typeIconTable [0, (int)def.Accessibility]; + } + } + public static IconId GetStockIcon (this IUnresolvedTypeDefinition def) + { + switch (def.Kind) { + case TypeKind.Class: + return typeIconTable [0, (int)def.Accessibility]; + case TypeKind.Enum: + return typeIconTable [1, (int)def.Accessibility]; + case TypeKind.Interface: + return typeIconTable [2, (int)def.Accessibility]; + case TypeKind.Struct: + return typeIconTable [3, (int)def.Accessibility]; + case TypeKind.Delegate: + return typeIconTable [4, (int)def.Accessibility]; + default: + return typeIconTable [0, (int)def.Accessibility]; + } + } + + static int GetTypeIndex (Microsoft.CodeAnalysis.TypeKind typeKind) + { + switch (typeKind) { + case Microsoft.CodeAnalysis.TypeKind.Unknown: + case Microsoft.CodeAnalysis.TypeKind.Array: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Class: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Delegate: + return 4; + case Microsoft.CodeAnalysis.TypeKind.Dynamic: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Enum: + return 1; + case Microsoft.CodeAnalysis.TypeKind.Error: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Interface: + return 2; + case Microsoft.CodeAnalysis.TypeKind.Module: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Pointer: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Struct: + return 3; + case Microsoft.CodeAnalysis.TypeKind.TypeParameter: + return 0; + case Microsoft.CodeAnalysis.TypeKind.Submission: + return 0; + default: + throw new ArgumentOutOfRangeException (); + } + } + + public static IconId GetStockIcon (this IField field) + { + return GetStockIcon ((IEntity)field); + } + + public static IconId GetStockIcon (this IVariable variable) + { + return Field; + } + + public static IconId GetStockIcon (this IParameter parameter) + { + return Field; + } + + public static IconId GetStockIcon (this IUnresolvedTypeParameter parameter) + { + return Field; + } + + public static IconId GetStockIcon (this IEntity entity, bool showAccessibility = true) + { + switch (entity.SymbolKind) { + case SymbolKind.TypeDefinition: + return GetStockIcon ((IType)entity); + case SymbolKind.Field: + if (showAccessibility) + return fieldIconTable [(int)entity.Accessibility]; + else + return fieldIconTable [0]; + case SymbolKind.Method: + case SymbolKind.Constructor: + case SymbolKind.Destructor: + case SymbolKind.Operator: + if (showAccessibility) { + if (((IMethod)entity).IsExtensionMethod) + return extensionMethodIconTable [(int)entity.Accessibility]; + return methodIconTable [(int)entity.Accessibility]; + } else { + if (((IMethod)entity).IsExtensionMethod) + return extensionMethodIconTable [0]; + return methodIconTable [0]; + } + case SymbolKind.Property: + case SymbolKind.Indexer: + if (showAccessibility) + return propertyIconTable [(int)entity.Accessibility]; + else + return propertyIconTable [0]; + case SymbolKind.Event: + if (showAccessibility) + return eventIconTable [(int)entity.Accessibility]; + else + return eventIconTable [0]; + } + return ""; + } + public static IconId GetStockIcon (this IUnresolvedEntity entity, bool showAccessibility = true) + { + switch (entity.SymbolKind) { + case SymbolKind.TypeDefinition: + return GetStockIcon ((IUnresolvedTypeDefinition)entity); + case SymbolKind.Field: + if (showAccessibility) + return fieldIconTable [(int)entity.Accessibility]; + else + return fieldIconTable [0]; + case SymbolKind.Method: + case SymbolKind.Constructor: + case SymbolKind.Destructor: + case SymbolKind.Operator: + if (showAccessibility) + return methodIconTable [(int)entity.Accessibility]; + else + return methodIconTable [0]; + case SymbolKind.Property: + case SymbolKind.Indexer: + if (showAccessibility) + return propertyIconTable [(int)entity.Accessibility]; + else + return propertyIconTable [0]; + case SymbolKind.Event: + if (showAccessibility) + return eventIconTable [(int)entity.Accessibility]; + else + return eventIconTable [0]; + } + return ""; + } + } +} + diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyBrowserTypeNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyBrowserTypeNodeBuilder.cs index 99f4050b9c..683c8b04a1 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyBrowserTypeNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyBrowserTypeNodeBuilder.cs @@ -32,6 +32,7 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation; using MonoDevelop.Core; using MonoDevelop.Projects; using MonoDevelop.Ide.TypeSystem; +using ICSharpCode.NRefactory.CSharp; namespace MonoDevelop.AssemblyBrowser { @@ -41,10 +42,11 @@ namespace MonoDevelop.AssemblyBrowser get; private set; } - - protected MonoDevelop.Ide.TypeSystem.Ambience Ambience { + readonly static CSharpAmbience ambience = new CSharpAmbience (); + + protected CSharpAmbience Ambience { get { - return Widget.Ambience; + return ambience; } } @@ -104,9 +106,11 @@ namespace MonoDevelop.AssemblyBrowser var simpleCompilation = new SimpleCompilation (mainAssembly); return new SimpleTypeResolveContext (simpleCompilation.MainAssembly); } - var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true); - var compilation = TypeSystemService.GetCompilation (project); - return new SimpleTypeResolveContext (compilation.MainAssembly); + // TODO: roslyn port ? + // var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true); + // var compilation = TypeSystemService.GetCompilation (project); + // return new SimpleTypeResolveContext (compilation.MainAssembly); + return null; } protected IMember Resolve (ITreeNavigator treeBuilder, IUnresolvedMember member, ITypeDefinition currentType = null) @@ -122,9 +126,11 @@ namespace MonoDevelop.AssemblyBrowser var simpleCompilation = new SimpleCompilation (mainAssembly); return type.Resolve (new SimpleTypeResolveContext (simpleCompilation.MainAssembly)); } - var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true); - var ctx = TypeSystemService.GetCompilation (project); - return ctx.MainAssembly.GetTypeDefinition (type.Namespace, type.Name, type.TypeParameters.Count); + // TODO: roslyn port ? + // var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true); + // var ctx = TypeSystemService.GetCompilation (project); + // return ctx.MainAssembly.GetTypeDefinition (type.Namespace, type.Name, type.TypeParameters.Count); + return null; } } } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyNodeBuilder.cs index a9dd6a68ba..21fdf47598 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/AssemblyNodeBuilder.cs @@ -36,10 +36,10 @@ using MonoDevelop.Core; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Pads; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor; using System.Collections.Generic; using ICSharpCode.NRefactory.TypeSystem; using System.IO; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -130,10 +130,10 @@ namespace MonoDevelop.AssemblyBrowser void PrintAssemblyHeader (StringBuilder result, AssemblyDefinition assemblyDefinition) { result.Append ("<span style=\"comment\">"); - result.Append (Ambience.SingleLineComment ( + result.Append ("// " + String.Format (GettextCatalog.GetString ("Assembly <b>{0}</b>, Version {1}"), assemblyDefinition.Name.Name, - assemblyDefinition.Name.Version))); + assemblyDefinition.Name.Version)); result.Append ("</span>"); result.AppendLine (); } @@ -151,7 +151,7 @@ namespace MonoDevelop.AssemblyBrowser return GettextCatalog.GetString ("Unknown"); } - public List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator) + public List<ReferenceSegment> Disassemble (TextEditor data, ITreeNavigator navigator) { var assembly = ((AssemblyLoader)navigator.DataItem).UnresolvedAssembly; var compilationUnit = Widget.CecilLoader.GetCecilObject (assembly); @@ -163,7 +163,7 @@ namespace MonoDevelop.AssemblyBrowser } - public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + public List<ReferenceSegment> Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { var assembly = ((AssemblyLoader)navigator.DataItem).UnresolvedAssembly; var compilationUnit = Widget.CecilLoader.GetCecilObject (assembly); @@ -177,7 +177,7 @@ namespace MonoDevelop.AssemblyBrowser }); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { var assembly = ((AssemblyLoader)navigator.DataItem).UnresolvedAssembly; var compilationUnit = Widget.CecilLoader.GetCecilObject (assembly); diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomEventNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomEventNodeBuilder.cs index d04c119022..cca966e2bc 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomEventNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomEventNodeBuilder.cs @@ -34,12 +34,13 @@ using MonoDevelop.Ide; using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler; using System.Threading; -using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using MonoDevelop.Ide.Editor; +using ICSharpCode.NRefactory.CSharp; namespace MonoDevelop.AssemblyBrowser { @@ -64,7 +65,7 @@ namespace MonoDevelop.AssemblyBrowser var evt = (IUnresolvedEvent)dataObject; try { var resolved = Resolve (treeBuilder, evt); - nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved)); } catch (Exception) { nodeInfo.Label = evt.Name; } @@ -90,7 +91,7 @@ namespace MonoDevelop.AssemblyBrowser } #region IAssemblyBrowserNodeBuilder - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditor data, ITreeNavigator navigator) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -98,7 +99,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleEvent (evt)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -106,7 +107,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), evt.DeclaringType, b => b.AddEvent (evt)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -120,17 +121,12 @@ namespace MonoDevelop.AssemblyBrowser var resolved = Resolve (navigator, evt); StringBuilder result = new StringBuilder (); result.Append ("<big>"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved))); result.Append ("</big>"); result.AppendLine (); - - var options = new AmbienceService.DocumentationFormatOptions (); - options.MaxLineLength = -1; - options.BigHeadings = true; - options.Ambience = Ambience; result.AppendLine (); - - result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); + + //result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomFieldNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomFieldNodeBuilder.cs index f56ad572f6..5271725dc4 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomFieldNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomFieldNodeBuilder.cs @@ -34,12 +34,12 @@ using MonoDevelop.Ide; using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler; using System.Threading; -using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -65,7 +65,7 @@ namespace MonoDevelop.AssemblyBrowser var field = (IUnresolvedField)dataObject; try { var resolved = Resolve (treeBuilder, field); - nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved)); } catch (Exception) { nodeInfo.Label = field.Name; } @@ -77,7 +77,7 @@ namespace MonoDevelop.AssemblyBrowser #region IAssemblyBrowserNodeBuilder - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditor data, ITreeNavigator navigator) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -85,7 +85,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleField (field)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -93,7 +93,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), field.DeclaringType, b => b.AddField (field)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -107,17 +107,11 @@ namespace MonoDevelop.AssemblyBrowser var resolved = Resolve (navigator, field); StringBuilder result = new StringBuilder (); result.Append ("<big>"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved))); result.Append ("</big>"); result.AppendLine (); - - var options = new AmbienceService.DocumentationFormatOptions (); - options.MaxLineLength = -1; - options.BigHeadings = true; - options.Ambience = Ambience; - result.AppendLine (); - - result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); + + //result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomMethodNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomMethodNodeBuilder.cs index 1a9b29e791..2fb905e139 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomMethodNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomMethodNodeBuilder.cs @@ -40,13 +40,14 @@ using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler; using System.Threading; using ICSharpCode.Decompiler.Disassembler; -using Mono.TextEditor; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; using System.IO; using ICSharpCode.NRefactory.CSharp; using MonoDevelop.Projects; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Core.Text; namespace MonoDevelop.AssemblyBrowser { @@ -78,8 +79,9 @@ namespace MonoDevelop.AssemblyBrowser var method = (IUnresolvedMethod)dataObject; var dt = new DefaultResolvedTypeDefinition (GetContext (treeBuilder), method.DeclaringTypeDefinition); var resolved = (DefaultResolvedMethod)Resolve (treeBuilder, method, dt); + var ambience = new CSharpAmbience (); try { - nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + nodeInfo.Label = ambience.ConvertSymbol (resolved); } catch (Exception) { nodeInfo.Label = method.Name; } @@ -119,16 +121,16 @@ namespace MonoDevelop.AssemblyBrowser return (ModuleDefinition)nav.DataItem; } - public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) + public static List<ReferenceSegment> Decompile (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) { - var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType); + var types = DesktopService.GetMimeTypeInheritanceChain (data.MimeType); var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types); var settings = DomTypeNodeBuilder.CreateDecompilerSettings (false, codePolicy); return Decompile (data, module, currentType, setData, settings); } - public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings) + public static List<ReferenceSegment> Decompile (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings) { var context = new DecompilerContext (module); var source = new CancellationTokenSource (); @@ -140,7 +142,7 @@ namespace MonoDevelop.AssemblyBrowser setData (astBuilder); astBuilder.RunTransformations (o => false); GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree); - var output = new ColoredCSharpFormatter (data.Document); + var output = new ColoredCSharpFormatter (data); astBuilder.GenerateCode (output); output.SetDocumentData (); return output.ReferencedSegments; @@ -152,10 +154,10 @@ namespace MonoDevelop.AssemblyBrowser setData (astBuilder); astBuilder.RunTransformations (o => false); GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree); - var output = new ColoredCSharpFormatter (data.Document); + var output = new ColoredCSharpFormatter (data); astBuilder.GenerateCode (output); output.SetDocumentData (); - data.Document.Insert (data.Document.TextLength, "/* body decompilation failed: \n" + e + " */"); + data.InsertText (data.Length, "/* body decompilation failed: \n" + e + " */"); } catch (Exception e2) { data.Text = "/* fallback decompilation failed: \n" + e2 +"*/"; } @@ -163,15 +165,15 @@ namespace MonoDevelop.AssemblyBrowser return null; } - public static List<ReferenceSegment> GetSummary (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) + public static List<ReferenceSegment> GetSummary (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) { - var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType); + var types = DesktopService.GetMimeTypeInheritanceChain (data.MimeType); var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types); var settings = DomTypeNodeBuilder.CreateDecompilerSettings (false, codePolicy); return GetSummary (data, module, currentType, setData, settings); } - public static List<ReferenceSegment> GetSummary (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings) + public static List<ReferenceSegment> GetSummary (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings) { var context = new DecompilerContext (module); var source = new CancellationTokenSource (); @@ -184,7 +186,7 @@ namespace MonoDevelop.AssemblyBrowser setData (astBuilder); astBuilder.RunTransformations (o => false); GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree); - var output = new ColoredCSharpFormatter (data.Document); + var output = new ColoredCSharpFormatter (data); astBuilder.GenerateCode (output); output.SetDocumentData (); return output.ReferencedSegments; @@ -194,20 +196,22 @@ namespace MonoDevelop.AssemblyBrowser return null; } - internal static string GetAttributes (Ambience ambience, IEnumerable<IAttribute> attributes) + internal static string GetAttributes (IEnumerable<IAttribute> attributes) { StringBuilder result = new StringBuilder (); + var ambience = new CSharpAmbience (); + foreach (var attr in attributes) { if (result.Length > 0) result.AppendLine (); - // result.Append (ambience.GetString (attr, OutputFlags.AssemblyBrowserDescription)); + // result.Append (ambience.ConvertSymbol (attr)); } if (result.Length > 0) result.AppendLine (); return result.ToString (); } - public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + public List<ReferenceSegment> Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { var method = (IUnresolvedMethod)navigator.DataItem; if (HandleSourceCodeEntity (navigator, data)) @@ -218,7 +222,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), cecilMethod.DeclaringType, b => b.AddMethod (cecilMethod)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { var method = (IUnresolvedMethod)navigator.DataItem; if (HandleSourceCodeEntity (navigator, data)) @@ -238,29 +242,29 @@ namespace MonoDevelop.AssemblyBrowser sb.Append ("</a></u></span>"); } - public static List<ReferenceSegment> Disassemble (TextEditorData data, Action<ReflectionDisassembler> setData) + public static List<ReferenceSegment> Disassemble (TextEditor data, Action<ReflectionDisassembler> setData) { var source = new CancellationTokenSource (); - var output = new ColoredCSharpFormatter (data.Document); + var output = new ColoredCSharpFormatter (data); var disassembler = new ReflectionDisassembler (output, true, source.Token); setData (disassembler); output.SetDocumentData (); return output.ReferencedSegments; } - internal static bool HandleSourceCodeEntity (ITreeNavigator navigator, TextEditorData data) + internal static bool HandleSourceCodeEntity (ITreeNavigator navigator, TextEditor data) { if (IsFromAssembly (navigator)) return false; var method = (IUnresolvedEntity)navigator.DataItem; - data.Text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (method.Region.FileName); - data.Caret.Location = method.Region.Begin; - data.CenterToCaret (); + var source = StringTextSource.ReadFrom (method.Region.FileName); + data.Text = source.Text; + data.CaretLocation = new MonoDevelop.Ide.Editor.DocumentLocation (method.Region.BeginLine, method.Region.BeginColumn); return true; } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditor data, ITreeNavigator navigator) { var method = (IUnresolvedMethod)navigator.DataItem; if (HandleSourceCodeEntity (navigator, data)) @@ -276,21 +280,15 @@ namespace MonoDevelop.AssemblyBrowser var method = (IUnresolvedMethod)navigator.DataItem; var resolved = Resolve (navigator, method); if (GetMainAssembly (navigator) == null) { - return Mono.TextEditor.Utils.TextFileUtility.ReadAllText (method.Region.FileName); + return StringTextSource.ReadFrom (method.Region.FileName).Text; } StringBuilder result = new StringBuilder (); result.Append ("<big>"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription | OutputFlags.IncludeConstraints)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved))); result.Append ("</big>"); result.AppendLine (); - - AmbienceService.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); - options.MaxLineLength = -1; - options.BigHeadings = true; - options.Ambience = Ambience; - result.AppendLine (); - - result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); + + //result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomPropertyNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomPropertyNodeBuilder.cs index 465b41300b..7461dd9a83 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomPropertyNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomPropertyNodeBuilder.cs @@ -35,12 +35,12 @@ using MonoDevelop.Projects.Text; using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler; using System.Threading; -using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -66,7 +66,7 @@ namespace MonoDevelop.AssemblyBrowser var property = (IUnresolvedProperty)dataObject; try { var resolved = Resolve (treeBuilder, property); - nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved)); } catch (Exception) { nodeInfo.Label = property.Name; } @@ -87,7 +87,7 @@ namespace MonoDevelop.AssemblyBrowser #region IAssemblyBrowserNodeBuilder - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditor data, ITreeNavigator navigator) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -107,7 +107,7 @@ namespace MonoDevelop.AssemblyBrowser return result; } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -115,7 +115,7 @@ namespace MonoDevelop.AssemblyBrowser return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), property.DeclaringType, b => b.AddProperty (property)); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -129,17 +129,11 @@ namespace MonoDevelop.AssemblyBrowser var resolved = Resolve (navigator, property); StringBuilder result = new StringBuilder (); result.Append ("<big>"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertSymbol (resolved))); result.Append ("</big>"); result.AppendLine (); - - AmbienceService.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); - options.MaxLineLength = -1; - options.BigHeadings = true; - options.Ambience = Ambience; - result.AppendLine (); - - result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); + + //result.Append (AmbienceService.GetDocumentationMarkup (resolved, AmbienceService.GetDocumentation (resolved), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomTypeNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomTypeNodeBuilder.cs index 35ba03ed84..362a78969e 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomTypeNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/DomTypeNodeBuilder.cs @@ -30,19 +30,21 @@ using System; using System.Text; using System.Linq; using Mono.Cecil; - using MonoDevelop.Core; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor.Highlighting; using MonoDevelop.Ide; using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler; using System.Threading; -using Mono.TextEditor; using System.Collections.Generic; using MonoDevelop.Ide.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Ide.Editor.Highlighting; +using Mono.TextEditor.Highlighting; +using MonoDevelop.Ide.Gui.Content; +using ICSharpCode.NRefactory.CSharp; namespace MonoDevelop.AssemblyBrowser { @@ -61,8 +63,7 @@ namespace MonoDevelop.AssemblyBrowser } - internal static OutputSettings settings; - static SyntaxMode mode = SyntaxModeService.GetSyntaxMode (null, "text/x-csharp"); + static SyntaxMode mode = Mono.TextEditor.Highlighting.SyntaxModeService.GetSyntaxMode (null, "text/x-csharp"); internal static string MarkupKeyword (string text) { @@ -75,34 +76,7 @@ namespace MonoDevelop.AssemblyBrowser } return text; } - - static DomTypeNodeBuilder () - { - DomTypeNodeBuilder.settings = new OutputSettings (OutputFlags.AssemblyBrowserDescription); - - DomTypeNodeBuilder.settings.MarkupCallback += delegate (string text) { - return "<span style=\"text\">" + text + "</span>"; - }; - DomTypeNodeBuilder.settings.EmitModifiersCallback = delegate (string text) { - return "<span style=\"keyword.modifier\">" + text + "</span>"; - }; - DomTypeNodeBuilder.settings.EmitKeywordCallback = delegate (string text) { - return MarkupKeyword (text); - }; -// DomTypeNodeBuilder.settings.EmitNameCallback = delegate (IEntity domVisitable, ref string outString) { -// if (domVisitable is IType) { -// outString = "<span style=\"text.link\"><u><a ref=\"" + ((IType)domVisitable).HelpUrl + "\">" + outString + "</a></u></span>"; -// } else { -// outString = "<span style=\"text\">" + outString + "</span>"; -// } -// }; -// DomTypeNodeBuilder.settings.PostProcessCallback = delegate (IEntity domVisitable, ref string outString) { -// if (domVisitable is IReturnType) { -// outString = "<span style=\"text.link\"><u><a ref=\"" + ((IReturnType)domVisitable).HelpUrl + "\">" + outString + "</a></u></span>"; -// } -// }; - } - + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { var type = (IUnresolvedTypeDefinition)dataObject; @@ -114,7 +88,7 @@ namespace MonoDevelop.AssemblyBrowser var type = (IUnresolvedTypeDefinition)dataObject; try { var resolved = Resolve (treeBuilder, type); - nodeInfo.Label = Ambience.GetString (resolved, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.UseNETTypeNames); + nodeInfo.Label = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertType (resolved)); } catch (Exception) { nodeInfo.Label = type.Name; } @@ -161,7 +135,7 @@ namespace MonoDevelop.AssemblyBrowser var resolved = Resolve (navigator, type); StringBuilder result = new StringBuilder (); result.Append ("<span font_family=\"monospace\">"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertType (resolved))); result.Append ("</span>"); result.AppendLine (); result.Append (String.Format (GettextCatalog.GetString ("<b>Name:</b>\t{0}"), type.FullName)); @@ -170,7 +144,7 @@ namespace MonoDevelop.AssemblyBrowser return result.ToString (); } - public List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator) + public List<ReferenceSegment> Disassemble (TextEditor data, ITreeNavigator navigator) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; @@ -193,19 +167,19 @@ namespace MonoDevelop.AssemblyBrowser LockStatement = true, AsyncAwait = true, ShowXmlDocumentation = true, - CSharpFormattingOptions = codePolicy.CreateOptions (), + CSharpFormattingOptions = FormattingOptionsFactory.CreateMono (), HideNonPublicMembers = publicOnly }; } - public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + public List<ReferenceSegment> Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; var type = CecilLoader.GetCecilObject ((IUnresolvedTypeDefinition)navigator.DataItem); if (type == null) return null; - var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType); + var types = DesktopService.GetMimeTypeInheritanceChain (data.MimeType); var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types); var settings = CreateDecompilerSettings (publicOnly, codePolicy); return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), type, builder => { @@ -213,14 +187,14 @@ namespace MonoDevelop.AssemblyBrowser }, settings); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) return null; var type = CecilLoader.GetCecilObject ((IUnresolvedTypeDefinition)navigator.DataItem); if (type == null) return null; - var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType); + var types = DesktopService.GetMimeTypeInheritanceChain (data.MimeType); var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types); var settings = CreateDecompilerSettings (publicOnly, codePolicy); return DomMethodNodeBuilder.GetSummary (data, DomMethodNodeBuilder.GetModule (navigator), type, builder => { @@ -228,24 +202,17 @@ namespace MonoDevelop.AssemblyBrowser }, settings); } - string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) { var type = (IUnresolvedTypeDefinition)navigator.DataItem; var resolved = Resolve (navigator, type); var result = new StringBuilder (); result.Append ("<big>"); - result.Append (Ambience.GetString (resolved, OutputFlags.AssemblyBrowserDescription)); + result.Append (MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (Ambience.ConvertType (resolved))); result.Append ("</big>"); result.AppendLine (); - AmbienceService.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); - options.MaxLineLength = -1; - options.BigHeadings = true; - options.Ambience = Ambience; - result.AppendLine (); - - result.Append (AmbienceService.GetDocumentationMarkup (resolved.GetDefinition (), AmbienceService.GetDocumentation (resolved.GetDefinition ()), options)); + //result.Append (AmbienceService.GetDocumentationMarkup (resolved.GetDefinition (), AmbienceService.GetDocumentation (resolved.GetDefinition ()), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/NamespaceBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/NamespaceBuilder.cs index e19351f894..dd0854bd00 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/NamespaceBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/NamespaceBuilder.cs @@ -31,9 +31,9 @@ using System.Text; using System.Linq; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor; using System.Collections.Generic; using MonoDevelop.Core; +using MonoDevelop.Ide.Editor; namespace MonoDevelop.AssemblyBrowser { @@ -98,7 +98,7 @@ namespace MonoDevelop.AssemblyBrowser #region IAssemblyBrowserNodeBuilder - public List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator) + public List<ReferenceSegment> Disassemble (TextEditor data, ITreeNavigator navigator) { // bool publicOnly = Widget.PublicApiOnly; Namespace ns = (Namespace)navigator.DataItem; @@ -107,12 +107,12 @@ namespace MonoDevelop.AssemblyBrowser return null; } - public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + public List<ReferenceSegment> Decompile (TextEditor data, ITreeNavigator navigator, bool publicOnly) { return Disassemble (data, navigator); } - List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditorData data, ITreeNavigator navigator, bool publicOnly) + List<ReferenceSegment> IAssemblyBrowserNodeBuilder.GetSummary (TextEditor data, ITreeNavigator navigator, bool publicOnly) { return Disassemble (data, navigator); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/ProjectNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/ProjectNodeBuilder.cs index 21269962f9..ba69c55f8a 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/ProjectNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/TreeNodes/ProjectNodeBuilder.cs @@ -34,7 +34,6 @@ using MonoDevelop.Core; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Pads; using MonoDevelop.Ide.Gui.Components; -using Mono.TextEditor; using System.Collections.Generic; using ICSharpCode.NRefactory.TypeSystem; using System.IO; @@ -76,33 +75,35 @@ namespace MonoDevelop.AssemblyBrowser public override void BuildChildNodes (ITreeBuilder builder, object dataObject) { var project = (Project)dataObject; - var ctx = TypeSystemService.GetProjectContext (project); - if (ctx == null) - return; - - var namespaces = new Dictionary<string, Namespace> (); - - foreach (var type in ctx.TopLevelTypeDefinitions) { - string namespaceName = string.IsNullOrEmpty (type.Namespace) ? "-" : type.Namespace; - if (!namespaces.ContainsKey (namespaceName)) - namespaces [namespaceName] = new Namespace (namespaceName); - - var ns = namespaces [namespaceName]; - ns.Types.Add (type); - } - - foreach (var ns in namespaces.Values) { - builder.AddChild (ns); - } + // TODO: Roslyn port. +// var ctx = TypeSystemService.GetProjectContext (project); +// if (ctx == null) +// return; +// +// var namespaces = new Dictionary<string, Namespace> (); +// +// foreach (var type in ctx.TopLevelTypeDefinitions) { +// string namespaceName = string.IsNullOrEmpty (type.Namespace) ? "-" : type.Namespace; +// if (!namespaces.ContainsKey (namespaceName)) +// namespaces [namespaceName] = new Namespace (namespaceName); +// +// var ns = namespaces [namespaceName]; +// ns.Types.Add (type); +// } +// +// foreach (var ns in namespaces.Values) { +// builder.AddChild (ns); +// } } public override bool HasChildNodes (ITreeBuilder builder, object dataObject) { var project = (Project)dataObject; - var ctx = TypeSystemService.GetProjectContext (project); - if (ctx == null) + // TODO: Roslyn port. + //var ctx = TypeSystemService.GetProjectContext (project); + //if (ctx == null) return false; - return ctx.TopLevelTypeDefinitions.Any (); + // return ctx.TopLevelTypeDefinitions.Any (); } public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/packages.config b/main/src/addins/MonoDevelop.AssemblyBrowser/packages.config new file mode 100644 index 0000000000..d3fca62c00 --- /dev/null +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/packages.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.CodeAnalysis.Common" version="1.0.0-rc1" targetFramework="net45" />
+ <package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" />
+ <package id="System.Reflection.Metadata" version="1.0.18-beta" targetFramework="net45" />
+</packages>
\ No newline at end of file |