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);
 }
 internal void DisposeHost()
 {
     try
     {
         if (this._loader != null)
         {
             this._loader.Dispose();
             this.Unload();
         }
         if (this._surface != null)
         {
             if (this._designerEventService != null)
             {
                 this._designerEventService.ActiveDesignerChanged -= new ActiveDesignerEventHandler(this.OnActiveDesignerChanged);
             }
             DesignSurfaceServiceContainer service = this.GetService(typeof(DesignSurfaceServiceContainer)) as DesignSurfaceServiceContainer;
             if (service != null)
             {
                 foreach (Type type in DefaultServices)
                 {
                     service.RemoveFixedService(type);
                 }
             }
             else
             {
                 IServiceContainer container2 = this.GetService(typeof(IServiceContainer)) as IServiceContainer;
                 if (container2 != null)
                 {
                     foreach (Type type2 in DefaultServices)
                     {
                         container2.RemoveService(type2);
                     }
                 }
             }
         }
     }
     finally
     {
         this._loader = null;
         this._surface = null;
         this._events.Dispose();
     }
     base.Dispose(true);
 }
 internal void BeginLoad(DesignerLoader loader)
 {
     if ((this._loader != null) && (this._loader != loader))
     {
         Exception exception = new InvalidOperationException(System.Design.SR.GetString("DesignerHostLoaderSpecified")) {
             HelpLink = "DesignerHostLoaderSpecified"
         };
         throw exception;
     }
     IDesignerEventService service = null;
     bool flag = this._loader != null;
     this._loader = loader;
     if (!flag)
     {
         if (loader is IExtenderProvider)
         {
             IExtenderProviderService service2 = this.GetService(typeof(IExtenderProviderService)) as IExtenderProviderService;
             if (service2 != null)
             {
                 service2.AddExtenderProvider((IExtenderProvider) loader);
             }
         }
         service = this.GetService(typeof(IDesignerEventService)) as IDesignerEventService;
         if (service != null)
         {
             service.ActiveDesignerChanged += new ActiveDesignerEventHandler(this.OnActiveDesignerChanged);
             this._designerEventService = service;
         }
     }
     this._state[StateLoading] = true;
     this._surface.OnLoading();
     try
     {
         this._loader.BeginLoad(this);
     }
     catch (Exception innerException)
     {
         if (innerException is TargetInvocationException)
         {
             innerException = innerException.InnerException;
         }
         string message = innerException.Message;
         if ((message == null) || (message.Length == 0))
         {
             innerException = new Exception(System.Design.SR.GetString("DesignSurfaceFatalError", new object[] { innerException.ToString() }), innerException);
         }
         ((IDesignerLoaderHost) this).EndLoad(null, false, new object[] { innerException });
     }
     if (this._designerEventService == null)
     {
         this.OnActiveDesignerChanged(null, new ActiveDesignerEventArgs(null, this));
     }
 }
Пример #4
0
        //****
        //****
        //**** IDisposable Implementation
        //****
        //****

        ///     Disposes of the DesignContainer.  This cleans up any objects we may be holding
        ///     and removes any services that we created.
        public void Dispose() {
        
            // Dispose the loader before destroying the designer.  Otherwise, the
            // act of destroying all the components on the designer surface will
            // be reflected in the loader, deleting the user's file.
            if (designerLoader != null) {
                try 
                {
                    designerLoader.Flush();
                }
                catch (Exception e1) 
                {
                    Debug.Fail("Designer loader '" + designerLoader.GetType().Name + "' threw during Flush: " + e1.ToString());
                    e1 = null;
                }

                try {
                    designerLoader.Dispose();
                }
                catch (Exception e2) {
                    Debug.Fail("Designer loader '" + designerLoader.GetType().Name + "' threw during Dispose: " + e2.ToString());
                    e2 = null;
                }
                designerLoader = null;
            }

            // Unload the document.
            UnloadDocument();

            // No services after this!
            serviceContainer = null;

            // Now tear down all of our services.
            if (menuEditorService != null) {
                IDisposable d = menuEditorService as IDisposable;
                if (d != null) d.Dispose();
                menuEditorService = null ;
            }

            if (selectionService != null) {
                IDisposable d = selectionService as IDisposable;
                if (d != null) d.Dispose();
                selectionService = null;
            }

            if (menuCommandService != null) {
                IDisposable d = menuCommandService as IDisposable;
                if (d != null) d.Dispose();
                menuCommandService = null;
            }

			if (toolboxService != null) 
			{
				IDisposable d = toolboxService as IDisposable;
				if (d != null) d.Dispose();
				toolboxService = null;
			}

            if (helpService != null) {
                IDisposable d = helpService as IDisposable;
                if (d != null) d.Dispose();
                helpService = null;
            }

            if (referenceService != null) {
                IDisposable d = referenceService as IDisposable;
                if (d != null) d.Dispose();
                referenceService = null;
            }

            // Destroy our document window.
            if (documentWindow != null) {
                documentWindow.Dispose();
                documentWindow = null;
            }
        }
Пример #5
0
        ///    Load the contents of the designer
        public void LoadDocument(DesignerLoader designerLoader) {
            try {
                this.designerLoader = designerLoader;
                
                // Create the Design View
                documentWindow = new SampleDocumentWindow(this);

                // Load the document
                Load(false);
                
            }
            catch (Exception t) {
                Debug.Fail(t.ToString());
                throw;
            }
        }
Пример #6
0
		public void UnloadDesigner()
		{
			designSurfaceManager.ActiveDesignSurface = null;
			
			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;
		}
Пример #7
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();
		}
		void UnloadDesigner()
		{
			LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
			designSurfaceManager.ActiveDesignSurface = null;
			
			bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;
			this.UserContent = 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 {
					WorkbenchSingleton.SafeThreadAsyncCall(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();
		}
		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).CompilationUnit.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, 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");
		}
Пример #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
		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);
		}
 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;
     }
 }