Example #1
0
        static int GenerateCode(string file, string[] args, int n, GenerationOptions ops)
        {
            foreach (string lib in libraries)
            {
                SteticApp.AddWidgetLibrary(lib);
            }

            SteticApp.UpdateWidgetLibraries(false);

            Project[] projects = new Project [args.Length - n];
            for (int i = n; i < args.Length; i++)
            {
                projects [i - n] = SteticApp.LoadProject(args [i]);
            }

            CodeDomProvider      provider = GetProvider(language);
            CodeGenerationResult res      = SteticApp.GenerateProjectCode(file, "Stetic", provider, ops, projects);

            foreach (SteticCompilationUnit f in res.Units)
            {
                Console.WriteLine("Generated file: " + f.Name);
            }
            foreach (string s in res.Warnings)
            {
                Console.WriteLine("WARNING: " + s);
            }
            return(0);
        }
		static CodeTypeDeclaration CreatePartialClass (SteticCompilationUnit globalUnit, List<SteticCompilationUnit> units, GenerationOptions options, string name)
		{
			SteticCompilationUnit unit;
			
			if (options.GenerateSingleFile)
				unit = globalUnit;
			else {
				unit = new SteticCompilationUnit (name);
				units.Add (unit);
			}
			
			string ns = "";
			int i = name.LastIndexOf ('.');
			if (i != -1) {
				ns = name.Substring (0, i);
				name = name.Substring (i+1);
			}
			
			CodeTypeDeclaration type = new CodeTypeDeclaration (name);
			type.IsPartial = true;
			type.Attributes = MemberAttributes.Public;
			type.TypeAttributes = TypeAttributes.Public;
			
			CodeNamespace cns = new CodeNamespace (ns);
			cns.Types.Add (type);
			unit.Namespaces.Add (cns);
			return type;
		}
Example #3
0
        static void GenerateWidgetCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
        {
            // Generate the build method

            CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);
            CodeMemberMethod met = new CodeMemberMethod ();
            met.Name = "Build";
            type.Members.Add (met);
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Family;

            if (options.GenerateEmptyBuildMethod) {
                GenerateWrapperFields (type, Wrapper.Widget.Lookup (w));
                return;
            }

            met.Statements.Add (
                    new CodeMethodInvokeExpression (
                        new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
                        "Initialize",
                        new CodeThisReferenceExpression ()
                    )
            );

            Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
            if (wwidget.GeneratePublic)
                type.TypeAttributes = TypeAttributes.Public;
            else
                type.TypeAttributes = TypeAttributes.NotPublic;

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);
            CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
        }
		public static void GenerateProjectGuiCode (CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
		{
			// Generate code for each project
			foreach (ProjectBackend gp in projects) {
			
				// Generate top levels
				foreach (Gtk.Widget w in gp.Toplevels) {
					Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
					string topLevelName = wwidget.Name;
					if (gp.ComponentNeedsCodeGeneration (topLevelName)) {
						//designer file for widget could be changed beyond stetic process 
						//and we nead update wrapper before code generation
						//during reloading wrappered widget w could be changed;
						Gtk.Widget currentw = w;
						if (gp.ReloadTopLevel (topLevelName)) {
							currentw = gp.GetWidget (topLevelName);
						}
						GenerateWidgetCode (globalNs, options, units, currentw, warnings);
					}
				}
					
				// Generate global action groups
				foreach (Wrapper.ActionGroup agroup in gp.ActionGroups) {
					string groupName = agroup.Name;
					if (gp.ComponentNeedsCodeGeneration (groupName)) {
						//designer file for action group could be changed beyond stetic process 
						//and we nead update wrapper
						gp.ReloadActionGroup (groupName);
						GenerateGlobalActionGroupCode (globalNs, options, units, agroup, warnings);
					}
				}
			}
		}
Example #5
0
 public GeneratorContext(CodeNamespace cns, string idPrefix, CodeStatementCollection statements, GenerationOptions options)
 {
     this.cns        = cns;
     this.idPrefix   = idPrefix;
     this.statements = statements;
     this.options    = options;
     map             = new WidgetMap(vars);
 }
		public GeneratorContext (CodeNamespace cns, string idPrefix, CodeStatementCollection statements, GenerationOptions options)
		{
			this.cns = cns;
			this.idPrefix = idPrefix;
			this.statements = statements;
			this.options = options;
			map = new WidgetMap (vars);
		}
Example #7
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, CodeExpression groupVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Action group " + grp.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     ctx.GenerateCreationCode (grp, groupVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
Example #8
0
        public CodeGenerationResult GenerateProjectCode(GenerationOptions options, params Project[] projects)
        {
            ProjectBackend[] pbs = new ProjectBackend [projects.Length];
            for (int n = 0; n < projects.Length; n++)
            {
                pbs [n] = projects [n].ProjectBackend;
            }

            return(Backend.GenerateProjectCode(options, pbs));
        }
Example #9
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Widget " + w.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (w);
     ctx.GenerateCreationCode (ww, widgetVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
		static void GenerateWidgetCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings, bool regenerateWidgetClass)
		{
			if (options.GenerateSingleFile)
				regenerateWidgetClass = true;

			// Don't register this unit if the class doesn't need to be regenerated
			if (!regenerateWidgetClass)
				units = null;

			CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);

			// Generate the build method
			CodeMemberMethod met = new CodeMemberMethod ();
			met.Name = "Build";
			type.Members.Add (met);
			met.ReturnType = new CodeTypeReference (typeof(void));
			met.Attributes = MemberAttributes.Family;
				
			Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);

			if (regenerateWidgetClass) {

				if (options.GenerateEmptyBuildMethod) {
					GenerateWrapperFields (type, wwidget);
					return;
				}

				met.Statements.Add (
						new CodeMethodInvokeExpression (
							new CodeTypeReferenceExpression (new CodeTypeReference (globalNs.Name + ".Gui", CodeTypeReferenceOptions.GlobalReference)),
							"Initialize",
				            new CodeThisReferenceExpression ()
						)
				);

				if (wwidget.GeneratePublic)
					type.TypeAttributes = TypeAttributes.Public;
				else
					type.TypeAttributes = TypeAttributes.NotPublic;
				
				if (!String.IsNullOrEmpty (wwidget.UIManagerName))
					type.Members.Add (new CodeMemberField (new CodeTypeReference ("Gtk.UIManager", CodeTypeReferenceOptions.GlobalReference), wwidget.UIManagerName));
			}

			// We need to generate the creation code even if regenerateWidgetClass is false because GenerateCreationCode
			// may inject support classes or methods into the global namespace, which is always generated

			Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);

			if (regenerateWidgetClass)
				CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
		}
		public static void GenerateProjectGuiCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
		{
			// Generate code for each project
			foreach (ProjectBackend gp in projects) {
			
				// Generate top levels
				foreach (Gtk.Widget w in gp.Toplevels)
					GenerateWidgetCode (globalUnit, globalNs, options, units, w, warnings);
					
				// Generate global action groups
				foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
					GenerateGlobalActionGroupCode (globalUnit, globalNs, options, units, agroup, warnings);
			}
		}
Example #12
0
        static void GenerateGlobalActionGroupCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Wrapper.ActionGroup agroup, ArrayList warnings)
        {
            CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, agroup.Name);

            // Generate the build method

            CodeMemberMethod met = new CodeMemberMethod ();
            met.Name = "Build";
            type.Members.Add (met);
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Public;

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, agroup, new CodeThisReferenceExpression (), met.Statements, options, warnings);

            foreach (Wrapper.Action ac in agroup.Actions)
                CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), ac, map, met.Statements, options);
        }
