/// <summary> /// This method writes out the contents of our designer in C# and VB. /// It generates code from our codeCompileUnit using CodeRpovider /// </summary> public string GetCode() { Flush(); StringWriter sw; CodeGeneratorOptions options = new CodeGeneratorOptions(); options.BlankLinesBetweenMembers = false; options.BracingStyle = "C"; options.ElseOnClosing = false; options.IndentString = " "; // PABC Code Generation sw = new StringWriter(); DesignerResourceService resourceService = host.GetService(typeof(IResourceService)) as DesignerResourceService; if (resourceService.ResourcesFileNames != null && resourceService.ResourcesFileNames.Count > 0) { for (int i = 0; i < resourceService.ResourcesFileNames.Count; i++) { sw.WriteLine("{$resource " + Path.GetFileName(resourceService.ResourcesFileNames[i]) + '}'); sw.Write(" "); } } ICodeGenerator abc = new PABCCodeGenerator(); PABCCodeGenerator pabc = abc as PABCCodeGenerator; pabc.UnitName = Path.GetFileNameWithoutExtension(unitFile); abc.GenerateCodeFromCompileUnit(codeCompileUnit, sw, options); PABCCodeGenerator inc_abc = new PABCCodeGenerator(); inc_abc.own_output = true; StreamWriter inc_sw = new StreamWriter(Path.Combine(Path.GetDirectoryName(VisualPascalABC.ProjectFactory.Instance.CurrentProject.Path), /*codeCompileUnit.Namespaces[0].Types[0].Name+".inc"*/ pabc.UnitName + "." + getFormName() + ".inc")); (inc_abc as ICodeGenerator).GenerateCodeFromCompileUnit(codeCompileUnit, inc_sw, options); inc_sw.Flush(); inc_sw.Close(); return(sw.ToString()); }
public void LoadDesigner(string formFile) { UnloadDesigner(); DefaultServiceContainer serviceContainer = new DefaultServiceContainer(); serviceContainer.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService()); serviceContainer.AddService(typeof(System.Drawing.Design.IToolboxService), ToolboxProvider.ToolboxService); serviceContainer.AddService(typeof(IHelpService), new HelpService()); serviceContainer.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService()); AmbientProperties ambientProperties = new AmbientProperties(); serviceContainer.AddService(typeof(AmbientProperties), ambientProperties); this.typeResolutionService = new TypeResolutionService(); serviceContainer.AddService(typeof(ITypeResolutionService), this.typeResolutionService); serviceContainer.AddService(typeof(DesignerOptionService), new SharpDevelopDesignerOptionService()); serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService()); serviceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService()); designSurface = CreateDesignSurface(serviceContainer); designSurface.Loading += this.DesignerLoading; designSurface.Loaded += this.DesignerLoaded; designSurface.Flushed += this.DesignerFlushed; designSurface.Unloading += this.DesignerUnloading; designerResourceService = new DesignerResourceService(this);//roman// serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService); loader = new CodeDomHostLoader(this.Host, formFile, FileName); serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormsDesigner.Services.MenuCommandService(Host)); ICSharpCode.FormsDesigner.Services.EventBindingService eventBindingService = new ICSharpCode.FormsDesigner.Services.EventBindingService(Host); serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), eventBindingService); designSurface.BeginLoad(loader); if (!designSurface.IsLoaded) { throw new FormsDesignerLoadException(FormatLoadErrors(designSurface)); } undoEngine = new FormsDesignerUndoEngine(Host); serviceContainer.AddService(typeof(UndoEngine), undoEngine); IComponentChangeService componentChangeService = (IComponentChangeService)designSurface.GetService(typeof(IComponentChangeService)); componentChangeService.ComponentChanged += ComponentChanged; componentChangeService.ComponentAdded += ComponentListChanged; componentChangeService.ComponentRemoved += ComponentListChanged; componentChangeService.ComponentRename += ComponentListChanged; this.Host.TransactionClosed += TransactionClose; ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService)); selectionService.SelectionChanged += SelectionChangedHandler; if (IsTabOrderMode) // fixes SD2-1015 { tabOrderMode = false; // let ShowTabOrder call the designer command again ShowTabOrder(); } UpdatePropertyPad(); hasUnmergedChanges = false; MakeDirty(); PropertyGrid grid = PropertyPad.Grid; var gridView = (Control)grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(grid); var edit = (Control)gridView.GetType().GetField("edit", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridView); edit.KeyPress += PropertyPadEditorKeyPress; edit.ContextMenu = new ContextMenu(); }