Example #1
0
        public override void Dispose()
        {
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   -= new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved -= new ComponentEventHandler(OnComponentAddedRemoved);
            }
        }
        protected virtual void Initialize()
        {
            _serializationMananger = new DesignerSerializationManager(_host);

            DesignSurfaceServiceContainer serviceContainer = _host.GetService(typeof(IServiceContainer)) as DesignSurfaceServiceContainer;

            if (serviceContainer != null)
            {
                serviceContainer.AddService(typeof(IDesignerLoaderService), (IDesignerLoaderService)this);
                serviceContainer.AddNonReplaceableService(typeof(IDesignerSerializationManager), _serializationMananger);
            }
        }
Example #3
0
 public static IComponent CreateComponent(IDesignerLoaderHost host, Type type, string name)
 {
     if (typeof(IComponent).IsAssignableFrom(type))
     {
         if (host != null)
         {
             INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService;
             if (cs != null)
             {
                 IVplNameService ns = cs as IVplNameService;
                 if (ns != null)
                 {
                     ns.ComponentType = type;
                 }
             }
             return(host.CreateComponent(type, name));
         }
         else
         {
             IComponent ic = (IComponent)CreateObject(type);
             ic.Site      = new XTypeSite(ic);
             ic.Site.Name = name;
             return(ic);
         }
     }
     if (host != null)
     {
         INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService;
         if (cs != null)
         {
             IVplNameService ns = cs as IVplNameService;
             if (ns != null)
             {
                 ns.ComponentType = typeof(XClass);
             }
         }
         XClass obj = (XClass)host.CreateComponent(typeof(XClass), name);
         obj.AssignType(type);
         obj.AssignValue(CreateObject(type));
         return(obj);
     }
     else
     {
         XClass obj = new XClass();
         obj.Site      = new XTypeSite(obj);
         obj.Site.Name = name;
         obj.AssignType(type);
         obj.AssignValue(CreateObject(type));
         return(obj);
     }
 }
		void SetDesignerSupportsProjectResourcesToFalse(IDesignerLoaderHost host)
		{
			ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;
			if (projectResourceService != null) {
				projectResourceService.DesignerSupportsProjectResources = false;
			}
		}
		public override void BeginLoad(IDesignerLoaderHost host)
		{
			this.loading = true;
			this.typeResolutionService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
			this.designerLoaderHost = host;
			
			base.BeginLoad(host);
		}
        public override void BeginLoad(IDesignerLoaderHost host)
        {
            this.loading = true;
            this.typeResolutionService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
            this.designerLoaderHost    = host;

            base.BeginLoad(host);
        }
        void SetDesignerSupportsProjectResourcesToFalse(IDesignerLoaderHost host)
        {
            ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;

            if (projectResourceService != null)
            {
                projectResourceService.DesignerSupportsProjectResources = false;
            }
        }
Example #8
0
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;

            if (host == null)
            {
                throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
            }

            ArrayList errors     = new ArrayList();
            bool      successful = true;
            string    baseClassName;

            if (fileName == null)
            {
                if (rootComponentType == typeof(Form))
                {
                    IComponent component = host.CreateComponent(rootComponentType);
                    (component as Form).FormBorderStyle = FormBorderStyle.None;
                    (component as Form).Size            = Screen.PrimaryScreen.Bounds.Size;
                    baseClassName = "Form1";
                }
                else if (rootComponentType == typeof(UserControl))
                {
                    host.CreateComponent(typeof(UserControl));
                    baseClassName = "UserControl1";
                }
                else if (rootComponentType == typeof(Component))
                {
                    host.CreateComponent(typeof(Component));
                    baseClassName = "Component1";
                }
                else
                {
                    throw new Exception("Undefined Host Type: " + rootComponentType.ToString());
                }
            }
            else
            {
                baseClassName = AssemblyHelper.ReadFile(fileName, errors, out xmlDocument, host);
            }

            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
            }

            host.EndLoad(baseClassName, successful, errors);

            _dirty   = true;
            _unsaved = false;
        }
Example #9
0
        public static XmlDocument WriteXmlDocument(IDesignerLoaderHost loaderHost)
        {
            XmlDocument document = new XmlDocument();

            document.AppendChild(document.CreateElement("DOCUMENT_ELEMENT"));

            IDesignerHost idh  = (IDesignerHost)loaderHost.GetService(typeof(IDesignerHost));
            IComponent    root = idh.RootComponent;

            Hashtable nametable = new Hashtable(idh.Container.Components.Count);
            IDesignerSerializationManager manager = loaderHost.GetService(typeof(IDesignerSerializationManager)) as IDesignerSerializationManager;

            document.DocumentElement.AppendChild(WriteObject(document, nametable, root, loaderHost));
            foreach (IComponent comp in idh.Container.Components)
            {
                if (comp != root && !nametable.ContainsKey(comp))
                {
                    document.DocumentElement.AppendChild(WriteObject(document, nametable, comp, loaderHost));
                }
            }
            return(document);
        }
