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();
                }
            }
        }
        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();
                }
            }
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawRibbonDesignGroupLines class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon control.</param>
        /// <param name="ribbonLines">Associated ribbon group lines.</param>
        /// <param name="currentSize">Size the view should use.</param>
        /// <param name="needPaint">Delegate for notifying paint requests.</param>
        public ViewDrawRibbonDesignGroupLines(KryptonRibbon ribbon,
                                              KryptonRibbonGroupLines ribbonLines,
                                              GroupItemSize currentSize,
                                              NeedPaintHandler needPaint)
            : base(ribbon, needPaint)
        {
            Debug.Assert(ribbonLines != null);

            _ribbonLines = ribbonLines;
            CurrentSize  = currentSize;
            _padding     = new Padding(0, (int)(2 * FactorDpiY), (int)(2 * FactorDpiX), (int)(4 * FactorDpiY));
        }
Esempio n. 4
0
        /// <summary>
        /// Initialize a new instance of the ViewLayoutRibbonGroupLines class.
        /// </summary>
        /// <param name="ribbon">Owning ribbon control instance.</param>
        /// <param name="ribbonLines">Reference to lines definition.</param>
        /// <param name="needPaint">Delegate for notifying paint requests.</param>
        public ViewLayoutRibbonGroupLines(KryptonRibbon ribbon,
                                          KryptonRibbonGroupLines ribbonLines,
                                          NeedPaintHandler needPaint)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonLines != null);
            Debug.Assert(needPaint != null);

            // Cache references
            _ribbon      = ribbon;
            _ribbonLines = ribbonLines;
            _needPaint   = needPaint;

            // Associate the component with this view element for design time selection
            Component = _ribbonLines;

            // Use hashtable to store relationships
            _itemToView      = new ItemToView();
            _viewToItem      = new ViewToItem();
            _sizeLargeList   = new SizeList();
            _sizeMediumList  = new SizeList();
            _sizeSmallList   = new SizeList();
            _viewLargeList   = new ViewList();
            _viewMediumList  = new ViewList();
            _viewSmallList   = new ViewList();
            _viewToLargeGap  = new ViewToGap();
            _viewToMediumGap = new ViewToGap();
            _viewToSmallGap  = new ViewToGap();

            // Get the initial size used for sizing and positioning
            ApplySize(ribbonLines.ItemSizeCurrent);

            // Hook into changes in the ribbon triple definition
            _ribbonLines.PropertyChanged += OnLinesPropertyChanged;
            _ribbonLines.LinesView        = this;

            // At design time we want to track the mouse and show feedback
            if (_ribbon.InDesignMode)
            {
                ViewHightlightController controller = new(this, needPaint);
                controller.ContextClick += OnContextClick;
                MouseController          = controller;
            }
        }
        private void UpdateVerbStatus()
        {
            // Create verbs first time around
            if (_verbs == null)
            {
                _verbs              = new DesignerVerbCollection();
                _toggleHelpersVerb  = new DesignerVerb(@"Toggle Helpers", OnToggleHelpers);
                _moveFirstVerb      = new DesignerVerb(@"Move Cluster First", OnMoveFirst);
                _movePrevVerb       = new DesignerVerb(@"Move Cluster Previous", OnMovePrevious);
                _moveNextVerb       = new DesignerVerb(@"Move Cluster Next", OnMoveNext);
                _moveLastVerb       = new DesignerVerb(@"Move Cluster Last", OnMoveLast);
                _addButtonVerb      = new DesignerVerb(@"Add Button", OnAddButton);
                _addColorButtonVerb = new DesignerVerb(@"Add Color Button", OnAddColorButton);
                _clearItemsVerb     = new DesignerVerb(@"Clear Items", OnClearItems);
                _deleteClusterVerb  = new DesignerVerb(@"Delete Cluster", OnDeleteCluster);
                _verbs.AddRange(new[] { _toggleHelpersVerb, _moveFirstVerb, _movePrevVerb, _moveNextVerb, _moveLastVerb,
                                        _addButtonVerb, _addColorButtonVerb, _clearItemsVerb, _deleteClusterVerb });
            }

            var moveFirst  = false;
            var movePrev   = false;
            var moveNext   = false;
            var moveLast   = false;
            var clearItems = false;

            if (_ribbonCluster?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupLines lines = (KryptonRibbonGroupLines)_ribbonCluster.RibbonContainer;

                moveFirst  = lines.Items.IndexOf(_ribbonCluster) > 0;
                movePrev   = lines.Items.IndexOf(_ribbonCluster) > 0;
                moveNext   = lines.Items.IndexOf(_ribbonCluster) < (lines.Items.Count - 1);
                moveLast   = lines.Items.IndexOf(_ribbonCluster) < (lines.Items.Count - 1);
                clearItems = _ribbonCluster.Items.Count > 0;
            }

            _moveFirstVerb.Enabled  = moveFirst;
            _movePrevVerb.Enabled   = movePrev;
            _moveNextVerb.Enabled   = moveNext;
            _moveLastVerb.Enabled   = moveLast;
            _clearItemsVerb.Enabled = clearItems;
        }