Example #13
0
        static void GenerateWidgetCode(CodeNamespace globalNs, GenerationOptions options, List <SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
        {
            // Generate the build method

            CodeTypeDeclaration type = CreatePartialClass(units, options, w.Name);
            CodeMemberMethod    met  = new CodeMemberMethod();

            met.Name = "Build";
            type.Members.Add(met);
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Family;

            Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup(w);

            if (options.GenerateEmptyBuildMethod)
            {
                GenerateWrapperFields(type, wwidget);
                return;
            }

            met.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference(globalNs.Name + ".Gui", CodeTypeReferenceOptions.GlobalReference)),
                    "Initialize",
                    new CodeThisReferenceExpression()
                    )
                );

            if (wwidget.GeneratePublic)
            {
                type.TypeAttributes = TypeAttributes.Public;
            }
            else
            {
                type.TypeAttributes = TypeAttributes.NotPublic;
            }

            if (!String.IsNullOrEmpty(wwidget.UIManagerName))
            {
                type.Members.Add(new CodeMemberField(new CodeTypeReference("Gtk.UIManager", CodeTypeReferenceOptions.GlobalReference), wwidget.UIManagerName));
            }

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, type, w, new CodeThisReferenceExpression(), met.Statements, options, warnings);
            CodeGenerator.BindSignalHandlers(new CodeThisReferenceExpression(), wwidget, map, met.Statements, options);
        }
Example #14
0
        static void GenerateGlobalActionGroupCode(CodeNamespace globalNs, GenerationOptions options, List <SteticCompilationUnit> units, Wrapper.ActionGroup agroup, ArrayList warnings)
        {
            CodeTypeDeclaration type = CreatePartialClass(units, options, agroup.Name);

            // Generate the build method

            CodeMemberMethod met = new CodeMemberMethod();

            met.Name = "Build";
            type.Members.Add(met);
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Public;

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, type, agroup, new CodeThisReferenceExpression(), met.Statements, options, warnings);

            foreach (Wrapper.Action ac in agroup.Actions)
            {
                CodeGenerator.BindSignalHandlers(new CodeThisReferenceExpression(), ac, map, met.Statements, options);
            }
        }
		public static void GenerateProjectCode (string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects)
		{
			CodeGenerationResult res = GenerateProjectCode (options, projects);
			
			string basePath = Path.GetDirectoryName (file);
			
			foreach (SteticCompilationUnit unit in res.Units) {
				string fname;
				if (unit.Name.Length == 0)
					fname = file;
				else
					fname = Path.Combine (basePath, unit.Name);
				StreamWriter fileStream = new StreamWriter (fname);
				try {
					provider.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
				} finally {
					fileStream.Close ();
				}
			}
		}
Example #16
0
        internal static void BindSignalHandlers(CodeExpression targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements, GenerationOptions options)
        {
            foreach (Signal signal in wrapper.Signals)
            {
                SignalDescriptor descriptor = signal.SignalDescriptor;

                CodeExpression createDelegate = new CodeDelegateCreateExpression(
                    new CodeTypeReference(descriptor.HandlerTypeName, CodeTypeReferenceOptions.GlobalReference),
                    new CodeThisReferenceExpression(),
                    signal.Handler);

                CodeAttachEventStatement cevent = new CodeAttachEventStatement(
                    new CodeEventReferenceExpression(
                        map.GetWidgetExp(wrapper),
                        descriptor.Name),
                    createDelegate);

                statements.Add(cevent);
            }

            Wrapper.Widget widget = wrapper as Wrapper.Widget;
            if (widget != null && widget.IsTopLevel)
            {
                // Bind local action signals
                foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups)
                {
                    foreach (Wrapper.Action ac in grp.Actions)
                    {
                        BindSignalHandlers(targetObjectVar, ac, map, statements, options);
                    }
                }
            }

            Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
            if (cont != null)
            {
                foreach (Gtk.Widget child in cont.AllChildren)
                {
                    Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(child);
                    if (ww != null)
                    {
                        BindSignalHandlers(targetObjectVar, ww, map, statements, options);
                    }
                }
            }
        }
Example #17
0
        static void GenerateProjectActionsCode(CodeNamespace cns, GenerationOptions options, params ProjectBackend[] projects)
        {
            bool multiProject = projects.Length > 1;

            CodeTypeDeclaration type = new CodeTypeDeclaration("ActionGroups");

            type.Attributes     = MemberAttributes.Private;
            type.TypeAttributes = TypeAttributes.NestedAssembly;
            cns.Types.Add(type);

            // Generate the global action group getter

            CodeMemberMethod met = new CodeMemberMethod();

            met.Name = "GetActionGroup";
            type.Members.Add(met);
            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Type), "type"));
            if (multiProject)
            {
                met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "file"));
            }
            met.ReturnType = new CodeTypeReference(typeof(Gtk.ActionGroup));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            CodeMethodInvokeExpression call = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference(cns.Name + ".ActionGroups")),
                    "GetActionGroup"
                    ),
                new CodePropertyReferenceExpression(
                    new CodeArgumentReferenceExpression("type"),
                    "FullName"
                    )
                );

            if (multiProject)
            {
                call.Parameters.Add(new CodeArgumentReferenceExpression("file"));
            }

            met.Statements.Add(new CodeMethodReturnStatement(call));

            // Generate the global action group getter (overload)

            met      = new CodeMemberMethod();
            met.Name = "GetActionGroup";
            type.Members.Add(met);
            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "name"));
            if (multiProject)
            {
                met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "file"));
            }
            met.ReturnType = new CodeTypeReference(typeof(Gtk.ActionGroup));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            CodeArgumentReferenceExpression cfile = new CodeArgumentReferenceExpression("file");
            CodeArgumentReferenceExpression cid   = new CodeArgumentReferenceExpression("name");

            CodeStatementCollection projectCol = met.Statements;
            int n = 1;

            foreach (ProjectBackend gp in projects)
            {
                CodeStatementCollection widgetCol;

                if (multiProject)
                {
                    CodeConditionStatement pcond = new CodeConditionStatement();
                    pcond.Condition = new CodeBinaryOperatorExpression(
                        cfile,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(gp.Id)
                        );
                    projectCol.Add(pcond);

                    widgetCol  = pcond.TrueStatements;
                    projectCol = pcond.FalseStatements;
                }
                else
                {
                    widgetCol = projectCol;
                }

                foreach (Wrapper.ActionGroup grp in gp.ActionGroups)
                {
                    string          fname    = "group" + (n++);
                    CodeMemberField grpField = new CodeMemberField(new CodeTypeReference(typeof(Gtk.ActionGroup), CodeTypeReferenceOptions.GlobalReference), fname);
                    grpField.Attributes |= MemberAttributes.Static;
                    type.Members.Add(grpField);
                    CodeFieldReferenceExpression grpVar = new CodeFieldReferenceExpression(
                        new CodeTypeReferenceExpression(new CodeTypeReference(cns.Name + ".ActionGroups", CodeTypeReferenceOptions.GlobalReference)),
                        fname
                        );

                    CodeConditionStatement pcond = new CodeConditionStatement();
                    pcond.Condition = new CodeBinaryOperatorExpression(
                        cid,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(grp.Name)
                        );
                    widgetCol.Add(pcond);

                    // If the group has not yet been created, create it
                    CodeConditionStatement pcondGrp = new CodeConditionStatement();
                    pcondGrp.Condition = new CodeBinaryOperatorExpression(
                        grpVar,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(null)
                        );

                    pcondGrp.TrueStatements.Add(
                        new CodeAssignStatement(
                            grpVar,
                            new CodeObjectCreateExpression(grp.Name)
                            )
                        );

                    pcond.TrueStatements.Add(pcondGrp);
                    pcond.TrueStatements.Add(new CodeMethodReturnStatement(grpVar));

                    widgetCol = pcond.FalseStatements;
                }
                widgetCol.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
            }
            if (met.Statements.Count == 0)
            {
                met.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
            }
        }
