コード例 #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");
 }
コード例 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_designerLoader != null)
            {
                _designerLoader.Dispose();
                _designerLoader = null;
            }
            if (_designerHost != null)
            {
                _designerHost.Dispose();
                _designerHost.DesignerLoaderHostLoaded    -= new LoadedEventHandler(OnDesignerHost_Loaded);
                _designerHost.DesignerLoaderHostLoading   -= new EventHandler(OnDesignerHost_Loading);
                _designerHost.DesignerLoaderHostUnloading -= new EventHandler(OnDesignerHost_Unloading);
                _designerHost.DesignerLoaderHostUnloaded  -= new EventHandler(OnDesignerHost_Unloaded);
                _designerHost.Activated -= new EventHandler(OnDesignerHost_Activated);
                _designerHost            = null;
            }
            if (_serviceContainer != null)
            {
                _serviceContainer.Dispose();
                _serviceContainer = null;
            }

            if (Disposed != null)
            {
                Disposed(this, EventArgs.Empty);
            }
        }
コード例 #3
0
        /// <include file='doc\DocumentManager.uex' path='docs/doc[@for="DocumentManager.CreateDesigner2"]/*' />
        /// <devdoc>
        ///     Creates a new instance of a form designer.  This takes a code stream and attempts
        ///     to create a design instance for it.
        /// </devdoc>
        public IDesignerDocument CreateDesigner(DesignerLoader loader, IServiceProvider provider)
        {
            DesignerHost dh = new DesignerHost();

            dh.Init(provider, loader);
            return(dh);
        }
コード例 #4
0
        /// <summary>
        /// Raises the <see cref="E:PropertyChanged"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Can be overridden in descendants for custom property change handling
        /// </remarks>
        public virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            // notify designer loader about the change
            this.DesignerLoader.OnPropertyChanged(this, e);

            switch (e.PropertyName)
            {
            case "name":
                OnUpdateControl();
                break;

            case "inherits":
                RemoveDesignerDefaults();
                if (DesignerLoader != null && !DesignerLoader.IsLoading && !DesignerLoader.IsSerializing)
                {
                    DesignerLoader.ReloadControls();
                }
                OnUpdateControl();
                break;

            case "SizeDimension":
                this.SuspendLayouting = true;
                try
                {
                    this.Size = this.LayoutFrameType.SizeInPixels;
                    ChangeLayoutOfDependencies();
                    this.OnPropertyChanged(new PropertyChangedEventArgs("size"));
                }
                finally
                {
                    this.SuspendLayouting = false;
                }
                break;
            }
        }
コード例 #5
0
        public void PythonDesignerLoaderCreated()
        {
            DesignerLoader loader = provider.CreateLoader(generator);

            using (IDisposable disposable = loader as IDisposable) {
                Assert.IsInstanceOf(typeof(PythonDesignerLoader), loader);
            }
        }
コード例 #6
0
        public void NoDesignerSpecified()
        {
            WixDialogDesignerLoaderProvider provider  = new WixDialogDesignerLoaderProvider();
            WixDialogDesignerGenerator      generator = new WixDialogDesignerGenerator();

            try {
                DesignerLoader loader = provider.CreateLoader(generator);
                Assert.Fail("Expected an argument exception before this line.");
            } catch (ArgumentException ex) {
                Assert.AreEqual("designer", ex.ParamName);
            }
        }
コード例 #7
0
 public void BeginLoad(DesignerLoader loader)
 {
     if (loader == null)
     {
         throw new ArgumentNullException("loader");
     }
     if (this._host == null)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     this._loadErrors = null;
     this._host.BeginLoad(loader);
 }
コード例 #8
0
        /// <summary>
        ///  This method begins the loading process with the given designer loader.  Designer loading can be asynchronous, so the loading may continue to  progress after this call has returned.  Listen to the Loaded event to know when the design surface has completed loading.
        /// </summary>
        public void BeginLoad(DesignerLoader loader)
        {
            ArgumentNullException.ThrowIfNull(loader);

            if (_host is null)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            // Create the designer host.  We need the host so we can begin the loading process.
            _loadErrors = null;
            _host.BeginLoad(loader);
        }
