/// <summary>
        ///     This function is the callback used to execute the command when the menu item is clicked. See the
        ///     constructor to see how the menu item is associated with this function using OleMenuCommandService
        ///     service and MenuCommand class.
        /// </summary>
        /// <param name="sender"> Event sender. </param>
        /// <param name="e"> Event args. </param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var dte = _sdteService as DTE;

            if (dte.SelectedItems.Count <= 0)
            {
                return;
            }

            var totalCount = _selectedItemCountExecutor.Execute(dte.SelectedItems);

            IVsThreadedWaitDialog2 dialog = null;

            if (totalCount > 1 && _dialogFactory != null)
            {
                //https://www.visualstudiogeeks.com/extensions/visualstudio/using-progress-dialog-in-visual-studio-extensions
                _dialogFactory.CreateInstance(out dialog);
            }

            var cts = new CancellationTokenSource();

            if (dialog == null ||
                dialog.StartWaitDialogWithPercentageProgress("Proto Attributor: Attributing Progress", "", $"0 of {totalCount} Processed",
                                                             null, DIALOG_ACTION, true, 0, totalCount, 0) != VSConstants.S_OK)
            {
                dialog = null;
            }

            try
            {
                _attributeExecutor.Execute(dte.SelectedItems, cts, dialog, totalCount, _textSelectionExecutor,
                                           (content) => _attributeService.RemoveAttributes(content));
            }
            finally
            {
                dialog?.EndWaitDialog(out var usercancel);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     This function is the callback used to execute the command when the menu item is clicked. See the
        ///     constructor to see how the menu item is associated with this function using OleMenuCommandService
        ///     service and MenuCommand class.
        /// </summary>
        /// <param name="sender"> Event sender. </param>
        /// <param name="e"> Event args. </param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var dte = _sdteService as DTE;

            if (dte.ActiveDocument != null)
            {
                _textSelectionExecutor.Execute((TextSelection)dte.ActiveDocument.Selection, (contents) => _attributeService.RemoveAttributes(contents));
            }
        }