Example #18
0
        public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects)
        {
            ArrayList            files = new ArrayList();
            CodeGenerationResult res   = GenerateProjectCode(options, projects);

            ICodeGenerator gen      = provider.CreateGenerator();
            string         basePath = Path.GetDirectoryName(file);
            string         ext      = Path.GetExtension(file);

            foreach (SteticCompilationUnit unit in res.Units)
            {
                string fname;
                if (unit.Name.Length == 0)
                {
                    fname = file;
                }
                else
                {
                    fname = Path.Combine(basePath, unit.Name) + ext;
                }
                files.Add(fname);
                unit.Name = fname;
                StreamWriter fileStream = new StreamWriter(fname);
                try {
                    gen.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions());
                } finally {
                    fileStream.Close();
                }
            }
            return(res);
        }
        static void GenerateWidgetCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List <SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings, bool regenerateWidgetClass)
        {
            if (options.GenerateSingleFile)
            {
                regenerateWidgetClass = true;
            }

            // Don't register this unit if the class doesn't need to be regenerated
            if (!regenerateWidgetClass)
            {
                units = null;
            }

            CodeTypeDeclaration type = CreatePartialClass(globalUnit, units, options, w.Name);

            // Generate the build method
            CodeMemberMethod met = new CodeMemberMethod();

            met.Name = "Build";
            type.Members.Add(met);
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Family;

            Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup(w);

            if (regenerateWidgetClass)
            {
                if (options.GenerateEmptyBuildMethod)
                {
                    GenerateWrapperFields(type, wwidget);
                    return;
                }

                met.Statements.Add(
                    new CodeMethodInvokeExpression(
                        new CodeTypeReferenceExpression(new CodeTypeReference(globalNs.Name + ".Gui", CodeTypeReferenceOptions.GlobalReference)),
                        "Initialize",
                        new CodeThisReferenceExpression()
                        )
                    );

                if (wwidget.GeneratePublic)
                {
                    type.TypeAttributes = TypeAttributes.Public;
                }
                else
                {
                    type.TypeAttributes = TypeAttributes.NotPublic;
                }

                if (!String.IsNullOrEmpty(wwidget.UIManagerName))
                {
                    type.Members.Add(new CodeMemberField(new CodeTypeReference("Gtk.UIManager", CodeTypeReferenceOptions.GlobalReference), wwidget.UIManagerName));
                }
            }

            // We need to generate the creation code even if regenerateWidgetClass is false because GenerateCreationCode
            // may inject support classes or methods into the global namespace, which is always generated

            Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, type, w, new CodeThisReferenceExpression(), met.Statements, options, warnings);

            if (regenerateWidgetClass)
            {
                CodeGenerator.BindSignalHandlers(new CodeThisReferenceExpression(), wwidget, map, met.Statements, options);
            }
        }
Example #20
0
        public static void GenerateProjectGuiCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
        {
            bool multiProject = projects.Length > 1;

            // Build method overload that takes a type as parameter.

            CodeMemberMethod met = new CodeMemberMethod ();
            met.Name = "Build";
            globalType.Members.Add (met);
            met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "cobj"));
            met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Type), "type"));
            if (multiProject)
                met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "file"));
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            CodeMethodInvokeExpression call = new CodeMethodInvokeExpression (
                    new CodeMethodReferenceExpression (
                        new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
                        "Build"
                    ),
                    new CodeArgumentReferenceExpression ("cobj"),
                    new CodePropertyReferenceExpression (
                        new CodeArgumentReferenceExpression ("type"),
                        "FullName"
                    )
            );
            if (multiProject)
                call.Parameters.Add (new CodeArgumentReferenceExpression ("file"));

            met.Statements.Add (call);

            // Generate the build method

            met = new CodeMemberMethod ();
            met.Name = "Build";
            globalType.Members.Add (met);

            met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "cobj"));
            met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "id"));
            if (multiProject)
                met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "file"));
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            if (options.GenerateEmptyBuildMethod)
                return;

            CodeArgumentReferenceExpression cobj = new CodeArgumentReferenceExpression ("cobj");
            CodeArgumentReferenceExpression cfile = new CodeArgumentReferenceExpression ("file");
            CodeArgumentReferenceExpression cid = new CodeArgumentReferenceExpression ("id");

            CodeStatementCollection projectCol = met.Statements;

            CodeConditionStatement tcond = new CodeConditionStatement ();
            tcond.Condition = new CodeMethodInvokeExpression (new CodeTypeOfExpression (typeof(Gtk.Widget)), "IsAssignableFrom", cobj);

            tcond.TrueStatements.Add (
                    new CodeMethodInvokeExpression (
                        new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
                        "Initialize",
                        cobj
                    )
            );

            // Generate code for each project

            foreach (ProjectBackend gp in projects) {

                CodeStatementCollection widgetCol;

                if (multiProject) {
                    CodeConditionStatement pcond = new CodeConditionStatement ();
                    pcond.Condition = new CodeBinaryOperatorExpression (
                        cfile,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression (gp.Id)
                    );
                    projectCol.Add (pcond);

                    widgetCol = pcond.TrueStatements;
                    projectCol = pcond.FalseStatements;
                } else {
                    widgetCol = projectCol;
                }

                // Generate top levels

                CodeIdentifiers ids = new CodeIdentifiers ();

                foreach (Gtk.Widget w in gp.Toplevels) {
                    CodeConditionStatement cond = new CodeConditionStatement ();
                    cond.Condition = new CodeBinaryOperatorExpression (
                        cid,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression (w.Name)
                    );
                    widgetCol.Add (cond);

                    GenerateComponentCode (w, globalUnit, globalNs, cobj, cond.TrueStatements, globalType, options, units, ids, warnings);

                    widgetCol = cond.FalseStatements;
                }

                // Generate action groups

                foreach (Wrapper.ActionGroup agroup in gp.ActionGroups) {
                    CodeConditionStatement cond = new CodeConditionStatement ();
                    cond.Condition = new CodeBinaryOperatorExpression (
                        cid,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression (agroup.Name)
                    );
                    widgetCol.Add (cond);

                    GenerateComponentCode (agroup, globalUnit, globalNs, cobj, cond.TrueStatements, globalType, options, units, ids, warnings);

                    widgetCol = cond.FalseStatements;
                }
            }
        }
Example #21
0
        public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, CodeExpression groupVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
        {
            statements.Add(new CodeCommentStatement("Action group " + grp.Name));
            GeneratorContext ctx = new ProjectGeneratorContext(cns, type, statements, options);

            ctx.GenerateCreationCode(grp, groupVarExp);
            ctx.EndGeneration();
            warnings.AddRange(ctx.Warnings);
            return(ctx.WidgetMap);
        }
