Пример #1
0
				public override void Undo (UndoEngine engine)
				{
					IDesignerHost host = engine.GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
					if (_added) {
						// Console.WriteLine ("Component*Add*RemoveAction.Undo (" + _componentName + ")");
						IComponent component = host.Container.Components[_componentName];
						if (component != null) // the component might have been destroyed already
							host.DestroyComponent (component);
						_added = false;
					} else {
						// Console.WriteLine ("ComponentAdd*Remove*Action.Undo (" + _componentName + ")");
						ComponentSerializationService serializationService = engine.GetRequiredService (
							typeof (ComponentSerializationService)) as ComponentSerializationService;

						serializationService.DeserializeTo (_serializedComponent, host.Container);
						_added = true;
					}
				}
Пример #2
0
				// Reminder: _component might no longer be a valid instance
				// so one should request a new one.
				// 
				public override void Undo (UndoEngine engine)
				{
					if (_beforeChange == null) {
						// Console.WriteLine ("ComponentChangeAction.Undo: ERROR: UndoUnit is not complete.");
						return;
					}

					// Console.WriteLine ("ComponentChangeAction.Undo (" + _componentName + "." + _member.Name + ")");
					IDesignerHost host = (IDesignerHost)engine.GetRequiredService (typeof(IDesignerHost));
					_component = host.Container.Components[_componentName];

					ComponentSerializationService serializationService = engine.GetRequiredService (
						typeof (ComponentSerializationService)) as ComponentSerializationService;
					serializationService.DeserializeTo (_beforeChange, host.Container);

					SerializationStore tmp = _beforeChange;
					_beforeChange = _afterChange;
					_afterChange = tmp;
				}
Пример #3
0
        internal virtual System.Windows.Forms.ToolStripItem MorphCurrentItem(System.Type t)
        {
            System.Windows.Forms.ToolStripItem component = null;
            IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                DesignerTransaction transaction     = host.CreateTransaction(System.Design.SR.GetString("ToolStripMorphingItemTransaction"));
                ToolStrip           immediateParent = (ToolStrip)this.ImmediateParent;
                if (immediateParent is ToolStripOverflow)
                {
                    immediateParent = this.ToolStripItem.Owner;
                }
                ToolStripMenuItemDesigner designer = null;
                int    index = immediateParent.Items.IndexOf(this.ToolStripItem);
                string name  = this.ToolStripItem.Name;
                System.Windows.Forms.ToolStripItem ownerItem = null;
                if (this.ToolStripItem.IsOnDropDown)
                {
                    ToolStripDropDown down = this.ImmediateParent as ToolStripDropDown;
                    if (down != null)
                    {
                        ownerItem = down.OwnerItem;
                        if (ownerItem != null)
                        {
                            designer = (ToolStripMenuItemDesigner)host.GetDesigner(ownerItem);
                        }
                    }
                }
                try
                {
                    ToolStripDesigner._autoAddNewItems = false;
                    ComponentSerializationService service = this.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
                    SerializationStore            store   = null;
                    if (service != null)
                    {
                        store = service.CreateStore();
                        service.Serialize(store, base.Component);
                        SerializationStore    store2        = null;
                        ToolStripDropDownItem toolStripItem = this.ToolStripItem as ToolStripDropDownItem;
                        if ((toolStripItem != null) && typeof(ToolStripDropDownItem).IsAssignableFrom(t))
                        {
                            toolStripItem.HideDropDown();
                            store2 = service.CreateStore();
                            this.SerializeDropDownItems(toolStripItem, ref store2, service);
                            store2.Close();
                        }
                        store.Close();
                        IComponentChangeService service2 = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
                        if (service2 != null)
                        {
                            if (immediateParent.Site != null)
                            {
                                service2.OnComponentChanging(immediateParent, TypeDescriptor.GetProperties(immediateParent)["Items"]);
                            }
                            else if (ownerItem != null)
                            {
                                service2.OnComponentChanging(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"]);
                                service2.OnComponentChanged(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"], null, null);
                            }
                        }
                        this.FireComponentChanging(toolStripItem);
                        immediateParent.Items.Remove(this.ToolStripItem);
                        host.DestroyComponent(this.ToolStripItem);
                        System.Windows.Forms.ToolStripItem item4 = (System.Windows.Forms.ToolStripItem)host.CreateComponent(t, name);
                        if ((item4 is ToolStripDropDownItem) && (store2 != null))
                        {
                            service.Deserialize(store2);
                        }
                        service.DeserializeTo(store, host.Container, false, true);
                        component = (System.Windows.Forms.ToolStripItem)host.Container.Components[name];
                        if ((component.Image == null) && (component is ToolStripButton))
                        {
                            Image image = null;
                            try
                            {
                                image = new Bitmap(typeof(ToolStripButton), "blank.bmp");
                            }
                            catch (Exception exception)
                            {
                                if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                                {
                                    throw;
                                }
                            }
                            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)["Image"];
                            if ((descriptor != null) && (image != null))
                            {
                                descriptor.SetValue(component, image);
                            }
                            PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(component)["DisplayStyle"];
                            if (descriptor2 != null)
                            {
                                descriptor2.SetValue(component, ToolStripItemDisplayStyle.Image);
                            }
                            PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(component)["ImageTransparentColor"];
                            if (descriptor3 != null)
                            {
                                descriptor3.SetValue(component, Color.Magenta);
                            }
                        }
                        immediateParent.Items.Insert(index, component);
                        if (service2 != null)
                        {
                            if (immediateParent.Site != null)
                            {
                                service2.OnComponentChanged(immediateParent, TypeDescriptor.GetProperties(immediateParent)["Items"], null, null);
                            }
                            else if (ownerItem != null)
                            {
                                service2.OnComponentChanging(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"]);
                                service2.OnComponentChanged(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"], null, null);
                            }
                        }
                        this.FireComponentChanged(toolStripItem);
                        if (component.IsOnDropDown && (designer != null))
                        {
                            designer.RemoveItemBodyGlyph(component);
                            designer.AddItemBodyGlyph(component);
                        }
                        ToolStripDesigner._autoAddNewItems = true;
                        if (component != null)
                        {
                            if (component is ToolStripSeparator)
                            {
                                immediateParent.PerformLayout();
                            }
                            BehaviorService service3 = (BehaviorService)component.Site.GetService(typeof(BehaviorService));
                            if (service3 != null)
                            {
                                service3.Invalidate();
                            }
                            ISelectionService service4 = (ISelectionService)component.Site.GetService(typeof(ISelectionService));
                            if (service4 != null)
                            {
                                service4.SetSelectedComponents(new object[] { component }, SelectionTypes.Replace);
                            }
                        }
                    }
                    return(component);
                }
                catch
                {
                    host.Container.Add(this.ToolStripItem);
                    immediateParent.Items.Insert(index, this.ToolStripItem);
                    if (transaction != null)
                    {
                        transaction.Cancel();
                        transaction = null;
                    }
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Commit();
                        transaction = null;
                    }
                }
            }
            return(component);
        }