Exemplo n.º 1
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static void Initialize(UndoCloseDocumentPackage package)
        {
            OleMenuCommandService commandService = package.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            IVsUIShell            uiShell        = package.GetService(typeof(SVsUIShell)) as IVsUIShell;
            DTE2 dte = package.GetService(typeof(DTE)) as DTE2;

            Instance = new UndoCloseDocument(package, commandService, uiShell, dte);
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override void Initialize()
        {
            Instance = this;

            base.Initialize();

            UndoCloseDocument.Initialize(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UndoCloseDocument"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private UndoCloseDocument(UndoCloseDocumentPackage package, OleMenuCommandService commandService, IVsUIShell uiShell, DTE2 dte)
        {
            this.package   = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

            this.uiShell = uiShell ?? throw new ArgumentNullException("IVsUIShell");
            this.dte     = dte ?? throw new ArgumentNullException("DTE");

            this.events                 = this.dte.Events ?? throw new NullReferenceException(nameof(this.events));
            this.solutionEvents         = this.events.SolutionEvents ?? throw new NullReferenceException("SolutionEvents");
            this.solutionEvents.Opened += SolutionEvents_Opened;
            //this.solutionEvents.BeforeClosing += SolutionEvents_BeforeClosing;
            this.solutionEvents.AfterClosing += SolutionEvents_AfterClosing;
            //this.documentEvents = this.events.DocumentEvents ?? throw new NullReferenceException("DocumentEvents");
            //this.documentEvents.DocumentOpening += DocumentEvents_DocumentOpening;
            //this.documentEvents.DocumentOpened += DocumentEvents_DocumentOpened;
            //this.documentEvents.DocumentClosing += DocumentEvents_DocumentClosing;
            this.windowEvents = this.events.WindowEvents ?? throw new NullReferenceException("WindowEvents");
            this.windowEvents.WindowCreated += WindowEvents_WindowCreated;
            this.windowEvents.WindowClosing += WindowEvents_WindowClosing;
            //this.commandEvents = this.events.CommandEvents ?? throw new NullReferenceException("CommandEvents");
            //this.commandEvents.BeforeExecute += CommandEvents_BeforeExecute;
            //this.commandEvents.AfterExecute += CommandEvents_AfterExecute;

            this.optionPage = package.GetDialogPage(typeof(UndoCloseDocumentOptionPage)) as UndoCloseDocumentOptionPage;
            if (this.optionPage == null)
            {
                throw new NullReferenceException("OptionPage");
            }

            var menuCommandID = new CommandID(CommandSet, CommandId);
            //var menuItem = new MenuCommand(this.Execute, menuCommandID);
            var menuItem = new OleMenuCommand(this.Execute, null, OnBeforeQueryStatus, menuCommandID);

            commandService.AddCommand(menuItem);

            CommandID dynamicItemRootId = new CommandID(CommandSet, DynamicItemMenuCommand.CommandId);
            DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand(dynamicItemRootId,
                                                                                   IsValidDynamicItem,
                                                                                   OnInvokedDynamicItem,
                                                                                   OnBeforeQueryStatusDynamicItem);

            commandService.AddCommand(dynamicMenuCommand);
        }