Example #22
0
        public static int Main(string[] args)
        {
            int n = 0;
            IsolationMode mode = IsolationMode.None;
            bool usePartial = false;
            bool useGettext = false;
            bool genEmpty = false;
            bool useMultifile = false;

            while (n < args.Length) {
                string arg = args[n];
                if (arg.StartsWith ("--language:"))
                    language = arg.Substring (11);
                else if (arg.StartsWith ("-l:"))
                    language = arg.Substring (3);
                else if (arg.StartsWith ("-lib:"))
                    libraries.Add (arg.Substring (5));
                else if (arg.StartsWith ("--library:"))
                    libraries.Add (arg.Substring (10));
                else if (arg == "--generate" || arg == "-g")
                    break;
                else if (arg == "--noisolation")
                    mode = IsolationMode.None;
                else if (arg == "--gen-partial")
                    usePartial = true;
                else if (arg == "--gen-gettext")
                    useGettext = true;
                else if (arg == "--gen-multifile")
                    useMultifile = true;
                else if (arg == "--gen-empty")
                    genEmpty = true;
                else
                    break;
                n++;
            }

            if (args.Length == 1 && args [0] == "--help") {
                Console.WriteLine (Catalog.GetString ("Stetic - A GTK User Interface Builder"));
                Console.WriteLine (Catalog.GetString ("Usage:"));
                Console.WriteLine ("\tstetic [<file>]");
                Console.WriteLine ("\tstetic [--language:<language>] [-lib:<library>...] --generate <sourceFile> <projectFile> ...");
                return 0;
            }

            Program = new Gnome.Program ("Stetic", "0.0", Gnome.Modules.UI, args);

            int ret;

            if (args.Length - n > 2 && ((args [n] == "--generate" || args [n] == "-g"))) {
                SteticApp = Stetic.ApplicationFactory.CreateApplication (IsolationMode.None);
                GenerationOptions ops = new GenerationOptions ();
                ops.UsePartialClasses = usePartial;
                ops.GenerateEmptyBuildMethod = genEmpty;
                ops.UseGettext = useGettext;
                ops.GenerateSingleFile = !useMultifile;
                ret = GenerateCode (args [n+1], args, n+2, ops);
            }
            else {
                SteticApp = Stetic.ApplicationFactory.CreateApplication (mode);
                SteticApp.AllowInProcLibraries = false;
                ret = RunApp (args, n);
            }

            SteticApp.Dispose ();
            return ret;
        }
Example #23
0
        public static void GenerateProjectGuiCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
        {
            bool multiProject = projects.Length > 1;

            // Build method overload that takes a type as parameter.

            CodeMemberMethod met = new CodeMemberMethod();

            met.Name = "Build";
            globalType.Members.Add(met);
            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "cobj"));
            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Type), "type"));
            if (multiProject)
            {
                met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "file"));
            }
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            CodeMethodInvokeExpression call = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(
                    new CodeTypeReferenceExpression(globalNs.Name + ".Gui"),
                    "Build"
                    ),
                new CodeArgumentReferenceExpression("cobj"),
                new CodePropertyReferenceExpression(
                    new CodeArgumentReferenceExpression("type"),
                    "FullName"
                    )
                );

            if (multiProject)
            {
                call.Parameters.Add(new CodeArgumentReferenceExpression("file"));
            }

            met.Statements.Add(call);

            // Generate the build method

            met      = new CodeMemberMethod();
            met.Name = "Build";
            globalType.Members.Add(met);

            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "cobj"));
            met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "id"));
            if (multiProject)
            {
                met.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "file"));
            }
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            if (options.GenerateEmptyBuildMethod)
            {
                return;
            }

            CodeArgumentReferenceExpression cobj  = new CodeArgumentReferenceExpression("cobj");
            CodeArgumentReferenceExpression cfile = new CodeArgumentReferenceExpression("file");
            CodeArgumentReferenceExpression cid   = new CodeArgumentReferenceExpression("id");

            CodeStatementCollection projectCol = met.Statements;

            CodeConditionStatement tcond = new CodeConditionStatement();

            tcond.Condition = new CodeMethodInvokeExpression(new CodeTypeOfExpression(typeof(Gtk.Widget)), "IsAssignableFrom", cobj);

            tcond.TrueStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(globalNs.Name + ".Gui"),
                    "Initialize",
                    cobj
                    )
                );

            // Generate code for each project

            foreach (ProjectBackend gp in projects)
            {
                CodeStatementCollection widgetCol;

                if (multiProject)
                {
                    CodeConditionStatement pcond = new CodeConditionStatement();
                    pcond.Condition = new CodeBinaryOperatorExpression(
                        cfile,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(gp.Id)
                        );
                    projectCol.Add(pcond);

                    widgetCol  = pcond.TrueStatements;
                    projectCol = pcond.FalseStatements;
                }
                else
                {
                    widgetCol = projectCol;
                }

                // Generate top levels

                CodeIdentifiers ids = new CodeIdentifiers();

                foreach (Gtk.Widget w in gp.Toplevels)
                {
                    CodeConditionStatement cond = new CodeConditionStatement();
                    cond.Condition = new CodeBinaryOperatorExpression(
                        cid,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(w.Name)
                        );
                    widgetCol.Add(cond);

                    GenerateComponentCode(w, globalUnit, globalNs, cobj, cond.TrueStatements, globalType, options, units, ids, warnings);

                    widgetCol = cond.FalseStatements;
                }

                // Generate action groups

                foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
                {
                    CodeConditionStatement cond = new CodeConditionStatement();
                    cond.Condition = new CodeBinaryOperatorExpression(
                        cid,
                        CodeBinaryOperatorType.IdentityEquality,
                        new CodePrimitiveExpression(agroup.Name)
                        );
                    widgetCol.Add(cond);

                    GenerateComponentCode(agroup, globalUnit, globalNs, cobj, cond.TrueStatements, globalType, options, units, ids, warnings);

                    widgetCol = cond.FalseStatements;
                }
            }
        }
Example #24
0
        static CodeMemberMethod GetBuildMethod(string name, string internalClassName, string typeName, SteticCompilationUnit globalUnit, GenerationOptions options, List <SteticCompilationUnit> units)
        {
            SteticCompilationUnit unit;

            if (options.GenerateSingleFile)
            {
                unit = globalUnit;
            }
            else
            {
                unit = new SteticCompilationUnit(name);
                units.Add(unit);
            }

            CodeTypeDeclaration type = new CodeTypeDeclaration(internalClassName);

            type.Attributes     = MemberAttributes.Private;
            type.TypeAttributes = TypeAttributes.NestedAssembly;

            CodeNamespace cns = new CodeNamespace(options.GlobalNamespace + ".SteticGenerated");

            cns.Types.Add(type);
            unit.Namespaces.Add(cns);

            // Create the build method for the component

            CodeMemberMethod met = new CodeMemberMethod();

            met.Name = "Build";
            type.Members.Add(met);

            met.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeName), "cobj"));
            met.ReturnType = new CodeTypeReference(typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            return(met);
        }
		public static CodeGenerationResult GenerateProjectCode (GenerationOptions options, ProjectBackend[] projects)
		{
			ArrayList warningList = new ArrayList ();
			
			List<SteticCompilationUnit> units = new List<SteticCompilationUnit> ();
			SteticCompilationUnit globalUnit = new SteticCompilationUnit ("");
			units.Add (globalUnit);
			
			if (options == null)
				options = new GenerationOptions ();
			CodeNamespace globalNs = new CodeNamespace (options.GlobalNamespace);
			globalUnit.Namespaces.Add (globalNs);
			
			// Global class
			
			CodeTypeDeclaration globalType = new CodeTypeDeclaration ("Gui");
			globalType.Attributes = MemberAttributes.Private;
			globalType.TypeAttributes = TypeAttributes.NestedAssembly;
			globalNs.Types.Add (globalType);
			
			// Create the project initialization method
			// This method will only be added at the end if there
			// is actually something to initialize
			
			CodeMemberMethod initMethod = new CodeMemberMethod ();
			initMethod.Name = "Initialize";
			initMethod.ReturnType = new CodeTypeReference (typeof(void));
			initMethod.Attributes = MemberAttributes.Assembly | MemberAttributes.Static;
			initMethod.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Gtk.Widget), "iconRenderer"));
			
			GeneratorContext initContext = new ProjectGeneratorContext (globalNs, globalType, initMethod.Statements, options);
			initContext.RootObject = new CodeArgumentReferenceExpression ("iconRenderer");
			
			// Generate icon factory creation

			foreach (ProjectBackend gp in projects) {
				if (gp.IconFactory.Icons.Count > 0)
					gp.IconFactory.GenerateBuildCode (initContext);
			}
			warningList.AddRange (initContext.Warnings);
					
			// Generate the code
			
			if (options.UsePartialClasses)
				CodeGeneratorPartialClass.GenerateProjectGuiCode (globalUnit, globalNs, globalType, options, units, projects, warningList);
			else
				CodeGeneratorInternalClass.GenerateProjectGuiCode (globalUnit, globalNs, globalType, options, units, projects, warningList);

			GenerateProjectActionsCode (globalNs, options, projects);
			
			// Final step. If there is some initialization code, add all needed infrastructure
			
			globalType.Members.Add (initMethod);
			
			CodeMemberField initField = new CodeMemberField (typeof(bool), "initialized");
			initField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
			globalType.Members.Add (initField);
			
			CodeFieldReferenceExpression initVar = new CodeFieldReferenceExpression (
				new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
				"initialized"
			);
			
			CodeConditionStatement initCondition = new CodeConditionStatement ();
			initCondition.Condition = new CodeBinaryOperatorExpression (
				initVar, 
				CodeBinaryOperatorType.IdentityEquality,
				new CodePrimitiveExpression (false)
			);
			initCondition.TrueStatements.Add (new CodeAssignStatement (
				initVar,
				new CodePrimitiveExpression (true)
			));
			initCondition.TrueStatements.AddRange (initMethod.Statements);
			initMethod.Statements.Clear ();
			initMethod.Statements.Add (initCondition);
			
			return new CodeGenerationResult (units.ToArray (), (string[]) warningList.ToArray (typeof(string)));
		}
