/// <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 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();

            TaskErrorViewModel.Errors.Clear();
            SquiggleViewModel.Squiggles.Clear();

            mCommandController = new CommandController(this);

            CommandTestUtility.CommandController = mCommandController;

            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;
            }

            mSettingsHandler = new SettingsHandler();
            mSettingsHandler.InitializeSettings();

            await mCommandController.InitializeCommandsAsync(this);

            mSettingsProvider = new SettingsProvider();

            RegisterToEvents();

            LicenseController mLicenseController = new LicenseController();
            await mLicenseController.CheckLicenseAsync();

            await base.InitializeAsync(cancellationToken, progress);
        }
        /// <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 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();

            mCommandController = new CommandController(this);
            CommandTestUtility.CommandController = mCommandController;

            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-Set 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;
                windowEvents   = dte2.Events.WindowEvents;
            }

            var settingsHandler = new SettingsHandler();
            settingsHandler.InitializeSettings();
            await settingsHandler.InitializeAccountSettingsAsync();

            string version = SettingsProvider.GeneralSettingsModel.Version;
            ShowToolbar(version);
            UpdateVersion(version); //.SafeFireAndForget();

            await mCommandController.InitializeCommandsAsync(this);

            RegisterToEvents();

            await base.InitializeAsync(cancellationToken, progress);
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StopClang"/> 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 StopClang(OleMenuCommandService aCommandService, CommandsController aCommandsController, ErrorWindowController aErrorWindow,
                   OutputWindowController aOutputWindow, AsyncPackage aPackage, Guid aGuid, int aId)
     : base(aCommandsController, aErrorWindow, aOutputWindow, aPackage, aGuid, aId)
 {
     if (null != aCommandService)
     {
         var menuCommandID = new CommandID(CommandSet, Id);
         var menuCommand   = new OleMenuCommand(mCommandsController.Execute, menuCommandID);
         menuCommand.BeforeQueryStatus += mCommandsController.OnBeforeClangCommand;
         menuCommand.Enabled            = true;
         aCommandService.AddCommand(menuCommand);
     }
 }
        /// <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);
            }
        }
        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;
            }
        }
        /// <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 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();

            mCommandController = new CommandController(this);
            CommandTestUtility.CommandController = mCommandController;

            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
            }
            if (string.IsNullOrWhiteSpace(SettingsProvider.GeneralSettings.Version) ||
                0 > string.Compare(SettingsProvider.GeneralSettings.Version, "5.0.0"))
            {
                System.Diagnostics.Process.Start(new ProcessStartInfo("https://clangpowertools.com/blog/future-of-clang-power-tools.html"));
            }

            var currentVersion = PackageUtility.GetVersion();
            if (!string.IsNullOrWhiteSpace(currentVersion) &&
                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;
            }

            SettingsHandler.SaveGeneralSettings();

            await mCommandController.InitializeCommandsAsync(this);

            mLicenseController = new LicenseController();

            RegisterToEvents();
            await mLicenseController.CheckLicenseAsync();

            await base.InitializeAsync(cancellationToken, progress);
        }
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static async System.Threading.Tasks.Task InitializeAsync(CommandsController aCommandsController,
                                                                        ErrorWindowController aErrorWindow, OutputWindowController aOutputWindow, AsyncPackage aPackage, Guid aGuid, int aId)
        {
            // Switch to the main thread - the call to AddCommand in TidyCommand's constructor requires
            // the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(aPackage.DisposalToken);

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

            Instance = new TidyCommand(commandService, aCommandsController, aErrorWindow, aOutputWindow, aPackage, aGuid, aId);
        }
Exemple #8
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();

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

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

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

            mCommandsController = new CommandsController(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;
            }

            // Get the general clang option page
            var generalOptions = (ClangGeneralOptionsView)GetDialogPage(typeof(ClangGeneralOptionsView));

            // Detect the first install
            if (null == generalOptions.Version || string.IsNullOrWhiteSpace(generalOptions.Version))
            {
                ShowToolbare(); // Show the toolbar on the first install
            }
            var currentVersion = GetPackageVersion();

            if (0 != string.Compare(generalOptions.Version, currentVersion))
            {
                mOutputController.Show();
                mOutputController.Write($"🎉\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();
            }


            await InitializeAsyncCommands();

            RegisterToVsEvents();

            await base.InitializeAsync(cancellationToken, progress);
        }
Exemple #9
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);
        }
        public async System.Threading.Tasks.Task InitializeAsyncCommands(AsyncPackage aAsyncPackage,
                                                                         ErrorWindowController aErrorController, OutputWindowController aOutputWindowController)
        {
            if (null == CompileCommand.Instance)
            {
                await CompileCommand.InitializeAsync(this, aErrorController, aOutputWindowController, aAsyncPackage, mCommandSet, CommandIds.kCompileId);
            }

            if (null == TidyCommand.Instance)
            {
                await TidyCommand.InitializeAsync(this, aErrorController, aOutputWindowController, aAsyncPackage, mCommandSet, CommandIds.kTidyId);

                await TidyCommand.InitializeAsync(this, aErrorController, aOutputWindowController, aAsyncPackage, mCommandSet, CommandIds.kTidyFixId);
            }

            if (null == ClangFormatCommand.Instance)
            {
                await ClangFormatCommand.InitializeAsync(this, aErrorController, aOutputWindowController, aAsyncPackage, mCommandSet, CommandIds.kClangFormat);
            }

            if (null == StopClang.Instance)
            {
                await StopClang.InitializeAsync(this, aErrorController, aOutputWindowController, aAsyncPackage, mCommandSet, CommandIds.kStopClang);
            }

            if (null == SettingsCommand.Instance)
            {
                await SettingsCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kSettingsId);
            }
        }