Exemplo n.º 1
0
        public ClangCommand(CommandsController aCommandsController, Package aPackage, Guid aGuid, int aId) : base(aPackage, aGuid, aId)
        {
            mCommand  = DTEObj.Commands as Commands2;
            VsEdition = DTEObj.Edition;
            mVsVersions.TryGetValue(DTEObj.Version, out string version);
            VsVersion = version;

            if (null == mCommandsController)
            {
                mCommandsController = aCommandsController;
            }

            mGeneralOptions = (ClangGeneralOptionsView)Package.GetDialogPage(typeof(ClangGeneralOptionsView));
        }
Exemplo n.º 2
0
        public ClangCommand(Package aPackage, Guid aGuid, int aId) : base(aPackage, aGuid, aId)
        {
            VsEdition = DTEObj.Edition;
            mVsVersions.TryGetValue(DTEObj.Version, out string version);
            VsVersion = version;

            if (null == mCommandsController)
            {
                mCommandsController = new CommandsController(ServiceProvider, DTEObj);
            }

            mErrorsManager  = new ErrorsManager(Package, DTEObj);
            mGeneralOptions = (GeneralOptions)Package.GetDialogPage(typeof(GeneralOptions));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompileCommand"/> 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 CompileCommand(CommandsController aCommandsController, IVsSolution aSolution,
                              DTE2 aDte, AsyncPackage aPackage, Guid aGuid, int aId)
            : base(aCommandsController, aSolution, aDte, aPackage, aGuid, aId)
        {
            var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != commandService)
            {
                var menuCommandID = new CommandID(CommandSet, Id);
                var menuCommand   = new OleMenuCommand(this.RunClangCompile, menuCommandID);
                menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler;
                menuCommand.Enabled            = true;
                commandService.AddCommand(menuCommand);
            }
        }
        /// <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>
        protected override void Initialize()
        {
            base.Initialize();
            mDte = (DTE2)GetService(typeof(DTE));
            mDte.Events.BuildEvents.OnBuildBegin +=
                new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);

            string edition = mDte.Edition;

            mVsVersions.TryGetValue(mDte.Version, out string version);
            mCommandsController = new CommandsController(this, mDte);

            TidyCommand.Initialize(this, mDte, edition, version, mCommandsController);
            CompileCommand.Initialize(this, mDte, edition, version, mCommandsController);
            SettingsCommand.Initialize(this);
        }
Exemplo n.º 5
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(OleMenuCommandService aCommandService, CommandsController aCommandsController,
                            ErrorWindowController aErrorWindow, OutputWindowController aOutputWindow, AsyncPackage aPackage, Guid aGuid, int aId)
            : base(aCommandsController, aErrorWindow, aOutputWindow, aPackage, aGuid, aId)
        {
            mTidyOptions      = (ClangTidyOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyOptionsView));
            mTidyChecks       = (ClangTidyPredefinedChecksOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyPredefinedChecksOptionsView));
            mTidyCustomChecks = (ClangTidyCustomChecksOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyCustomChecksOptionsView));
            mClangFormatView  = (ClangFormatOptionsView)AsyncPackage.GetDialogPage(typeof(ClangFormatOptionsView));

            if (null != aCommandService)
            {
                var menuCommandID = new CommandID(CommandSet, Id);
                var menuCommand   = new OleMenuCommand(RunClangTidy, menuCommandID);
                menuCommand.BeforeQueryStatus += mCommandsController.OnBeforeClangCommand;
                menuCommand.Enabled            = true;
                aCommandService.AddCommand(menuCommand);
            }
        }
