36
36
using MonoDevelop.Ide.Codons;
37
37
using MonoDevelop.Ide.Gui;
38
38
using MonoDevelop.Projects;
39
using MonoDevelop.Projects.Parser;
39
using MonoDevelop.Projects.Dom;
40
using MonoDevelop.Projects.Dom.Parser;
40
41
using MonoDevelop.Projects.CodeGeneration;
41
42
using MonoDevelop.GtkCore.Dialogs;
76
77
excludeThis = true;
77
78
IDisplayBinding db = IdeApp.Workbench.DisplayBindings.GetBindingPerFileName (fileName);
79
Project project = IdeApp.ProjectOperations.CurrentOpenCombine.GetProjectContainingFile (fileName);
80
GtkDesignInfo info = GtkCoreService.EnableGtkSupport (project);
80
Project project = IdeApp.Workspace.GetProjectContainingFile (fileName);
81
GtkDesignInfo info = GtkDesignInfo.FromProject ((DotNetProject) project);
82
83
ActionGroupView view = new ActionGroupView (db.CreateContentForFile (fileName), GetActionGroup (fileName), info.GuiBuilderProject);
83
84
excludeThis = false;
92
93
Stetic.ActionGroupInfo GetActionGroup (string file)
94
Project project = IdeApp.ProjectOperations.CurrentOpenCombine.GetProjectContainingFile (file);
98
GtkDesignInfo info = GtkCoreService.GetGtkInfo (project);
99
if (info == null || !info.SupportsDesigner)
102
return info.GuiBuilderProject.GetActionGroupForFile (file);
95
Project project = IdeApp.Workspace.GetProjectContainingFile (file);
96
if (!GtkDesignInfo.HasDesignedObjects (project))
99
return GtkDesignInfo.FromProject (project).GuiBuilderProject.GetActionGroupForFile (file);
105
102
internal static string BindToClass (Project project, Stetic.ActionGroupInfo group)
107
GuiBuilderProject gproject = GuiBuilderService.GetGuiBuilderProject (project);
104
GuiBuilderProject gproject = GtkDesignInfo.FromProject (project).GuiBuilderProject;
108
105
string file = gproject.GetSourceCodeFile (group);
109
106
if (file != null)
112
109
// Find the classes that could be bound to this design
114
111
ArrayList list = new ArrayList ();
115
IParserContext ctx = gproject.GetParserContext ();
116
foreach (IClass cls in ctx.GetProjectContents ())
112
ProjectDom ctx = gproject.GetParserContext ();
113
foreach (IType cls in ctx.Types)
117
114
if (IsValidClass (ctx, cls))
118
list.Add (cls.FullyQualifiedName);
115
list.Add (cls.FullName);
120
117
// Ask what to do
132
129
return gproject.GetSourceCodeFile (group);
135
static IClass CreateClass (Project project, Stetic.ActionGroupComponent group, string name, string namspace, string folder)
132
static IType CreateClass (Project project, Stetic.ActionGroupComponent group, string name, string namspace, string folder)
137
134
string fullName = namspace.Length > 0 ? namspace + "." + name : name;
139
CodeRefactorer gen = new CodeRefactorer (project.RootCombine, IdeApp.ProjectOperations.ParserDatabase);
136
CodeRefactorer gen = new CodeRefactorer (project.ParentSolution);
141
138
CodeTypeDeclaration type = new CodeTypeDeclaration ();
142
139
type.Name = name;
179
176
// Create the class
181
IClass cls = gen.CreateClass (project, ((DotNetProject)project).LanguageName, folder, namspace, type);
179
cls = gen.CreateClass (project, ((DotNetProject)project).LanguageName, folder, namspace, type);
183
181
throw new UserException ("Could not create class " + fullName);
185
project.AddFile (cls.Region.FileName, BuildAction.Compile);
186
IdeApp.ProjectOperations.SaveProject (project);
183
project.AddFile (cls.CompilationUnit.FileName, BuildAction.Compile);
184
IdeApp.ProjectOperations.Save (project);
188
186
// Make sure the database is up-to-date
189
IdeApp.ProjectOperations.ParserDatabase.UpdateFile (project, cls.Region.FileName, null);
187
ProjectDomService.Parse (project, cls.CompilationUnit.FileName, null);
193
internal static bool IsValidClass (IParserContext ctx, IClass cls)
191
internal static bool IsValidClass (ProjectDom ctx, IType cls)
195
193
if (cls.BaseTypes != null) {
196
194
foreach (IReturnType bt in cls.BaseTypes) {
197
if (bt.FullyQualifiedName == "Gtk.ActionGroup")
195
if (bt.FullName == "Gtk.ActionGroup")
200
IClass baseCls = ctx.GetClass (bt.FullyQualifiedName, true, true);
198
IType baseCls = ctx.GetType (bt);
201
199
if (baseCls != null && IsValidClass (ctx, baseCls))