diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs')
-rw-r--r-- | main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs index 603b0beccb..a5a71f065d 100644 --- a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs +++ b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GuiBuilderDisplayBinding.cs @@ -30,6 +30,11 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Projects; using MonoDevelop.Ide; using MonoDevelop.Ide.TypeSystem; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Linq; +using Microsoft.CodeAnalysis.CSharp; +using System; +using ICSharpCode.NRefactory6.CSharp; namespace MonoDevelop.GtkCore.GuiBuilder @@ -54,7 +59,7 @@ namespace MonoDevelop.GtkCore.GuiBuilder if (fileName.IsNullOrEmpty) return false; - if (GetWindow (fileName) == null) + if (GetWindow (fileName, ownerProject) == null) return false; excludeThis = true; @@ -68,37 +73,41 @@ namespace MonoDevelop.GtkCore.GuiBuilder excludeThis = true; var db = DisplayBindingService.GetDefaultViewBinding (fileName, mimeType, ownerProject); var content = db.CreateContent (fileName, mimeType, ownerProject); - GuiBuilderView view = new GuiBuilderView (content, GetWindow (fileName)); + var window = GetWindow (fileName, ownerProject); + if (window == null) + throw new InvalidOperationException ("GetWindow == null"); + GuiBuilderView view = new GuiBuilderView (content, window); excludeThis = false; return view; } - internal static GuiBuilderWindow GetWindow (string file) + internal static GuiBuilderWindow GetWindow (string file, Project project) { if (!IdeApp.Workspace.IsOpen) return null; - - Project project = null; - foreach (Project p in IdeApp.Workspace.GetAllProjects ()) { - if (p.IsFileInProject (file)) { - project = p; - break; - } - } - if (!GtkDesignInfo.HasDesignedObjects (project)) return null; - GtkDesignInfo info = GtkDesignInfo.FromProject (project); if (file.StartsWith (info.GtkGuiFolder)) return null; - - var doc = TypeSystemService.ParseFile (project, file); + var docId = TypeSystemService.GetDocumentId (project, file); + if (docId == null) + return null; + var doc = TypeSystemService.GetCodeAnysisDocument (docId); if (doc == null) return null; - - foreach (var t in doc.TopLevelTypeDefinitions) { - GuiBuilderWindow win = info.GuiBuilderProject.GetWindowForClass (t.FullName); + Microsoft.CodeAnalysis.SemanticModel semanticModel; + try { + semanticModel = doc.GetSemanticModelAsync ().Result; + } catch { + return null; + } + if (semanticModel == null) + return null; + var root = semanticModel.SyntaxTree.GetRoot (); + foreach (var classDeclaration in root.DescendantNodesAndSelf (child => !(child is BaseTypeDeclarationSyntax)).OfType<ClassDeclarationSyntax> ()) { + var c = semanticModel.GetDeclaredSymbol (classDeclaration); + GuiBuilderWindow win = info.GuiBuilderProject.GetWindowForClass (c.ToDisplayString (Microsoft.CodeAnalysis.SymbolDisplayFormat.CSharpErrorMessageFormat)); if (win != null) return win; } |