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

using Haestad.Support.Library;
using Haestad.Support.Support;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.RibbonView;

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// A base class for headless UI commands that can be used to register hot keys that are not associated
    /// with any Ribbon UI elements. Such commands are invisible to ribbon search.
    /// </summary>
    internal abstract class HeadlessUICommandBase : IRibbonUICommand
    {
        #region Constructor
        internal HeadlessUICommandBase()
        {
            SatisfyWhinyCompilerRegardingCanExecuteChanged();
            m_ribbonHotKey = null;
        }
        #endregion

        #region IRibbonUICommand Members
        public string GraphicResourceKey
        {
            get
            {
                return String.Empty;
            }
        }

        public RibbonHotKey HotKey
        {
            get
            {
                if (m_ribbonHotKey == null)
                    m_ribbonHotKey = NewHotKey();
                return m_ribbonHotKey;
            }
        }

        public string Label
        {
            get
            {
                return String.Empty;
            }
        }

        public string LargeGraphicResourceKey
        {
            get
            {
                return String.Empty;
            }
        }

        public string Name
        {
            get
            {
                return String.Empty;
            }
        }

        public string ToolTipDescription
        {
            get
            {
                return String.Empty;
            }
        }

        public string ToolTipTitle
        {
            get
            {
                return String.Empty;
            }
        }

        public bool UseHotKeyInToolTip
        {
            get
            {
                return false;
            }

            set
            {
            }
        }

        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public abstract void Execute(object parameter);

        public string GetCleanLabel()
        {
            return String.Empty;
        }

        public string GetCleanToolTipDescription()
        {
            return String.Empty;
        }

        public string GetCleanToolTipTitle()
        {
            return String.Empty;
        }
        #endregion

        #region Protected Abstract Methods
        protected abstract RibbonHotKey NewHotKey();
        #endregion

        #region Private Methods
        private void SatisfyWhinyCompilerRegardingCanExecuteChanged()
        {
            // If we don't do this, the compiler gets all upset that we have an event that we expose, that we never trigger.
            // (Error CS0067  The event 'RibbonNavigationActivationUICommand.CanExecuteChanged' is never used)
            if (CanExecuteChanged != null)
                CanExecuteChanged = null;
        }
        #endregion

        #region Private Fields
        private RibbonHotKey m_ribbonHotKey;
        #endregion
    }
}
