Exemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DataAnnoAddAttrCommand" /> 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 DataAnnoAddAttrCommand(AsyncPackage package, OleMenuCommandService commandService, SDTE SDTEService,
                                       IDataAnnoAttributeService attributeService, TextSelectionExecutor textSelectionExecutor,
                                       IVsThreadedWaitDialogFactory dialogFactory, SelectedItemCountExecutor selectedItemCountExecutor,
                                       AttributeExecutor attributeExecutor)
        {
            _package                   = package ?? throw new ArgumentNullException(nameof(package));
            commandService             = commandService ?? throw new ArgumentNullException(nameof(commandService));
            _sdteService               = SDTEService;
            _attributeService          = attributeService;
            _textSelectionExecutor     = textSelectionExecutor;
            _dialogFactory             = dialogFactory;
            _selectedItemCountExecutor = selectedItemCountExecutor;
            _attributeExecutor         = attributeExecutor;
            var menuCommandID = new CommandID(_commandSet, CommandId);
            var menuItem      = new MenuCommand(Execute, menuCommandID);

            commandService.AddCommand(menuItem);
        }
        /// <summary> Initializes the singleton instance of the command. </summary>
        /// <param name="package"> Owner package, not null. </param>
        public static async Task InitializeAsync(AsyncPackage package)
        {
            // Switch to the main thread - the call to AddCommand in ProtoCommand's constructor requires the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            var attributeService = await package.GetServiceAsync(typeof(IProtoAttributeService)) as IProtoAttributeService;

            var dialogFactory = await package.GetServiceAsync(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;

            var SDTE = await package.GetServiceAsync(typeof(SDTE)) as SDTE;

            var textSelectionExecutor     = new TextSelectionExecutor();
            var selectedItemCountExecutor = new SelectedItemCountExecutor();
            var attributeExecutor         = new AttributeExecutor();

            Instance = new ProtoRenumberAttrCommand(package, commandService, SDTE, attributeService, textSelectionExecutor,
                                                    dialogFactory, selectedItemCountExecutor, attributeExecutor);
        }