コード例 #9
0
 public void LoadDocument(DesignerLoader designerLoader)
 {
     try
     {
         this.designerLoader = designerLoader;
         this.documentWindow = new SampleDocumentWindow(this);
         this.Load(false);
     }
     catch (Exception t)
     {
         Debug.Fail(t.ToString());
         throw;
     }
 }
コード例 #10
0
        public void BeginLoad(DesignerLoader loader)
        {
            if (loader == null)
            {
                throw new System.ArgumentNullException("loader");
            }
            if (_designerHost == null)
            {
                throw new ObjectDisposedException("DesignSurface");
            }

            if (!_isLoaded)
            {
                _loadErrors     = null;
                _designerLoader = loader;
                this.OnLoading(EventArgs.Empty);
                _designerLoader.BeginLoad(_designerHost);
            }
        }
コード例 #11
0
        void UnloadDesigner()
        {
            LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
            designSurfaceManager.ActiveDesignSurface = null;
            timer.Stop();

            bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;

            this.UserContent = this.pleaseWaitLabel;
            if (this.DesignerCodeFile != null)
            {
                this.DesignerCodeFile.IsDirty = savedIsDirty;
            }

            if (designSurface != null)
            {
                designSurface.Loading   -= this.DesignerLoading;
                designSurface.Loaded    -= this.DesignerLoaded;
                designSurface.Flushed   -= this.DesignerFlushed;
                designSurface.Unloading -= this.DesignerUnloading;

                IComponentChangeService componentChangeService = designSurface.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (componentChangeService != null)
                {
                    componentChangeService.ComponentChanged -= ComponentChanged;
                    componentChangeService.ComponentAdded   -= ComponentListChanged;
                    componentChangeService.ComponentRemoved -= ComponentListChanged;
                    componentChangeService.ComponentRename  -= ComponentListChanged;
                }
                if (this.Host != null)
                {
                    this.Host.TransactionClosed -= TransactionClose;
                }

                ISelectionService selectionService = designSurface.GetService(typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged -= SelectionChangedHandler;
                }

                designSurface.Unloaded += delegate {
                    ServiceContainer serviceContainer = designSurface.GetService(typeof(ServiceContainer)) as ServiceContainer;
                    if (serviceContainer != null)
                    {
                        // Workaround for .NET bug: .NET unregisters the designer host only if no component throws an exception,
                        // but then in a finally block assumes that the designer host is already unloaded.
                        // Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
                        // when any component throws an exception.

                        // See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
                        // Reproducible with a custom control that has a designer that crashes on unloading
                        // e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx

                        // We work around this problem by unregistering the designer host manually.
                        try {
                            var services = (Dictionary <Type, object>) typeof(ServiceContainer).InvokeMember(
                                "Services",
                                BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic,
                                null, serviceContainer, null);
                            foreach (var pair in services.ToArray())
                            {
                                if (pair.Value is IDesignerHost)
                                {
                                    serviceContainer.GetType().InvokeMember(
                                        "RemoveFixedService",
                                        BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
                                        null, serviceContainer, new object[] { pair.Key });
                                }
                            }
                        } catch (Exception ex) {
                            LoggingService.Error(ex);
                        }
                    }
                };
                try {
                    designSurface.Dispose();
                } catch (ExceptionCollection exceptions) {
                    foreach (Exception ex in exceptions.Exceptions)
                    {
                        LoggingService.Error(ex);
                    }
                } finally {
                    designSurface = null;
                }
            }

            this.typeResolutionService = null;
            this.loader = null;
            UpdatePropertyPad();

            foreach (KeyValuePair <Type, TypeDescriptionProvider> entry in this.addedTypeDescriptionProviders)
            {
                TypeDescriptor.RemoveProvider(entry.Value, entry.Key);
            }
            this.addedTypeDescriptionProviders.Clear();
        }
