void SetupModel(Interface referer) { foreach (IElement elem in referer.Symbols) { model.AppendValues (true, elem.Name, elem); } selectedCount = model.IterNChildren (); countLabel.Text = selectedCount.ToString (); codeTextView.Buffer.Text = renderer (elements); }
public string Generate(Interface @interface) { CodeTypeDeclaration type = GenerateCodeDom(@interface); PopulateWithElements (@interface.Symbols, type); StringBuilder sb = new StringBuilder(); sb.AppendLine(); provider.GenerateCodeFromType(type, new StringWriter(sb), opt); sb.AppendLine(); return sb.ToString (); }
public GenerationDialog(Window parent, Interface referer, Func<IEnumerable<IElement>, string> renderer) : base(referer.Name, parent, DialogFlags.Modal | DialogFlags.DestroyWithParent) { this.TransientFor = parent; this.Build(); this.renderer = renderer; elements = new List<IElement> (referer.Symbols); model = new ListStore (typeof (bool), typeof (string), typeof (IElement)); selectionTv.Model = model; SetupModel (referer); SetupTreeview (); }
CodeTypeDeclaration GenerateCodeDom(Interface i) { int index = i.Name.LastIndexOf("."); string name = index != - 1 ? i.Name.Substring(index + 1) : i.Name; CodeTypeDeclaration type = new CodeTypeDeclaration(name); type.Attributes = MemberAttributes.Public; type.IsInterface = true; // Add "Interface" attribute CodeAttributeDeclarationCollection attrs = new CodeAttributeDeclarationCollection(); attrs.Add(new CodeAttributeDeclaration("Interface", new CodeAttributeArgument(new CodePrimitiveExpression(i.Name)))); type.CustomAttributes = attrs; return type; }
/*public GenerationMenuWidget(PathContainer referer) { MenuItem path = new MenuItem("Generate path " + referer.Path + " ..."); path.Activated += delegate { GenerationDialog d = new GenerationDialog(); d.Modal = true; if (d.Run() == (int)ResponseType.Ok) { IGenerator generator = new CSharpCodeDomGenerator(); generator.Generate(referer, d.PathToSave); } d.Destroy(); }; this.Append(path); path.ShowAll(); }*/ public GenerationMenuWidget(Window parent, Interface referer) { MenuItem path = new MenuItem("Generate " + referer.Name + "..."); IGenerator generator = new CSharpCodeDomGenerator(); Func<IEnumerable<IElement>, string> renderer = (elements) => { try { return generator.Generate(elements); } catch (Exception e) { Logging.Error ("Error during generation", e, parent); return string.Empty; } }; path.Activated += delegate { GenerationDialog d = new GenerationDialog (parent, referer, renderer); d.Modal = true; d.Run (); d.Destroy(); }; this.Append(path); path.ShowAll(); }