Esempio n. 6
0
        private void OnAddLines(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 AddLines");

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

                    RaiseComponentChanging(propertyItems);

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

                    // Get access to the Lines.Items property
                    MemberDescriptor propertyLinesItems = TypeDescriptor.GetProperties(lines)[@"Items"];

                    RaiseComponentChanging(propertyLinesItems);

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

                    RaiseComponentChanged(propertyLinesItems, null, null);
                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
Esempio n. 7
0
        public void InitializeRibbonTools(KryptonRibbon ribbon)
        {
            ribbon.RibbonTabs.Clear();
            var tools = extensionManager.GetExtensions <Tool>().ToList();
            var toolsGroupedByTabs = from tool in tools
                                     group tool by tool.ToolTab into toolTabGroup
                                     orderby toolTabGroup.Key.OrderingIndex
                                     select toolTabGroup;

            foreach (var toolGroupingTabDefinition in toolsGroupedByTabs)
            {
                var ribbonTab = new KryptonRibbonTab
                {
                    Text   = toolGroupingTabDefinition.Key.Name,
                    KeyTip = toolGroupingTabDefinition.Key.KeyTip
                };

                ribbon.RibbonTabs.Add(ribbonTab);

                var toolsGroupedByGroup = from tool in toolGroupingTabDefinition
                                          group tool by tool.ToolGroup into toolGroup
                                          orderby toolGroup.Key.OrderingIndex
                                          select toolGroup;

                foreach (var toolGroupingDefinition in toolsGroupedByGroup)
                {
                    var ribbonGroup = new KryptonRibbonGroup
                    {
                        TextLine1 = toolGroupingDefinition.Key.Name
                    };

                    var toolContainerTriple = new KryptonRibbonGroupTriple();
                    var toolContainerLines  = new KryptonRibbonGroupLines {
                        MaximumSize = GroupItemSize.Large
                    };

                    foreach (var tool in toolGroupingDefinition.OrderBy(t => t.OrderingIndex))
                    {
                        switch (tool)
                        {
                        case ButtonTool buttonTool:
                            var button = new KryptonRibbonGroupButton
                            {
                                TextLine1    = buttonTool.ToolName,
                                ImageSmall   = buttonTool.ToolIconSmall,
                                ImageLarge   = buttonTool.ToolIconLarge,
                                ToolTipStyle = LabelStyle.ToolTip,
                                ToolTipTitle = buttonTool.ToolTip,
                                Tag          = buttonTool
                            };

                            button.Click += Button_Click;

                            if (buttonTool.IsFocusedTool)
                            {
                                var splittedTexts = buttonTool.ToolName.Split(' ', '-');
                                if (splittedTexts.Length == 2)
                                {
                                    button.TextLine1 = splittedTexts[0];
                                    button.TextLine2 = splittedTexts[1];
                                }
                                else
                                {
                                    button.TextLine1 = buttonTool.ToolName;
                                }

                                toolContainerTriple.Items.Add(button);
                            }
                            else
                            {
                                toolContainerLines.Items.Add(button);
                            }

                            toolStrips.Add(button);

                            break;

                        case DropdownTool dropDownTool:
                            var dropDown = new KryptonRibbonGroupComboBox();
                            toolContainerLines.Items.Add(dropDown);
                            break;
                        }
                    }

                    if (toolContainerTriple.Items.Any())
                    {
                        ribbonGroup.Items.Add(toolContainerTriple);
                    }

                    if (toolContainerLines.Items.Any())
                    {
                        ribbonGroup.Items.Add(toolContainerLines);
                    }

                    ribbonTab.Groups.Add(ribbonGroup);
                }
            }
        }