コード例 #1
0
        public void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider)
        {
            if (m_metaCommand != null || m_serviceProvider != null)
            {
                throw new InvalidOperationException("Associate should only be called once on a IFeature instance.");
            }

            if (metaFeature == null)
            {
                throw new ArgumentNullException("metaFeature");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            m_metaCommand     = metaFeature as MetaCommand;
            m_serviceProvider = serviceProvider;

            IMenuCommandService menuService = m_serviceProvider.GetService <IMenuCommandService>();

            Debug.Assert(menuService != null);
            if (menuService != null)
            {
                menuService.AddCommand(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Uninstalls specified command from the product.
        /// </summary>
        /// <param name="metaFeature">MetaCommand to uninstall.</param>
        public void Uninstall(MetaFeature metaFeature)
        {
            MetaCommand metaCommand = metaFeature as MetaCommand;

            Debug.Assert(metaCommand != null);
            if (metaCommand != null && metaCommand.IsCustomCommand)
            {
                string canonicalName = m_commandService.GetCanonicalName(metaCommand.Name);

                if (metaCommand.CustomCommandId == null)
                {
                    metaCommand.CustomCommandId = m_commandService.FindCommandId(canonicalName);
                }

                if (metaCommand.CustomCommandId != null)
                {
                    m_commandService.DeleteCommand(canonicalName);
                    metaCommand.CustomCommandId = null;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Checks whether given command is already installed.
        /// </summary>
        /// <param name="metaFeature">MetaCommand.</param>
        /// <returns>True if installed and false otherwise.</returns>
        public bool IsInstalled(MetaFeature metaFeature)
        {
            MetaCommand metaCommand = metaFeature as MetaCommand;

            Debug.Assert(metaCommand != null);
            if (metaCommand != null)
            {
                if (metaCommand.IsCustomCommand)
                {
                    if (metaCommand.CustomCommandId == null)
                    {
                        metaCommand.CustomCommandId = m_commandService.FindCommandId(m_commandService.GetCanonicalName(metaCommand.Name));
                    }
                    return(metaCommand.CustomCommandId != null);
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        protected virtual void Dispose(bool disposing)
        {
            Debug.Assert(disposing, "Finalizing CustomCommand without disposing.");

            if (disposing)
            {
                if (m_serviceProvider != null)
                {
                    IMenuCommandService menuService = m_serviceProvider.GetService <IMenuCommandService>();
                    if (menuService != null)
                    {
                        menuService.RemoveCommand(this);
                    }
                    m_serviceProvider = null;
                }
            }

            m_metaCommand = null;
            m_selection   = null;

            Debug.WriteLine("Unloaded and disposed command " + m_metaCommand);
        }
コード例 #5
0
        /// <summary>
        /// Installs the command into the product.
        /// </summary>
        /// <param name="metaFeature">MetaCommand to install.</param>
        public void Install(MetaFeature metaFeature)
        {
            MetaCommand metaCommand = metaFeature as MetaCommand;

            Debug.Assert(metaCommand != null && !IsInstalled(metaCommand));
            if (metaCommand != null && metaCommand.IsCustomCommand)
            {
                string canonicalName = m_commandService.GetCanonicalName(metaCommand.Name);
                if (metaCommand.CustomCommandId == null)
                {
                    metaCommand.CustomCommandId = m_commandService.FindCommandId(canonicalName);
                    if (metaCommand.CustomCommandId == null)
                    {
                        metaCommand.CustomCommandId = m_commandService.CreateCommand(canonicalName, metaCommand.Name, metaCommand.Description);
                    }
                }

                foreach (CommandPlacementAttribute attr in ReflectionHelper.GetAttributes <CommandPlacementAttribute>(metaCommand.FeatureType))
                {
                    m_commandService.PlaceCommand(canonicalName, attr.CommandBarPath);
                }
            }
        }