コード例 #12
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();
        }
コード例 #13
0
 public IComponent CreateRootComponent(DesignerLoader loader, Size controlSize)
 {
     return(CreateRootComponentCore(null, controlSize, loader));
 }
コード例 #14
0
 public VsCodeDomLoader(DesignerLoader loader, IVsHierarchy hier, int itemid, CodeDomProvider provider, TextBuffer buffer, IDesignerLoaderHost host) : base(loader, provider, buffer, host)
 {
     this.vsHierarchy = hier;
     this.itemid      = itemid;
 }
コード例 #15
0
        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");
        }
コード例 #16
0
 public void BeginLoad(DesignerLoader loader)
 {
     throw null;
 }
コード例 #17
0
        public void Dispose()
        {
            IDisposable d;

            if (this.designerLoader != null)
            {
                try
                {
                    this.designerLoader.Flush();
                }
                catch (Exception e1)
                {
                    Debug.Fail("Designer loader '" + this.designerLoader.GetType().Name + "' threw during Flush: " + e1.ToString());
                    e1 = null;
                }
                try
                {
                    this.designerLoader.Dispose();
                }
                catch (Exception e2)
                {
                    Debug.Fail("Designer loader '" + this.designerLoader.GetType().Name + "' threw during Dispose: " + e2.ToString());
                    e2 = null;
                }
                this.designerLoader = null;
            }
            this.UnloadDocument();
            this.serviceContainer = null;
            if (this.menuEditorService != null)
            {
                d = this.menuEditorService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.menuEditorService = null;
            }
            if (this.selectionService != null)
            {
                d = this.selectionService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.selectionService = null;
            }
            if (this.menuCommandService != null)
            {
                d = this.menuCommandService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.menuCommandService = null;
            }
            if (this.toolboxService != null)
            {
                d = this.toolboxService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.toolboxService = null;
            }
            if (this.helpService != null)
            {
                d = this.helpService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.helpService = null;
            }
            if (this.referenceService != null)
            {
                d = this.referenceService as IDisposable;
                if (d != null)
                {
                    d.Dispose();
                }
                this.referenceService = null;
            }
            if (this.documentWindow != null)
            {
                this.documentWindow.Dispose();
                this.documentWindow = null;
            }
        }
コード例 #18
0
 /// <include file='doc\DocumentManager.uex' path='docs/doc[@for="DocumentManager.CreateDesigner"]/*' />
 /// <devdoc>
 ///     Creates a new instance of a form designer.  This takes a code stream and attempts
 ///     to create a design instance for it.
 /// </devdoc>
 public IDesignerDocument CreateDesigner(DesignerLoader loader)
 {
     return(CreateDesigner(loader, provider));
 }