Example #26
0
//		public static void GenerateProjectCode (string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects)
//		{
//			CodeGenerationResult res = GenerateProjectCode (options, projects);
//
//			string basePath = Path.GetDirectoryName (file);
//
//			foreach (SteticCompilationUnit unit in res.Units) {
//				string fname;
//				if (unit.Name.Length == 0)
//					fname = file;
//				else
//					fname = Path.Combine (basePath, unit.Name);
//				StreamWriter fileStream = new StreamWriter (fname);
//				try {
//					provider.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
//				} finally {
//					fileStream.Close ();
//				}
//			}
//		}

        public static CodeGenerationResult GenerateProjectCode(GenerationOptions options, ProjectBackend[] projects)
        {
            ArrayList warningList = new ArrayList();

            List <SteticCompilationUnit> units = new List <SteticCompilationUnit> ();

//			SteticCompilationUnit globalUnit = new SteticCompilationUnit ("");
//			units.Add (globalUnit);

            if (options == null)
            {
                options = new GenerationOptions();
            }
            CodeNamespace globalNs = new CodeNamespace(options.GlobalNamespace);
//			globalUnit.Namespaces.Add (globalNs);

            // Global class

            CodeTypeDeclaration globalType = new CodeTypeDeclaration("Gui");

            globalType.Attributes     = MemberAttributes.Private;
            globalType.TypeAttributes = TypeAttributes.NestedAssembly;
            globalNs.Types.Add(globalType);

            // Create the project initialization method
            // This method will only be added at the end if there
            // is actually something to initialize

            CodeMemberMethod initMethod = new CodeMemberMethod();

            initMethod.Name       = "Initialize";
            initMethod.ReturnType = new CodeTypeReference(typeof(void));
            initMethod.Attributes = MemberAttributes.Assembly | MemberAttributes.Static;
            initMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Gtk.Widget), "iconRenderer"));

            GeneratorContext initContext = new ProjectGeneratorContext(globalNs, globalType, initMethod.Statements, options);

            initContext.RootObject = new CodeArgumentReferenceExpression("iconRenderer");

            // Generate icon factory creation

            foreach (ProjectBackend gp in projects)
            {
                if (gp.IconFactory.Icons.Count > 0)
                {
                    gp.IconFactory.GenerateBuildCode(initContext);
                }
            }
            warningList.AddRange(initContext.Warnings);

            // Generate the code
            CodeGeneratorPartialClass.GenerateProjectGuiCode(globalNs, globalType, options, units, projects, warningList);

            GenerateProjectActionsCode(globalNs, options, projects);

            // Final step. If there is some initialization code, add all needed infrastructure

            globalType.Members.Add(initMethod);

            CodeMemberField initField = new CodeMemberField(typeof(bool), "initialized");

            initField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
            globalType.Members.Add(initField);

            CodeFieldReferenceExpression initVar = new CodeFieldReferenceExpression(
                new CodeTypeReferenceExpression(globalNs.Name + ".Gui"),
                "initialized"
                );

            CodeConditionStatement initCondition = new CodeConditionStatement();

            initCondition.Condition = new CodeBinaryOperatorExpression(
                initVar,
                CodeBinaryOperatorType.IdentityEquality,
                new CodePrimitiveExpression(false)
                );
            initCondition.TrueStatements.Add(new CodeAssignStatement(
                                                 initVar,
                                                 new CodePrimitiveExpression(true)
                                                 ));
            initCondition.TrueStatements.AddRange(initMethod.Statements);
            initMethod.Statements.Clear();
            initMethod.Statements.Add(initCondition);

            //create separate compilation unit for each type in the global namespace
            //and insert them at the begining of the units list.
            int index = 0;

            foreach (CodeTypeDeclaration type in globalNs.Types)
            {
                SteticCompilationUnit unit = new SteticCompilationUnit(type.Name);
                CodeNamespace         ns   = new CodeNamespace(globalNs.Name);

                ns.Types.Add(type);
                unit.Namespaces.Add(ns);
                units.Insert(index++, unit);
            }

            return(new CodeGenerationResult(units.ToArray(), (string[])warningList.ToArray(typeof(string))));
        }
Example #27
0
        public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
        {
            statements.Add(new CodeCommentStatement("Widget " + w.Name));
            GeneratorContext ctx = new ProjectGeneratorContext(cns, type, statements, options);

            Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(w);
            ctx.GenerateCreationCode(ww, widgetVarExp);
            ctx.EndGeneration();
            warnings.AddRange(ctx.Warnings);
            return(ctx.WidgetMap);
        }
Example #28
0
        public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects)
        {
            ArrayList            files = new ArrayList();
            CodeGenerationResult res   = GenerateProjectCode(options, projects);

            string basePath = Path.GetDirectoryName(file);
            string ext      = Path.GetExtension(file);

            foreach (SteticCompilationUnit unit in res.Units)
            {
                string fname;
                if (unit.Name.Length == 0)
                {
                    if (provider is Microsoft.CSharp.CSharpCodeProvider && unit.Namespaces.Count > 0)
                    {
                        var types = unit.Namespaces [0].Types;
                        if (types.Count > 0)
                        {
                            types [0].Members.Insert(0, new CodeSnippetTypeMember("#pragma warning disable 436"));
                        }
                    }
                    fname = file;
                }
                else
                {
                    fname = Path.Combine(basePath, unit.Name) + ext;
                }
                files.Add(fname);
                unit.Name = fname;
                StreamWriter fileStream = new StreamWriter(fname);
                try {
                    provider.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions());
                } finally {
                    fileStream.Close();
                }
            }
            return(res);
        }
        static CodeTypeDeclaration CreatePartialClass(SteticCompilationUnit globalUnit, List <SteticCompilationUnit> units, GenerationOptions options, string name)
        {
            SteticCompilationUnit unit;

            if (options.GenerateSingleFile)
            {
                unit = globalUnit;
            }
            else
            {
                unit = new SteticCompilationUnit(name);
                units.Add(unit);
            }

            string ns = "";
            int    i  = name.LastIndexOf('.');

            if (i != -1)
            {
                ns   = name.Substring(0, i);
                name = name.Substring(i + 1);
            }

            CodeTypeDeclaration type = new CodeTypeDeclaration(name);

            type.IsPartial      = true;
            type.Attributes     = MemberAttributes.Public;
            type.TypeAttributes = TypeAttributes.Public;

            CodeNamespace cns = new CodeNamespace(ns);

            cns.Types.Add(type);
            unit.Namespaces.Add(cns);
            return(type);
        }
