Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TidyCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>

        public TidyCommand(Package aPackage, Guid aGuid, int aId) : base(aPackage, aGuid, aId)
        {
            mTidyOptions = (TidyOptions)Package.GetDialogPage(typeof(TidyOptions));
            mTidyChecks  = (TidyChecks)Package.GetDialogPage(typeof(TidyChecks));
            mFileOpener  = new FileOpener(DTEObj);
            if (ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                var menuCommandID = new CommandID(CommandSet, Id);
                var menuCommand   = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
                menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler;
                menuCommand.Enabled            = true;
                commandService.AddCommand(menuCommand);
            }
        }
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 RunClangTidy(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments((DTE)DTEObj);
                    AutomationUtil.SaveDirtyProjects(DTEObj.Solution);

                    CollectSelectedItems(ScriptConstants.kAcceptedFileExtensions);

                    mFileWatcher             = new FileChangerWatcher();
                    mFileOpener              = new FileOpener(DTEObj);
                    var silentFileController = new SilentFileController();

                    using (var guard = silentFileController.GetSilentFileChangerGuard())
                    {
                        if (true == mTidyOptions.Fix || true == mTidyOptions.AutoTidyOnSave)
                        {
                            WatchFiles();

                            FilePathCollector fileCollector = new FilePathCollector();
                            var filesPath = fileCollector.Collect(mItemsCollector.GetItems).ToList();

                            silentFileController.SilentFiles(AsyncPackage, guard, filesPath);
                            silentFileController.SilentOpenFiles(AsyncPackage, guard, DTEObj);
                        }
                        RunScript(OutputWindowConstants.kTidyCodeCommand, mTidyOptions, mTidyChecks, mTidyCustomChecks, mClangFormatView);
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                finally
                {
                    mForceTidyToFix = false;
                }
            }).ContinueWith(tsk => mCommandsController.AfterExecute());
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TidyCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>

        public TidyCommand(Package aPackage, Guid aGuid, int aId, CommandsController aCommandsController)
            : base(aCommandsController, aPackage, aGuid, aId)
        {
            mTidyOptions      = (ClangTidyOptionsView)Package.GetDialogPage(typeof(ClangTidyOptionsView));
            mTidyChecks       = (ClangTidyPredefinedChecksOptionsView)Package.GetDialogPage(typeof(ClangTidyPredefinedChecksOptionsView));
            mTidyCustomChecks = (ClangTidyCustomChecksOptionsView)Package.GetDialogPage(typeof(ClangTidyCustomChecksOptionsView));
            mClangFormatView  = (ClangFormatOptionsView)Package.GetDialogPage(typeof(ClangFormatOptionsView));

            mFileOpener = new FileOpener(DTEObj);

            if (ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                var menuCommandID = new CommandID(CommandSet, Id);
                var menuCommand   = new OleMenuCommand(this.RunClangTidy, menuCommandID);
                menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler;
                menuCommand.Enabled            = true;
                commandService.AddCommand(menuCommand);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TidyCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>

        private TidyCommand(Package aPackage, DTE2 aDte, string aEdition,
                            string aVersion, CommandsController aCommandsController)
        {
            mPackage = aPackage ?? throw new ArgumentNullException("package");

            mDte                = aDte;
            mVsEdition          = aEdition;
            mVsVersion          = aVersion;
            mCommandsController = aCommandsController;
            mErrorsManager      = new ErrorsManager(mPackage, mDte);
            mFileOpener         = new FileOpener(mDte);

            if (this.ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuCommand   = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
                //menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler;
                commandService.AddCommand(menuCommand);
            }
        }