コード例 #19
0
        /// <include file='doc\DesignerEditorFactory.uex' path='docs/doc[@for="DesignerEditorFactory.CreateEditorInstance"]/*' />
        /// <devdoc>
        ///     Creates a new editor for the given pile of flags.
        /// </devdoc>
        public virtual int CreateEditorInstance(int vscreateeditorflags, string fileName, string physicalView,
                                                IVsHierarchy hierarchy, int itemid, object existingDocData,
                                                out object docView, out object docData,
                                                out string caption, out Guid cmdUIGuid)
        {
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            IVsTextStream textStream = null;          // the buffer we will use

            // We support a design view only
            //
            if (physicalView == null || !physicalView.Equals(physicalViewName))
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : Invalid physical view name.");
                throw new COMException("Invalid physical view", NativeMethods.E_NOTIMPL);
            }

            // perform parameter validation and initialization.
            //
            if (((vscreateeditorflags & (__VSCREATEEDITORFLAGS.CEF_OPENFILE | __VSCREATEEDITORFLAGS.CEF_SILENT)) == 0))
            {
                throw new ArgumentException("vscreateeditorflags");
            }

            docView = null;
            docData = null;
            caption = null;

            IVSMDDesignerService ds = (IVSMDDesignerService)serviceProvider.GetService(typeof(IVSMDDesignerService));

            if (ds == null)
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : No designer service.");
                throw new Exception(SR.GetString(SR.EDITORNoDesignerService, fileName));
            }

            // Create our doc data if we don't have an existing one.
            //
            if (existingDocData == null)
            {
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "EditorFactory : No existing doc data, creating one.");
                ILocalRegistry localRegistry = (ILocalRegistry)serviceProvider.GetService(typeof(ILocalRegistry));
                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tobtained local registry");

                if (localRegistry == null)
                {
                    Debug.Fail("Shell did not offer local registry, so we can't create a text buffer.");
                    throw new COMException("Unable to create text buffer", NativeMethods.E_FAIL);
                }

                Debug.Assert(!(typeof(VsTextBuffer)).GUID.Equals(Guid.Empty), "EE has munched on text buffer guid.");

                try {
                    Guid guidTemp = typeof(IVsTextStream).GUID;
                    textStream = (IVsTextStream)localRegistry.CreateInstance(typeof(VsTextBuffer).GUID,
                                                                             null,
                                                                             ref guidTemp,
                                                                             NativeMethods.CLSCTX_INPROC_SERVER);
                }
                #if DEBUG
                catch (ExternalException ex) {
                    Guid SID_VsTextBuffer  = typeof(VsTextBuffer).GUID;
                    Guid IID_IVsTextStream = typeof(IVsTextStream).GUID;
                    Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tILocalRegistry.CreateInstance(" + SID_VsTextBuffer.ToString() + ", " + IID_IVsTextStream.ToString() + ") failed (hr=" + ex.ErrorCode.ToString() + ")");
                #else
                catch (Exception) {
                #endif
                    throw new COMException("Failed to create text buffer", NativeMethods.E_FAIL);
                }

                Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tcreated text buffer");
            }
            else
            {
                Debug.Assert(existingDocData is IVsTextStream, "Existing doc data must implement IVsTextStream");
                textStream = (IVsTextStream)existingDocData;
            }

            // Create and initialize our code stream.
            //
            object loaderObj = ds.CreateDesignerLoader(ds.GetDesignerLoaderClassForFile(fileName));

            // Before we embark on creating the designer, we need to do a quick check
            // to see if this file can be designed.  If it can't be we will fail this
            // editor create, and the shell will go on to the next editor in the list.
            //
            Debug.Assert(loaderObj is DesignerLoader, "loader must inherit from DesignerLoader: " + loaderObj.GetType().FullName);
            Debug.Assert(loaderObj is IVSMDDesignerLoader, "code stream must implement IVSMDDesignerLoader: " + loaderObj.GetType().FullName);
            NativeMethods.IOleServiceProvider oleProvider = (NativeMethods.IOleServiceProvider)serviceProvider.GetService(typeof(NativeMethods.IOleServiceProvider));
            ((IVSMDDesignerLoader)loaderObj).Initialize(oleProvider, hierarchy, itemid, textStream);

            DesignerLoader loader = (DesignerLoader)loaderObj;

            if (existingDocData == null)
            {
                if (textStream is NativeMethods.IObjectWithSite)
                {
                    ((NativeMethods.IObjectWithSite)textStream).SetSite(site);
                    Debug.WriteLineIf(Switches.TRACEEDIT.TraceVerbose, "\tsited text buffer");
                }
            }

            // Now slam the two together and make a designer
            //
            IVSMDDesigner designer = ds.CreateDesigner(oleProvider, loader);
            Debug.Assert(designer != null, "Designer service should have thrown if it had a problem.");

            // Now ask for the view and setup our out-parameters
            //
            int attrs = NativeMethods.GetFileAttributes(fileName);
            if ((attrs & NativeMethods.FILE_ATTRIBUTE_READONLY) != 0)
            {
                attrs = _READONLYSTATUS.ROSTATUS_ReadOnly;
            }
            else
            {
                attrs = _READONLYSTATUS.ROSTATUS_NotReadOnly;
            }

            docView   = designer.View;
            docData   = textStream;
            caption   = ((IVSMDDesignerLoader)loaderObj).GetEditorCaption(attrs);
            cmdUIGuid = designer.CommandGuid;

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

            return(0);
        }