Example #30
0
        public static void GenerateProjectCode(string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects)
        {
            CodeGenerationResult res = GenerateProjectCode(options, projects);

            ICodeGenerator gen      = provider.CreateGenerator();
            string         basePath = Path.GetDirectoryName(file);

            foreach (SteticCompilationUnit unit in res.Units)
            {
                string fname;
                if (unit.Name.Length == 0)
                {
                    fname = file;
                }
                else
                {
                    fname = Path.Combine(basePath, unit.Name);
                }
                StreamWriter fileStream = new StreamWriter(fname);
                try {
                    gen.GenerateCodeFromCompileUnit(unit, fileStream, new CodeGeneratorOptions());
                } finally {
                    fileStream.Close();
                }
            }
        }
Example #31
0
        public static void GenerateProjectGuiCode(CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
        {
            // Generate code for each project
            foreach (ProjectBackend gp in projects)
            {
                // Generate top levels
                foreach (Gtk.Widget w in gp.Toplevels)
                {
                    Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup(w);
                    string topLevelName           = wwidget.Name;
                    if (gp.ComponentNeedsCodeGeneration(topLevelName))
                    {
                        //designer file for widget could be changed beyond stetic process
                        //and we nead update wrapper before code generation
                        //during reloading wrappered widget w could be changed;
                        Gtk.Widget currentw = w;
                        if (gp.ReloadTopLevel(topLevelName))
                        {
                            currentw = gp.GetWidget(topLevelName);
                        }
                        GenerateWidgetCode(globalNs, options, units, currentw, warnings);
                    }
                }

                // Generate global action groups
                foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
                {
                    string groupName = agroup.Name;
                    if (gp.ComponentNeedsCodeGeneration(groupName))
                    {
                        //designer file for action group could be changed beyond stetic process
                        //and we nead update wrapper
                        gp.ReloadActionGroup(groupName);
                        GenerateGlobalActionGroupCode(globalNs, options, units, agroup, warnings);
                    }
                }
            }
        }
Example #32
0
        static int GenerateCode(string file, string[] args, int n, GenerationOptions ops)
        {
            foreach (string lib in libraries)
                SteticApp.AddWidgetLibrary (lib);

            SteticApp.UpdateWidgetLibraries (false);

            Project[] projects = new Project [args.Length - n];
            for (int i=n; i<args.Length; i++)
                projects [i - n] = SteticApp.LoadProject (args [i]);

            CodeDomProvider provider = GetProvider (language);
            CodeGenerationResult res = SteticApp.GenerateProjectCode (file, "Stetic", provider, ops, projects);
            foreach (SteticCompilationUnit f in res.Units)
                Console.WriteLine ("Generated file: " + f.Name);
            foreach (string s in res.Warnings)
                Console.WriteLine ("WARNING: " + s);
            return 0;
        }
Example #33
0
 public ProjectGeneratorContext(CodeNamespace cns, CodeTypeDeclaration type, CodeStatementCollection statements, GenerationOptions options) : base(cns, "w", statements, options)
 {
     this.type = type;
 }
Example #34
0
        public static int Main(string[] args)
        {
            int           n            = 0;
            IsolationMode mode         = IsolationMode.None;
            bool          usePartial   = false;
            bool          useGettext   = false;
            bool          genEmpty     = false;
            bool          useMultifile = false;

            while (n < args.Length)
            {
                string arg = args[n];
                if (arg.StartsWith("--language:"))
                {
                    language = arg.Substring(11);
                }
                else if (arg.StartsWith("-l:"))
                {
                    language = arg.Substring(3);
                }
                else if (arg.StartsWith("-lib:"))
                {
                    libraries.Add(arg.Substring(5));
                }
                else if (arg.StartsWith("--library:"))
                {
                    libraries.Add(arg.Substring(10));
                }
                else if (arg == "--generate" || arg == "-g")
                {
                    break;
                }
                else if (arg == "--noisolation")
                {
                    mode = IsolationMode.None;
                }
                else if (arg == "--gen-partial")
                {
                    usePartial = true;
                }
                else if (arg == "--gen-gettext")
                {
                    useGettext = true;
                }
                else if (arg == "--gen-multifile")
                {
                    useMultifile = true;
                }
                else if (arg == "--gen-empty")
                {
                    genEmpty = true;
                }
                else
                {
                    break;
                }
                n++;
            }

            if (args.Length == 1 && args [0] == "--help")
            {
                Console.WriteLine(Catalog.GetString("Stetic - A GTK User Interface Builder"));
                Console.WriteLine(Catalog.GetString("Usage:"));
                Console.WriteLine("\tstetic [<file>]");
                Console.WriteLine("\tstetic [--language:<language>] [-lib:<library>...] --generate <sourceFile> <projectFile> ...");
                return(0);
            }

            Program = new Gnome.Program("Stetic", "0.0", Gnome.Modules.UI, args);

            int ret;

            if (args.Length - n > 2 && ((args [n] == "--generate" || args [n] == "-g")))
            {
                SteticApp = Stetic.ApplicationFactory.CreateApplication(IsolationMode.None);
                GenerationOptions ops = new GenerationOptions();
                ops.UsePartialClasses        = usePartial;
                ops.GenerateEmptyBuildMethod = genEmpty;
                ops.UseGettext         = useGettext;
                ops.GenerateSingleFile = !useMultifile;
                ret = GenerateCode(args [n + 1], args, n + 2, ops);
            }
            else
            {
                SteticApp = Stetic.ApplicationFactory.CreateApplication(mode);
                SteticApp.AllowInProcLibraries = false;
                ret = RunApp(args, n);
            }

            SteticApp.Dispose();
            return(ret);
        }
Example #35
0
		public CodeGenerationResult GenerateProjectCode (GenerationOptions options, ProjectBackend[] projects)
		{
			return CodeGenerator.GenerateProjectCode (options, projects);
		}
		internal static void BindSignalHandlers (CodeExpression targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements, GenerationOptions options)
		{
			foreach (Signal signal in wrapper.Signals) {
				SignalDescriptor descriptor = signal.SignalDescriptor;
				
				CodeExpression createDelegate;
				
				if (options.UsePartialClasses) {
					createDelegate =
						new CodeDelegateCreateExpression (
							new CodeTypeReference (descriptor.HandlerTypeName, CodeTypeReferenceOptions.GlobalReference),
							new CodeThisReferenceExpression (),
							signal.Handler);
				} else {
					createDelegate =
						new CodeMethodInvokeExpression (
							new CodeTypeReferenceExpression (new CodeTypeReference (typeof(Delegate), CodeTypeReferenceOptions.GlobalReference)),
							"CreateDelegate",
							new CodeTypeOfExpression (descriptor.HandlerTypeName),
							targetObjectVar,
							new CodePrimitiveExpression (signal.Handler));
					
					createDelegate = new CodeCastExpression (descriptor.HandlerTypeName.ToGlobalTypeRef (), createDelegate);
				}
				
				CodeAttachEventStatement cevent = new CodeAttachEventStatement (
					new CodeEventReferenceExpression (
						map.GetWidgetExp (wrapper),
						descriptor.Name),
					createDelegate);
				
				statements.Add (cevent);
			}
			
			Wrapper.Widget widget = wrapper as Wrapper.Widget;
			if (widget != null && widget.IsTopLevel) {
				// Bind local action signals
				foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups) {
					foreach (Wrapper.Action ac in grp.Actions)
						BindSignalHandlers (targetObjectVar, ac, map, statements, options);
				}
			}
			
			Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
			if (cont != null) {
				foreach (Gtk.Widget child in cont.AllChildren) {
					Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (child);
					if (ww != null)
						BindSignalHandlers (targetObjectVar, ww, map, statements, options);
				}
			}
			
		}
