예제 #1
0
        private void OnMoveNext(object sender, EventArgs e)
        {
            if ((_ribbonGroup?.Ribbon != null) && _ribbonGroup.RibbonTab.Groups.Contains(_ribbonGroup))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroup MoveNext");

                try
                {
                    // Get access to the Group property
                    MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonGroup.RibbonTab)["Groups"];

                    RaiseComponentChanging(propertyGroups);

                    // Move position of the group
                    KryptonRibbonTab ribbonTab = _ribbonGroup.RibbonTab;
                    int index = ribbonTab.Groups.IndexOf(_ribbonGroup) + 1;
                    index = Math.Min(index, ribbonTab.Groups.Count - 1);
                    ribbonTab.Groups.Remove(_ribbonGroup);
                    ribbonTab.Groups.Insert(index, _ribbonGroup);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyGroups, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
예제 #2
0
        private void OnDeleteCheckBox(object sender, EventArgs e)
        {
            if (_ribbonCheckBox?.Ribbon != null)
            {
                // Get access to the parent collection of items
                TypedRestrictCollection <KryptonRibbonGroupItem> items = ParentItems;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCheckBox DeleteCheckBox");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCheckBox.RibbonContainer)["Items"];

                    // Remove the ribbon group from the ribbon tab
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(propertyItems);

                    // Remove the check box from the group
                    items.Remove(_ribbonCheckBox);

                    // Get designer to destroy it
                    _designerHost.DestroyComponent(_ribbonCheckBox);

                    RaiseComponentChanged(propertyItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
예제 #3
0
        private void OnMoveLast(object sender, EventArgs e)
        {
            if ((_ribbonSeparator?.Ribbon != null) && _ribbonSeparator.RibbonGroup.Items.Contains(_ribbonSeparator))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupSeparator MoveLast");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonSeparator.RibbonGroup)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    KryptonRibbonGroup ribbonGroup = _ribbonSeparator.RibbonGroup;
                    ribbonGroup.Items.Remove(_ribbonSeparator);
                    ribbonGroup.Items.Insert(ribbonGroup.Items.Count, _ribbonSeparator);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnRemovePage(object sender, EventArgs e)
        {
            // Use a transaction to support undo/redo actions
            DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonNavigator RemovePage");

            try
            {
                // Get access to the Pages property
                MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_navigator)["Pages"];

                // Remove the selected page from the navigator
                RaiseComponentChanging(propertyPages);

                // Get the page we are going to remove
                KryptonPage removePage = _navigator.SelectedPage;

                // Get designer to destroy it
                _designerHost.DestroyComponent(removePage);

                RaiseComponentChanged(propertyPages, null, null);
            }
            finally
            {
                // If we managed to create the transaction, then do it
                transaction?.Commit();
            }
        }
        private void OnClearPages(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure that all pages should be removed?",
                                "Clear Pages",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonNavigator RemovePage");

                try
                {
                    // Get access to the Pages property
                    MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_navigator)["Pages"];

                    // Remove all pages from the navigator
                    RaiseComponentChanging(propertyPages);

                    // Get the designer to destroy each page in turn
                    for (int i = _navigator.Pages.Count; i > 0; i--)
                    {
                        _designerHost.DestroyComponent(_navigator.Pages[0]);
                    }

                    RaiseComponentChanged(propertyPages, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnClearItems(object sender, EventArgs e)
        {
            if (_ribbonCluster?.Ribbon != null)
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster ClearItems");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCluster)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Need access to host in order to delete a component
                    IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

                    // We need to remove all the buttons from the cluster group
                    for (int i = _ribbonCluster.Items.Count - 1; i >= 0; i--)
                    {
                        KryptonRibbonGroupItem item = _ribbonCluster.Items[i];
                        _ribbonCluster.Items.Remove(item);
                        host.DestroyComponent(item);
                    }

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMovePrevious(object sender, EventArgs e)
        {
            if (_ribbonLabel?.Ribbon != null)
            {
                // Get access to the parent collection of items
                TypedRestrictCollection <KryptonRibbonGroupItem> items = ParentItems;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupLabel MovePrevious");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonLabel.RibbonContainer)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    int index = items.IndexOf(_ribbonLabel) - 1;
                    index = Math.Max(index, 0);
                    items.Remove(_ribbonLabel);
                    items.Insert(index, _ribbonLabel);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnAddGroup(object sender, EventArgs e)
        {
            if ((_ribbonTab?.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab AddGroup");

                try
                {
                    // Get access to the Groups property
                    MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonTab)["Groups"];

                    RaiseComponentChanging(propertyGroups);

                    // Get designer to create the new group component
                    KryptonRibbonGroup group = (KryptonRibbonGroup)_designerHost.CreateComponent(typeof(KryptonRibbonGroup));
                    _ribbonTab.Groups.Add(group);

                    RaiseComponentChanged(propertyGroups, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnClearGroups(object sender, EventArgs e)
        {
            if ((_ribbonTab?.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab ClearGroups");

                try
                {
                    // Get access to the Groups property
                    MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonTab)["Groups"];

                    RaiseComponentChanging(propertyGroups);

                    // Need access to host in order to delete a component
                    IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

                    // We need to remove all the groups from the tab
                    for (int i = _ribbonTab.Groups.Count - 1; i >= 0; i--)
                    {
                        KryptonRibbonGroup group = _ribbonTab.Groups[i];
                        _ribbonTab.Groups.Remove(group);
                        host.DestroyComponent(group);
                    }

                    RaiseComponentChanged(propertyGroups, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMoveNext(object sender, EventArgs e)
        {
            if (_ribbonColorButton?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupCluster cluster = (KryptonRibbonGroupCluster)_ribbonColorButton.RibbonContainer;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupColorClusterButton MoveNext");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(cluster)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    int index = cluster.Items.IndexOf(_ribbonColorButton) + 1;
                    index = Math.Min(index, cluster.Items.Count - 1);
                    cluster.Items.Remove(_ribbonColorButton);
                    cluster.Items.Insert(index, _ribbonColorButton);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMoveLast(object sender, EventArgs e)
        {
            if ((_ribbonTab?.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab MoveLast");

                try
                {
                    // Get access to the RibbonTabs property
                    MemberDescriptor propertyTabs = TypeDescriptor.GetProperties(_ribbonTab.Ribbon)["RibbonTabs"];

                    RaiseComponentChanging(propertyTabs);

                    // Move position of the tab
                    KryptonRibbon ribbon = _ribbonTab.Ribbon;
                    ribbon.RibbonTabs.Remove(_ribbonTab);
                    ribbon.RibbonTabs.Insert(ribbon.RibbonTabs.Count, _ribbonTab);
                    ribbon.SelectedTab = _ribbonTab;
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyTabs, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnClearTabs(object sender, EventArgs e)
        {
            // Use a transaction to support undo/redo actions
            DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbon ClearTabs");

            try
            {
                // Get access to the tabs property
                MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_ribbon)["RibbonTabs"];

                RaiseComponentChanging(propertyPages);

                // Need access to host in order to delete a component
                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

                // We need to remove all the tabs from the ribbon
                for (int i = _ribbon.RibbonTabs.Count - 1; i >= 0; i--)
                {
                    KryptonRibbonTab tab = _ribbon.RibbonTabs[i];
                    _ribbon.RibbonTabs.Remove(tab);
                    host.DestroyComponent(tab);
                }

                RaiseComponentChanged(propertyPages, null, null);
            }
            finally
            {
                // If we managed to create the transaction, then do it
                transaction?.Commit();

                UpdateVerbStatus();
            }
        }
        private void OnAddTab(object sender, EventArgs e)
        {
            // Use a transaction to support undo/redo actions
            DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbon AddTab");

            try
            {
                // Get access to the tabs property
                MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_ribbon)["RibbonTabs"];

                RaiseComponentChanging(propertyPages);

                // Get designer to create the new tab component
                KryptonRibbonTab page = (KryptonRibbonTab)_designerHost.CreateComponent(typeof(KryptonRibbonTab));
                _ribbon.RibbonTabs.Add(page);

                RaiseComponentChanged(propertyPages, null, null);
            }
            finally
            {
                // If we managed to create the transaction, then do it
                transaction?.Commit();

                UpdateVerbStatus();
            }
        }
예제 #14
0
        private void OnAddGallery(object sender, EventArgs e)
        {
            if ((_ribbonGroup?.Ribbon != null) && _ribbonGroup.RibbonTab.Groups.Contains(_ribbonGroup))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroup AddGallery");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonGroup)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Get designer to create the new gallery component
                    KryptonRibbonGroupGallery gallery = (KryptonRibbonGroupGallery)_designerHost.CreateComponent(typeof(KryptonRibbonGroupGallery));
                    _ribbonGroup.Items.Add(gallery);

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMoveLast(object sender, EventArgs e)
        {
            if (_ribbonCluster?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupLines lines = (KryptonRibbonGroupLines)_ribbonCluster.RibbonContainer;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster MoveLast");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(lines)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the cluster
                    lines.Items.Remove(_ribbonCluster);
                    lines.Items.Insert(lines.Items.Count, _ribbonCluster);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnDeleteTab(object sender, EventArgs e)
        {
            if ((_ribbonTab?.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab DeleteTab");

                try
                {
                    // Get access to the RibbonTabs property
                    MemberDescriptor propertyTabs = TypeDescriptor.GetProperties(_ribbonTab.Ribbon)["RibbonTabs"];

                    // Remove the ribbon tab from the ribbon
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(propertyTabs);

                    // Remove the page from the ribbon
                    _ribbonTab.Ribbon.RibbonTabs.Remove(_ribbonTab);

                    // Get designer to destroy it
                    _designerHost.DestroyComponent(_ribbonTab);

                    RaiseComponentChanged(propertyTabs, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnAddColorButton(object sender, EventArgs e)
        {
            if (_ribbonCluster?.Ribbon != null)
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster AddColorButton");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCluster)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Get designer to create a cluster color button item
                    KryptonRibbonGroupClusterColorButton button = (KryptonRibbonGroupClusterColorButton)_designerHost.CreateComponent(typeof(KryptonRibbonGroupClusterColorButton));
                    _ribbonCluster.Items.Add(button);

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMoveLast(object sender, EventArgs e)
        {
            if (_ribbonColorButton?.Ribbon != null)
            {
                // Get access to the parent collection of items
                var items = ParentItems;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction(@"KryptonRibbonGroupColorButton MoveLast");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonColorButton.RibbonContainer)[@"Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    items.Remove(_ribbonColorButton);
                    items.Insert(items.Count, _ribbonColorButton);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnDeleteCluster(object sender, EventArgs e)
        {
            if (_ribbonCluster?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupLines lines = (KryptonRibbonGroupLines)_ribbonCluster.RibbonContainer;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupTriple DeleteTriple");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(lines)["Items"];

                    // Remove the ribbon group from the ribbon tab
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(propertyItems);

                    // Remove the cluster from the lines
                    lines.Items.Remove(_ribbonCluster);

                    // Get designer to destroy it
                    _designerHost.DestroyComponent(_ribbonCluster);

                    RaiseComponentChanged(propertyItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
예제 #20
0
        private void OnDeleteSeparator(object sender, EventArgs e)
        {
            if ((_ribbonSeparator?.Ribbon != null) && _ribbonSeparator.RibbonGroup.Items.Contains(_ribbonSeparator))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupSeparator DeleteSeparator");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonSeparator.RibbonGroup)["Items"];

                    // Remove the ribbon group from the ribbon tab
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(propertyItems);

                    // Remove the separator from the group
                    _ribbonSeparator.RibbonGroup.Items.Remove(_ribbonSeparator);

                    // Get designer to destroy it
                    _designerHost.DestroyComponent(_ribbonSeparator);

                    RaiseComponentChanged(propertyItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
예제 #21
0
        private void OnAddPage(object sender, EventArgs e)
        {
            // Use a transaction to support undo/redo actions
            DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonNavigator AddPage");

            try
            {
                // Get access to the Pages property
                MemberDescriptor propertyPages = TypeDescriptor.GetProperties(Navigator)["Pages"];

                // Do we need to raise the changing notification?
                if (!_ignoreOnAddPage)
                {
                    RaiseComponentChanging(propertyPages);
                }

                // Get designer to create the new page component
                KryptonPage page = (KryptonPage)_designerHost.CreateComponent(typeof(KryptonPage));

                // Get access to the Name and Text propertues of the new page
                PropertyDescriptor propertyName = TypeDescriptor.GetProperties(page)["Name"];
                PropertyDescriptor propertyText = TypeDescriptor.GetProperties(page)["Text"];

                // If we managed to get the property and it is the string we are expecting
                if ((propertyName != null) && (propertyName.PropertyType == typeof(string)) &&
                    (propertyText != null) && (propertyText.PropertyType == typeof(string)))
                {
                    // Grab the design time name
                    string name = (string)propertyName.GetValue(page);

                    // If the name is valid
                    if ((name != null) && (name.Length > 0))
                    {
                        // Use the design time name as the page text
                        propertyText.SetValue(page, name);
                    }
                }

                // Add a new defaulted page to the navigator
                Navigator.Pages.Add(page);

                // Do we need to raise the changed notification?
                if (!_ignoreOnAddPage)
                {
                    RaiseComponentChanged(propertyPages, null, null);
                }
            }
            finally
            {
                // If we managed to create the transaction, then do it
                transaction?.Commit();
            }
        }
        internal override bool SendNotification(GridEntry entry, Notify notification)
        {
            DesignerTransaction transaction = DesignerHost?.CreateTransaction();

            try
            {
                return(base.SendNotification(entry, notification));
            }
            finally
            {
                transaction?.Commit();
            }
        }
        protected internal override bool NotifyChildValue(GridEntry entry, Notify type)
        {
            DesignerTransaction transaction = DesignerHost?.CreateTransaction();

            try
            {
                return(base.NotifyChildValue(entry, type));
            }
            finally
            {
                transaction?.Commit();
            }
        }
예제 #24
0
        private void OnMoveToTab(object sender, EventArgs e)
        {
            if ((_ribbonGroup != null) &&
                (_ribbonGroup.Ribbon != null) &&
                _ribbonGroup.RibbonTab.Groups.Contains(_ribbonGroup))
            {
                // Cast to correct type
                ToolStripMenuItem tabMenuItem = (ToolStripMenuItem)sender;

                // Get access to the destination tab
                KryptonRibbonTab destination = (KryptonRibbonTab)tabMenuItem.Tag;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroup MoveTabTo");

                try
                {
                    // Get access to the Groups property
                    MemberDescriptor oldGroups    = TypeDescriptor.GetProperties(_ribbonGroup.RibbonTab)["Groups"];
                    MemberDescriptor newGroups    = TypeDescriptor.GetProperties(destination)["Groups"];
                    MemberDescriptor newGroupsTab = TypeDescriptor.GetProperties(_ribbonGroup.Ribbon)["RibbonTabs"];

                    // Remove the ribbon tab from the ribbon
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(oldGroups);
                    RaiseComponentChanging(newGroups);
                    RaiseComponentChanging(newGroupsTab);

                    // Remove group from current group
                    _ribbonGroup.RibbonTab.Groups.Remove(_ribbonGroup);

                    // Append to the new destination group
                    destination.Groups.Add(_ribbonGroup);

                    RaiseComponentChanged(newGroupsTab, null, null);
                    RaiseComponentChanged(newGroups, null, null);
                    RaiseComponentChanged(oldGroups, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        internal void RemovePageFromWizard(WizardPage page)
        {
            var h = DesignerHost;
            var c = ComponentChangeService;

            if (h == null || c == null)
            {
                throw new ArgumentException("Both IDesignerHost and IComponentChangeService arguments cannot be null.");
            }

            if (Control == null || !Control.Pages.Contains(page))
            {
                return;
            }

            DesignerTransaction dt = null;

            try
            {
                dt = h.CreateTransaction("Remove Wizard Page");

                MemberDescriptor member = TypeDescriptor.GetProperties(Control)["Pages"];
                RaiseComponentChanging(member);

                if (page.Owner != null)
                {
                    //c.OnComponentChanging(page.Owner, null);
                    page.Owner.Pages.Remove(page);
                    //c.OnComponentChanged(page.Owner, null, null, null);
                    h.DestroyComponent(page);
                }
                else
                {
                    //c.OnComponentChanging(page, null);
                    page.Dispose();
                    //c.OnComponentChanged(page, null, null, null);
                }
                RaiseComponentChanged(member, null, null);
            }
            finally
            {
                dt?.Commit();
            }
            RefreshDesigner();
        }
예제 #26
0
        private void OnAddTriple(object sender, EventArgs e)
        {
            if ((_ribbonGroup != null) &&
                (_ribbonGroup.Ribbon != null) &&
                _ribbonGroup.RibbonTab.Groups.Contains(_ribbonGroup))
            {
                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroup AddTriple");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonGroup)["Items"];

                    RaiseComponentChanging(propertyItems);

                    // Get designer to create the new triple component
                    KryptonRibbonGroupTriple triple = (KryptonRibbonGroupTriple)_designerHost.CreateComponent(typeof(KryptonRibbonGroupTriple));
                    _ribbonGroup.Items.Add(triple);

                    // Get access to the Triple.Items property
                    MemberDescriptor propertyTripleItems = TypeDescriptor.GetProperties(triple)["Items"];

                    RaiseComponentChanging(propertyTripleItems);

                    // Get designer to create three new button components
                    KryptonRibbonGroupButton button1 = (KryptonRibbonGroupButton)_designerHost.CreateComponent(typeof(KryptonRibbonGroupButton));
                    KryptonRibbonGroupButton button2 = (KryptonRibbonGroupButton)_designerHost.CreateComponent(typeof(KryptonRibbonGroupButton));
                    KryptonRibbonGroupButton button3 = (KryptonRibbonGroupButton)_designerHost.CreateComponent(typeof(KryptonRibbonGroupButton));
                    triple.Items.Add(button1);
                    triple.Items.Add(button2);
                    triple.Items.Add(button3);

                    RaiseComponentChanged(propertyTripleItems, null, null);
                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnMoveToGroup(object sender, EventArgs e)
        {
            if ((_ribbonSeparator?.Ribbon != null) && _ribbonSeparator.RibbonGroup.Items.Contains(_ribbonSeparator))
            {
                // Cast to correct type
                ToolStripMenuItem groupMenuItem = (ToolStripMenuItem)sender;

                // Get access to the destination tab
                KryptonRibbonGroup destination = (KryptonRibbonGroup)groupMenuItem.Tag;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction(@"KryptonRibbonGroupSeparator MoveSeparatorToGroup");

                try
                {
                    // Get access to the Groups property
                    MemberDescriptor oldItems = TypeDescriptor.GetProperties(_ribbonSeparator.RibbonGroup)[@"Items"];
                    MemberDescriptor newItems = TypeDescriptor.GetProperties(destination)[@"Items"];

                    // Remove the ribbon tab from the ribbon
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(oldItems);
                    RaiseComponentChanging(newItems);

                    // Remove group from current group
                    _ribbonSeparator.RibbonGroup.Items.Remove(_ribbonSeparator);

                    // Append to the new destination group
                    destination.Items.Add(_ribbonSeparator);

                    RaiseComponentChanged(newItems, null, null);
                    RaiseComponentChanged(oldItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
예제 #28
0
        internal void InsertPageIntoWizard(bool add)
        {
            var h   = DesignerHost;
            var c   = ComponentChangeService;
            var wiz = Control;

            if (h == null || c == null)
            {
                throw new ArgumentException("Both IDesignerHost and IComponentChangeService arguments cannot be null.");
            }

            DesignerTransaction dt = null;

            try
            {
                dt = h.CreateTransaction("Insert Wizard Page");
                var page = (WizardPage)h.CreateComponent(typeof(WizardPage));
                MemberDescriptor member = TypeDescriptor.GetProperties(wiz)["Pages"];
                RaiseComponentChanging(member);

                //Add a new page to the collection
                if (wiz.Pages.Count == 0 || add)
                {
                    wiz.Pages.Add(page);
                }
                else
                {
                    wiz.Pages.Insert(wiz.SelectedPageIndex, page);
                }

                RaiseComponentChanged(member, null, null);
            }
            finally
            {
                dt?.Commit();
            }
            RefreshDesigner();
        }
        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));
        }
        protected internal override bool NotifyValueGivenParent(object @object, Notify type)
        {
            if (@object is ICustomTypeDescriptor descriptor)
            {
                @object = descriptor.GetPropertyOwner(_propertyInfo);
            }

            switch (type)
            {
            case Notify.Reset:

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

                if (objects is not null && objects.Length > 0)
                {
                    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(@object);

                        if (needChangeNotify)
                        {
                            OnComponentChanged();
                        }

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

                return(false);

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

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

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

                    return(false);
                }
                else
                {
                    return(base.NotifyValueGivenParent(@object, type));
                }
            }

            return(base.NotifyValueGivenParent(@object, type));
        }