예제 #1
0
        private void InsertToolStripItem(System.Type t)
        {
            IDesignerHost       host        = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));
            ToolStrip           parentTool  = this.ParentTool;
            int                 index       = parentTool.Items.IndexOf(this.currentItem);
            IDesigner           designer    = null;
            DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("ToolStripAddingItem"));

            try
            {
                ToolStripDesigner._autoAddNewItems = false;
                IComponent component = host.CreateComponent(t);
                designer = host.GetDesigner(component);
                if (designer is ComponentDesigner)
                {
                    ((ComponentDesigner)designer).InitializeNewComponent(null);
                }
                if (((component is ToolStripButton) || (component is ToolStripSplitButton)) || (component is ToolStripDropDownButton))
                {
                    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);
                    }
                }
                parentTool.Items.Insert(index, (ToolStripItem)component);
                ISelectionService service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                if (service != null)
                {
                    service.SetSelectedComponents(new object[] { component }, SelectionTypes.Replace);
                }
            }
            catch (Exception exception2)
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                if (System.Windows.Forms.ClientUtils.IsCriticalException(exception2))
                {
                    throw;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
                ToolStripDesigner._autoAddNewItems = true;
                ToolStripDropDown down = parentTool as ToolStripDropDown;
                if ((down != null) && down.Visible)
                {
                    ToolStripDropDownItem ownerItem = down.OwnerItem as ToolStripDropDownItem;
                    if (ownerItem != null)
                    {
                        ToolStripMenuItemDesigner designer2 = host.GetDesigner(ownerItem) as ToolStripMenuItemDesigner;
                        if (designer2 != null)
                        {
                            designer2.ResetGlyphs(ownerItem);
                        }
                    }
                }
            }
        }
        /// <summary>
        ///  Here is where all the fun stuff starts.  We create the structure and apply the naming here.
        /// </summary>
        private void CreateStandardMenuStrip(IDesignerHost host, MenuStrip tool)
        {
            // build the static menu items structure.
            string[][] menuItemNames = new string[][]
            {
                new string[] { SR.StandardMenuFile, SR.StandardMenuNew, SR.StandardMenuOpen, "-", SR.StandardMenuSave, SR.StandardMenuSaveAs, "-", SR.StandardMenuPrint, SR.StandardMenuPrintPreview, "-", SR.StandardMenuExit },
                new string[] { SR.StandardMenuEdit, SR.StandardMenuUndo, SR.StandardMenuRedo, "-", SR.StandardMenuCut, SR.StandardMenuCopy, SR.StandardMenuPaste, "-", SR.StandardMenuSelectAll },
                new string[] { SR.StandardMenuTools, SR.StandardMenuCustomize, SR.StandardMenuOptions },
                new string[] { SR.StandardMenuHelp, SR.StandardMenuContents, SR.StandardMenuIndex, SR.StandardMenuSearch, "-", SR.StandardMenuAbout }
            };

            // build the static menu items image list that maps one-one with above menuItems structure. this is required so that the in LOCALIZED build we dont use the Localized item string.
            string[][] menuItemImageNames = new string[][]
            {
                new string[] { "", "new", "open", "-", "save", "", "-", "print", "printPreview", "-", "" },
                new string[] { "", "", "", "-", "cut", "copy", "paste", "-", "" },
                new string[] { "", "", "" },
                new string[] { "", "", "", "", "-", "" }
            };

            Keys[][] menuItemShortcuts = new Keys[][]
            {
                new Keys[] { /*File*/ Keys.None, /*New*/ Keys.Control | Keys.N, /*Open*/ Keys.Control | Keys.O, /*Separator*/ Keys.None, /*Save*/ Keys.Control | Keys.S, /*SaveAs*/ Keys.None, Keys.None, /*Print*/ Keys.Control | Keys.P, /*PrintPreview*/ Keys.None, /*Separator*/ Keys.None, /*Exit*/ Keys.None },
                new Keys[] { /*Edit*/ Keys.None, /*Undo*/ Keys.Control | Keys.Z, /*Redo*/ Keys.Control | Keys.Y, /*Separator*/ Keys.None, /*Cut*/ Keys.Control | Keys.X, /*Copy*/ Keys.Control | Keys.C, /*Paste*/ Keys.Control | Keys.V, /*Separator*/ Keys.None, /*SelectAll*/ Keys.None },
                new Keys[] { /*Tools*/ Keys.None, /*Customize*/ Keys.None, /*Options*/ Keys.None },
                new Keys[] { /*Help*/ Keys.None, /*Contents*/ Keys.None, /*Index*/ Keys.None, /*Search*/ Keys.None, /*Separator*/ Keys.None, /*About*/ Keys.None }
            };

            Debug.Assert(host != null, "can't create standard menu without designer _host.");
            if (host is null)
            {
                return;
            }

            tool.SuspendLayout();
            ToolStripDesigner.s_autoAddNewItems = false;
            // create a transaction so this happens as an atomic unit.
            DesignerTransaction createMenu = _host.CreateTransaction(SR.StandardMenuCreateDesc);

            try
            {
                INameCreationService nameCreationService = (INameCreationService)_provider.GetService(typeof(INameCreationService));
                string defaultName = "standardMainMenuStrip";
                string name        = defaultName;
                int    index       = 1;

                if (host != null)
                {
                    while (_host.Container.Components[name] != null)
                    {
                        name = defaultName + (index++).ToString(CultureInfo.InvariantCulture);
                    }
                }

                // now build the menu items themselves.
                for (int j = 0; j < menuItemNames.Length; j++)
                {
                    string[]          menuArray = menuItemNames[j];
                    ToolStripMenuItem rootItem  = null;
                    for (int i = 0; i < menuArray.Length; i++)
                    {
                        name = null;
                        // for separators, just use the default name.  Otherwise, remove any non-characters and  get the name from the text.
                        string itemText = menuArray[i];
                        name = NameFromText(itemText, typeof(ToolStripMenuItem), nameCreationService, true);
                        ToolStripItem item = null;
                        if (name.Contains("Separator"))
                        {
                            // create the componennt.
                            item = (ToolStripSeparator)_host.CreateComponent(typeof(ToolStripSeparator), name);
                            IDesigner designer = _host.GetDesigner(item);
                            if (designer is ComponentDesigner)
                            {
                                ((ComponentDesigner)designer).InitializeNewComponent(null);
                            }

                            item.Text = itemText;
                        }
                        else
                        {
                            // create the componennt.
                            item = (ToolStripMenuItem)_host.CreateComponent(typeof(ToolStripMenuItem), name);
                            IDesigner designer = _host.GetDesigner(item);
                            if (designer is ComponentDesigner)
                            {
                                ((ComponentDesigner)designer).InitializeNewComponent(null);
                            }

                            item.Text = itemText;
                            Keys shortcut = menuItemShortcuts[j][i];
                            if ((item is ToolStripMenuItem) && shortcut != Keys.None)
                            {
                                if (!ToolStripManager.IsShortcutDefined(shortcut) && ToolStripManager.IsValidShortcut(shortcut))
                                {
                                    ((ToolStripMenuItem)item).ShortcutKeys = shortcut;
                                }
                            }

                            Bitmap image = null;
                            try
                            {
                                image = GetImage(menuItemImageNames[j][i]);
                            }
                            catch
                            {
                                // eat the exception.. as you may not find image for all MenuItems.
                            }

                            if (image != null)
                            {
                                PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(item)["Image"];
                                Debug.Assert(imageProperty != null, "Could not find 'Image' property in ToolStripItem.");
                                if (imageProperty != null)
                                {
                                    imageProperty.SetValue(item, image);
                                }

                                item.ImageTransparentColor = Color.Magenta;
                            }
                        }

                        // the first item in each array is the root item.
                        if (i == 0)
                        {
                            rootItem = (ToolStripMenuItem)item;
                            rootItem.DropDown.SuspendLayout();
                        }
                        else
                        {
                            rootItem.DropDownItems.Add(item);
                        }

                        //If Last SubItem Added the Raise the Events
                        if (i == menuArray.Length - 1)
                        {
                            // member is OK to be null...
                            MemberDescriptor member = TypeDescriptor.GetProperties(rootItem)["DropDownItems"];
                            _componentChangeSvc.OnComponentChanging(rootItem, member);
                            _componentChangeSvc.OnComponentChanged(rootItem, member, null, null);
                        }
                    }

                    // finally, add it to the MainMenu.
                    rootItem.DropDown.ResumeLayout(false);
                    tool.Items.Add(rootItem);
                    //If Last SubItem Added the Raise the Events
                    if (j == menuItemNames.Length - 1)
                    {
                        // member is OK to be null...
                        MemberDescriptor topMember = TypeDescriptor.GetProperties(tool)["Items"];
                        _componentChangeSvc.OnComponentChanging(tool, topMember);
                        _componentChangeSvc.OnComponentChanged(tool, topMember, null, null);
                    }
                }
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService));
                    uiService.ShowError(e.Message);
                }

                if (createMenu != null)
                {
                    createMenu.Cancel();
                    createMenu = null;
                }
            }
            finally
            {
                ToolStripDesigner.s_autoAddNewItems = true;
                if (createMenu != null)
                {
                    createMenu.Commit();
                    createMenu = null;
                }

                tool.ResumeLayout();
                // Select the Main Menu...
                ISelectionService selSvc = (ISelectionService)_provider.GetService(typeof(ISelectionService));
                if (selSvc != null)
                {
                    selSvc.SetSelectedComponents(new object[] { _designer.Component });
                }

                //Refresh the Glyph
                DesignerActionUIService actionUIService = (DesignerActionUIService)_provider.GetService(typeof(DesignerActionUIService));
                if (actionUIService != null)
                {
                    actionUIService.Refresh(_designer.Component);
                }

                // this will invalidate the Selection Glyphs.
                SelectionManager selMgr = (SelectionManager)_provider.GetService(typeof(SelectionManager));
                selMgr.Refresh();
            }
        }