Exemplo n.º 6
0
        public int OnAfterOpenSolution(object aPUnkReserved, int aFNewSolution)
        {
            try
            {
                mCommandsController = new CommandsController(this, mDte);

                InitializeCommands();

                StatusBarHandler.Initialize(this);
                ErrorManager.Initialize(this);

                var generalOptions = (ClangGeneralOptionsView)this.GetDialogPage(typeof(ClangGeneralOptionsView));
                var currentVersion = GetPackageVersion();

                if (0 != string.Compare(generalOptions.Version, currentVersion))
                {
                    OutputManager outputManager = new OutputManager(mDte);
                    outputManager.Show();
                    outputManager.AddMessage($"🎉\tClang Power Tools was upgraded to v{currentVersion}\n" +
                                             $"\tCheck out what's new at http://www.clangpowertools.com/CHANGELOG");

                    generalOptions.Version = currentVersion;
                    generalOptions.SaveSettingsToStorage();
                }

                mBuildEvents.OnBuildBegin += ErrorManager.Instance.OnBuildBegin;

                mBuildEvents.OnBuildBegin += mCommandsController.OnBuildBegin;
                mBuildEvents.OnBuildDone  += mCommandsController.OnBuildDone;

                mBuildEvents.OnBuildDone += mCompileCmd.OnBuildDone;

                mCommandEvents.BeforeExecute += mCompileCmd.CommandEventsBeforeExecute;
                mCommandEvents.BeforeExecute += mTidyCmd.CommandEventsBeforeExecute;

                mRunningDocTableEvents.BeforeSave += mTidyCmd.OnBeforeSave;
                mRunningDocTableEvents.BeforeSave += mClangFormatCmd.OnBeforeSave;
            }
            catch (Exception)
            {
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompileCommand"/> 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 CompileCommand(Package aPackage, DTE2 aDte, string aEdition,
                               string aVersion, CommandsController aCommandsController)
        {
            this.mPackage = aPackage ?? throw new ArgumentNullException("package");

            mDte                = aDte;
            mVsEdition          = aEdition;
            mVsVersion          = aVersion;
            mCommandsController = aCommandsController;
            mErrorsManager      = new ErrorsManager(mPackage, 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);
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        public ClangCommand(CommandsController aCommandsController, ErrorWindowController aErrorWindow,
                            OutputWindowController aOutputWindow, AsyncPackage aPackage, Guid aGuid, int aId)
            : base(aPackage, aGuid, aId)
        {
            if (null == mCommandsController)
            {
                mCommandsController = aCommandsController;
            }

            mErrorWindow  = aErrorWindow;
            mOutputWindow = aOutputWindow;

            if (VsServiceProvider.TryGetService(typeof(DTE), out object dte))
            {
                var dte2 = dte as DTE2;
                //mCommand = dte2.Commands as Commands2;
                VsEdition = dte2.Edition;
                mVsVersions.TryGetValue(dte2.Version, out string version);
                VsVersion = version;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Package aPackage, DTE2 aDte, string aEdition,
                               string aVersion, CommandsController aCommandsController)
 {
     Instance = new TidyCommand(aPackage, aDte, aEdition, aVersion, aCommandsController);
 }
Exemplo n.º 11
0
        /// <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>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // Switches to the UI thread in order to consume some services used in command initialization
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await RegisterVsServicesAsync();

            mCommandsController = new CommandsController(this);

            var vsOutputWindow = VsServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            mOutputWindowController = new OutputWindowController();
            mOutputWindowController.Initialize(this, vsOutputWindow);

            mRunningDocTableEvents = new RunningDocTableEvents(this);
            mErrorWindowController = new ErrorWindowController(this);

            #region Get Pointer to IVsSolutionEvents

            if (VsServiceProvider.TryGetService(typeof(SVsSolution), out object vsSolutionService))
            {
                var vsSolution = vsSolutionService as IVsSolution;
                UnadviseSolutionEvents(vsSolution);
                AdviseSolutionEvents(vsSolution);
            }

            #endregion

            // Get the build and command events from DTE
            if (VsServiceProvider.TryGetService(typeof(DTE), out object dte))
            {
                var dte2 = dte as DTE2;
                mBuildEvents   = dte2.Events.BuildEvents;
                mCommandEvents = dte2.Events.CommandEvents;
                mDteEvents     = dte2.Events.DTEEvents;
            }

            DispatcherHandler.Initialize(dte as DTE2);
            SettingsProvider.Initialize(this);

            // Detect the first install
            if (string.IsNullOrWhiteSpace(SettingsProvider.GeneralSettings.Version))
            {
                ShowToolbare(); // Show the toolbar on the first install
            }
            var currentVersion = GetPackageVersion();
            if (0 > string.Compare(SettingsProvider.GeneralSettings.Version, currentVersion))
            {
                mOutputWindowController.Clear();
                mOutputWindowController.Show();
                mOutputWindowController.Write($"🎉\tClang Power Tools was upgraded to v{currentVersion}\n" +
                                              $"\tCheck out what's new at http://www.clangpowertools.com/CHANGELOG");

                SettingsProvider.GeneralSettings.Version = currentVersion;
            }
            SettingsProvider.SaveGeneralSettings();

            await mCommandsController.InitializeCommandsAsync(this);

            RegisterToEvents();

            await base.InitializeAsync(cancellationToken, progress);
        }
Exemplo n.º 12
0
        /// <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>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // Switches to the UI thread in order to consume some services used in command initialization
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await RegisterVsServices();

            mCommandsController = new CommandsController(this);
            SettingsProvider.Initialize(this);

            var vsOutputWindow = VsServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            mOutputWindowController = new OutputWindowController();
            mOutputWindowController.Initialize(this, vsOutputWindow);

            //mCommandsController.ClangCommandMessageEvent += mOutputWindowController.Write;

            //PowerShellWrapper.DataHandler += mOutputWindowController.OutputDataReceived;
            //PowerShellWrapper.DataErrorHandler += mOutputWindowController.OutputDataErrorReceived;
            //PowerShellWrapper.ExitedHandler += mOutputWindowController.ClosedDataConnection;

            mRunningDocTableEvents = new RunningDocTableEvents(this);
            mErrorWindowController = new ErrorWindowController(this);

            //mOutputWindowController.ErrorDetectedEvent += mErrorWindowController.OnErrorDetected;


            #region Get Pointer to IVsSolutionEvents

            if (VsServiceProvider.TryGetService(typeof(SVsSolution), out object vsSolutionService))
            {
                var vsSolution = vsSolutionService as IVsSolution;
                UnadviseSolutionEvents(vsSolution);
                AdviseSolutionEvents(vsSolution);
            }

            #endregion

            // Get the build and command events from DTE
            if (VsServiceProvider.TryGetService(typeof(DTE), out object dte))
            {
                var dte2 = dte as DTE2;
                mBuildEvents   = dte2.Events.BuildEvents;
                mCommandEvents = dte2.Events.CommandEvents;
                mDteEvents     = dte2.Events.DTEEvents;
            }

            DispatcherHandler.Initialize(dte as DTE2);

            // Get the general clang option page
            var generalSettings = SettingsProvider.GetSettingsPage(typeof(ClangGeneralOptionsView)) as ClangGeneralOptionsView;

            // Detect the first install
            if (string.IsNullOrWhiteSpace(generalSettings.Version))
            {
                ShowToolbare(); // Show the toolbar on the first install
            }
            var currentVersion = GetPackageVersion();
            if (0 > string.Compare(generalSettings.Version, currentVersion))
            {
                mOutputWindowController.Clear();
                mOutputWindowController.Show();
                mOutputWindowController.Write($"🎉\tClang Power Tools was upgraded to v{currentVersion}\n" +
                                              $"\tCheck out what's new at http://www.clangpowertools.com/CHANGELOG");

                generalSettings.Version = currentVersion;
                generalSettings.SaveSettingsToStorage();
            }

            await mCommandsController.InitializeAsyncCommands(this);

            //mCommandsController.HierarchyDetectedEvent += mOutputWindowController.OnFileHierarchyDetected;
            //mOutputWindowController.MissingLlvmEvent += mCommandsController.OnMissingLLVMDetected;

            //RegisterToCPTEvents();
            //RegisterToVsEvents();

            RegisterToEvents();

            await base.InitializeAsync(cancellationToken, progress);
        }