コード例 #20
0
        private IComponent CreateRootComponentCore(Type controlType, Size controlSize, DesignerLoader loader)
        {
            const string _signature_ = _Name_ + @"::CreateRootComponentCore()";

            try {
                //- step.1
                //- get the IDesignerHost
                //- if we are not not able to get it
                //- then rollback (return without do nothing)
                IDesignerHost host = GetIDesignerHost();
                if (null == host)
                {
                    return(null);
                }
                //- check if the root component has already been set
                //- if so then rollback (return without do nothing)
                if (null != host.RootComponent)
                {
                    return(null);
                }
                //-
                //-
                //- step.2
                //- create a new root component and initialize it via its designer
                //- if the component has not a designer
                //- then rollback (return without do nothing)
                //- else do the initialization
                if (null != loader)
                {
                    this.BeginLoad(loader);
                    if (this.LoadErrors.Count > 0)
                    {
                        throw new Exception(_signature_ + " - Exception: the BeginLoad(loader) failed!");
                    }
                }
                else
                {
                    this.BeginLoad(controlType);
                    if (this.LoadErrors.Count > 0)
                    {
                        throw new Exception(_signature_ + " - Exception: the BeginLoad(Type) failed! Some error during " + controlType.ToString() + " loading");
                    }
                }
                //-
                //-
                //- step.3
                //- try to modify the Size of the object just created
                IDesignerHost ihost = GetIDesignerHost();
                //- Set the backcolor and the Size
                Control ctrl = null;
                if (host.RootComponent is  Form)
                {
                    ctrl           = this.View as Control;
                    ctrl.BackColor = Color.LightGray;
                    //- set the Size
                    PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ctrl);
                    //- Sets a PropertyDescriptor to the specific property
                    PropertyDescriptor pdS = pdc.Find("Size", false);
                    if (null != pdS)
                    {
                        pdS.SetValue(ihost.RootComponent, controlSize);
                    }
                }
                else if (host.RootComponent is UserControl)
                {
                    ctrl           = this.View as Control;
                    ctrl.BackColor = Color.Gray;
                    //- set the Size
                    PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ctrl);
                    //- Sets a PropertyDescriptor to the specific property
                    PropertyDescriptor pdS = pdc.Find("Size", false);
                    if (null != pdS)
                    {
                        pdS.SetValue(ihost.RootComponent, controlSize);
                    }
                }
                else if (host.RootComponent is  Control)
                {
                    ctrl           = this.View as Control;
                    ctrl.BackColor = Color.LightGray;
                    //- set the Size
                    PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ctrl);
                    //- Sets a PropertyDescriptor to the specific property
                    PropertyDescriptor pdS = pdc.Find("Size", false);
                    if (null != pdS)
                    {
                        pdS.SetValue(ihost.RootComponent, controlSize);
                    }
                }
                else if (host.RootComponent is  Component)
                {
                    ctrl           = this.View as Control;
                    ctrl.BackColor = Color.White;
                    //- don't set the Size
                }
                else
                {
                    //- Undefined Host Type
                    ctrl           = this.View as Control;
                    ctrl.BackColor = Color.Red;
                }

                return(ihost.RootComponent);
            }//end_try
            catch (Exception exx) {
                Debug.WriteLine(exx.Message);
                if (null != exx.InnerException)
                {
                    Debug.WriteLine(exx.InnerException.Message);
                }

                throw;
            }//end_catch
        }