Example #37
0
        public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects)
        {
            ArrayList files = new ArrayList ();
            CodeGenerationResult res = GenerateProjectCode (options, projects);

            ICodeGenerator gen = provider.CreateGenerator ();
            string basePath = Path.GetDirectoryName (file);
            string ext = Path.GetExtension (file);

            foreach (SteticCompilationUnit unit in res.Units) {
                string fname;
                if (unit.Name.Length == 0)
                    fname = file;
                else
                    fname = Path.Combine (basePath, unit.Name) + ext;
                files.Add (fname);
                unit.Name = fname;
                StreamWriter fileStream = new StreamWriter (fname);
                try {
                    gen.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
                } finally {
                    fileStream.Close ();
                }
            }
            return res;
        }
		static void GenerateProjectActionsCode (CodeNamespace cns, GenerationOptions options, params ProjectBackend[] projects)
		{
			bool multiProject = projects.Length > 1;
			
			CodeTypeDeclaration type = new CodeTypeDeclaration ("ActionGroups");
			type.Attributes = MemberAttributes.Private;
			type.TypeAttributes = TypeAttributes.NestedAssembly;
			cns.Types.Add (type);

			// Generate the global action group getter
			
			CodeMemberMethod met = new CodeMemberMethod ();
			met.Name = "GetActionGroup";
			type.Members.Add (met);
			met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Type), "type"));
			if (multiProject)
				met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "file"));
			met.ReturnType = new CodeTypeReference (typeof(Gtk.ActionGroup));
			met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

			CodeMethodInvokeExpression call = new CodeMethodInvokeExpression (
					new CodeMethodReferenceExpression (
						new CodeTypeReferenceExpression (new CodeTypeReference (cns.Name + ".ActionGroups")),
						"GetActionGroup"
					),
					new CodePropertyReferenceExpression (
						new CodeArgumentReferenceExpression ("type"),
						"FullName"
					)
			);
			if (multiProject)
				call.Parameters.Add (new CodeArgumentReferenceExpression ("file"));
				
			met.Statements.Add (new CodeMethodReturnStatement (call));

			// Generate the global action group getter (overload)
			
			met = new CodeMemberMethod ();
			met.Name = "GetActionGroup";
			type.Members.Add (met);
			met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "name"));
			if (multiProject)
				met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "file"));
			met.ReturnType = new CodeTypeReference (typeof(Gtk.ActionGroup));
			met.Attributes = MemberAttributes.Public | MemberAttributes.Static;
			
			CodeArgumentReferenceExpression cfile = new CodeArgumentReferenceExpression ("file");
			CodeArgumentReferenceExpression cid = new CodeArgumentReferenceExpression ("name");
			
			CodeStatementCollection projectCol = met.Statements;
			int n=1;
			
			foreach (ProjectBackend gp in projects) {
			
				CodeStatementCollection widgetCol;
				
				if (multiProject) {
					CodeConditionStatement pcond = new CodeConditionStatement ();
					pcond.Condition = new CodeBinaryOperatorExpression (
						cfile, 
						CodeBinaryOperatorType.IdentityEquality,
						new CodePrimitiveExpression (gp.Id)
					);
					projectCol.Add (pcond);
					
					widgetCol = pcond.TrueStatements;
					projectCol = pcond.FalseStatements;
				} else {
					widgetCol = projectCol;
				}
				
				foreach (Wrapper.ActionGroup grp in gp.ActionGroups) {
					string fname = "group" + (n++);
					CodeMemberField grpField = new CodeMemberField (new CodeTypeReference (typeof(Gtk.ActionGroup), CodeTypeReferenceOptions.GlobalReference), fname);
					grpField.Attributes |= MemberAttributes.Static;
					type.Members.Add (grpField);
					CodeFieldReferenceExpression grpVar = new CodeFieldReferenceExpression (
						new CodeTypeReferenceExpression (new CodeTypeReference (cns.Name + ".ActionGroups", CodeTypeReferenceOptions.GlobalReference)),
						fname
					);
					
					CodeConditionStatement pcond = new CodeConditionStatement ();
					pcond.Condition = new CodeBinaryOperatorExpression (
						cid, 
						CodeBinaryOperatorType.IdentityEquality,
						new CodePrimitiveExpression (grp.Name)
					);
					widgetCol.Add (pcond);
					
					// If the group has not yet been created, create it
					CodeConditionStatement pcondGrp = new CodeConditionStatement ();
					pcondGrp.Condition = new CodeBinaryOperatorExpression (
						grpVar, 
						CodeBinaryOperatorType.IdentityEquality,
						new CodePrimitiveExpression (null)
					);
					
					pcondGrp.TrueStatements.Add (
						new CodeAssignStatement (
							grpVar,
							new CodeObjectCreateExpression (grp.Name)
						)
					);
					
					pcond.TrueStatements.Add (pcondGrp);
					pcond.TrueStatements.Add (new CodeMethodReturnStatement (grpVar));
					
					widgetCol = pcond.FalseStatements;
				}
				widgetCol.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (null)));
			}
			if (met.Statements.Count == 0)
				met.Statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (null)));
		}
Example #39
0
		public CodeGenerationResult GenerateProjectCode (string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects)
		{
			ArrayList files = new ArrayList ();
			CodeGenerationResult res = GenerateProjectCode (options, projects);
			
			string basePath = Path.GetDirectoryName (file);
			string ext = Path.GetExtension (file);
			
			foreach (SteticCompilationUnit unit in res.Units) {
				string fname;
				if (unit.Name.Length == 0) {
					if (provider is Microsoft.CSharp.CSharpCodeProvider && unit.Namespaces.Count > 0) {
						var types = unit.Namespaces [0].Types;
						if (types.Count > 0) {
							types [0].Members.Insert (0, new CodeSnippetTypeMember ("#pragma warning disable 436"));
						}
					}
					fname = file;
				} else
					fname = Path.Combine (basePath, unit.Name) + ext;
				files.Add (fname);
				unit.Name = fname;
				StreamWriter fileStream = new StreamWriter (fname);
				try {
					provider.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
				} finally {
					fileStream.Close ();
				}
			}
			return res;
		}
		public ProjectGeneratorContext (CodeNamespace cns, CodeTypeDeclaration type, CodeStatementCollection statements, GenerationOptions options): base (cns, "w", statements, options)
		{
			this.type = type;
		}
Example #41
0
		public CodeGenerationResult GenerateProjectCode (GenerationOptions options, params Project[] projects)
		{
			ProjectBackend[] pbs = new ProjectBackend [projects.Length];
			for (int n=0; n<projects.Length; n++)
				pbs [n] = projects [n].ProjectBackend;
				
			return Backend.GenerateProjectCode (options, pbs);
		}
