Author: lluis
Date: 2006-12-17 07:49:38 -0500 (Sun, 17 Dec 2006)
New Revision: 69599
Added:
trunk/stetic/libsteticui/CodeGeneratorInternalClass.cs
trunk/stetic/libsteticui/CodeGeneratorPartialClass.cs
Modified:
trunk/stetic/ChangeLog
trunk/stetic/configure.in
trunk/stetic/libstetic/GeneratorContext.cs
trunk/stetic/libstetic/wrapper/Bin.cs
trunk/stetic/libsteticui/Application.cs
trunk/stetic/libsteticui/ApplicationBackend.cs
trunk/stetic/libsteticui/CodeGenerator.cs
trunk/stetic/libsteticui/Component.cs
trunk/stetic/libsteticui/Makefile.am
trunk/stetic/libsteticui/WidgetComponent.cs
trunk/stetic/stetic/Stetic.cs
Log:
* libsteticui/ProjectBackend.cs, libsteticui/WidgetEditSession.cs,
libsteticui/WidgetDesigner.cs, libsteticui/Project.cs: Added new
Changed event.
* libsteticui/PaletteBackend.cs, libsteticui/UndoQueue.cs,
libstetic/undo/DiffGenerator.cs,
libstetic/undo/ActionDiffAdaptor.cs, libstetic/wrapper/Action.cs,
libstetic/wrapper/Container.cs, libstetic/wrapper/Widget.cs,
libstetic/wrapper/ActionGroup.cs, libstetic/wrapper/MenuBar.cs,
libstetic/wrapper/ActionTree.cs,
libstetic/editor/ActionMenuItem.cs,
libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionMenu.cs,
libstetic/editor/ActionToolItem.cs,
libstetic/editor/ActionToolbar.cs: Improved support for Undo.
* libstetic/undo/UndoManager.cs: Removed debug code.
* libstetic/undo/XmlDiffAdaptor.cs: Fix support for name and id
properties when diffing.
* libstetic/wrapper/objects.xml: HasFocus property doesn't need to be
available at design time.
* libstetic/wrapper/ActionToolbarWrapper.cs: Implemented support for
Undo.
Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog 2006-12-17 12:46:05 UTC (rev 69598)
+++ trunk/stetic/ChangeLog 2006-12-17 12:49:38 UTC (rev 69599)
@@ -21,6 +21,29 @@
* libstetic/wrapper/ActionToolbarWrapper.cs: Implemented support for
Undo.
+2006-12-17 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * libsteticui/ProjectBackend.cs, libsteticui/WidgetEditSession.cs,
+ libsteticui/WidgetDesigner.cs, libsteticui/Project.cs: Added new
+ Changed event.
+ * libsteticui/PaletteBackend.cs, libsteticui/UndoQueue.cs,
+ libstetic/undo/DiffGenerator.cs,
+ libstetic/undo/ActionDiffAdaptor.cs, libstetic/wrapper/Action.cs,
+ libstetic/wrapper/Container.cs, libstetic/wrapper/Widget.cs,
+ libstetic/wrapper/ActionGroup.cs, libstetic/wrapper/MenuBar.cs,
+ libstetic/wrapper/ActionTree.cs,
+ libstetic/editor/ActionMenuItem.cs,
+ libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionMenu.cs,
+ libstetic/editor/ActionToolItem.cs,
+ libstetic/editor/ActionToolbar.cs: Improved support for Undo.
+ * libstetic/undo/UndoManager.cs: Removed debug code.
+ * libstetic/undo/XmlDiffAdaptor.cs: Fix support for name and id
+ properties when diffing.
+ * libstetic/wrapper/objects.xml: HasFocus property doesn't need to be
+ available at design time.
+ * libstetic/wrapper/ActionToolbarWrapper.cs: Implemented support for
+ Undo.
+
2006-12-05 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* libsteticui/UndoQueue.cs: Added debug method.
Modified: trunk/stetic/configure.in
===================================================================
--- trunk/stetic/configure.in 2006-12-17 12:46:05 UTC (rev 69598)
+++ trunk/stetic/configure.in 2006-12-17 12:49:38 UTC (rev 69599)
@@ -14,7 +14,7 @@
PKG_CHECK_MODULES(MONO, mono >= $MONO_REQUIRED_VERSION)
AC_PATH_PROG(MONO, mono, no)
-AC_PATH_PROG(MCS, mcs, no)
+AC_PATH_PROG(MCS, gmcs, no)
CS="C#"
if test "$MCS" = "no" ; then
Modified: trunk/stetic/libstetic/GeneratorContext.cs
===================================================================
--- trunk/stetic/libstetic/GeneratorContext.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libstetic/GeneratorContext.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -25,7 +25,7 @@
map = new WidgetMap (vars, widgets);
}
- public CodeNamespace CodeNamespace {
+ public CodeNamespace GlobalCodeNamespace {
get { return cns; }
}
@@ -126,7 +126,7 @@
if (value is Wrapper.ActionGroup) {
return new CodeMethodInvokeExpression (
new CodeMethodReferenceExpression (
- new CodeTypeReferenceExpression
(CodeNamespace.Name + ".ActionGroups"),
+ new CodeTypeReferenceExpression
(GlobalCodeNamespace.Name + ".ActionGroups"),
"GetActionGroup"
),
new CodePrimitiveExpression
(((Wrapper.ActionGroup)value).Name)
@@ -222,11 +222,41 @@
public class GenerationOptions
{
bool useGettext;
+ bool partialClasses;
+ bool generateEmptyBuildMethod;
+ bool generateSingleFile = true;
+ string path;
+ string globalNamespace = "Stetic";
public bool UseGettext {
get { return useGettext; }
set { useGettext = value; }
}
+
+ public bool UsePartialClasses {
+ get { return partialClasses; }
+ set { partialClasses = value; }
+ }
+
+ public string Path {
+ get { return path; }
+ set { path = value; }
+ }
+
+ public bool GenerateEmptyBuildMethod {
+ get { return generateEmptyBuildMethod; }
+ set { generateEmptyBuildMethod = value; }
+ }
+
+ public bool GenerateSingleFile {
+ get { return generateSingleFile; }
+ set { generateSingleFile = value; }
+ }
+
+ public string GlobalNamespace {
+ get { return globalNamespace; }
+ set { globalNamespace = value; }
+ }
}
}
Modified: trunk/stetic/libstetic/wrapper/Bin.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Bin.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libstetic/wrapper/Bin.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -23,7 +23,7 @@
// the app.
bool found = false;
- foreach (CodeTypeDeclaration dec in
ctx.CodeNamespace.Types) {
+ foreach (CodeTypeDeclaration dec in
ctx.GlobalCodeNamespace.Types) {
if (dec.Name == "BinContainer") {
found = true;
break;
@@ -34,7 +34,7 @@
GenerateHelperClass (ctx);
CodeMethodInvokeExpression attachExp = new
CodeMethodInvokeExpression (
- new CodeTypeReferenceExpression
("BinContainer"),
+ new CodeTypeReferenceExpression
(ctx.GlobalCodeNamespace.Name + ".BinContainer"),
"Attach",
new CodeVariableReferenceExpression
(varName)
);
@@ -50,7 +50,7 @@
binContainerVar = ctx.NewId ();
ctx.Statements.Add (
new
CodeVariableDeclarationStatement (
- "BinContainer",
+
ctx.GlobalCodeNamespace.Name + ".BinContainer",
binContainerVar,
attachExp
)
@@ -82,7 +82,7 @@
CodeTypeDeclaration type = new CodeTypeDeclaration
("BinContainer");
type.Attributes = MemberAttributes.Private;
type.TypeAttributes = TypeAttributes.NestedAssembly;
- ctx.CodeNamespace.Types.Add (type);
+ ctx.GlobalCodeNamespace.Types.Add (type);
CodeMemberField field = new CodeMemberField
("Gtk.Widget", "child");
field.Attributes = MemberAttributes.Private;
Modified: trunk/stetic/libsteticui/Application.cs
===================================================================
--- trunk/stetic/libsteticui/Application.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libsteticui/Application.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -243,28 +243,39 @@
projects.Remove (p);
}
- public void GenerateProjectCode (string file, string
namespaceName, CodeDomProvider provider, GenerationOptions options, params
Project[] projects)
+ public string[] GenerateProjectCode (string file, string
namespaceName, CodeDomProvider provider, GenerationOptions options, params
Project[] projects)
{
- CodeCompileUnit cunit = GenerateProjectCode
(namespaceName, options, projects);
+ ArrayList files = new ArrayList ();
+ SteticCompilationUnit[] units = GenerateProjectCode
(options, projects);
ICodeGenerator gen = provider.CreateGenerator ();
- StreamWriter fileStream = new StreamWriter (file);
- try {
- gen.GenerateCodeFromCompileUnit (cunit,
fileStream, new CodeGeneratorOptions ());
- } finally {
- fileStream.Close ();
+ string basePath = Path.GetDirectoryName (file);
+ string ext = Path.GetExtension (file);
+
+ foreach (SteticCompilationUnit unit in units) {
+ string fname;
+ if (unit.Name.Length == 0)
+ fname = file;
+ else
+ fname = Path.Combine (basePath,
unit.Name) + ext;
+ files.Add (fname);
+ StreamWriter fileStream = new StreamWriter
(fname);
+ try {
+ gen.GenerateCodeFromCompileUnit (unit,
fileStream, new CodeGeneratorOptions ());
+ } finally {
+ fileStream.Close ();
+ }
}
+ return (string[]) files.ToArray (typeof(string));
}
- public CodeCompileUnit GenerateProjectCode (string
namespaceName, GenerationOptions options, params Project[] projects)
+ public SteticCompilationUnit[] 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;
- CodeCompileUnit cunit = new CodeCompileUnit ();
- cunit.Namespaces.Add (backend.GenerateProjectCode
(namespaceName, options, pbs));
- return cunit;
+ return backend.GenerateProjectCode (options, pbs);
}
internal bool UseExternalBackend {
@@ -372,7 +383,7 @@
components [cbackend] = c;
return c;
}
- catch (System.Runtime.Remoting.RemotingException ex)
+ catch (System.Runtime.Remoting.RemotingException)
{
// There may be a remoting exception if the
remote wrapper
// has already been disconnected when trying to
create the
Modified: trunk/stetic/libsteticui/ApplicationBackend.cs
===================================================================
--- trunk/stetic/libsteticui/ApplicationBackend.cs 2006-12-17 12:46:05 UTC
(rev 69598)
+++ trunk/stetic/libsteticui/ApplicationBackend.cs 2006-12-17 12:49:38 UTC
(rev 69599)
@@ -113,9 +113,9 @@
return p;
}
- public CodeNamespace GenerateProjectCode (string namespaceName,
GenerationOptions options, ProjectBackend[] projects)
+ public SteticCompilationUnit[] GenerateProjectCode
(GenerationOptions options, ProjectBackend[] projects)
{
- return CodeGenerator.GenerateProjectCode
(namespaceName, options, projects);
+ return CodeGenerator.GenerateProjectCode (options,
projects);
}
public ArrayList GlobalWidgetLibraries {
@@ -452,5 +452,10 @@
{
return widget.LocalActionGroups.ToArray ();
}
+
+ internal ObjectBindInfo[] GetBoundComponents (ObjectWrapper
wrapper)
+ {
+ return CodeGenerator.GetFieldsToBind (wrapper).ToArray
();
+ }
}
}
Modified: trunk/stetic/libsteticui/CodeGenerator.cs
===================================================================
--- trunk/stetic/libsteticui/CodeGenerator.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libsteticui/CodeGenerator.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -2,63 +2,53 @@
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
+using System.Collections.Generic;
using System.IO;
namespace Stetic
{
internal static class CodeGenerator
{
- static CodeExpression bindingFlags;
-
- static CodeGenerator ()
+ public static void GenerateProjectCode (string file,
CodeDomProvider provider, GenerationOptions options, params ProjectBackend[]
projects)
{
- CodeTypeReferenceExpression flagsType = new
CodeTypeReferenceExpression ("System.Reflection.BindingFlags");
- bindingFlags = new CodeBinaryOperatorExpression (
- new CodeFieldReferenceExpression (flagsType,
"Public"),
- CodeBinaryOperatorType.BitwiseOr,
- new CodeFieldReferenceExpression (flagsType,
"NonPublic")
- );
+ SteticCompilationUnit[] units = GenerateProjectCode
(options, projects);
- bindingFlags = new CodeBinaryOperatorExpression (
- bindingFlags,
- CodeBinaryOperatorType.BitwiseOr,
- new CodeFieldReferenceExpression (flagsType,
"Instance")
- );
- }
-
- public static void GenerateProjectCode (string file, string
namespaceName, CodeDomProvider provider, GenerationOptions options, params
ProjectBackend[] projects)
- {
- CodeCompileUnit cunit = new CodeCompileUnit ();
- cunit.Namespaces.Add (GenerateProjectCode
(namespaceName, options, projects));
-
ICodeGenerator gen = provider.CreateGenerator ();
- StreamWriter fileStream = new StreamWriter (file);
- try {
- gen.GenerateCodeFromCompileUnit (cunit,
fileStream, new CodeGeneratorOptions ());
- } finally {
- fileStream.Close ();
+ string basePath = Path.GetDirectoryName (file);
+
+ foreach (SteticCompilationUnit unit in 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 ();
+ }
}
}
- public static CodeNamespace GenerateProjectCode (string
namespaceName, GenerationOptions options, params ProjectBackend[] projects)
+ public static SteticCompilationUnit[] GenerateProjectCode
(GenerationOptions options, params ProjectBackend[] projects)
{
+ List<SteticCompilationUnit> units = new
List<SteticCompilationUnit> ();
+ SteticCompilationUnit globalUnit = new
SteticCompilationUnit ("");
+ units.Add (globalUnit);
+
if (options == null)
options = new GenerationOptions ();
- CodeNamespace cns = new CodeNamespace (namespaceName);
- GenerateProjectGuiCode (cns, options, projects);
- GenerateProjectActionsCode (cns, options, projects);
- return cns;
- }
-
- static void GenerateProjectGuiCode (CodeNamespace cns,
GenerationOptions options, params ProjectBackend[] projects)
- {
- bool multiProject = projects.Length > 1;
+ CodeNamespace globalNs = new CodeNamespace
(options.GlobalNamespace);
+ globalUnit.Namespaces.Add (globalNs);
- CodeTypeDeclaration type = new CodeTypeDeclaration
("Gui");
- type.Attributes = MemberAttributes.Private;
- type.TypeAttributes = TypeAttributes.NestedAssembly;
- cns.Types.Add (type);
+ // 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
@@ -67,229 +57,35 @@
initMethod.Name = "Initialize";
initMethod.ReturnType = new CodeTypeReference
(typeof(void));
initMethod.Attributes = MemberAttributes.Private |
MemberAttributes.Static;
- GeneratorContext initContext = new
ProjectGeneratorContext (cns, initMethod.Statements, options);
+ GeneratorContext initContext = new
ProjectGeneratorContext (globalNs, globalType, initMethod.Statements, options);
- // Build method overload that takes a type as parameter.
-
- CodeMemberMethod met = new CodeMemberMethod ();
- met.Name = "Build";
- type.Members.Add (met);
- met.Parameters.Add (new
CodeParameterDeclarationExpression (typeof(object), "obj"));
- 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
(cns.Name + ".Gui"),
- "Build"
- ),
- new CodeArgumentReferenceExpression
("obj"),
- new CodePropertyReferenceExpression (
- new
CodeArgumentReferenceExpression ("type"),
- "FullName"
- )
- );
- if (multiProject)
- call.Parameters.Add (new
CodeArgumentReferenceExpression ("file"));
+ // Generate icon factory creation
- met.Statements.Add (call);
-
- // Generate the build method
-
- met = new CodeMemberMethod ();
- met.Name = "Build";
- type.Members.Add (met);
-
- met.Parameters.Add (new
CodeParameterDeclarationExpression (typeof(object), "obj"));
- 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;
-
- CodeArgumentReferenceExpression cobj = new
CodeArgumentReferenceExpression ("obj");
- CodeArgumentReferenceExpression cfile = new
CodeArgumentReferenceExpression ("file");
- CodeArgumentReferenceExpression cid = new
CodeArgumentReferenceExpression ("id");
-
- CodeVariableDeclarationStatement varDecHash = new
CodeVariableDeclarationStatement (typeof(System.Collections.Hashtable),
"bindings");
- met.Statements.Add (varDecHash);
- varDecHash.InitExpression = new
CodeObjectCreateExpression (
- typeof(System.Collections.Hashtable),
- new CodeExpression [0]
- );
-
- CodeStatementCollection projectCol = met.Statements;
-
- // 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 widget factory creation
-
if (gp.IconFactory.Icons.Count > 0)
gp.IconFactory.GenerateBuildCode
(initContext);
-
- // Generate top levels
-
- 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);
+ }
- Stetic.Wrapper.Widget wwidget =
Stetic.Wrapper.Widget.Lookup (w);
-
- CodeVariableDeclarationStatement varDec
= new CodeVariableDeclarationStatement
(wwidget.ClassDescriptor.WrappedTypeName, "cobj");
- varDec.InitExpression = new
CodeCastExpression (wwidget.ClassDescriptor.WrappedTypeName, cobj);
- cond.TrueStatements.Add (varDec);
+ // Generate the code
+
+ if (options.UsePartialClasses)
+
CodeGeneratorPartialClass.GenerateProjectGuiCode (globalUnit, globalNs,
globalType, options, units, projects);
+ else
+
CodeGeneratorInternalClass.GenerateProjectGuiCode (globalUnit, globalNs,
globalType, options, units, projects);
- Stetic.WidgetMap map =
Stetic.CodeGenerator.GenerateCreationCode (cns, w, "cobj", cond.TrueStatements,
options);
-
- CodeVariableReferenceExpression
targetObjectVar = new CodeVariableReferenceExpression ("cobj");
- BindSignalHandlers (targetObjectVar,
wwidget, map, cond.TrueStatements);
-
- 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);
-
- CodeVariableDeclarationStatement varDec
= new CodeVariableDeclarationStatement ("Gtk.ActionGroup", "cobj");
- varDec.InitExpression = new
CodeCastExpression ("Gtk.ActionGroup", cobj);
- cond.TrueStatements.Add (varDec);
-
- Stetic.WidgetMap map =
Stetic.CodeGenerator.GenerateCreationCode (cns, agroup, "cobj",
cond.TrueStatements, options);
-
- CodeVariableReferenceExpression
targetObjectVar = new CodeVariableReferenceExpression ("cobj");
- foreach (Wrapper.Action ac in
agroup.Actions)
- BindSignalHandlers
(targetObjectVar, ac, map, cond.TrueStatements);
-
- widgetCol = cond.FalseStatements;
- }
- }
+ GenerateProjectActionsCode (globalNs, options,
projects);
- // Bind the fields
-
- CodeVariableDeclarationStatement varDecIndex = new
CodeVariableDeclarationStatement (typeof(int), "n");
- varDecIndex.InitExpression = new
CodePrimitiveExpression (0);
- CodeExpression varIndex = new
CodeVariableReferenceExpression ("n");
-
- CodeVariableDeclarationStatement varDecArray = new
CodeVariableDeclarationStatement (typeof(FieldInfo[]), "fields");
- varDecArray.InitExpression = new
CodeMethodInvokeExpression (
- new CodeMethodInvokeExpression (
- cobj,
- "GetType",
- new CodeExpression [0]
- ),
- "GetFields",
- bindingFlags
- );
- met.Statements.Add (varDecArray);
- CodeVariableReferenceExpression varArray = new
CodeVariableReferenceExpression ("fields");
-
- CodeIterationStatement iteration = new
CodeIterationStatement ();
- met.Statements.Add (iteration);
-
- iteration.InitStatement = varDecIndex;
-
- iteration.TestExpression = new
CodeBinaryOperatorExpression (
- varIndex,
- CodeBinaryOperatorType.LessThan,
- new CodePropertyReferenceExpression (varArray,
"Length")
- );
- iteration.IncrementStatement = new CodeAssignStatement (
- varIndex,
- new CodeBinaryOperatorExpression (
- varIndex,
- CodeBinaryOperatorType.Add,
- new CodePrimitiveExpression (1)
- )
- );
-
- CodeVariableDeclarationStatement varDecField = new
CodeVariableDeclarationStatement (typeof(FieldInfo), "field");
- varDecField.InitExpression = new
CodeArrayIndexerExpression (varArray, new CodeExpression [] {varIndex});
- CodeVariableReferenceExpression varField = new
CodeVariableReferenceExpression ("field");
- iteration.Statements.Add (varDecField);
-
- CodeVariableDeclarationStatement varDecWidget = new
CodeVariableDeclarationStatement (typeof(object), "widget");
- iteration.Statements.Add (varDecWidget);
- varDecWidget.InitExpression = new CodeIndexerExpression
(
- new CodeVariableReferenceExpression
("bindings"),
- new CodePropertyReferenceExpression (varField,
"Name")
- );
- CodeVariableReferenceExpression varWidget = new
CodeVariableReferenceExpression ("widget");
-
- // Make sure the type of the field matches the type of
the widget
-
- CodeConditionStatement fcond = new
CodeConditionStatement ();
- iteration.Statements.Add (fcond);
- fcond.Condition = new CodeBinaryOperatorExpression (
- new CodeBinaryOperatorExpression (
- varWidget,
-
CodeBinaryOperatorType.IdentityInequality,
- new CodePrimitiveExpression (null)
- ),
- CodeBinaryOperatorType.BooleanAnd,
- new CodeMethodInvokeExpression (
- new CodePropertyReferenceExpression
(varField, "FieldType"),
- "IsInstanceOfType",
- varWidget
- )
- );
-
- // Set the variable value
-
- fcond.TrueStatements.Add (
- new CodeMethodInvokeExpression (
- varField,
- "SetValue",
- cobj,
- varWidget
- )
- );
-
// Final step. If there is some initialization code,
add all needed infrastructure
if (initMethod.Statements.Count > 0) {
- type.Members.Add (initMethod);
+ globalType.Members.Add (initMethod);
CodeMemberField initField = new CodeMemberField
(typeof(bool), "initialized");
initField.Attributes = MemberAttributes.Private
| MemberAttributes.Static;
- type.Members.Add (initField);
+ globalType.Members.Add (initField);
CodeFieldReferenceExpression initVar = new
CodeFieldReferenceExpression (
- new CodeTypeReferenceExpression
(cns.Name + ".Gui"),
+ new CodeTypeReferenceExpression
(globalNs.Name + ".Gui"),
"initialized"
);
@@ -301,29 +97,40 @@
);
initCondition.TrueStatements.Add (
new CodeMethodInvokeExpression (
- new CodeTypeReferenceExpression
(cns.Name + ".Gui"),
+ new CodeTypeReferenceExpression
(globalNs.Name + ".Gui"),
"Initialize"
)
);
- met.Statements.Insert (0, initCondition);
+ initMethod.Statements.Insert (0, initCondition);
}
+ return units.ToArray ();
}
- static void BindSignalHandlers (CodeExpression targetObjectVar,
ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements)
+ internal static void BindSignalHandlers (CodeExpression
targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map,
CodeStatementCollection statements, GenerationOptions options)
{
foreach (Signal signal in wrapper.Signals) {
TypedSignalDescriptor descriptor =
signal.SignalDescriptor as TypedSignalDescriptor;
if (descriptor == null) continue;
- CodeExpression createDelegate =
- new CodeMethodInvokeExpression (
- new CodeTypeReferenceExpression
(typeof(Delegate)),
- "CreateDelegate",
- new CodeTypeOfExpression
(descriptor.HandlerTypeName),
- targetObjectVar,
- new CodePrimitiveExpression
(signal.Handler));
+ CodeExpression createDelegate;
- createDelegate = new CodeCastExpression
(descriptor.HandlerTypeName, createDelegate);
+ if (options.UsePartialClasses) {
+ createDelegate =
+ new
CodeDelegateCreateExpression (
+ new CodeTypeReference
(descriptor.HandlerTypeName),
+ new
CodeThisReferenceExpression (),
+ signal.Handler);
+ } else {
+ createDelegate =
+ new CodeMethodInvokeExpression (
+ new
CodeTypeReferenceExpression (typeof(Delegate)),
+ "CreateDelegate",
+ new
CodeTypeOfExpression (descriptor.HandlerTypeName),
+ targetObjectVar,
+ new
CodePrimitiveExpression (signal.Handler));
+
+ createDelegate = new CodeCastExpression
(descriptor.HandlerTypeName, createDelegate);
+ }
CodeAttachEventStatement cevent = new
CodeAttachEventStatement (
new CodeEventReferenceExpression (
@@ -339,7 +146,7 @@
// Bind local action signals
foreach (Wrapper.ActionGroup grp in
widget.LocalActionGroups) {
foreach (Wrapper.Action ac in
grp.Actions)
- BindSignalHandlers
(targetObjectVar, ac, map, statements);
+ BindSignalHandlers
(targetObjectVar, ac, map, statements, options);
}
}
@@ -348,7 +155,7 @@
foreach (Gtk.Widget child in cont.AllChildren) {
Stetic.Wrapper.Widget ww =
Stetic.Wrapper.Widget.Lookup (child);
if (ww != null)
- BindSignalHandlers
(targetObjectVar, ww, map, statements);
+ BindSignalHandlers
(targetObjectVar, ww, map, statements, options);
}
}
@@ -467,20 +274,64 @@
}
}
- public static WidgetMap GenerateCreationCode (CodeNamespace
cns, Gtk.Widget w, string widgetVarName, CodeStatementCollection statements,
GenerationOptions options)
+ internal static List<ObjectBindInfo> GetFieldsToBind
(ObjectWrapper wrapper)
{
+ List<ObjectBindInfo> tobind = new List<ObjectBindInfo>
();
+ GetFieldsToBind (tobind, wrapper);
+ return tobind;
+ }
+
+ static void GetFieldsToBind (List<ObjectBindInfo> tobind,
ObjectWrapper wrapper)
+ {
+ string memberName = null;
+
+ if (wrapper is Wrapper.Widget) {
+ Wrapper.Widget ww = wrapper as Wrapper.Widget;
+
+ if (!ww.IsTopLevel && ww.InternalChildProperty
== null)
+ memberName = ((Wrapper.Widget)
wrapper).Wrapped.Name;
+ }
+ else if (wrapper is Wrapper.Action)
+ memberName = ((Wrapper.Action) wrapper).Name;
+
+ if (memberName != null) {
+ ObjectBindInfo binfo = new ObjectBindInfo
(wrapper.ClassDescriptor.WrappedTypeName, memberName);
+ tobind.Add (binfo);
+ }
+
+ Wrapper.Widget widget = wrapper as Wrapper.Widget;
+ if (widget != null && widget.IsTopLevel) {
+ // Generate fields for local actions
+ foreach (Wrapper.ActionGroup grp in
widget.LocalActionGroups) {
+ foreach (Wrapper.Action ac in
grp.Actions)
+ GetFieldsToBind (tobind, ac);
+ }
+ }
+
+ 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)
+ GetFieldsToBind (tobind, ww);
+ }
+ }
+ }
+
+ public static WidgetMap GenerateCreationCode (CodeNamespace
cns, CodeTypeDeclaration type, Gtk.Widget w, string widgetVarName,
CodeStatementCollection statements, GenerationOptions options)
+ {
statements.Add (new CodeCommentStatement ("Widget " +
w.Name));
- GeneratorContext ctx = new ProjectGeneratorContext
(cns, statements, options);
+ GeneratorContext ctx = new ProjectGeneratorContext
(cns, type, statements, options);
Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup
(w);
ctx.GenerateCreationCode (ww, widgetVarName);
ctx.EndGeneration ();
return ctx.WidgetMap;
}
- public static WidgetMap GenerateCreationCode (CodeNamespace
cns, Wrapper.ActionGroup grp, string groupVarName, CodeStatementCollection
statements, GenerationOptions options)
+ public static WidgetMap GenerateCreationCode (CodeNamespace
cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, string groupVarName,
CodeStatementCollection statements, GenerationOptions options)
{
statements.Add (new CodeCommentStatement ("Action group
" + grp.Name));
- GeneratorContext ctx = new ProjectGeneratorContext
(cns, statements, options);
+ GeneratorContext ctx = new ProjectGeneratorContext
(cns, type, statements, options);
ctx.GenerateCreationCode (grp, groupVarName);
ctx.EndGeneration ();
return ctx.WidgetMap;
@@ -489,8 +340,11 @@
class ProjectGeneratorContext: GeneratorContext
{
- public ProjectGeneratorContext (CodeNamespace cns,
CodeStatementCollection statements, GenerationOptions options): base (cns, "w",
statements, options)
+ CodeTypeDeclaration type;
+
+ public ProjectGeneratorContext (CodeNamespace cns,
CodeTypeDeclaration type, CodeStatementCollection statements, GenerationOptions
options): base (cns, "w", statements, options)
{
+ this.type = type;
}
public override void GenerateBuildCode (ObjectWrapper wrapper,
string varName)
@@ -502,18 +356,56 @@
memberName = ((Wrapper.Widget)
wrapper).Wrapped.Name;
else if (wrapper is Wrapper.Action)
memberName = ((Wrapper.Action) wrapper).Name;
-
+
if (memberName != null) {
- Statements.Add (
- new CodeAssignStatement (
- new CodeIndexerExpression (
- new
CodeVariableReferenceExpression ("bindings"),
- new
CodePrimitiveExpression (memberName)
- ),
- new
CodeVariableReferenceExpression (varName)
- )
- );
+ if (Options.UsePartialClasses) {
+ // Don't generate fields for top level
widgets and for widgets accessible
+ // through other widget's properties
+ Wrapper.Widget ww = wrapper as
Wrapper.Widget;
+ if (ww == null || (!ww.IsTopLevel &&
ww.InternalChildProperty == null)) {
+ type.Members.Add (
+ new CodeMemberField (
+
wrapper.ClassDescriptor.WrappedTypeName,
+ memberName
+ )
+ );
+ Statements.Add (
+ new CodeAssignStatement
(
+ new
CodeFieldReferenceExpression (
+ new
CodeThisReferenceExpression (),
+
memberName
+ ),
+ new
CodeVariableReferenceExpression (varName)
+ )
+ );
+ }
+ } else {
+ Statements.Add (
+ new CodeAssignStatement (
+ new
CodeIndexerExpression (
+ new
CodeVariableReferenceExpression ("bindings"),
+ new
CodePrimitiveExpression (memberName)
+ ),
+ new
CodeVariableReferenceExpression (varName)
+ )
+ );
+ }
}
}
}
+
+ [Serializable]
+ public class SteticCompilationUnit: CodeCompileUnit
+ {
+ string name;
+
+ public SteticCompilationUnit (string name)
+ {
+ this.name = name;
+ }
+
+ public string Name {
+ get { return name; }
+ }
+ }
}
Added: trunk/stetic/libsteticui/CodeGeneratorInternalClass.cs
===================================================================
--- trunk/stetic/libsteticui/CodeGeneratorInternalClass.cs 2006-12-17
12:46:05 UTC (rev 69598)
+++ trunk/stetic/libsteticui/CodeGeneratorInternalClass.cs 2006-12-17
12:49:38 UTC (rev 69599)
@@ -0,0 +1,302 @@
+
+using System;
+using System.Reflection;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Stetic
+{
+ internal static class CodeGeneratorInternalClass
+ {
+ static CodeExpression bindingFlags;
+
+ static CodeGeneratorInternalClass ()
+ {
+ CodeTypeReferenceExpression flagsType = new
CodeTypeReferenceExpression ("System.Reflection.BindingFlags");
+ bindingFlags = new CodeBinaryOperatorExpression (
+ new CodeFieldReferenceExpression (flagsType,
"Public"),
+ CodeBinaryOperatorType.BitwiseOr,
+ new CodeFieldReferenceExpression (flagsType,
"NonPublic")
+ );
+
+ bindingFlags = new CodeBinaryOperatorExpression (
+ bindingFlags,
+ CodeBinaryOperatorType.BitwiseOr,
+ new CodeFieldReferenceExpression (flagsType,
"Instance")
+ );
+ }
+
+ public static void GenerateProjectGuiCode
(SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration
globalType, GenerationOptions options, List<SteticCompilationUnit> units,
params ProjectBackend[] projects)
+ {
+ 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), "obj"));
+ 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
("obj"),
+ 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), "obj"));
+ 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 ("obj");
+ CodeArgumentReferenceExpression cfile = new
CodeArgumentReferenceExpression ("file");
+ CodeArgumentReferenceExpression cid = new
CodeArgumentReferenceExpression ("id");
+
+ CodeStatementCollection projectCol = met.Statements;
+
+ // 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
+
+ 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);
+
+ 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);
+
+ widgetCol = cond.FalseStatements;
+ }
+ }
+ }
+
+ static CodeMemberMethod GetBuildMethod (string name, 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
(name);
+ 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), "obj"));
+ met.ReturnType = new CodeTypeReference (typeof(void));
+ met.Attributes = MemberAttributes.Public |
MemberAttributes.Static;
+
+ return met;
+ }
+
+ static void GenerateComponentCode (object component,
SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeExpression cobj,
CodeStatementCollection statements, CodeTypeDeclaration globalType,
GenerationOptions options, List<SteticCompilationUnit> units)
+ {
+ 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 typeName = widget != null ?
wwidget.ClassDescriptor.WrappedTypeName : "Gtk.ActionGroup";
+ // Create the build method for the top level
+
+ CodeMemberMethod met;
+ met = GetBuildMethod (name , 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, "cobj", met.Statements, options);
+ CodeGenerator.BindSignalHandlers
(targetObjectVar, wwidget, map, met.Statements, options);
+ } else {
+ map = Stetic.CodeGenerator.GenerateCreationCode
(globalNs, globalType, agroup, "cobj", met.Statements, options);
+ 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." + name),
+ "Build",
+ new CodeCastExpression (typeName, cobj)
+ )
+ );
+ }
+
+ static void GenerateBindFieldCode (CodeStatementCollection
statements, CodeExpression cobj)
+ {
+ // Bind the fields
+
+ CodeVariableDeclarationStatement varDecIndex = new
CodeVariableDeclarationStatement (typeof(int), "n");
+ varDecIndex.InitExpression = new
CodePrimitiveExpression (0);
+ CodeExpression varIndex = new
CodeVariableReferenceExpression ("n");
+
+ CodeVariableDeclarationStatement varDecArray = new
CodeVariableDeclarationStatement (typeof(FieldInfo[]), "fields");
+ varDecArray.InitExpression = new
CodeMethodInvokeExpression (
+ new CodeMethodInvokeExpression (
+ cobj,
+ "GetType",
+ new CodeExpression [0]
+ ),
+ "GetFields",
+ bindingFlags
+ );
+ statements.Add (varDecArray);
+ CodeVariableReferenceExpression varArray = new
CodeVariableReferenceExpression ("fields");
+
+ CodeIterationStatement iteration = new
CodeIterationStatement ();
+ statements.Add (iteration);
+
+ iteration.InitStatement = varDecIndex;
+
+ iteration.TestExpression = new
CodeBinaryOperatorExpression (
+ varIndex,
+ CodeBinaryOperatorType.LessThan,
+ new CodePropertyReferenceExpression (varArray,
"Length")
+ );
+ iteration.IncrementStatement = new CodeAssignStatement (
+ varIndex,
+ new CodeBinaryOperatorExpression (
+ varIndex,
+ CodeBinaryOperatorType.Add,
+ new CodePrimitiveExpression (1)
+ )
+ );
+
+ CodeVariableDeclarationStatement varDecField = new
CodeVariableDeclarationStatement (typeof(FieldInfo), "field");
+ varDecField.InitExpression = new
CodeArrayIndexerExpression (varArray, new CodeExpression [] {varIndex});
+ CodeVariableReferenceExpression varField = new
CodeVariableReferenceExpression ("field");
+ iteration.Statements.Add (varDecField);
+
+ CodeVariableDeclarationStatement varDecWidget = new
CodeVariableDeclarationStatement (typeof(object), "widget");
+ iteration.Statements.Add (varDecWidget);
+ varDecWidget.InitExpression = new CodeIndexerExpression
(
+ new CodeVariableReferenceExpression
("bindings"),
+ new CodePropertyReferenceExpression (varField,
"Name")
+ );
+ CodeVariableReferenceExpression varWidget = new
CodeVariableReferenceExpression ("widget");
+
+ // Make sure the type of the field matches the type of
the widget
+
+ CodeConditionStatement fcond = new
CodeConditionStatement ();
+ iteration.Statements.Add (fcond);
+ fcond.Condition = new CodeBinaryOperatorExpression (
+ new CodeBinaryOperatorExpression (
+ varWidget,
+
CodeBinaryOperatorType.IdentityInequality,
+ new CodePrimitiveExpression (null)
+ ),
+ CodeBinaryOperatorType.BooleanAnd,
+ new CodeMethodInvokeExpression (
+ new CodePropertyReferenceExpression
(varField, "FieldType"),
+ "IsInstanceOfType",
+ varWidget
+ )
+ );
+
+ // Set the variable value
+
+ fcond.TrueStatements.Add (
+ new CodeMethodInvokeExpression (
+ varField,
+ "SetValue",
+ cobj,
+ varWidget
+ )
+ );
+ }
+ }
+}
Added: trunk/stetic/libsteticui/CodeGeneratorPartialClass.cs
===================================================================
--- trunk/stetic/libsteticui/CodeGeneratorPartialClass.cs 2006-12-17
12:46:05 UTC (rev 69598)
+++ trunk/stetic/libsteticui/CodeGeneratorPartialClass.cs 2006-12-17
12:49:38 UTC (rev 69599)
@@ -0,0 +1,122 @@
+
+using System;
+using System.Reflection;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Stetic
+{
+ internal static class CodeGeneratorPartialClass
+ {
+ public static void GenerateProjectGuiCode
(SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration
globalType, GenerationOptions options, List<SteticCompilationUnit> units,
params ProjectBackend[] projects)
+ {
+ // 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);
+
+ // Generate global action groups
+ foreach (Wrapper.ActionGroup agroup in
gp.ActionGroups)
+ GenerateGlobalActionGroupCode
(globalUnit, globalNs, options, units, agroup);
+ }
+ }
+
+ 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;
+ }
+
+
+ static void GenerateWidgetCode (SteticCompilationUnit
globalUnit, CodeNamespace globalNs, GenerationOptions options,
List<SteticCompilationUnit> units, Gtk.Widget w)
+ {
+ // 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;
+ }
+
+ Stetic.Wrapper.Widget wwidget =
Stetic.Wrapper.Widget.Lookup (w);
+
+ CodeVariableDeclarationStatement varDec = new
CodeVariableDeclarationStatement (wwidget.ClassDescriptor.WrappedTypeName,
"cobj");
+ varDec.InitExpression = new CodeThisReferenceExpression
();
+ met.Statements.Add (varDec);
+
+ Stetic.WidgetMap map =
Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, "cobj",
met.Statements, options);
+
+ CodeVariableReferenceExpression targetObjectVar = new
CodeVariableReferenceExpression ("cobj");
+ CodeGenerator.BindSignalHandlers (targetObjectVar,
wwidget, map, met.Statements, options);
+ }
+
+ static void GenerateWrapperFields (CodeTypeDeclaration type,
ObjectWrapper wrapper)
+ {
+ foreach (ObjectBindInfo binfo in
CodeGenerator.GetFieldsToBind (wrapper)) {
+ type.Members.Add (
+ new CodeMemberField (
+ binfo.TypeName,
+ binfo.Name
+ )
+ );
+ }
+ }
+
+
+ static void GenerateGlobalActionGroupCode
(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions
options, List<SteticCompilationUnit> units, Wrapper.ActionGroup agroup)
+ {
+ 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;
+
+ CodeVariableDeclarationStatement varDec = new
CodeVariableDeclarationStatement ("Gtk.ActionGroup", "cobj");
+ varDec.InitExpression = new CodeThisReferenceExpression
();
+ met.Statements.Add (varDec);
+
+ Stetic.WidgetMap map =
Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, agroup, "cobj",
met.Statements, options);
+
+ CodeVariableReferenceExpression targetObjectVar = new
CodeVariableReferenceExpression ("cobj");
+ foreach (Wrapper.Action ac in agroup.Actions)
+ CodeGenerator.BindSignalHandlers
(targetObjectVar, ac, map, met.Statements, options);
+ }
+ }
+}
Modified: trunk/stetic/libsteticui/Component.cs
===================================================================
--- trunk/stetic/libsteticui/Component.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libsteticui/Component.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -132,5 +132,14 @@
{
return base.ToString() + " " + backend;
}
+
+ public ObjectBindInfo[] GetObjectBindInfo ()
+ {
+ ObjectWrapper ww = backend as ObjectWrapper;
+ if (ww != null)
+ return app.Backend.GetBoundComponents (ww);
+ else
+ return new ObjectBindInfo [0];
+ }
}
}
Modified: trunk/stetic/libsteticui/Makefile.am
===================================================================
--- trunk/stetic/libsteticui/Makefile.am 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libsteticui/Makefile.am 2006-12-17 12:49:38 UTC (rev
69599)
@@ -24,6 +24,8 @@
ComponentSignalEventHandler.cs \
ComponentType.cs \
CodeGenerator.cs \
+ CodeGeneratorInternalClass.cs \
+ CodeGeneratorPartialClass.cs \
EmbedWindow.cs \
Glade.cs \
Grid.cs \
Modified: trunk/stetic/libsteticui/WidgetComponent.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetComponent.cs 2006-12-17 12:46:05 UTC (rev
69598)
+++ trunk/stetic/libsteticui/WidgetComponent.cs 2006-12-17 12:49:38 UTC (rev
69599)
@@ -93,4 +93,25 @@
}
}
}
+
+ [Serializable]
+ public class ObjectBindInfo
+ {
+ string typeName;
+ string name;
+
+ public ObjectBindInfo (string typeName, string name)
+ {
+ this.typeName = typeName;
+ this.name = name;
+ }
+
+ public string TypeName {
+ get { return typeName; }
+ }
+
+ public string Name {
+ get { return name; }
+ }
+ }
}
Modified: trunk/stetic/stetic/Stetic.cs
===================================================================
--- trunk/stetic/stetic/Stetic.cs 2006-12-17 12:46:05 UTC (rev 69598)
+++ trunk/stetic/stetic/Stetic.cs 2006-12-17 12:49:38 UTC (rev 69599)
@@ -36,6 +36,10 @@
{
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];
@@ -51,6 +55,14 @@
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++;
@@ -70,7 +82,12 @@
if (args.Length - n > 2 && ((args [n] == "--generate"
|| args [n] == "-g"))) {
SteticApp = new Stetic.Application
(IsolationMode.None);
- ret = GenerateCode (args [n+1], args, n+2);
+ 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 = new Stetic.Application (mode);
@@ -81,7 +98,7 @@
return ret;
}
- static int GenerateCode (string file, string[] args, int n)
+ static int GenerateCode (string file, string[] args, int n,
GenerationOptions ops)
{
foreach (string lib in libraries)
SteticApp.AddWidgetLibrary (lib);
@@ -93,7 +110,9 @@
projects [i - n] = SteticApp.LoadProject (args
[i]);
CodeDomProvider provider = GetProvider (language);
- SteticApp.GenerateProjectCode (file, "Stetic",
provider, null, projects);
+ string[] files = SteticApp.GenerateProjectCode (file,
"Stetic", provider, ops, projects);
+ foreach (string f in files)
+ Console.WriteLine ("Generated file: " + f);
return 0;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches