예제 #1
0
				public void SetModifiedState (UndoEngine engine, IComponent component, MemberDescriptor member)
				{
					// Console.WriteLine ("ComponentChangeAction.SetModifiedState (" + (_componentName != null ? (_componentName + ".") : "") +
					// 		   member.Name + "): " +
					// 		   (((PropertyDescriptor)member).GetValue (component) == null ? "null" :
					// 		   ((PropertyDescriptor)member).GetValue (component).ToString ()));
					ComponentSerializationService serializationService = engine.GetRequiredService (
						typeof (ComponentSerializationService)) as ComponentSerializationService;
					_afterChange = serializationService.CreateStore ();
					serializationService.SerializeMemberAbsolute (_afterChange, component, member);
					_afterChange.Close ();
				}
예제 #2
0
        /// <summary>
        /// Serializes a collection of objects and stores them in a
        /// serialization data object.
        /// </summary>
        public object Serialize(ICollection objects)
        {
            ComponentSerializationService serializationService = (ComponentSerializationService)serviceProvider.GetService(typeof(ComponentSerializationService));
            SerializationStore            store = serializationService.CreateStore();

            foreach (object value in objects)
            {
                serializationService.Serialize(store, value);
            }
            store.Close();
            return(store);
        }
        /// <summary>
        /// Serializes a collection of objects and stores them in a
        /// serialization data object.
        /// </summary>
        public object Serialize(ICollection objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }
            ComponentSerializationService serializationService = (ComponentSerializationService)serviceProvider.GetService(typeof(ComponentSerializationService));
            SerializationStore            store = serializationService.CreateStore();

            foreach (object value in objects)
            {
                serializationService.Serialize(store, value);
            }
            store.Close();
            return(store);
        }
예제 #4
0
				public ComponentAddRemoveAction (UndoEngine engine, IComponent component, bool added)
				{
					if (component == null)
						throw new ArgumentNullException ("component");
					// Console.WriteLine ((added ? "Component*Add*RemoveAction" : "ComponentAdd*Remove*Action") +
					// 		   " (" + component.Site.Name + ")");
					ComponentSerializationService serializationService = engine.GetRequiredService (
						typeof (ComponentSerializationService)) as ComponentSerializationService;

					_serializedComponent = serializationService.CreateStore ();
					serializationService.Serialize (_serializedComponent, component);
					_serializedComponent.Close ();

					_added = added;
					_componentName = component.Site.Name;
				}
예제 #5
0
 public static ICollection CopyDragObjects(ICollection objects, IServiceProvider svcProvider)
 {
     if ((objects != null) && (svcProvider != null))
     {
         Cursor current = Cursor.Current;
         try
         {
             Cursor.Current = Cursors.WaitCursor;
             ComponentSerializationService service = svcProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
             IDesignerHost host = svcProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
             if ((service != null) && (host != null))
             {
                 SerializationStore store = null;
                 store = service.CreateStore();
                 foreach (IComponent component in GetCopySelection(objects, host))
                 {
                     service.Serialize(store, component);
                 }
                 store.Close();
                 ICollection is2  = service.Deserialize(store);
                 ArrayList   list = new ArrayList(objects.Count);
                 foreach (IComponent component2 in is2)
                 {
                     Control control = component2 as Control;
                     if ((control != null) && (control.Parent == null))
                     {
                         list.Add(component2);
                     }
                     else if (control == null)
                     {
                         ToolStripItem item = component2 as ToolStripItem;
                         if ((item != null) && (item.GetCurrentParent() == null))
                         {
                             list.Add(component2);
                         }
                     }
                 }
                 return(list);
             }
         }
         finally
         {
             Cursor.Current = current;
         }
     }
     return(null);
 }
예제 #6
0
        /// <summary>
        /// Used to create copies of the objects that we are dragging in a drag operation
        /// </summary>
        public static ICollection CopyDragObjects(ICollection objects, IServiceProvider svcProvider)
        {
            if (objects == null || svcProvider == null)
            {
                Debug.Fail("Invalid parameter passed to DesignerUtils.CopyObjects.");
                return(null);
            }

            Cursor oldCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                ComponentSerializationService css = svcProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
                IDesignerHost host = svcProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

                Debug.Assert(css != null, "No component serialization service -- we cannot copy the objects");
                Debug.Assert(host != null, "No host -- we cannot copy the objects");
                if (css != null && host != null)
                {
                    SerializationStore store = null;

                    store = css.CreateStore();

                    // Get all the objects, meaning we want the children too
                    ICollection copyObjects = GetCopySelection(objects, host);

                    // The serialization service does not (yet) handle serializing collections
                    foreach (IComponent comp in copyObjects)
                    {
                        css.Serialize(store, comp);
                    }
                    store.Close();
                    copyObjects = css.Deserialize(store);

                    // Now, copyObjects contains a flattened list of all the controls contained in the original drag objects, that's not what we want to return.
                    // We only want to return the root drag objects, so that the caller gets an identical copy - identical in terms of objects.Count
                    ArrayList newObjects = new ArrayList(objects.Count);
                    foreach (IComponent comp in copyObjects)
                    {
                        Control c = comp as Control;
                        if (c != null && c.Parent == null)
                        {
                            newObjects.Add(comp);
                        }
                        else if (c == null)
                        { // this happens when we are dragging a toolstripitem
                            // TODO: Can we remove the ToolStrip specific code?
                            if (comp is ToolStripItem item && item.GetCurrentParent() == null)
                            {
                                newObjects.Add(comp);
                            }
                        }
                    }
                    Debug.Assert(newObjects.Count == objects.Count, "Why is the count of the copied objects not the same?");
                    return(newObjects);
                }
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
            return(null);
        }
예제 #7
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);
        }