~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/ActionGroupDisplayBinding.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
42
43
 
54
55
                {
55
56
                        if (excludeThis)
56
57
                                return false;
57
 
                        if (IdeApp.ProjectOperations.CurrentOpenCombine == null)
 
58
                        if (!IdeApp.Workspace.IsOpen)
58
59
                                return false;
59
60
                        
60
61
                        if (GetActionGroup (fileName) == null)
76
77
                        excludeThis = true;
77
78
                        IDisplayBinding db = IdeApp.Workbench.DisplayBindings.GetBindingPerFileName (fileName);
78
79
                        
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);
81
82
                        
82
83
                        ActionGroupView view = new ActionGroupView (db.CreateContentForFile (fileName), GetActionGroup (fileName), info.GuiBuilderProject);
83
84
                        excludeThis = false;
91
92
                
92
93
                Stetic.ActionGroupInfo GetActionGroup (string file)
93
94
                {
94
 
                        Project project = IdeApp.ProjectOperations.CurrentOpenCombine.GetProjectContainingFile (file);
95
 
                        if (project == null)
96
 
                                return null;
97
 
                                
98
 
                        GtkDesignInfo info = GtkCoreService.GetGtkInfo (project);
99
 
                        if (info == null || !info.SupportsDesigner)
100
 
                                return null;
101
 
                                
102
 
                        return info.GuiBuilderProject.GetActionGroupForFile (file);
 
95
                        Project project = IdeApp.Workspace.GetProjectContainingFile (file);
 
96
                        if (!GtkDesignInfo.HasDesignedObjects (project))
 
97
                                return null;
 
98
                                
 
99
                        return GtkDesignInfo.FromProject (project).GuiBuilderProject.GetActionGroupForFile (file);
103
100
                }
104
101
                
105
102
                internal static string BindToClass (Project project, Stetic.ActionGroupInfo group)
106
103
                {
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)
110
107
                                return file;
112
109
                        // Find the classes that could be bound to this design
113
110
                        
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);
119
116
                
120
117
                        // Ask what to do
121
118
                        
132
129
                        return gproject.GetSourceCodeFile (group);
133
130
                }
134
131
                
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)
136
133
                {
137
134
                        string fullName = namspace.Length > 0 ? namspace + "." + name : name;
138
135
                        
139
 
                        CodeRefactorer gen = new CodeRefactorer (project.RootCombine, IdeApp.ProjectOperations.ParserDatabase);
 
136
                        CodeRefactorer gen = new CodeRefactorer (project.ParentSolution);
140
137
                        
141
138
                        CodeTypeDeclaration type = new CodeTypeDeclaration ();
142
139
                        type.Name = name;
178
175
                        
179
176
                        // Create the class
180
177
                        
181
 
                        IClass cls = gen.CreateClass (project, ((DotNetProject)project).LanguageName, folder, namspace, type);
 
178
                        IType cls = null;
 
179
                        cls = gen.CreateClass (project, ((DotNetProject)project).LanguageName, folder, namspace, type);
182
180
                        if (cls == null)
183
181
                                throw new UserException ("Could not create class " + fullName);
184
182
                        
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);
187
185
                        
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);
190
188
                        return cls;
191
189
                }
192
190
                
193
 
                internal static bool IsValidClass (IParserContext ctx, IClass cls)
 
191
                internal static bool IsValidClass (ProjectDom ctx, IType cls)
194
192
                {
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")
198
196
                                                return true;
199
197
                                        
200
 
                                        IClass baseCls = ctx.GetClass (bt.FullyQualifiedName, true, true);
 
198
                                        IType baseCls = ctx.GetType (bt);
201
199
                                        if (baseCls != null && IsValidClass (ctx, baseCls))
202
200
                                                return true;
203
201
                                }