示例#1
0
 private void LoadDesigner()
 {
     //LoggingService.Info("Form Designer: BEGIN INITIALIZE");
     DefaultServiceContainer parentProvider = new DefaultServiceContainer();
     parentProvider.AddService(typeof(IUIService), new UIService());
     parentProvider.AddService(typeof(IToolboxService), new ToolboxService());
     parentProvider.AddService(typeof(IPropertyValueUIService), new PropertyValueUIService());
     AmbientProperties serviceInstance = new AmbientProperties();
     parentProvider.AddService(typeof(AmbientProperties), serviceInstance);
     parentProvider.AddService(typeof(IDesignerEventService), new FormsDesigner.Services.DesignerEventService());
     this.designSurface = new System.ComponentModel.Design.DesignSurface(parentProvider);
     parentProvider.AddService(typeof(IMenuCommandService), new FormsDesigner.Services.MenuCommandService(this.p, this.designSurface));
     parentProvider.AddService(typeof(ITypeResolutionService), new TypeResolutionService());
     DesignerLoader loader = this.loaderProvider.CreateLoader(this.generator);
     //加载XML内容
     this.designSurface.BeginLoad(loader);
     this.generator.Attach(this);
     this.undoEngine = new FormsDesignerUndoEngine(this.Host);
     IComponentChangeService service = (IComponentChangeService) this.designSurface.GetService(typeof(IComponentChangeService));
     service.ComponentChanged += delegate {
         this.viewContent.IsDirty = true;
     };
     service.ComponentAdded += new ComponentEventHandler(this.ComponentListChanged);
     service.ComponentRemoved += new ComponentEventHandler(this.ComponentListChanged);
     service.ComponentRename += new ComponentRenameEventHandler(this.ComponentListChanged);
     this.Host.TransactionClosed += new DesignerTransactionCloseEventHandler(this.TransactionClose);
     ISelectionService service2 = (ISelectionService) this.designSurface.GetService(typeof(ISelectionService));
     service2.SelectionChanged += new EventHandler(this.SelectionChangedHandler);
     if (this.IsTabOrderMode)
     {
         this.tabOrderMode = false;
         this.ShowTabOrder();
     }
     //LoggingService.Info("Form Designer: END INITIALIZE");
 }
        void LoadDesigner()
        {
            LoggingService.Info("Form Designer: BEGIN INITIALIZE");

            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());

            serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), new DesignerResourceService(this.resourceStore));
            AmbientProperties ambientProperties = new AmbientProperties();

            serviceContainer.AddService(typeof(AmbientProperties), ambientProperties);
            this.typeResolutionService = new TypeResolutionService(this.PrimaryFileName);
            serviceContainer.AddService(typeof(ITypeResolutionService), this.typeResolutionService);
            serviceContainer.AddService(typeof(DesignerOptionService), new SharpDevelopDesignerOptionService());
            serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
            serviceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService());
            serviceContainer.AddService(typeof(ProjectResourceService), new ProjectResourceService(ParserService.GetParseInformation(this.DesignerCodeFile.FileName).MostRecentCompilationUnit.ProjectContent));

            // Provide the ImageResourceEditor for all Image and Icon properties
            this.addedTypeDescriptionProviders.Add(typeof(Image), TypeDescriptor.AddAttributes(typeof(Image), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor))));
            this.addedTypeDescriptionProviders.Add(typeof(Icon), TypeDescriptor.AddAttributes(typeof(Icon), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor))));

            if (generator.CodeDomProvider != null)
            {
                serviceContainer.AddService(typeof(System.CodeDom.Compiler.CodeDomProvider), generator.CodeDomProvider);
            }

            designSurface            = CreateDesignSurface(serviceContainer);
            designSurface.Loading   += this.DesignerLoading;
            designSurface.Loaded    += this.DesignerLoaded;
            designSurface.Flushed   += this.DesignerFlushed;
            designSurface.Unloading += this.DesignerUnloading;

            serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormsDesigner.Services.MenuCommandService(this.Control, designSurface));
            ICSharpCode.FormsDesigner.Services.EventBindingService eventBindingService = new ICSharpCode.FormsDesigner.Services.EventBindingService(this, designSurface);
            serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), eventBindingService);

            this.loader = loaderProvider.CreateLoader(generator);
            designSurface.BeginLoad(this.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;

            LoggingService.Info("Form Designer: END INITIALIZE");
        }
示例#3
0
        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();
        }