コード例 #1
0
		static IType CreateClass (Project project, Stetic.ActionGroupComponent group, string name, string namspace, string folder)
		{
			string fullName = namspace.Length > 0 ? namspace + "." + name : name;
			
			CodeRefactorer gen = new CodeRefactorer (project.ParentSolution);
			
			CodeTypeDeclaration type = new CodeTypeDeclaration ();
			type.Name = name;
			type.IsClass = true;
			type.BaseTypes.Add (new CodeTypeReference ("Gtk.ActionGroup"));
			
			// Generate the constructor. It contains the call that builds the widget.
			
			CodeConstructor ctor = new CodeConstructor ();
			ctor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			ctor.BaseConstructorArgs.Add (new CodePrimitiveExpression (fullName));
			
			CodeMethodInvokeExpression call = new CodeMethodInvokeExpression (
				new CodeMethodReferenceExpression (
					new CodeTypeReferenceExpression ("Stetic.Gui"),
					"Build"
				),
				new CodeThisReferenceExpression (),
				new CodeTypeOfExpression (fullName)
			);
			ctor.Statements.Add (call);
			type.Members.Add (ctor);
			
			// Add signal handlers
			
			foreach (Stetic.ActionComponent action in group.GetActions ()) {
				foreach (Stetic.Signal signal in action.GetSignals ()) {
					CodeMemberMethod met = new CodeMemberMethod ();
					met.Name = signal.Handler;
					met.Attributes = MemberAttributes.Family;
					met.ReturnType = new CodeTypeReference (signal.SignalDescriptor.HandlerReturnTypeName);
					
					foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters)
						met.Parameters.Add (new CodeParameterDeclarationExpression (pinfo.TypeName, pinfo.Name));
						
					type.Members.Add (met);
				}
			}
			
			// Create the class
			
			IType cls = null;
			cls = gen.CreateClass (project, ((DotNetProject)project).LanguageName, folder, namspace, type);
			if (cls == null)
				throw new UserException ("Could not create class " + fullName);
			
			project.AddFile (cls.CompilationUnit.FileName, BuildAction.Compile);
			IdeApp.ProjectOperations.Save (project);
			
			// Make sure the database is up-to-date
			ProjectDomService.Parse (project, cls.CompilationUnit.FileName);
			return cls;
		}
コード例 #2
0
		void CreateClass (string name, string namspace, string folder)
		{
			string fullName = namspace.Length > 0 ? namspace + "." + name : name;
			
			CodeRefactorer gen = new CodeRefactorer (fproject.Project.ParentSolution);
			bool partialSupport = fproject.Project.UsePartialTypes;
			Stetic.WidgetComponent component = (Stetic.WidgetComponent) rootWidget.Component;
			
			CodeTypeDeclaration type = new CodeTypeDeclaration ();
			type.Name = name;
			type.IsClass = true;
			type.IsPartial = partialSupport;
			type.BaseTypes.Add (new CodeTypeReference (component.Type.ClassName));
			
			// Generate the constructor. It contains the call that builds the widget.
			
			CodeConstructor ctor = new CodeConstructor ();
			ctor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			
			foreach (object val in component.Type.InitializationValues) {
				if (val is Enum) {
					ctor.BaseConstructorArgs.Add (
						new CodeFieldReferenceExpression (
							new CodeTypeReferenceExpression (val.GetType ()),
							val.ToString ()
						)
					);
				}
				else
					ctor.BaseConstructorArgs.Add (new CodePrimitiveExpression (val));
			}
			
			if (partialSupport) {
				CodeMethodInvokeExpression call = new CodeMethodInvokeExpression (
					new CodeMethodReferenceExpression (
						new CodeThisReferenceExpression (),
						"Build"
					)
				);
				ctor.Statements.Add (call);
			} else {
				CodeMethodInvokeExpression call = new CodeMethodInvokeExpression (
					new CodeMethodReferenceExpression (
						new CodeTypeReferenceExpression ("Stetic.Gui"),
						"Build"
					),
					new CodeThisReferenceExpression (),
					new CodeTypeOfExpression (fullName)
				);
				ctor.Statements.Add (call);
			}
			type.Members.Add (ctor);
			
			// Add signal handlers
			
			AddSignalsRec (type, component);
			foreach (Stetic.Component ag in component.GetActionGroups ())
				AddSignalsRec (type, ag);
			
			// Create the class
			IType cls = gen.CreateClass (Project.Project, ((DotNetProject)Project.Project).LanguageName, folder, namspace, type);
			if (cls == null)
				throw new UserException ("Could not create class " + fullName);
			
			Project.Project.AddFile (cls.CompilationUnit.FileName, BuildAction.Compile);
			IdeApp.ProjectOperations.Save (Project.Project);
			
			// Make sure the database is up-to-date
			ProjectDomService.Parse (Project.Project, cls.CompilationUnit.FileName, null);
		}