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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/lib/stetic/libsteticui/CodeGeneratorPartialClass.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:
1
 
 
2
 
using System;
3
 
using System.Reflection;
4
 
using System.CodeDom;
5
 
using System.CodeDom.Compiler;
6
 
using System.Collections.Generic;
7
 
using System.Collections;
8
 
using System.IO;
9
 
 
10
 
namespace Stetic
11
 
{
12
 
        internal static class CodeGeneratorPartialClass
13
 
        {
14
 
                public static void GenerateProjectGuiCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
15
 
                {
16
 
                        // Generate code for each project
17
 
                        foreach (ProjectBackend gp in projects) {
18
 
                        
19
 
                                // Generate top levels
20
 
                                foreach (Gtk.Widget w in gp.Toplevels)
21
 
                                        GenerateWidgetCode (globalUnit, globalNs, options, units, w, warnings);
22
 
                                        
23
 
                                // Generate global action groups
24
 
                                foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
25
 
                                        GenerateGlobalActionGroupCode (globalUnit, globalNs, options, units, agroup, warnings);
26
 
                        }
27
 
                }
28
 
                
29
 
                static CodeTypeDeclaration CreatePartialClass (SteticCompilationUnit globalUnit, List<SteticCompilationUnit> units, GenerationOptions options, string name)
30
 
                {
31
 
                        SteticCompilationUnit unit;
32
 
                        
33
 
                        if (options.GenerateSingleFile)
34
 
                                unit = globalUnit;
35
 
                        else {
36
 
                                unit = new SteticCompilationUnit (name);
37
 
                                units.Add (unit);
38
 
                        }
39
 
                        
40
 
                        string ns = "";
41
 
                        int i = name.LastIndexOf ('.');
42
 
                        if (i != -1) {
43
 
                                ns = name.Substring (0, i);
44
 
                                name = name.Substring (i+1);
45
 
                        }
46
 
                        
47
 
                        CodeTypeDeclaration type = new CodeTypeDeclaration (name);
48
 
                        type.IsPartial = true;
49
 
                        type.Attributes = MemberAttributes.Public;
50
 
                        type.TypeAttributes = TypeAttributes.Public;
51
 
                        
52
 
                        CodeNamespace cns = new CodeNamespace (ns);
53
 
                        cns.Types.Add (type);
54
 
                        unit.Namespaces.Add (cns);
55
 
                        return type;
56
 
                }
57
 
                
58
 
                
59
 
                static void GenerateWidgetCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
60
 
                {
61
 
                        // Generate the build method
62
 
                        
63
 
                        CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);
64
 
                        CodeMemberMethod met = new CodeMemberMethod ();
65
 
                        met.Name = "Build";
66
 
                        type.Members.Add (met);
67
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
68
 
                        met.Attributes = MemberAttributes.Family;
69
 
                        
70
 
                        if (options.GenerateEmptyBuildMethod) {
71
 
                                GenerateWrapperFields (type, Wrapper.Widget.Lookup (w));
72
 
                                return;
73
 
                        }
74
 
 
75
 
                        met.Statements.Add (
76
 
                                        new CodeMethodInvokeExpression (
77
 
                                                new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
78
 
                                                "Initialize",
79
 
                                    new CodeThisReferenceExpression ()
80
 
                                        )
81
 
                        );
82
 
 
83
 
                        Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
84
 
                        if (wwidget.GeneratePublic)
85
 
                                type.TypeAttributes = TypeAttributes.Public;
86
 
                        else
87
 
                                type.TypeAttributes = TypeAttributes.NotPublic;
88
 
                        
89
 
                        Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);
90
 
                        CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
91
 
                }
92
 
                
93
 
                static void GenerateWrapperFields (CodeTypeDeclaration type, ObjectWrapper wrapper)
94
 
                {
95
 
                        foreach (ObjectBindInfo binfo in CodeGenerator.GetFieldsToBind (wrapper)) {
96
 
                                type.Members.Add (
97
 
                                        new CodeMemberField (
98
 
                                                binfo.TypeName,
99
 
                                                binfo.Name
100
 
                                        )
101
 
                                );
102
 
                        }
103
 
                }
104
 
 
105
 
                
106
 
                static void GenerateGlobalActionGroupCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Wrapper.ActionGroup agroup, ArrayList warnings)
107
 
                {
108
 
                        CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, agroup.Name);
109
 
                        
110
 
                        // Generate the build method
111
 
                        
112
 
                        CodeMemberMethod met = new CodeMemberMethod ();
113
 
                        met.Name = "Build";
114
 
                        type.Members.Add (met);
115
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
116
 
                        met.Attributes = MemberAttributes.Public;
117
 
                        
118
 
                        Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, agroup, new CodeThisReferenceExpression (), met.Statements, options, warnings);
119
 
                        
120
 
                        foreach (Wrapper.Action ac in agroup.Actions)
121
 
                                CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), ac, map, met.Statements, options);
122
 
                }
123
 
        }
124
 
}