예제 #3
0
        // This method is called when a user double-clicks (the representation of) a component.
        // Tries to bind the default event to a method or creates a new one.
        //
        public virtual void DoDefaultAction()
        {
            IDesignerHost       host        = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            DesignerTransaction transaction = null;

            if (host != null)
            {
                transaction = host.CreateTransaction("ComponentDesigner_AddEvent");
            }

            IEventBindingService eventBindingService    = GetService(typeof(IEventBindingService)) as IEventBindingService;
            EventDescriptor      defaultEventDescriptor = null;

            if (eventBindingService != null)
            {
                ISelectionService selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService;
                try {
                    if (selectionService != null)
                    {
                        ICollection selectedComponents = selectionService.GetSelectedComponents();

                        foreach (IComponent component in selectedComponents)
                        {
                            EventDescriptor eventDescriptor = TypeDescriptor.GetDefaultEvent(component);
                            if (eventDescriptor != null)
                            {
                                PropertyDescriptor eventProperty = eventBindingService.GetEventProperty(eventDescriptor);
                                if (eventProperty != null && !eventProperty.IsReadOnly)
                                {
                                    string methodName = eventProperty.GetValue(component) as string;
                                    bool   newMethod  = true;

                                    if (methodName != null || methodName != String.Empty)
                                    {
                                        ICollection compatibleMethods = eventBindingService.GetCompatibleMethods(eventDescriptor);
                                        foreach (string signature in compatibleMethods)
                                        {
                                            if (signature == methodName)
                                            {
                                                newMethod = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (newMethod)
                                    {
                                        if (methodName == null)
                                        {
                                            methodName = eventBindingService.CreateUniqueMethodName(component, eventDescriptor);
                                        }

                                        eventProperty.SetValue(component, methodName);
                                    }

                                    if (component == _component)
                                    {
                                        defaultEventDescriptor = eventDescriptor;
                                    }
                                }
                            }
                        }
                    }
                }
                catch {
                    if (transaction != null)
                    {
                        transaction.Cancel();
                        transaction = null;
                    }
                }
                finally {
                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                }

                if (defaultEventDescriptor != null)
                {
                    eventBindingService.ShowCode(_component, defaultEventDescriptor);
                }
            }
        }
예제 #4
0
        internal virtual void x46ff430ed3944e0f(xedb4922162c60d3d.DockTarget x11d58b056c032b03)
        {
            IComponentChangeService service1 = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
            bool flag;

            if ((uint)flag - (uint)flag > uint.MaxValue)
            {
                goto label_36;
            }
            else
            {
                goto label_37;
            }
label_1:
            bool x49cf4e0157d9436c;

            if ((uint)x49cf4e0157d9436c + (uint)x49cf4e0157d9436c > uint.MaxValue || x11d58b056c032b03.type == xedb4922162c60d3d.DockTargetType.AlreadyActioned)
            {
                return;
            }
            IDesignerHost       service2;
            DesignerTransaction transaction = service2.CreateTransaction("Move DockControl");
            ControlLayoutSystem xf333586e50dccad2;
            DockControl         selectedControl;
            ISelectionService   service3;

            try
            {
                if (this.x0467b00af7810f0c.Manager != null)
                {
                    goto label_32;
                }
label_31:
                Control control1 = (Control)null;
                goto label_33;
label_32:
                control1 = this.x0467b00af7810f0c.Manager.DockSystemContainer;
label_33:
                Control control2 = control1;
label_28:
                if ((uint)x49cf4e0157d9436c + (uint)x49cf4e0157d9436c > uint.MaxValue)
                {
                    goto label_5;
                }
                else
                {
                    goto label_29;
                }
label_4:
                service1.OnComponentChanged((object)control2, (MemberDescriptor)TypeDescriptor.GetProperties((object)control2)["Controls"], (object)null, (object)null);
label_5:
                transaction.Commit();
                if (((x49cf4e0157d9436c ? 1 : 0) | int.MaxValue) != 0)
                {
                    if (true)
                    {
                        return;
                    }
                    goto label_31;
                }
                else
                {
                    goto label_14;
                }
label_10:
                if (x11d58b056c032b03.dockContainer == null)
                {
                    if (x11d58b056c032b03.type == xedb4922162c60d3d.DockTargetType.CreateNewContainer)
                    {
                        if (control2 != null)
                        {
                            goto label_9;
                        }
label_7:
                        xf333586e50dccad2.x6b145af772038ef2(selectedControl.Manager, selectedControl, x49cf4e0157d9436c, x11d58b056c032b03);
                        service2.Container.Add((IComponent)selectedControl.LayoutSystem.DockContainer);
                        if (control2 != null)
                        {
                            goto label_4;
                        }
                        else
                        {
                            goto label_5;
                        }
label_9:
                        service1.OnComponentChanging((object)control2, (MemberDescriptor)TypeDescriptor.GetProperties((object)control2)["Controls"]);
                        if (true)
                        {
                            goto label_7;
                        }
                        else
                        {
                            goto label_4;
                        }
                    }
                    else
                    {
                        goto label_5;
                    }
                }
                else
                {
                    service1.OnComponentChanging((object)x11d58b056c032b03.dockContainer, (MemberDescriptor)TypeDescriptor.GetProperties((object)x11d58b056c032b03.dockContainer)["LayoutSystem"]);
                    xf333586e50dccad2.x6b145af772038ef2(x11d58b056c032b03.dockContainer.Manager, selectedControl, x49cf4e0157d9436c, x11d58b056c032b03);
                    service1.OnComponentChanged((object)x11d58b056c032b03.dockContainer, (MemberDescriptor)TypeDescriptor.GetProperties((object)x11d58b056c032b03.dockContainer)["LayoutSystem"], (object)null, (object)null);
                    goto label_5;
                }
label_14:
                service1.OnComponentChanged((object)control2, (MemberDescriptor)TypeDescriptor.GetProperties((object)control2)["Controls"], (object)null, (object)null);
label_27:
                if (((x49cf4e0157d9436c ? 1 : 0) | int.MaxValue) != 0)
                {
                    goto label_10;
                }
                else
                {
                    goto label_28;
                }
label_29:
                if (false)
                {
                    goto label_20;
                }
                else
                {
                    goto label_22;
                }
label_18:
                do
                {
                    service1.OnComponentChanging((object)this.x0467b00af7810f0c, (MemberDescriptor)TypeDescriptor.GetProperties((object)this.x0467b00af7810f0c)["Manager"]);
                    service1.OnComponentChanging((object)this.x0467b00af7810f0c, (MemberDescriptor)TypeDescriptor.GetProperties((object)this.x0467b00af7810f0c)["LayoutSystem"]);
                    if (!x49cf4e0157d9436c)
                    {
                        if (true)
                        {
                            LayoutUtilities.xf1cbd48a28ce6e74(selectedControl);
                            if (true)
                            {
                                goto label_26;
                            }
                        }
                        else
                        {
                            goto label_31;
                        }
                    }
                    else
                    {
                        goto label_19;
                    }
                }while ((uint)x49cf4e0157d9436c + (uint)x49cf4e0157d9436c < 0U);
                goto label_22;
label_13:
                service1.OnComponentChanged((object)this.x0467b00af7810f0c, (MemberDescriptor)TypeDescriptor.GetProperties((object)this.x0467b00af7810f0c)["LayoutSystem"], (object)null, (object)null);
                service1.OnComponentChanged((object)this.x0467b00af7810f0c, (MemberDescriptor)TypeDescriptor.GetProperties((object)this.x0467b00af7810f0c)["Manager"], (object)null, (object)null);
                if (control2 == null)
                {
                    goto label_10;
                }
                else
                {
                    goto label_14;
                }
label_19:
                LayoutUtilities.x4487f2f8917e3fd0(xf333586e50dccad2);
                goto label_13;
label_26:
                if ((uint)x49cf4e0157d9436c - (uint)x49cf4e0157d9436c >= 0U)
                {
                    goto label_13;
                }
                else
                {
                    goto label_27;
                }
label_20:
                if (control2 == null)
                {
                    goto label_18;
                }
label_21:
                service1.OnComponentChanging((object)control2, (MemberDescriptor)TypeDescriptor.GetProperties((object)control2)["Controls"]);
                if ((uint)x49cf4e0157d9436c + (uint)x49cf4e0157d9436c < 0U)
                {
                    goto label_4;
                }
                else
                {
                    goto label_18;
                }
label_22:
                if (control2 != null)
                {
                    service3.SetSelectedComponents((ICollection) new object[1]
                    {
                        (object)this.x0467b00af7810f0c.Manager.DockSystemContainer
                    }, SelectionTypes.Replace);
                    goto label_20;
                }
                else
                {
                    service3.SetSelectedComponents((ICollection) new object[1]
                    {
                        (object)service2.RootComponent
                    }, SelectionTypes.Replace);
                    if (((x49cf4e0157d9436c ? 1 : 0) & 0) == 0)
                    {
                        goto label_20;
                    }
                    else
                    {
                        goto label_21;
                    }
                }
            }
            catch
            {
                transaction.Cancel();
                return;
            }
label_36:
            x49cf4e0157d9436c = this.x531514c39973cbc6.x59ae058c4a0dec87 == null;
            selectedControl   = xf333586e50dccad2.SelectedControl;
            this.xf6aefb7d0abb95ba();
            if (x11d58b056c032b03 == null || x11d58b056c032b03.type == xedb4922162c60d3d.DockTargetType.None)
            {
                return;
            }
            goto label_1;
label_37:
            service2          = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            service3          = (ISelectionService)this.GetService(typeof(ISelectionService));
            xf333586e50dccad2 = (ControlLayoutSystem)this.x531514c39973cbc6.xf333586e50dccad2;
            if ((uint)flag > uint.MaxValue)
            {
                goto label_1;
            }
            else
            {
                goto label_36;
            }
        }
        /// <summary>
        ///  Here is where all the fun stuff starts.  We create the structure and apply the naming here.
        /// </summary>
        private void CreateStandardToolStrip(IDesignerHost host, ToolStrip tool)
        {
            // build the static menu items structure.
            //
            string[] menuItemNames = new string[] { SR.StandardMenuNew, SR.StandardMenuOpen, SR.StandardMenuSave, SR.StandardMenuPrint, "-", SR.StandardToolCut, SR.StandardMenuCopy, SR.StandardMenuPaste, "-", SR.StandardToolHelp };

            // build a image list mapping one-one the above menuItems list... this is required so that the in LOCALIZED build we dont use the Localized item string.
            string[] menuItemImageNames = new string[] { "new", "open", "save", "print", "-", "cut", "copy", "paste", "-", "help" };
            Debug.Assert(host != null, "can't create standard menu without designer _host.");

            if (host is null)
            {
                return;
            }

            tool.SuspendLayout();
            ToolStripDesigner.s_autoAddNewItems = false;
            // create a transaction so this happens as an atomic unit.
            DesignerTransaction createMenu = _host.CreateTransaction(SR.StandardMenuCreateDesc);

            try
            {
                INameCreationService nameCreationService = (INameCreationService)_provider.GetService(typeof(INameCreationService));
                string defaultName = "standardMainToolStrip";
                string name        = defaultName;
                int    index       = 1;
                if (host != null)
                {
                    while (_host.Container.Components[name] != null)
                    {
                        name = defaultName + (index++).ToString(CultureInfo.InvariantCulture);
                    }
                }

                //keep an index in the MenuItemImageNames .. so that mapping is maintained.
                int menuItemImageNamesCount = 0;
                // now build the menu items themselves.
                foreach (string itemText in menuItemNames)
                {
                    name = null;
                    // for separators, just use the default name.  Otherwise, remove any non-characters and get the name from the text.
                    defaultName = "ToolStripButton";
                    name        = NameFromText(itemText, typeof(ToolStripButton), nameCreationService, true);
                    ToolStripItem item = null;
                    if (name.Contains("Separator"))
                    {
                        // create the componennt.
                        item = (ToolStripSeparator)_host.CreateComponent(typeof(ToolStripSeparator), name);
                        IDesigner designer = _host.GetDesigner(item);
                        if (designer is ComponentDesigner)
                        {
                            ((ComponentDesigner)designer).InitializeNewComponent(null);
                        }
                    }
                    else
                    {
                        // create the component.
                        item = (ToolStripButton)_host.CreateComponent(typeof(ToolStripButton), name);
                        IDesigner designer = _host.GetDesigner(item);
                        if (designer is ComponentDesigner)
                        {
                            ((ComponentDesigner)designer).InitializeNewComponent(null);
                        }

                        PropertyDescriptor displayStyleProperty = TypeDescriptor.GetProperties(item)["DisplayStyle"];
                        Debug.Assert(displayStyleProperty != null, "Could not find 'Text' property in ToolStripItem.");
                        if (displayStyleProperty != null)
                        {
                            displayStyleProperty.SetValue(item, ToolStripItemDisplayStyle.Image);
                        }

                        PropertyDescriptor textProperty = TypeDescriptor.GetProperties(item)["Text"];
                        Debug.Assert(textProperty != null, "Could not find 'Text' property in ToolStripItem.");
                        if (textProperty != null)
                        {
                            textProperty.SetValue(item, itemText);
                        }

                        Bitmap image = null;
                        try
                        {
                            image = GetImage(menuItemImageNames[menuItemImageNamesCount]);
                        }
                        catch
                        {
                            // eat the exception.. as you may not find image for all MenuItems.
                        }

                        if (image != null)
                        {
                            PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(item)["Image"];
                            Debug.Assert(imageProperty != null, "Could not find 'Image' property in ToolStripItem.");
                            if (imageProperty != null)
                            {
                                imageProperty.SetValue(item, image);
                            }

                            item.ImageTransparentColor = Color.Magenta;
                        }
                    }

                    tool.Items.Add(item);
                    //increment the counter...
                    menuItemImageNamesCount++;
                }

                // finally, add it to the Main ToolStrip.
                MemberDescriptor topMember = TypeDescriptor.GetProperties(tool)["Items"];
                _componentChangeSvc.OnComponentChanging(tool, topMember);
                _componentChangeSvc.OnComponentChanged(tool, topMember, null, null);
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService));
                    uiService.ShowError(e.Message);
                }

                if (createMenu != null)
                {
                    createMenu.Cancel();
                    createMenu = null;
                }
            }
            finally
            {
                //Reset the AutoAdd state
                ToolStripDesigner.s_autoAddNewItems = true;
                if (createMenu != null)
                {
                    createMenu.Commit();
                    createMenu = null;
                }

                tool.ResumeLayout();
                // Select the Main Menu...
                ISelectionService selSvc = (ISelectionService)_provider.GetService(typeof(ISelectionService));
                if (selSvc != null)
                {
                    selSvc.SetSelectedComponents(new object[] { _designer.Component });
                }

                //Refresh the Glyph
                DesignerActionUIService actionUIService = (DesignerActionUIService)_provider.GetService(typeof(DesignerActionUIService));
                if (actionUIService != null)
                {
                    actionUIService.Refresh(_designer.Component);
                }

                // this will invalidate the Selection Glyphs.
                SelectionManager selMgr = (SelectionManager)_provider.GetService(typeof(SelectionManager));
                selMgr.Refresh();
            }
        }
