/// <summary>
        ///  When the verb is invoked, use all the stuff above to show the dialog, etc.
        /// </summary>
        public void InsertItems()
        {
            DesignerActionUIService actionUIService = (DesignerActionUIService)_host.GetService(typeof(DesignerActionUIService));

            if (actionUIService != null)
            {
                actionUIService.HideUI(_designer.Component);
            }

            Cursor current = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (_designer.Component is MenuStrip)
                {
                    CreateStandardMenuStrip(_host, (MenuStrip)_designer.Component);
                }
                else
                {
                    CreateStandardToolStrip(_host, (ToolStrip)_designer.Component);
                }
            }
            finally
            {
                Cursor.Current = current;
            }
        }
        private void InvokeEmbedVerb()
        {
            DesignerActionUIService service = (DesignerActionUIService)this._toolStrip.Site.GetService(typeof(DesignerActionUIService));

            if (service != null)
            {
                service.HideUI(this._toolStrip);
            }
            this.changeParentVerb.ChangeParent();
        }
        private void OnEditItems(object sender, EventArgs e)
        {
            DesignerActionUIService service = (DesignerActionUIService)((IServiceProvider)this).GetService(typeof(DesignerActionUIService));

            if (service != null)
            {
                service.HideUI(this._designer.Component);
            }
            object component = this._targetProperty.GetValue(this._designer.Component);

            if (component != null)
            {
                CollectionEditor editor = TypeDescriptor.GetEditor(component, typeof(UITypeEditor)) as CollectionEditor;
                if (editor != null)
                {
                    editor.EditValue(this, this, component);
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///  When the verb is invoked, change the parent of the ToolStrip.
        /// </summary>
        // This is actually called...
        public void ChangeParent()
        {
            Cursor current = Cursor.Current;
            // create a transaction so this happens as an atomic unit.
            DesignerTransaction changeParent = _host.CreateTransaction("Add ToolStripContainer Transaction");

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                //Add a New ToolStripContainer to the RootComponent ...
                Control root = _host.RootComponent as Control;
                if (_host.GetDesigner(root) is ParentControlDesigner rootDesigner)
                {
                    // close the DAP first - this is so that the autoshown panel on drag drop here is not conflicting with the currently opened panel
                    // if the verb was called from the panel
                    ToolStrip toolStrip = _designer.Component as ToolStrip;
                    if (toolStrip != null && _designer != null && _designer.Component != null && _provider != null)
                    {
                        DesignerActionUIService dapuisvc = _provider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
                        dapuisvc.HideUI(toolStrip);
                    }

                    // Get OleDragHandler ...
                    ToolboxItem        tbi = new ToolboxItem(typeof(ToolStripContainer));
                    OleDragDropHandler ddh = rootDesigner.GetOleDragHandler();
                    if (ddh != null)
                    {
                        IComponent[] newComp = ddh.CreateTool(tbi, root, 0, 0, 0, 0, false, false);
                        if (newComp[0] is ToolStripContainer tsc)
                        {
                            if (toolStrip != null)
                            {
                                var                changeService = _provider.GetService <IComponentChangeService>();
                                Control            newParent     = GetParent(tsc, toolStrip);
                                PropertyDescriptor controlsProp  = TypeDescriptor.GetProperties(newParent)["Controls"];
                                Control            oldParent     = toolStrip.Parent;
                                if (oldParent != null)
                                {
                                    changeService.OnComponentChanging(oldParent, controlsProp);
                                    //remove control from the old parent
                                    oldParent.Controls.Remove(toolStrip);
                                }

                                if (newParent != null)
                                {
                                    changeService.OnComponentChanging(newParent, controlsProp);
                                    //finally add & relocate the control with the new parent
                                    newParent.Controls.Add(toolStrip);
                                }

                                //fire our comp changed events
                                if (changeService != null && oldParent != null && newParent != null)
                                {
                                    changeService.OnComponentChanged(oldParent, controlsProp);
                                    changeService.OnComponentChanged(newParent, controlsProp);
                                }

                                //Set the Selection on the new Parent ... so that the selection is restored to the new item,
                                if (_provider.GetService(typeof(ISelectionService)) is ISelectionService selSvc)
                                {
                                    selSvc.SetSelectedComponents(new IComponent[] { tsc });
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService));
                    uiService.ShowError(e.Message);
                }

                if (changeParent != null)
                {
                    changeParent.Cancel();
                    changeParent = null;
                }
            }
            finally
            {
                if (changeParent != null)
                {
                    changeParent.Commit();
                }

                Cursor.Current = current;
            }
        }