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

using System;
using System.Windows;
using Haestad.Framework.Manager;
using Haestad.Framework.UI.Integration;
using Haestad.Support.Storage;

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// A class that defines a global settings element that stores ribbon global settings.
    /// </summary>
    public class RibbonGlobalUserSettingsElement : ElementListManagerElementBase, IStorageAtom, ICloneableElement
    {
        #region Constructor
        public RibbonGlobalUserSettingsElement(int id, RibbonGlobalUserSettingsManager manager)
            : base(id, manager)
        {
        }
        #endregion

        #region IStorageAtom Members
        public string Name
        {
            get { return String.Empty; }
        }

        public virtual void Read(IStorageReadStream stream, int version)
        {
            if (version >= 1)
            {
                IsRibbonMinimized = stream.ReadBooleanAttribute(RibbonGlobalUserSettingsElementNames.IsRibbonMinimized);
                IsQuickAccessToolBarAboveRibbon = stream.ReadBooleanAttribute(RibbonGlobalUserSettingsElementNames.IsQuickAccessToolBarAboveRibbon);
            }
        }

        public virtual void Write(IStorageWriteStream stream)
        {
            stream.WriteAttribute(RibbonGlobalUserSettingsElementNames.IsRibbonMinimized, IsRibbonMinimized);
            stream.WriteAttribute(RibbonGlobalUserSettingsElementNames.IsQuickAccessToolBarAboveRibbon, IsQuickAccessToolBarAboveRibbon);
        }
        #endregion

        #region IClonableElement Members
        public void AddClone()
        {
            int position = Manager.Add();
            RibbonGlobalUserSettingsElement newElement = Manager.ElementAt(position) as RibbonGlobalUserSettingsElement;
            CloneProperties(newElement);
        }
        #endregion

        #region Private Methods
        private void CloneProperties(RibbonGlobalUserSettingsElement clone)
        {
            clone.IsRibbonMinimized = IsRibbonMinimized;
            clone.IsQuickAccessToolBarAboveRibbon = IsQuickAccessToolBarAboveRibbon;
        }
        #endregion

        #region Public Override Properties
        public override string Label
        {
            get { return string.Empty; }
            set { }
        }
        #endregion

        #region Public Properties
        public bool IsRibbonMinimized
        {
            get;
            set;
        }

        public bool IsQuickAccessToolBarAboveRibbon
        {
            get;
            set;
        }
        #endregion

        #region Private Structs
        private struct RibbonGlobalUserSettingsElementNames
        {
            public const string IsRibbonMinimized = "IsRibbonMinimized";
            public const string IsQuickAccessToolBarAboveRibbon = "IsQuickAccessToolBarAboveRibbon";
        }
        #endregion
    }
}
