using System;
using System.Xml;
using nft.framework;
using nft.framework.plugin;
using nft.util;
using nft.ui.mainframe_old;
using nft.framework.drawing;
using nft.ui.command;

namespace nft.contributions.ui
{
	/// <summary>
	/// CtbMenuItem の概要の説明です。
	/// </summary>
	public class CtbCommandUI : Contribution
	{
        private static readonly Type singleDefault = typeof(TriggerCommandUI);
		public readonly string location;
		protected readonly string after = null;
		protected readonly string before = null;

		/// <summary>
		/// Contributes a menu and submenu items to mainmenu.
		/// 
		/// This contribution can add several items at once.
		/// </summary>
        public CtbCommandUI(Plugin p, ParamsReader e)
            : base(p, e) 
		{
            object[] args = new object[] { this, e };
            CommandUI cui = (CommandUI)PluginUtil.loadObjectFromManifest(e, args, singleDefault);
            ParamsReader ndSetup = e["setup"];
            if (!ndSetup.IsNull) {
                ParamsReader ndMenu = ndSetup["menu-item"];
                ConfirmIDAttribute(ndMenu);
                ParamsReader ndTool = ndSetup["tool-item"];
                ConfirmIDAttribute(ndTool);
                CommandPathHint hint = new CommandPathHint(ndMenu);
                CommandPathHint hint2 = new CommandPathHint(ndTool);
                CommandManager.TheInstance.RegisterCommand(this, cui, hint, hint2);
            }
		}

        protected void ConfirmIDAttribute(ParamsReader e) {
            if (e["id"].IsNull) {
                e.OverWrite("id", this.id.AsString);
            }
        }
	}
}
