// QATButtonManager.cs
// Copyright (c) 2016 Bentley Systems, Incorporated. All Rights Reserved.

using System;
using Haestad.Framework.Manager;
using Haestad.Framework.UI.Integration;

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// A manager for the Telerik Quick Access ToolBar buttons.
    /// Allows users to customize the QAT content.
    /// </summary>
    public class QATButtonManager : RibbonUIButtonElementManagerBase
    {
        #region Constructor
        public QATButtonManager(IRibbonUICommandFactory ribbonUIcommandFactory)
            : base (
                  RibbonCommandCustomizationStorageElementIDs.QuickAccessToolBar,
                  RibbonCommandCustomizationStorageElementNames.QuickAccessToolBar,
                  RibbonCommandCustomizationStorageElementVersions.QuickAccessToolBar,
                  ribbonUIcommandFactory)
        {
        }
        #endregion

        #region Protected Override Methods
        protected override void InitializeSupportedFields()
        {
            // Note: <whar> This manager has no user facing UI that requires fields,
            // so as far as I know I don't need to do anything here (unless we wish to expose a UI).
        }

        protected override void AfterSynchronize()
        {
            ElementListManagerElementCollection collection = Elements();
            for (int i = 0; i < DefaultElements.Count; i++)
            {
                RibbonUIButton defaultButton = DefaultElements[i] as RibbonUIButton;
                RibbonUIButton loadedButton = collection[i] as RibbonUIButton;

                if (defaultButton.Name != loadedButton.Name)
                    throw new Exception("Expecting commands and command order to match in QATButtonManager::AfterSynchronize()"); // I18N. OK.

                // Note: <whar> We do not yet users customize these fields, so enforce default values.
                loadedButton.SeparatorAfter = defaultButton.SeparatorAfter;
                loadedButton.ButtonSize = defaultButton.ButtonSize;
                loadedButton.ButtonStyle = defaultButton.ButtonStyle;
            }
        }
        #endregion

        #region Public Override Properties
        public override Type ElementType
        {
            get { return typeof(RibbonUIButton); }
        }
        #endregion
    }
}