Example #42
0
        static void GenerateComponentCode(object component, SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeExpression cobj, CodeStatementCollection statements, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, CodeIdentifiers ids, ArrayList warnings)
        {
            Gtk.Widget          widget  = component as Gtk.Widget;
            Wrapper.Widget      wwidget = Stetic.Wrapper.Widget.Lookup(widget);
            Wrapper.ActionGroup agroup  = component as Wrapper.ActionGroup;

            string name = widget != null ? widget.Name : agroup.Name;
            string internalClassName = ids.MakeUnique(CodeIdentifier.MakeValid(name));

            string typeName = widget != null ? wwidget.WrappedTypeName : "Gtk.ActionGroup";
            // Create the build method for the top level

            CodeMemberMethod met;

            met = GetBuildMethod(name, internalClassName, typeName, globalUnit, options, units);

            // Generate the build code

            CodeVariableDeclarationStatement varDecHash = new CodeVariableDeclarationStatement(typeof(System.Collections.Hashtable), "bindings");

            met.Statements.Add(varDecHash);
            varDecHash.InitExpression = new CodeObjectCreateExpression(
                typeof(System.Collections.Hashtable),
                new CodeExpression [0]
                );

            CodeVariableReferenceExpression targetObjectVar = new CodeVariableReferenceExpression("cobj");

            Stetic.WidgetMap map;

            if (widget != null)
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, widget, targetObjectVar, met.Statements, options, warnings);
                CodeGenerator.BindSignalHandlers(targetObjectVar, wwidget, map, met.Statements, options);
            }
            else
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, agroup, targetObjectVar, met.Statements, options, warnings);
                foreach (Wrapper.Action ac in agroup.Actions)
                {
                    CodeGenerator.BindSignalHandlers(targetObjectVar, ac, map, met.Statements, options);
                }
            }

            GenerateBindFieldCode(met.Statements, cobj);

            // Add a method call to the build method

            statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(options.GlobalNamespace + ".SteticGenerated." + internalClassName),
                    "Build",
                    new CodeCastExpression(typeName, cobj)
                    )
                );
        }
Example #43
0
        static void GenerateComponentCode(object component, SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeExpression cobj, CodeStatementCollection statements, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, CodeIdentifiers ids, ArrayList warnings)
        {
            Gtk.Widget widget = component as Gtk.Widget;
            Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (widget);
            Wrapper.ActionGroup agroup = component as Wrapper.ActionGroup;

            string name = widget != null ? widget.Name : agroup.Name;
            string internalClassName = ids.MakeUnique (CodeIdentifier.MakeValid (name));

            string typeName = widget != null ? wwidget.WrappedTypeName : "Gtk.ActionGroup";
            // Create the build method for the top level

            CodeMemberMethod met;
            met = GetBuildMethod (name, internalClassName, typeName, globalUnit, options, units);

            // Generate the build code

            CodeVariableDeclarationStatement varDecHash = new CodeVariableDeclarationStatement (typeof(System.Collections.Hashtable), "bindings");
            met.Statements.Add (varDecHash);
            varDecHash.InitExpression = new CodeObjectCreateExpression (
                typeof(System.Collections.Hashtable),
                new CodeExpression [0]
            );

            CodeVariableReferenceExpression targetObjectVar = new CodeVariableReferenceExpression ("cobj");
            Stetic.WidgetMap map;

            if (widget != null) {
                map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, globalType, widget, targetObjectVar, met.Statements, options, warnings);
                CodeGenerator.BindSignalHandlers (targetObjectVar, wwidget, map, met.Statements, options);
            } else {
                map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, globalType, agroup, targetObjectVar, met.Statements, options, warnings);
                foreach (Wrapper.Action ac in agroup.Actions)
                    CodeGenerator.BindSignalHandlers (targetObjectVar, ac, map, met.Statements, options);
            }

            GenerateBindFieldCode (met.Statements, cobj);

            // Add a method call to the build method

            statements.Add (
                new CodeMethodInvokeExpression (
                    new CodeTypeReferenceExpression (options.GlobalNamespace + ".SteticGenerated." + internalClassName),
                    "Build",
                    new CodeCastExpression (typeName, cobj)
                )
            );
        }
        public static void GenerateProjectGuiCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
        {
            // Generate code for each project
            foreach (ProjectBackend gp in projects)
            {
                // Generate top levels
                foreach (Gtk.Widget w in gp.Toplevels)
                {
                    GenerateWidgetCode(globalUnit, globalNs, options, units, w, warnings);
                }

                // Generate global action groups
                foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
                {
                    GenerateGlobalActionGroupCode(globalUnit, globalNs, options, units, agroup, warnings);
                }
            }
        }
Example #45
0
        static CodeMemberMethod GetBuildMethod(string name, string internalClassName, string typeName, SteticCompilationUnit globalUnit, GenerationOptions options, List<SteticCompilationUnit> units)
        {
            SteticCompilationUnit unit;

            if (options.GenerateSingleFile)
                unit = globalUnit;
            else {
                unit = new SteticCompilationUnit (name);
                units.Add (unit);
            }

            CodeTypeDeclaration type = new CodeTypeDeclaration (internalClassName);
            type.Attributes = MemberAttributes.Private;
            type.TypeAttributes = TypeAttributes.NestedAssembly;

            CodeNamespace cns = new CodeNamespace (options.GlobalNamespace + ".SteticGenerated");
            cns.Types.Add (type);
            unit.Namespaces.Add (cns);

            // Create the build method for the component

            CodeMemberMethod met = new CodeMemberMethod ();
            met.Name = "Build";
            type.Members.Add (met);

            met.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference (typeName), "cobj"));
            met.ReturnType = new CodeTypeReference (typeof(void));
            met.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            return met;
        }
Example #46
0
 public CodeGenerationResult GenerateProjectCode(GenerationOptions options, ProjectBackend[] projects)
 {
     return(CodeGenerator.GenerateProjectCode(options, projects));
 }
Example #47
0
        internal static void BindSignalHandlers(CodeExpression targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements, GenerationOptions options)
        {
            foreach (Signal signal in wrapper.Signals)
            {
                SignalDescriptor descriptor = signal.SignalDescriptor;

                CodeExpression createDelegate;

                if (options.UsePartialClasses)
                {
                    var rgx = new Regex(@"`\d+");
                    createDelegate =
                        new CodeDelegateCreateExpression(
                            new CodeTypeReference(rgx.Replace(descriptor.HandlerTypeName, ""), CodeTypeReferenceOptions.GlobalReference),
                            new CodeThisReferenceExpression(),
                            signal.Handler);
                }
                else
                {
                    createDelegate =
                        new CodeMethodInvokeExpression(
                            new CodeTypeReferenceExpression(new CodeTypeReference(typeof(Delegate), CodeTypeReferenceOptions.GlobalReference)),
                            "CreateDelegate",
                            new CodeTypeOfExpression(descriptor.HandlerTypeName),
                            targetObjectVar,
                            new CodePrimitiveExpression(signal.Handler));

                    createDelegate = new CodeCastExpression(descriptor.HandlerTypeName.ToGlobalTypeRef(), createDelegate);
                }

                CodeAttachEventStatement cevent = new CodeAttachEventStatement(
                    new CodeEventReferenceExpression(
                        map.GetWidgetExp(wrapper),
                        descriptor.Name),
                    createDelegate);

                statements.Add(cevent);
            }

            Wrapper.Widget widget = wrapper as Wrapper.Widget;
            if (widget != null && widget.IsTopLevel)
            {
                // Bind local action signals
                foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups)
                {
                    foreach (Wrapper.Action ac in grp.Actions)
                    {
                        BindSignalHandlers(targetObjectVar, ac, map, statements, options);
                    }
                }
            }

            Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
            if (cont != null)
            {
                foreach (Gtk.Widget child in cont.AllChildren)
                {
                    Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(child);
                    if (ww != null)
                    {
                        BindSignalHandlers(targetObjectVar, ww, map, statements, options);
                    }
                }
            }
        }