/// <summary> /// Initialize a new instance of the ViewLayoutRibbonQATContents class. /// </summary> /// <param name="ribbon">Owning ribbon control instance.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> /// <param name="showExtraButton">Should the extra button be shown.</param> public ViewLayoutRibbonQATContents(KryptonRibbon ribbon, NeedPaintHandler needPaint, bool showExtraButton) { Debug.Assert(ribbon != null); Debug.Assert(needPaint != null); Ribbon = ribbon; _needPaint = needPaint; // Create initial lookup table _qatButtonToView = new QATButtonToView(); // Create the extra button for customization/overflow if (showExtraButton) { _extraButton = new ViewDrawRibbonQATExtraButton(ribbon, needPaint); _extraButton.ClickAndFinish += OnExtraButtonClick; } }
private void SyncChildren(bool layout) { // Remove all child elements Clear(); // Create a new lookup that reflects any changes in QAT buttons QATButtonToView regenerate = new QATButtonToView(); // Get an array with all the buttons to be considered for display IQuickAccessToolbarButton[] qatButtons = QATButtons; // Make sure we have a view element to match each QAT button definition foreach (IQuickAccessToolbarButton qatButton in qatButtons) { ViewDrawRibbonQATButton view = null; // Get the currently cached view for the button if (_qatButtonToView.ContainsKey(qatButton)) { view = _qatButtonToView[qatButton]; } // If a new button, create a view for it now if (view == null) { view = new ViewDrawRibbonQATButton(Ribbon, qatButton, _needPaint); } // Add to the lookup for future reference regenerate.Add(qatButton, view); } // Add child elements appropriate for each qat button for (int i = 0; i < qatButtons.Length; i++) { IQuickAccessToolbarButton qatButton = qatButtons[i]; // Does the layout processing require the view to be updated if (layout) { // Update the enabled/visible state of the button regenerate[qatButton].Enabled = Ribbon.InDesignHelperMode || qatButton.GetEnabled(); regenerate[qatButton].Visible = Ribbon.InDesignHelperMode || qatButton.GetVisible(); } // Always add the group view Add(regenerate[qatButton]); // Remove entries we are still using if (_qatButtonToView.ContainsKey(qatButton)) { _qatButtonToView.Remove(qatButton); } } // Dispose of views no longer required foreach (ViewDrawRibbonQATButton view in _qatButtonToView.Values) { view.Dispose(); } // No longer need the old lookup _qatButtonToView = regenerate; // Always add the customization/overflow button last if (_extraButton != null) { Add(_extraButton); } }