コード例 #21
0
        void UnloadDesigner()
        {
            LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
            designSurfaceManager.ActiveDesignSurface = null;

            bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;

            this.UserControl = this.pleaseWaitLabel;
            Application.DoEvents();
            if (this.DesignerCodeFile != null)
            {
                this.DesignerCodeFile.IsDirty = savedIsDirty;
            }

            // We cannot dispose the design surface now because of SD2-451:
            // When the switch to the source view was triggered by a double-click on an event
            // in the PropertyPad, "InvalidOperationException: The container cannot be disposed
            // at design time" is thrown.
            // This is solved by calling dispose after the double-click event has been processed.
            if (designSurface != null)
            {
                designSurface.Loading   -= this.DesignerLoading;
                designSurface.Loaded    -= this.DesignerLoaded;
                designSurface.Flushed   -= this.DesignerFlushed;
                designSurface.Unloading -= this.DesignerUnloading;

                IComponentChangeService componentChangeService = designSurface.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (componentChangeService != null)
                {
                    componentChangeService.ComponentChanged -= ComponentChanged;
                    componentChangeService.ComponentAdded   -= ComponentListChanged;
                    componentChangeService.ComponentRemoved -= ComponentListChanged;
                    componentChangeService.ComponentRename  -= ComponentListChanged;
                }
                if (this.Host != null)
                {
                    this.Host.TransactionClosed -= TransactionClose;
                }

                ISelectionService selectionService = designSurface.GetService(typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged -= SelectionChangedHandler;
                }

                if (disposing)
                {
                    designSurface.Dispose();
                }
                else
                {
                    this.Control.BeginInvoke(new MethodInvoker(designSurface.Dispose));
                }
                designSurface = null;
            }

            this.typeResolutionService = null;
            this.loader = null;

            foreach (KeyValuePair <Type, TypeDescriptionProvider> entry in this.addedTypeDescriptionProviders)
            {
                TypeDescriptor.RemoveProvider(entry.Value, entry.Key);
            }
            this.addedTypeDescriptionProviders.Clear();
        }
コード例 #22
0
        private IComponent CreateRootComponentCore(Type controlType, string name, Size controlSize, DesignerLoader loader)
        {
            const string _signature_ = _name + @"::CreateRootComponentCore()";

            try
            {   //- step.1
                //- Get the IDesignerHost, if we are not not able to get it, then rollback (return without do nothing)
                //- Check if the root component has already been set, if so then rollback (return without do nothing)
                IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (null == host || null != host.RootComponent)
                {
                    return(null);
                }


                //- step.2
                //- Create a new root component and initialize it via its designer, if the component has not a designer
                //- then rollback (return without do nothing), else do the initialization
                if (null != loader)
                {
                    this.BeginLoad(loader);
                }
                else
                {
                    this.BeginLoad(controlType);
                }
                if (this.LoadErrors.Count > 0)
                {
                    throw new Exception(_signature_ + $" - Exception: the BeginLoad failed!");
                }

                //- step.3
                //- try to modify the Size of the object just created
                //IDesignerHost ihost = GetIDesignerHost();
                //- Set the backcolor and the Size
                Control ctrl = this.View as Control;
                if (host.RootComponent is Control) // Form, UserControl, Panel, Control
                {
                    ctrl.BackColor = Color.LightGray;
                    PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ctrl);  //- set the Size
                    pdc.Find("Size", false)?.SetValue(host.RootComponent, controlSize);
                }
                else if (host.RootComponent is Component) // Timer, ImageList
                {
                    ctrl.BackColor = Color.White;
                }
                else     //- Undefined Host Type
                {
                    ctrl.BackColor = Color.Red;
                }
                if (!string.IsNullOrEmpty(name))
                {
                    if (host.RootComponent.Site != null)
                    {
                        host.RootComponent.Site.Name = name;
                    }
                }
                return(host.RootComponent);
            }
            catch (Exception exx)
            {
                Debug.WriteLine(exx.Message);
                if (null != exx.InnerException)
                {
                    Debug.WriteLine(exx.InnerException.Message);
                }
                throw;
            }
        }