Example #10
0
        // Called by the host when we load a document.
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;

            if (host == null)
            {
                throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
            }

            // The loader will put error messages in here.
            ArrayList errors        = new ArrayList();
            bool      successful    = true;
            string    baseClassName = "Form1";


            if (rootComponentType == typeof(Form))
            {
                //Control control = (Control)host.CreateComponent(typeof(GuiForm));

                ControlFactory factory = new ControlFactory(host, createAllOwnerDrawControls, getControlDesignerInfo, runtimeHostSurface);
                Form           form    = factory.PrepearForm(formToClone, null) as Form;
                TypeDescriptor.GetProperties(form)["Locked"].SetValue(form, true);
                baseClassName = "Form1";

                SetSerializedValues(form);

                SetVisibility(form);
            }

            // Now that we are done with the load work, we need to begin to listen to events.
            // Listening to event notifications is how a designer "Loader" can also be used
            // to save data.  If we wanted to integrate this loader with source code control,
            // we would listen to the "ing" events as well as the "ed" events.
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
            }

            // Let the host know we are done loading.
            host.EndLoad(baseClassName, successful, errors);

            // We've just loaded a document, so you can bet we need to flush changes.
            dirty   = true;
            unsaved = false;
        }
        public override void BeginLoad(IDesignerLoaderHost host)
        {
            host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host));
            host.AddService(typeof(INameCreationService), new RubyNameCreationService(host));
            host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host));

            ProjectResourceService projectResourceService = host.GetService(typeof(ProjectResourceService)) as ProjectResourceService;

            if (projectResourceService != null)
            {
                projectResourceService.DesignerSupportsProjectResources = false;
            }

            base.BeginLoad(host);
        }
Example #12
0
        // Called by the host when we load a document.
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;

            if (host == null)
            {
                throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
            }

            // The loader will put error messages in here.
            ArrayList errors     = new ArrayList();
            bool      successful = true;
            string    baseClassName;

            // If no filename was passed in, just create a form and be done with it.  If a file name
            // was passed, read it.
            if (fileName == null)
            {
                host.CreateComponent(rootComponentType);
                baseClassName = rootComponentType.Name;
            }
            else
            {
                baseClassName = ReadFile(fileName, errors, out xmlDocument);
            }

            // Now that we are done with the load work, we need to begin to listen to events.
            // Listening to event notifications is how a designer "Loader" can also be used
            // to save data.  If we wanted to integrate this loader with source code control,
            // we would listen to the "ing" events as well as the "ed" events.
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
            }

            // Let the host know we are done loading.
            host.EndLoad(baseClassName, successful, errors);

            // We've just loaded a document, so you can bet we need to flush changes.
            dirty   = true;
            unsaved = false;
        }
        protected override void Initialize()
        {
            CodeDomLocalizationModel model = FormsDesigner.Gui.OptionPanels.LocalizationModelOptionsPanel.DefaultLocalizationModel;

            if (FormsDesigner.Gui.OptionPanels.LocalizationModelOptionsPanel.KeepLocalizationModel)
            {
                // Try to find out the current localization model of the designed form
                CodeDomLocalizationModel existingModel = this.GetCurrentLocalizationModelFromDesignedFile();
                if (existingModel != CodeDomLocalizationModel.None)
                {
                    LoggingService.Debug("Determined existing localization model, using that: " + existingModel.ToString());
                    model = existingModel;
                }
                else
                {
                    LoggingService.Debug("Could not determine existing localization model, using default: " + model.ToString());
                }
            }
            else
            {
                LoggingService.Debug("Using default localization model: " + model.ToString());
            }

            CodeDomLocalizationProvider   localizationProvider = new CodeDomLocalizationProvider(designerLoaderHost, model);
            IDesignerSerializationManager manager = (IDesignerSerializationManager)designerLoaderHost.GetService(typeof(IDesignerSerializationManager));

            manager.AddSerializationProvider(new SharpDevelopSerializationProvider());
            manager.AddSerializationProvider(localizationProvider);
            base.Initialize();

            IComponentChangeService componentChangeService = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));

            if (componentChangeService != null)
            {
                LoggingService.Debug("Forms designer: Adding ComponentAdded handler for nested container setup");
                componentChangeService.ComponentAdded += ComponentContainerSetUp;
            }
            else
            {
                LoggingService.Warn("Forms designer: Cannot add ComponentAdded handler for nested container setup because IComponentChangeService is unavailable");
            }
        }
        public override void BeginLoad(IDesignerLoaderHost host)
        {
            string baseClassName;

            if (host == null)
            {
                throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
            }
            this.host = host;
            ArrayList errors     = new ArrayList();
            bool      successful = true;

            host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
            host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
            host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
            host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
            host.AddService(typeof(IResourceService), new SampleResourceService(host));
            if (this.fileName == null)
            {
                baseClassName = host.CreateComponent(typeof(Form)).Site.Name;
            }
            else
            {
                baseClassName = this.ReadFile(this.fileName, errors, out this.xmlDocument);
            }
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(this.OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddedRemoved);
            }
            host.EndLoad(baseClassName, successful, errors);
            this.dirty   = true;
            this.unsaved = false;
        }
 public override void BeginLoad(IDesignerLoaderHost host)
 {
     string baseClassName;
     if (host == null)
     {
         throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
     }
     this.host = host;
     ArrayList errors = new ArrayList();
     bool successful = true;
     host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
     host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
     host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
     host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
     host.AddService(typeof(IResourceService), new SampleResourceService(host));
     if (this.fileName == null)
     {
         baseClassName = host.CreateComponent(typeof(Form)).Site.Name;
     }
     else
     {
         baseClassName = this.ReadFile(this.fileName, errors, out this.xmlDocument);
     }
     IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
     if (cs != null)
     {
         cs.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
         cs.ComponentAdded += new ComponentEventHandler(this.OnComponentAddedRemoved);
         cs.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddedRemoved);
     }
     host.EndLoad(baseClassName, successful, errors);
     this.dirty = true;
     this.unsaved = false;
 }