예제 #6
0
        protected override void OnDragDrop(DragEventArgs de)
        {
            bool flag = false;

            if (((this.dragControls != null) && (this.primaryDragControl != null)) && this.Control.Controls.Contains(this.primaryDragControl))
            {
                flag = true;
            }
            if (!flag)
            {
                if (this.Control != null)
                {
                    this.Control.ControlAdded += new ControlEventHandler(this.OnChildControlAdded);
                }
                try
                {
                    base.OnDragDrop(de);
                }
                finally
                {
                    if (this.Control != null)
                    {
                        this.Control.ControlAdded -= new ControlEventHandler(this.OnChildControlAdded);
                    }
                }
            }
            else
            {
                IDesignerHost host = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (host != null)
                {
                    string str;
                    DesignerTransaction transaction = null;
                    bool              flag2         = de.Effect == DragDropEffects.Copy;
                    ArrayList         list          = null;
                    ISelectionService service       = null;
                    if (this.dragControls.Count == 1)
                    {
                        string componentName = TypeDescriptor.GetComponentName(this.dragControls[0]);
                        if ((componentName == null) || (componentName.Length == 0))
                        {
                            componentName = this.dragControls[0].GetType().Name;
                        }
                        str = System.Design.SR.GetString(flag2 ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                    }
                    else
                    {
                        str = System.Design.SR.GetString(flag2 ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { this.dragControls.Count });
                    }
                    transaction = host.CreateTransaction(str);
                    try
                    {
                        while ((this.insertIndex < (this.childInfo.Length - 1)) && this.childInfo[this.insertIndex].inSelectionColl)
                        {
                            this.insertIndex++;
                        }
                        IComponentChangeService      service2 = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                        PropertyDescriptor           member   = TypeDescriptor.GetProperties(this.Control)["Controls"];
                        System.Windows.Forms.Control child    = null;
                        if (this.insertIndex != this.childInfo.Length)
                        {
                            child = this.Control.Controls[this.insertIndex];
                        }
                        else
                        {
                            this.insertIndex = -1;
                        }
                        if ((service2 != null) && (member != null))
                        {
                            service2.OnComponentChanging(this.Control, member);
                        }
                        if (!flag2)
                        {
                            for (int j = 0; j < this.dragControls.Count; j++)
                            {
                                this.Control.Controls.Remove(this.dragControls[j] as System.Windows.Forms.Control);
                            }
                            if (child != null)
                            {
                                this.insertIndex = this.Control.Controls.GetChildIndex(child, false);
                            }
                        }
                        else
                        {
                            ArrayList objects = new ArrayList();
                            for (int k = 0; k < this.dragControls.Count; k++)
                            {
                                objects.Add(this.dragControls[k]);
                            }
                            objects = DesignerUtils.CopyDragObjects(objects, base.Component.Site) as ArrayList;
                            if (objects == null)
                            {
                                return;
                            }
                            list = new ArrayList();
                            for (int m = 0; m < objects.Count; m++)
                            {
                                list.Add(this.dragControls[m]);
                                if (this.primaryDragControl.Equals(this.dragControls[m] as System.Windows.Forms.Control))
                                {
                                    this.primaryDragControl = objects[m] as System.Windows.Forms.Control;
                                }
                                this.dragControls[m] = objects[m];
                            }
                            service = (ISelectionService)this.GetService(typeof(ISelectionService));
                        }
                        if (this.insertIndex == -1)
                        {
                            this.insertIndex = this.Control.Controls.Count;
                        }
                        this.Control.Controls.Add(this.primaryDragControl);
                        this.Control.Controls.SetChildIndex(this.primaryDragControl, this.insertIndex);
                        this.insertIndex++;
                        if (service != null)
                        {
                            service.SetSelectedComponents(new object[] { this.primaryDragControl }, SelectionTypes.Click | SelectionTypes.Replace);
                        }
                        for (int i = this.dragControls.Count - 1; i >= 0; i--)
                        {
                            if (!this.primaryDragControl.Equals(this.dragControls[i] as System.Windows.Forms.Control))
                            {
                                this.Control.Controls.Add(this.dragControls[i] as System.Windows.Forms.Control);
                                this.Control.Controls.SetChildIndex(this.dragControls[i] as System.Windows.Forms.Control, this.insertIndex);
                                this.insertIndex++;
                                if (service != null)
                                {
                                    service.SetSelectedComponents(new object[] { this.dragControls[i] }, SelectionTypes.Add);
                                }
                            }
                        }
                        if ((service2 != null) && (member != null))
                        {
                            service2.OnComponentChanged(this.Control, member, null, null);
                        }
                        if (list != null)
                        {
                            for (int n = 0; n < list.Count; n++)
                            {
                                this.dragControls[n] = list[n];
                            }
                        }
                        base.OnDragComplete(de);
                        if (transaction != null)
                        {
                            transaction.Commit();
                            transaction = null;
                        }
                    }
                    finally
                    {
                        if (transaction != null)
                        {
                            transaction.Cancel();
                        }
                    }
                }
            }
            this.insertIndex = InvalidIndex;
        }
예제 #7
0
        protected bool ViewEvent(object obj, string newHandler, EventDescriptor eventdesc, bool alwaysNavigate)
        {
            object propertyValueCore = this.GetPropertyValueCore(obj);
            string str = propertyValueCore as string;

            if (((str == null) && (propertyValueCore != null)) && ((this.TypeConverter != null) && this.TypeConverter.CanConvertTo(typeof(string))))
            {
                str = this.TypeConverter.ConvertToString(propertyValueCore);
            }
            if ((newHandler == null) && !string.IsNullOrEmpty(str))
            {
                newHandler = str;
            }
            else if ((str == newHandler) && !string.IsNullOrEmpty(newHandler))
            {
                return(true);
            }
            IComponent component = obj as IComponent;

            if ((component == null) && (this.propertyInfo is MergePropertyDescriptor))
            {
                Array array = obj as Array;
                if ((array != null) && (array.Length > 0))
                {
                    component = array.GetValue(0) as IComponent;
                }
            }
            if (component == null)
            {
                return(false);
            }
            if (this.propertyInfo.IsReadOnly)
            {
                return(false);
            }
            if (eventdesc == null)
            {
                if (this.eventBindings == null)
                {
                    this.eventBindings = (IEventBindingService)this.GetService(typeof(IEventBindingService));
                }
                if (this.eventBindings != null)
                {
                    eventdesc = this.eventBindings.GetEvent(this.propertyInfo);
                }
            }
            IDesignerHost       designerHost = this.DesignerHost;
            DesignerTransaction transaction  = null;

            try
            {
                if (eventdesc.EventType == null)
                {
                    return(false);
                }
                if (designerHost != null)
                {
                    string str2 = (component.Site != null) ? component.Site.Name : component.GetType().Name;
                    transaction = this.DesignerHost.CreateTransaction(System.Windows.Forms.SR.GetString("WindowsFormsSetEvent", new object[] { str2 + "." + this.PropertyName }));
                }
                if (this.eventBindings == null)
                {
                    ISite site = component.Site;
                    if (site != null)
                    {
                        this.eventBindings = (IEventBindingService)site.GetService(typeof(IEventBindingService));
                    }
                }
                if ((newHandler == null) && (this.eventBindings != null))
                {
                    newHandler = this.eventBindings.CreateUniqueMethodName(component, eventdesc);
                }
                if (newHandler != null)
                {
                    if (this.eventBindings != null)
                    {
                        bool flag = false;
                        foreach (string str3 in this.eventBindings.GetCompatibleMethods(eventdesc))
                        {
                            if (newHandler == str3)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            alwaysNavigate = true;
                        }
                    }
                    this.propertyInfo.SetValue(obj, newHandler);
                }
                if (alwaysNavigate && (this.eventBindings != null))
                {
                    targetBindingService = this.eventBindings;
                    targetComponent      = component;
                    targetEventdesc      = eventdesc;
                    Application.Idle    += new EventHandler(PropertyDescriptorGridEntry.ShowCodeIdle);
                }
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                throw;
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                }
            }
            return(true);
        }
        public override void OnDragDrop(Glyph g, DragEventArgs e)
        {
            ToolStripItem dragItem = ToolStripDesigner.dragItem;

            if ((e.Data is ToolStripItemDataObject) && (dragItem != null))
            {
                ToolStripItemDataObject data             = (ToolStripItemDataObject)e.Data;
                ToolStripItem           primarySelection = data.PrimarySelection;
                IDesignerHost           host             = (IDesignerHost)dragItem.Site.GetService(typeof(IDesignerHost));
                if ((dragItem != primarySelection) && (host != null))
                {
                    string    str;
                    ArrayList dragComponents = data.DragComponents;
                    ToolStrip currentParent  = dragItem.GetCurrentParent();
                    int       index          = -1;
                    bool      flag           = e.Effect == DragDropEffects.Copy;
                    if (dragComponents.Count == 1)
                    {
                        string componentName = TypeDescriptor.GetComponentName(dragComponents[0]);
                        if ((componentName == null) || (componentName.Length == 0))
                        {
                            componentName = dragComponents[0].GetType().Name;
                        }
                        str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                    }
                    else
                    {
                        str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { dragComponents.Count });
                    }
                    DesignerTransaction transaction = host.CreateTransaction(str);
                    try
                    {
                        IComponentChangeService service = (IComponentChangeService)dragItem.Site.GetService(typeof(IComponentChangeService));
                        if (service != null)
                        {
                            ToolStripDropDown down = currentParent as ToolStripDropDown;
                            if (down != null)
                            {
                                ToolStripItem ownerItem = down.OwnerItem;
                                service.OnComponentChanging(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"]);
                            }
                            else
                            {
                                service.OnComponentChanging(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"]);
                            }
                        }
                        if (flag)
                        {
                            if (primarySelection != null)
                            {
                                index = dragComponents.IndexOf(primarySelection);
                            }
                            ToolStripKeyboardHandlingService keyBoardHandlingService = this.GetKeyBoardHandlingService(primarySelection);
                            if (keyBoardHandlingService != null)
                            {
                                keyBoardHandlingService.CopyInProgress = true;
                            }
                            dragComponents = DesignerUtils.CopyDragObjects(dragComponents, dragItem.Site) as ArrayList;
                            if (keyBoardHandlingService != null)
                            {
                                keyBoardHandlingService.CopyInProgress = false;
                            }
                            if (index != -1)
                            {
                                primarySelection = dragComponents[index] as ToolStripItem;
                            }
                        }
                        if ((e.Effect == DragDropEffects.Move) || flag)
                        {
                            ISelectionService selectionService = this.GetSelectionService(dragItem);
                            if (selectionService != null)
                            {
                                if (currentParent is ToolStripOverflow)
                                {
                                    currentParent = ((ToolStripOverflow)currentParent).OwnerItem.Owner;
                                }
                                int num2 = currentParent.Items.IndexOf(ToolStripDesigner.dragItem);
                                if (num2 != -1)
                                {
                                    int num3 = 0;
                                    if (primarySelection != null)
                                    {
                                        num3 = currentParent.Items.IndexOf(primarySelection);
                                    }
                                    if ((num3 != -1) && (num2 > num3))
                                    {
                                        num2--;
                                    }
                                    foreach (ToolStripItem item4 in dragComponents)
                                    {
                                        currentParent.Items.Insert(num2, item4);
                                    }
                                }
                                selectionService.SetSelectedComponents(new IComponent[] { primarySelection }, SelectionTypes.Click | SelectionTypes.Replace);
                            }
                        }
                        if (service != null)
                        {
                            ToolStripDropDown down2 = currentParent as ToolStripDropDown;
                            if (down2 != null)
                            {
                                ToolStripItem component = down2.OwnerItem;
                                service.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["DropDownItems"], null, null);
                            }
                            else
                            {
                                service.OnComponentChanged(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"], null, null);
                            }
                            if (flag)
                            {
                                if (down2 != null)
                                {
                                    ToolStripItem item6 = down2.OwnerItem;
                                    service.OnComponentChanging(item6, TypeDescriptor.GetProperties(item6)["DropDownItems"]);
                                    service.OnComponentChanged(item6, TypeDescriptor.GetProperties(item6)["DropDownItems"], null, null);
                                }
                                else
                                {
                                    service.OnComponentChanging(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"]);
                                    service.OnComponentChanged(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"], null, null);
                                }
                            }
                        }
                        foreach (ToolStripItem item7 in dragComponents)
                        {
                            if (item7 is ToolStripDropDownItem)
                            {
                                ToolStripMenuItemDesigner designer = host.GetDesigner(item7) as ToolStripMenuItemDesigner;
                                if (designer != null)
                                {
                                    designer.InitializeDropDown();
                                }
                            }
                            ToolStripDropDown down3 = item7.GetCurrentParent() as ToolStripDropDown;
                            if ((down3 != null) && !(down3 is ToolStripOverflow))
                            {
                                ToolStripDropDownItem item8 = down3.OwnerItem as ToolStripDropDownItem;
                                if (item8 != null)
                                {
                                    ToolStripMenuItemDesigner designer2 = host.GetDesigner(item8) as ToolStripMenuItemDesigner;
                                    if (designer2 != null)
                                    {
                                        designer2.InitializeBodyGlyphsForItems(false, item8);
                                        designer2.InitializeBodyGlyphsForItems(true, item8);
                                    }
                                }
                            }
                        }
                        BehaviorService behaviorService = this.GetBehaviorService(dragItem);
                        if (behaviorService != null)
                        {
                            behaviorService.SyncSelection();
                        }
                    }
                    catch (Exception exception)
                    {
                        if (transaction != null)
                        {
                            transaction.Cancel();
                            transaction = null;
                        }
                        if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        if (transaction != null)
                        {
                            transaction.Commit();
                            transaction = null;
                        }
                    }
                }
            }
        }
        public void ChangeParent()
        {
            Cursor current = Cursor.Current;
            DesignerTransaction transaction = this._host.CreateTransaction("Add ToolStripContainer Transaction");

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Control rootComponent          = this._host.RootComponent as Control;
                ParentControlDesigner designer = this._host.GetDesigner(rootComponent) as ParentControlDesigner;
                if (designer != null)
                {
                    ToolStrip component = this._designer.Component as ToolStrip;
                    if (((component != null) && (this._designer != null)) && ((this._designer.Component != null) && (this._provider != null)))
                    {
                        (this._provider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService).HideUI(component);
                    }
                    ToolboxItem        tool           = new ToolboxItem(typeof(ToolStripContainer));
                    OleDragDropHandler oleDragHandler = designer.GetOleDragHandler();
                    if (oleDragHandler != null)
                    {
                        ToolStripContainer container = oleDragHandler.CreateTool(tool, rootComponent, 0, 0, 0, 0, false, false)[0] as ToolStripContainer;
                        if ((container != null) && (component != null))
                        {
                            IComponentChangeService service = this._provider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                            Control            parent       = this.GetParent(container, component);
                            PropertyDescriptor member       = TypeDescriptor.GetProperties(parent)["Controls"];
                            Control            control3     = component.Parent;
                            if (control3 != null)
                            {
                                service.OnComponentChanging(control3, member);
                                control3.Controls.Remove(component);
                            }
                            if (parent != null)
                            {
                                service.OnComponentChanging(parent, member);
                                parent.Controls.Add(component);
                            }
                            if (((service != null) && (control3 != null)) && (parent != null))
                            {
                                service.OnComponentChanged(control3, member, null, null);
                                service.OnComponentChanged(parent, member, null, null);
                            }
                            ISelectionService service3 = this._provider.GetService(typeof(ISelectionService)) as ISelectionService;
                            if (service3 != null)
                            {
                                service3.SetSelectedComponents(new IComponent[] { container });
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception is InvalidOperationException)
                {
                    ((IUIService)this._provider.GetService(typeof(IUIService))).ShowError(exception.Message);
                }
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
                Cursor.Current = current;
            }
        }
        private void ReParentControls(ArrayList controls, bool copy)
        {
            IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if ((host != null) && (controls.Count > 0))
            {
                string str;
                if ((controls.Count == 1) && (controls[0] is ToolStrip))
                {
                    string componentName = TypeDescriptor.GetComponentName(controls[0]);
                    if ((componentName == null) || (componentName.Length == 0))
                    {
                        componentName = controls[0].GetType().Name;
                    }
                    str = System.Design.SR.GetString(copy ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                }
                else
                {
                    str = System.Design.SR.GetString(copy ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { controls.Count });
                }
                DesignerTransaction transaction = host.CreateTransaction(str);
                try
                {
                    ArrayList         objects = null;
                    ISelectionService service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                    if (copy)
                    {
                        objects = new ArrayList();
                        service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                    }
                    for (int i = 0; i < controls.Count; i++)
                    {
                        Control control = controls[i] as Control;
                        if (control is ToolStrip)
                        {
                            if (copy)
                            {
                                objects.Clear();
                                objects.Add(control);
                                objects = DesignerUtils.CopyDragObjects(objects, this.serviceProvider) as ArrayList;
                                if (objects != null)
                                {
                                    control         = objects[0] as Control;
                                    control.Visible = true;
                                }
                            }
                            Control relatedControl           = this.relatedControl;
                            IComponentChangeService service2 = this.serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                            PropertyDescriptor      member   = TypeDescriptor.GetProperties(relatedControl)["Controls"];
                            Control parent = control.Parent;
                            if ((parent != null) && !copy)
                            {
                                if (service2 != null)
                                {
                                    service2.OnComponentChanging(parent, member);
                                }
                                parent.Controls.Remove(control);
                            }
                            if (service2 != null)
                            {
                                service2.OnComponentChanging(relatedControl, member);
                            }
                            relatedControl.Controls.Add(control);
                            if (((service2 != null) && (parent != null)) && !copy)
                            {
                                service2.OnComponentChanged(parent, member, null, null);
                            }
                            if (service2 != null)
                            {
                                service2.OnComponentChanged(relatedControl, member, null, null);
                            }
                            if (service != null)
                            {
                                service.SetSelectedComponents(new object[] { control }, (i == 0) ? (SelectionTypes.Click | SelectionTypes.Replace) : SelectionTypes.Add);
                            }
                        }
                    }
                }
                catch
                {
                    if (transaction != null)
                    {
                        transaction.Cancel();
                        transaction = null;
                    }
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Commit();
                        transaction = null;
                    }
                }
            }
        }
예제 #11
0
        private void EndDragDrop(bool allowSetChildIndexOnDrop)
        {
            Control target = this.data.Target as Control;

            if (target != null)
            {
                if (this.serviceProviderTarget == null)
                {
                    this.serviceProviderTarget = target.Site;
                    if (this.serviceProviderTarget == null)
                    {
                        return;
                    }
                }
                if (this.destHost == null)
                {
                    this.destHost = (IDesignerHost)this.serviceProviderTarget.GetService(typeof(IDesignerHost));
                    if (this.destHost == null)
                    {
                        return;
                    }
                }
                if (this.behaviorServiceTarget == null)
                {
                    this.behaviorServiceTarget = (BehaviorService)this.serviceProviderTarget.GetService(typeof(BehaviorService));
                    if (this.behaviorServiceTarget == null)
                    {
                        return;
                    }
                }
                ArrayList               list        = null;
                bool                    flag        = this.lastEffect == DragDropEffects.Copy;
                Control                 source      = this.data.Source;
                bool                    localDrag   = source.Equals(target);
                PropertyDescriptor      member      = TypeDescriptor.GetProperties(target)["Controls"];
                PropertyDescriptor      descriptor2 = TypeDescriptor.GetProperties(source)["Controls"];
                IComponentChangeService service     = (IComponentChangeService)this.serviceProviderSource.GetService(typeof(IComponentChangeService));
                IComponentChangeService service2    = (IComponentChangeService)this.serviceProviderTarget.GetService(typeof(IComponentChangeService));
                if (this.dragAssistanceManager != null)
                {
                    this.dragAssistanceManager.OnMouseUp();
                }
                ISelectionService service3 = null;
                if (flag || ((this.srcHost != this.destHost) && (this.destHost != null)))
                {
                    service3 = (ISelectionService)this.serviceProviderTarget.GetService(typeof(ISelectionService));
                }
                try
                {
                    if ((this.dragComponents != null) && (this.dragComponents.Length > 0))
                    {
                        string str;
                        DesignerTransaction transaction  = null;
                        DesignerTransaction transaction2 = null;
                        if (this.dragComponents.Length == 1)
                        {
                            string componentName = TypeDescriptor.GetComponentName(this.dragComponents[0].dragComponent);
                            if ((componentName == null) || (componentName.Length == 0))
                            {
                                componentName = this.dragComponents[0].dragComponent.GetType().Name;
                            }
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                        }
                        else
                        {
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { this.dragComponents.Length });
                        }
                        if ((this.srcHost != null) && (((this.srcHost == this.destHost) || (this.destHost == null)) || !flag))
                        {
                            transaction = this.srcHost.CreateTransaction(str);
                        }
                        if ((this.srcHost != this.destHost) && (this.destHost != null))
                        {
                            transaction2 = this.destHost.CreateTransaction(str);
                        }
                        try
                        {
                            ComponentTray tray = null;
                            int           num  = 0;
                            if (flag)
                            {
                                tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                num  = (tray != null) ? tray.Controls.Count : 0;
                                ArrayList objects = new ArrayList();
                                for (int j = 0; j < this.dragComponents.Length; j++)
                                {
                                    objects.Add(this.dragComponents[j].dragComponent);
                                }
                                objects = DesignerUtils.CopyDragObjects(objects, this.serviceProviderTarget) as ArrayList;
                                if (objects == null)
                                {
                                    return;
                                }
                                list = new ArrayList();
                                for (int k = 0; k < objects.Count; k++)
                                {
                                    list.Add(this.dragComponents[k].dragComponent);
                                    this.dragComponents[k].dragComponent = objects[k];
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanging(target, member);
                                if (!flag)
                                {
                                    service.OnComponentChanging(source, descriptor2);
                                }
                            }
                            int num4 = ParentControlDesigner.DetermineTopChildIndex(target);
                            this.DropControl(this.primaryComponentIndex, target, source, localDrag);
                            Point p = this.behaviorServiceSource.AdornerWindowPointToScreen(this.dragComponents[this.primaryComponentIndex].draggedLocation);
                            p = ((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.PointToClient(p);
                            if (((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.IsMirrored)
                            {
                                p.Offset(-((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Width, 0);
                            }
                            Control            dragComponent = this.dragComponents[this.primaryComponentIndex].dragComponent as Control;
                            PropertyDescriptor descriptor3   = TypeDescriptor.GetProperties(dragComponent)["Location"];
                            if ((dragComponent != null) && (descriptor3 != null))
                            {
                                try
                                {
                                    service2.OnComponentChanging(dragComponent, descriptor3);
                                }
                                catch (CheckoutException exception)
                                {
                                    if (exception != CheckoutException.Canceled)
                                    {
                                        throw;
                                    }
                                    return;
                                }
                            }
                            this.SetLocationPropertyAndChildIndex(this.primaryComponentIndex, target, p, this.shareParent ? (num4 + this.dragComponents[this.primaryComponentIndex].zorderIndex) : num4, allowSetChildIndexOnDrop);
                            if (service3 != null)
                            {
                                service3.SetSelectedComponents(new object[] { this.dragComponents[this.primaryComponentIndex].dragComponent }, SelectionTypes.Click | SelectionTypes.Replace);
                            }
                            for (int i = 0; i < this.dragComponents.Length; i++)
                            {
                                if (i != this.primaryComponentIndex)
                                {
                                    this.DropControl(i, target, source, localDrag);
                                    Point dropPoint = new Point(p.X + this.dragComponents[i].positionOffset.X, p.Y + this.dragComponents[i].positionOffset.Y);
                                    this.SetLocationPropertyAndChildIndex(i, target, dropPoint, this.shareParent ? (num4 + this.dragComponents[i].zorderIndex) : num4, allowSetChildIndexOnDrop);
                                    if (service3 != null)
                                    {
                                        service3.SetSelectedComponents(new object[] { this.dragComponents[i].dragComponent }, SelectionTypes.Add);
                                    }
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanged(target, member, target.Controls, target.Controls);
                                if (!flag)
                                {
                                    service.OnComponentChanged(source, descriptor2, source.Controls, source.Controls);
                                }
                            }
                            if (list != null)
                            {
                                for (int m = 0; m < list.Count; m++)
                                {
                                    this.dragComponents[m].dragComponent = list[m];
                                }
                                list = null;
                            }
                            if (flag)
                            {
                                if (tray == null)
                                {
                                    tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                }
                                if (tray != null)
                                {
                                    int num7 = tray.Controls.Count - num;
                                    if (num7 > 0)
                                    {
                                        ArrayList components = new ArrayList();
                                        for (int n = 0; n < num7; n++)
                                        {
                                            components.Add(tray.Controls[num + n]);
                                        }
                                        tray.UpdatePastePositions(components);
                                    }
                                }
                            }
                            this.CleanupDrag(false);
                            if (transaction != null)
                            {
                                transaction.Commit();
                                transaction = null;
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Commit();
                                transaction2 = null;
                            }
                        }
                        finally
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Cancel();
                            }
                        }
                    }
                }
                finally
                {
                    if (list != null)
                    {
                        for (int num9 = 0; num9 < list.Count; num9++)
                        {
                            this.dragComponents[num9].dragComponent = list[num9];
                        }
                    }
                    this.CleanupDrag(false);
                    if (this.statusCommandUITarget != null)
                    {
                        this.statusCommandUITarget.SetStatusInformation((service3 == null) ? (this.dragComponents[this.primaryComponentIndex].dragComponent as Component) : (service3.PrimarySelection as Component));
                    }
                }
                this.lastFeedbackLocation = new Point(-1, -1);
            }
        }
        public override bool EditComponent(ITypeDescriptorContext context, object component,
                                           IWin32Window owner)
        {
            SageCRMBaseEntryBlock block = component as SageCRMBaseEntryBlock;

            if (block == null)
            {
                throw new ArgumentException("Component must be a SageCRMEntryBlock or SageCRMPortalEntryBlock", "component");
            }
            IServiceProvider        site          = block.Site;
            IComponentChangeService changeservice = null;
            DesignerTransaction     transaction   = null;
            bool changed = false;

            try
            {
                if (site != null)
                {
                    IDesignerHost designerhost = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                    transaction   = designerhost.CreateTransaction("Property Builder");
                    changeservice = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                    if (changeservice != null)
                    {
                        try
                        {
                            changeservice.OnComponentChanging(block, null);
                        }
                        catch (CheckoutException ex)
                        {
                            if (ex == CheckoutException.Canceled)
                            {
                                return(false);
                            }
                            throw ex;
                        }
                    }
                }
                try
                {
                    block.SageCRMConnection.DesignRequest = true;
                    crmEditor form = new crmEditor(null, block, null, null, null);
                    form.ShowDialog(owner);
                    changed = true;
                    block.SageCRMConnection.DesignRequest = false;
                }
                finally
                {
                    if (changed && changeservice != null)
                    {
                        changeservice.OnComponentChanged(block, null, null, null);
                    }
                }
            }
            finally
            {
                if (transaction != null)
                {
                    if (changed)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Cancel();
                    }
                }
            }
            return(changed);
        }
예제 #13
0
        internal virtual void CommitEdit(System.Type type, string text, bool commit, bool enterKeyPressed, bool tabKeyPressed)
        {
            System.Windows.Forms.ToolStripItem component = null;
            SelectionManager manager         = (SelectionManager)this.GetService(typeof(SelectionManager));
            BehaviorService  service         = (BehaviorService)this.GetService(typeof(BehaviorService));
            ToolStrip        immediateParent = this.ImmediateParent as ToolStrip;

            immediateParent.SuspendLayout();
            this.HideDummyNode();
            IDesignerHost     host     = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            ToolStripDesigner designer = (ToolStripDesigner)host.GetDesigner(this.ToolStripItem.Owner);

            if ((designer != null) && (designer.EditManager != null))
            {
                designer.EditManager.ActivateEditor(null, false);
            }
            if ((immediateParent is MenuStrip) && (type == typeof(ToolStripSeparator)))
            {
                IDesignerHost host2 = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                if (host2 != null)
                {
                    IUIService service2 = (IUIService)host2.GetService(typeof(IUIService));
                    if (service2 != null)
                    {
                        service2.ShowError(System.Design.SR.GetString("ToolStripSeparatorError"));
                        commit = false;
                        if (this.selSvc != null)
                        {
                            this.selSvc.SetSelectedComponents(new object[] { immediateParent });
                        }
                    }
                }
            }
            if (!commit)
            {
                if (this.dummyItemAdded)
                {
                    this.dummyItemAdded = false;
                    this.RemoveItem();
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Cancel();
                        designer.NewItemTransaction = null;
                    }
                }
                goto Label_0246;
            }
            if (this.dummyItemAdded)
            {
                try
                {
                    this.RemoveItem();
                    component = designer.AddNewItem(type, text, enterKeyPressed, false);
                    goto Label_020B;
                }
                finally
                {
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Commit();
                        designer.NewItemTransaction = null;
                    }
                }
            }
            DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("ToolStripItemPropertyChangeTransaction"));

            try
            {
                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.ToolStripItem)["Text"];
                string             str        = (string)descriptor.GetValue(this.ToolStripItem);
                if ((descriptor != null) && (text != str))
                {
                    descriptor.SetValue(this.ToolStripItem, text);
                }
                if (enterKeyPressed && (this.selSvc != null))
                {
                    this.SelectNextItem(this.selSvc, enterKeyPressed, designer);
                }
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                if (manager != null)
                {
                    manager.Refresh();
                }
                if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                {
                    throw;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
            }
Label_020B:
            this.dummyItemAdded = false;
Label_0246:
            immediateParent.ResumeLayout();
            if ((component != null) && !component.IsOnDropDown)
            {
                ToolStripDropDownItem item2 = component as ToolStripDropDownItem;
                if (item2 != null)
                {
                    Rectangle glyphBounds   = ((ToolStripItemDesigner)host.GetDesigner(component)).GetGlyphBounds();
                    Control   rootComponent = host.RootComponent as Control;
                    if ((rootComponent != null) && (service != null))
                    {
                        Rectangle parentBounds = service.ControlRectInAdornerWindow(rootComponent);
                        if (!ToolStripDesigner.IsGlyphTotallyVisible(glyphBounds, parentBounds))
                        {
                            item2.HideDropDown();
                        }
                    }
                }
            }
            if (manager != null)
            {
                manager.Refresh();
            }
        }
예제 #14
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);
        }
예제 #15
0
        void OpenCalcPropertiesDialog()
        {
            Form form1 = null; //should be a CalcPropertiesEditorForm which is private
            Cube cube  = (Cube)this.ApplicationObject.ActiveWindow.ProjectItem.Object;

            System.IServiceProvider provider = (System.IServiceProvider) this.ApplicationObject.ActiveWindow.ProjectItem.ContainingProject;
            using (WaitCursor cursor1 = new WaitCursor())
            {
                IUserPromptService oService = (IUserPromptService)provider.GetService(typeof(IUserPromptService));

                foreach (Type t in System.Reflection.Assembly.GetAssembly(typeof(Microsoft.AnalysisServices.Design.Scripts)).GetTypes())
                {
                    if (t.FullName == "Microsoft.AnalysisServices.Design.Calculations.CalcPropertiesEditorForm")
                    {
                        form1 = (Form)t.GetConstructor(new Type[] { typeof(IUserPromptService) }).Invoke(new object[] { oService });
                        break;
                    }
                }
                if (form1 == null)
                {
                    throw new Exception("Couldn't create instance of CalcPropertiesEditorForm");
                }

                object script1 = null; //should be a Microsoft.AnalysisServices.MdxCodeDom.MdxCodeScript object
                try
                {
                    //validate the script because deploying an invalid script makes cube unusable
                    Microsoft.AnalysisServices.Design.Scripts scripts  = new Microsoft.AnalysisServices.Design.Scripts(cube);
                    System.Reflection.BindingFlags            getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance;
                    script1 = scripts.GetType().InvokeMember("mdxCodeScript", getflags, null, scripts, null);
                }
                catch (Microsoft.AnalysisServices.Design.ScriptParsingFailed ex)
                {
                    string throwaway = ex.Message; //prevents a warning during compile
                    MessageBox.Show("MDX Script in " + cube.Name + " is not valid.", "Problem Deploying MDX Script");
                    return;
                }

                if (cube.MdxScripts.Count == 0)
                {
                    MessageBox.Show("There is no MDX script defined in this cube yet.");
                    return;
                }

                System.Reflection.BindingFlags getmethodflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance;
                form1.GetType().InvokeMember("Initialize", getmethodflags, null, form1, new object[] { cube.MdxScripts[0], script1, cube, null });

                //now make custom changes to the form
                Button okButton = (Button)form1.Controls.Find("okButton", true)[0];
                Panel  panel    = (Panel)form1.Controls.Find("gridPanel", true)[0];

                Button descButton = new Button();
                descButton.Text   = "Edit Description";
                descButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
                descButton.Left   = panel.Left;
                descButton.Top    = okButton.Top;
                descButton.Width += 40;
                descButton.Click += new EventHandler(descButton_Click);
                form1.Controls.Add(descButton);
            }

            if (Microsoft.DataWarehouse.DataWarehouseUtilities.ShowDialog(form1, provider) == DialogResult.OK)
            {
                using (WaitCursor cursor2 = new WaitCursor())
                {
                    System.Reflection.BindingFlags getflags    = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance;
                    CalculationPropertyCollection  collection1 = (CalculationPropertyCollection)form1.GetType().InvokeMember("GetResultProperties", getflags, null, form1, new object[] { });

                    DesignerTransaction transaction1 = null;
                    try
                    {
                        IDesignerHost host1 = (IDesignerHost)ApplicationObject.ActiveWindow.Object;
                        transaction1 = host1.CreateTransaction("BidsHelperCalcPropertiesUndoBatchDesc");
                        IComponentChangeService service1 = (IComponentChangeService)ApplicationObject.ActiveWindow.Object;
                        service1.OnComponentChanging(cube.MdxScripts[0].CalculationProperties, null);
                        cube.MdxScripts[0].CalculationProperties.Clear();
                        for (int num1 = collection1.Count - 1; num1 >= 0; num1--)
                        {
                            CalculationProperty property1 = collection1[num1];
                            collection1.RemoveAt(num1);
                            cube.MdxScripts[0].CalculationProperties.Insert(0, property1);
                        }
                        service1.OnComponentChanged(cube.MdxScripts[0].CalculationProperties, null, null, null);
                    }
                    catch (CheckoutException exception1)
                    {
                        if (transaction1 != null)
                        {
                            transaction1.Cancel();
                        }
                        if (exception1 != CheckoutException.Canceled)
                        {
                            throw exception1;
                        }
                    }
                    finally
                    {
                        if (transaction1 != null)
                        {
                            transaction1.Commit();
                        }
                    }
                }
            }
        }
예제 #16
0
        public override bool EditComponent(ITypeDescriptorContext context, object component,
                                           IWin32Window owner)
        {
            SageCRMBaseListBlock block = component as SageCRMBaseListBlock;

            if (block == null)
            {
                throw new ArgumentException("Component must be a SageCRMListBlock or SageCRMPortalListBlock", "component");
            }
            IServiceProvider        site          = block.Site;
            IComponentChangeService changeservice = null;
            DesignerTransaction     transaction   = null;
            bool changed = false;

            try
            {
                if (site != null)
                {
                    IDesignerHost designerhost = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                    transaction   = designerhost.CreateTransaction("Property Editor");
                    changeservice = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                    if (changeservice != null)
                    {
                        try
                        {
                            changeservice.OnComponentChanging(block, null);
                        }
                        catch (CheckoutException ex)
                        {
                            if (ex == CheckoutException.Canceled)
                            {
                                return(false);
                            }
                            throw ex;
                        }
                    }
                }
                try
                {
                    block.SageCRMConnection.DesignRequest = true;
                    ListPropEditor form = new ListPropEditor(block);
                    form.ListBlock       = block.ListBlock;
                    form.EntityName      = block.EntityName;
                    form.BlockTitle      = block.BlockTitle;
                    form.SelectSQL       = block.SelectSQL;
                    form.WhereClause     = block.EntityWhere;
                    form.EntryBlockName  = block.EntryBlockName;
                    form.FilterBlockName = block.FilterBlockName;
                    if (block is SageCRMListBlock)
                    {
                        form.showWorkFlow();
                        form.WorkFlowTable          = (block as SageCRMListBlock).WorkflowTable;
                        form.ShowNewWorkflowButtons = (block as SageCRMListBlock).ShowNewWorkFlowButtons;
                        form.ShowWorkflowButtons    = (block as SageCRMListBlock).ShowWorkFlowButtons;
                    }
                    else //i assume its the portal
                    {
                        form.hideWorkFlow();
                    }
                    if (form.ShowDialog(owner) == DialogResult.OK)
                    {
                        changed = true;
                    }
                    block.SageCRMConnection.DesignRequest = false;
                }
                finally
                {
                    if (changed && changeservice != null)
                    {
                        changeservice.OnComponentChanged(block, null, null, null);
                    }
                }
            }
            finally
            {
                if (transaction != null)
                {
                    if (changed)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Cancel();
                    }
                }
            }
            return(changed);
        }
예제 #17
0
        public override bool EditComponent(ITypeDescriptorContext context, object component, IWin32Window owner)
        {
            ActiveUp.WebControls.Editor editor = component as ActiveUp.WebControls.Editor;
            if (editor == null)
            {
                throw new ArgumentException("Component must be a ActiveUp.WebControls.Editor object.", "component");
            }

            IServiceProvider        site          = editor.Site;
            IComponentChangeService changeService = null;

            DesignerTransaction transaction = null;
            bool changed = false;

            try
            {
                if (site != null)
                {
                    IDesignerHost designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                    transaction = designerHost.CreateTransaction("Property Builder");

                    changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                    if (changeService != null)
                    {
                        try
                        {
                            changeService.OnComponentChanging(editor, null);
                        }
                        catch (CheckoutException ex)
                        {
                            if (ex == CheckoutException.Canceled)
                            {
                                return(false);
                            }
                            throw ex;
                        }
                    }
                }

                try
                {
                    EditorPropertyBuilderForm form = new EditorPropertyBuilderForm(editor);
                    if (form.ShowDialog(owner) == DialogResult.OK)
                    {
                        changed = true;
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                finally
                {
                    if (changed && changeService != null)
                    {
                        changeService.OnComponentChanged(editor, null, null, null);
                    }
                }
            }
            finally
            {
                if (transaction != null)
                {
                    if (changed)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Cancel();
                    }
                }
            }

            return(changed);
        }
        protected override bool SendNotification(object owner, Notify notification)
        {
            if (owner is ICustomTypeDescriptor descriptor)
            {
                owner = descriptor.GetPropertyOwner(PropertyDescriptor);
            }

            switch (notification)
            {
            case Notify.Reset:

                object[] objects = (object[])owner;

                if (objects is null || objects.Length == 0)
                {
                    return(false);
                }

                IDesignerHost       host        = DesignerHost;
                DesignerTransaction transaction = host?.CreateTransaction(string.Format(SR.PropertyGridResetValue, PropertyName));

                try
                {
                    bool needChangeNotify = objects[0] is not IComponent component || component.Site is null;
                    if (needChangeNotify)
                    {
                        if (!OnComponentChanging())
                        {
                            transaction?.Cancel();
                            transaction = null;

                            return(false);
                        }
                    }

                    _mergedDescriptor.ResetValue(owner);

                    if (needChangeNotify)
                    {
                        OnComponentChanged();
                    }

                    NotifyParentsOfChanges(this);
                }
                finally
                {
                    transaction?.Commit();
                }

                return(false);

            case Notify.DoubleClick:
            case Notify.Return:
                Debug.Assert(PropertyDescriptor is MergePropertyDescriptor, "Did not get a MergePropertyDescriptor!!!");
                Debug.Assert(owner is object[], "Did not get an array of objects!!");

                if (PropertyDescriptor is MergePropertyDescriptor mergeDescriptor)
                {
                    _eventBindings ??= this.GetService <IEventBindingService>();

                    if (_eventBindings is not null)
                    {
                        EventDescriptor eventDescriptor = _eventBindings.GetEvent(mergeDescriptor[0]);
                        if (eventDescriptor is not null)
                        {
                            return(ViewEvent(owner, null, eventDescriptor, true));
                        }
                    }

                    return(false);
                }
                else
                {
                    return(base.SendNotification(owner, notification));
                }
            }

            return(base.SendNotification(owner, notification));
        }
예제 #19
0
        public override bool EditComponent(ITypeDescriptorContext context, object component, IWin32Window owner)
        {
            TabControl              tabControl             = (TabControl)component;
            IServiceProvider        site                   = tabControl.Site;
            IComponentChangeService componentChangeService = null;
            DesignerTransaction     designerTransaction    = null;
            bool flag = false;

            try
            {
                if (site != null)
                {
                    IDesignerHost designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                    designerTransaction    = designerHost.CreateTransaction("BuildTabStrip");
                    componentChangeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                    if (componentChangeService != null)
                    {
                        try
                        {
                            componentChangeService.OnComponentChanging(component, null);
                        }
                        catch (CheckoutException ex)
                        {
                            if (ex == CheckoutException.Canceled)
                            {
                                return(false);
                            }
                            throw ex;
                        }
                    }
                }
                try
                {
                    TabEditorForm tabEditorForm = new TabEditorForm(tabControl);
                    if (tabEditorForm.ShowDialog(owner) == DialogResult.OK)
                    {
                        flag = true;
                    }
                }
                finally
                {
                    if (flag && componentChangeService != null)
                    {
                        componentChangeService.OnComponentChanged(tabControl, null, null, null);
                    }
                }
            }
            finally
            {
                if (designerTransaction != null)
                {
                    if (flag)
                    {
                        designerTransaction.Commit();
                    }
                    else
                    {
                        designerTransaction.Cancel();
                    }
                }
            }
            return(flag);
        }
예제 #20
0
        private object SetPropertyValue(object obj, object objVal, bool reset, string undoText)
        {
            DesignerTransaction transaction = null;

            try
            {
                object propertyValueCore = this.GetPropertyValueCore(obj);
                if ((objVal != null) && objVal.Equals(propertyValueCore))
                {
                    return(objVal);
                }
                base.ClearCachedValues();
                IDesignerHost designerHost = this.DesignerHost;
                if (designerHost != null)
                {
                    string description = (undoText == null) ? System.Windows.Forms.SR.GetString("PropertyGridSetValue", new object[] { this.propertyInfo.Name }) : undoText;
                    transaction = designerHost.CreateTransaction(description);
                }
                bool flag = !(obj is IComponent) || (((IComponent)obj).Site == null);
                if (flag)
                {
                    try
                    {
                        if (this.ComponentChangeService != null)
                        {
                            this.ComponentChangeService.OnComponentChanging(obj, this.propertyInfo);
                        }
                    }
                    catch (CheckoutException exception)
                    {
                        if (exception != CheckoutException.Canceled)
                        {
                            throw exception;
                        }
                        return(propertyValueCore);
                    }
                }
                bool internalExpanded = this.InternalExpanded;
                int  oldCount         = -1;
                if (internalExpanded)
                {
                    oldCount = base.ChildCount;
                }
                RefreshPropertiesAttribute attribute = (RefreshPropertiesAttribute)this.propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)];
                bool flag3 = internalExpanded || ((attribute != null) && !attribute.RefreshProperties.Equals(RefreshProperties.None));
                if (flag3)
                {
                    this.DisposeChildren();
                }
                EventDescriptor eventdesc = null;
                if ((obj != null) && (objVal is string))
                {
                    if (this.eventBindings == null)
                    {
                        this.eventBindings = (IEventBindingService)this.GetService(typeof(IEventBindingService));
                    }
                    if (this.eventBindings != null)
                    {
                        eventdesc = this.eventBindings.GetEvent(this.propertyInfo);
                    }
                    if (eventdesc == null)
                    {
                        object component = obj;
                        if ((this.propertyInfo is MergePropertyDescriptor) && (obj is Array))
                        {
                            Array array = obj as Array;
                            if (array.Length > 0)
                            {
                                component = array.GetValue(0);
                            }
                        }
                        eventdesc = TypeDescriptor.GetEvents(component)[this.propertyInfo.Name];
                    }
                }
                bool flag4 = false;
                try
                {
                    if (reset)
                    {
                        this.propertyInfo.ResetValue(obj);
                    }
                    else if (eventdesc != null)
                    {
                        this.ViewEvent(obj, (string)objVal, eventdesc, false);
                    }
                    else
                    {
                        this.SetPropertyValueCore(obj, objVal, true);
                    }
                    flag4 = true;
                    if (flag && (this.ComponentChangeService != null))
                    {
                        this.ComponentChangeService.OnComponentChanged(obj, this.propertyInfo, null, objVal);
                    }
                    this.NotifyParentChange(this);
                }
                finally
                {
                    if (flag3 && (this.GridEntryHost != null))
                    {
                        base.RecreateChildren(oldCount);
                        if (flag4)
                        {
                            this.GridEntryHost.Refresh((attribute != null) && attribute.Equals(RefreshPropertiesAttribute.All));
                        }
                    }
                }
                return(obj);
            }
            catch (CheckoutException exception2)
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                if (exception2 != CheckoutException.Canceled)
                {
                    throw;
                }
                return(null);
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                throw;
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                }
            }
            return(obj);
        }