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; }
/// <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 ViewHightlightController(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 DesignerVerb[] { _toggleHelpersVerb, _moveFirstVerb, _movePrevVerb, _moveNextVerb, _moveLastVerb, _addButtonVerb, _addColorButtonVerb, _clearItemsVerb, _deleteClusterVerb }); } bool moveFirst = false; bool movePrev = false; bool moveNext = false; bool moveLast = false; bool 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; }
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(); } } }