Example #16
0
		// Called by the host when we load a document.
		protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
		{
			this.host = this.LoaderHost;

			if (host == null)
			{
				throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
			}

			// The loader will put error messages in here.
			ArrayList errors = new ArrayList();
			bool successful = true;
			string baseClassName;

			// If no filename was passed in, just create a form and be done with it.  If a file name
			// was passed, read it.
			if (fileName == null)
			{
                baseClassName = name;
				if (rootComponentType == typeof(Form))
				{
					host.CreateComponent(typeof(Form));
				}
				else if (rootComponentType == typeof(UserControl))
				{
					host.CreateComponent(typeof(UserControl));
				}
				else if (rootComponentType == typeof(Component))
				{
					host.CreateComponent(typeof(Component));
				}
				else
				{
					throw new Exception("Undefined Host Type: " + rootComponentType.ToString());
				}
			}
			else
			{
				baseClassName = ReadFile(fileName, errors, out xmlDocument);
			}

			// Now that we are done with the load work, we need to begin to listen to events.
			// Listening to event notifications is how a designer "Loader" can also be used
			// to save data.  If we wanted to integrate this loader with source code control,
			// we would listen to the "ing" events as well as the "ed" events.
			IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

			if (cs != null)
			{
				cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
				cs.ComponentAdded += new ComponentEventHandler(OnComponentAddedRemoved);
				cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
			}

			// Let the host know we are done loading.
			host.EndLoad(baseClassName, successful, errors);

			// We've just loaded a document, so you can bet we need to flush changes.
			dirty = true;
			unsaved = false;
		}
		// Called by the host when we load a document.
		public override void BeginLoad(IDesignerLoaderHost host) 
		{
			if (host == null) 
			{
				throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
			}

			this.host = host;

			// The loader will put error messages in here.
			//
			ArrayList errors = new ArrayList();
			bool successful = true;
			string baseClassName;
			
			// The loader is responsible for providing certain services to the host.
			//
			host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
			host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
			host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
			host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
			host.AddService(typeof(IResourceService), new SampleResourceService(host));

			// If no filename was passed in, just create a form and be done with it.  If a file name
			// was passed, read it.
			//
			if (fileName == null) 
			{
				baseClassName = host.CreateComponent(typeof(System.Windows.Forms.Form)).Site.Name;
			}
			else 
			{
				baseClassName = ReadFile(fileName, errors, out xmlDocument);
			}

			// Now that we are done with the load work, we need to begin to listen to events.
			// Listening to event notifications is how a designer "Loader" can also be used
			// to save data.  If we wanted to integrate this loader with source code control,
			// we would listen to the "ing" events as well as the "ed" events.
			//
			IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
			if (cs != null)
			{
				cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
				cs.ComponentAdded += new ComponentEventHandler(OnComponentAddedRemoved);
				cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
			}

			// Let the host know we are done loading.
			host.EndLoad(baseClassName, successful, errors);
			
			// We've just loaded a document, so you can bet we need to flush changes.
			dirty = true;
			unsaved = false;
		}