Ejemplo n.º 1
0
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            _dte            = (EnvDTE.DTE)GetService(typeof(SDTE));
            _eventsHandlers = _dte.Events.DocumentEvents;
            _eventsHandlers.DocumentSaved += documentSaved;

            _outputPane = _dte.AddOutputWindowPane("cppcheck analysis output");

            AnalyzerCppcheck cppcheckAnalayzer = new AnalyzerCppcheck();

            cppcheckAnalayzer.ProgressUpdated += checkProgressUpdated;
            _analyzers.Add(cppcheckAnalayzer);

            if (String.IsNullOrEmpty(Properties.Settings.Default.DefaultArguments))
            {
                Properties.Settings.Default.DefaultArguments = CppcheckSettings.DefaultArguments;
            }

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the menu item.
                CommandID   menuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck);
                MenuCommand menuItem      = new MenuCommand(onCheckCurrentProjectRequested, menuCommandID);
                mcs.AddCommand(menuItem);
                // Create the command for the settings window
                CommandID   settingsWndCmdId = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidSettings);
                MenuCommand menuSettings     = new MenuCommand(onSettingsWindowRequested, settingsWndCmdId);
                mcs.AddCommand(menuSettings);

                CommandID   projectMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck1);
                MenuCommand projectMenuItem      = new MenuCommand(onCheckCurrentProjectRequested, projectMenuCommandID);
                mcs.AddCommand(projectMenuItem);

                CommandID   projectsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginMultiProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectsCppcheck);
                MenuCommand projectsMenuItem      = new MenuCommand(onCheckAllProjectsRequested, projectsMenuCommandID);
                mcs.AddCommand(projectsMenuItem);
            }

            // Creating the tool window
            FindToolWindow(typeof(MainToolWindow), 0, true);
        }
Ejemplo n.º 2
0
        private XmlDocument LoadChecksList()
        {
            using (var process = new System.Diagnostics.Process())
            {
                var startInfo = process.StartInfo;
                startInfo.UseShellExecute        = false;
                startInfo.CreateNoWindow         = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.FileName         = AnalyzerCppcheck.cppcheckExePath();
                startInfo.WorkingDirectory = Path.GetDirectoryName(startInfo.FileName);
                startInfo.Arguments        = "--errorlist --xml-version=2";
                process.Start();
                String output;
                using (var outputStream = process.StandardOutput)
                {
                    output = outputStream.ReadToEnd();
                }
                process.WaitForExit();

                var checksList = new XmlDocument();
                checksList.LoadXml(output);
                return(checksList);
            }
        }
        protected override void Initialize()
        {
            Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            _dte = (EnvDTE.DTE)GetService(typeof(SDTE));
            _eventsHandlers = _dte.Events.DocumentEvents;
            _eventsHandlers.DocumentSaved += documentSaved;

            _outputPane = _dte.AddOutputWindowPane("cppcheck analysis output");

            AnalyzerCppcheck cppcheckAnalayzer = new AnalyzerCppcheck();
            cppcheckAnalayzer.ProgressUpdated += checkProgressUpdated;
            _analyzers.Add(cppcheckAnalayzer);

            if (String.IsNullOrEmpty(Properties.Settings.Default.DefaultArguments))
                Properties.Settings.Default.DefaultArguments = CppcheckSettings.DefaultArguments;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if ( null != mcs )
            {
                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck);
                MenuCommand menuItem = new MenuCommand(onCheckCurrentProjectRequested, menuCommandID);
                mcs.AddCommand( menuItem );

                CommandID solutionMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckSolutionCppcheck);
                MenuCommand solutionMenuItem = new MenuCommand(onCheckSolution, solutionMenuCommandID);
                mcs.AddCommand(solutionMenuItem);

                // Create the command for the settings window
                CommandID settingsWndCmdId = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidSettings);
                MenuCommand menuSettings = new MenuCommand(onSettingsWindowRequested, settingsWndCmdId);
                mcs.AddCommand(menuSettings);

                CommandID projectMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck1);
                MenuCommand projectMenuItem = new MenuCommand(onCheckCurrentProjectRequested, projectMenuCommandID);
                mcs.AddCommand(projectMenuItem);

                CommandID projectsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginMultiProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectsCppcheck);
                MenuCommand projectsMenuItem = new MenuCommand(onCheckAllProjectsRequested, projectsMenuCommandID);
                mcs.AddCommand(projectsMenuItem);
            }

            // Creating the tool window
            FindToolWindow(typeof(MainToolWindow), 0, true);
        }
        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);

            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));

            _dte = await GetServiceAsync(typeof(DTE)) as DTE;

            Assumes.Present(_dte);
            if (_dte == null)
            {
                return;
            }

            _eventsHandlers = _dte.Events.DocumentEvents;
            _eventsHandlers.DocumentSaved += documentSavedSync;

            _commandEventsHandlers = _dte.Events.CommandEvents;
            _commandEventsHandlers.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(CommandEvents_BeforeExecute);

            var outputWindow = (OutputWindow)_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object;

            _outputPane = outputWindow.OutputWindowPanes.Add("cppcheck analysis output");

            AnalyzerCppcheck cppcheckAnalayzer = new AnalyzerCppcheck();

            cppcheckAnalayzer.ProgressUpdated += checkProgressUpdated;
            _analyzers.Add(cppcheckAnalayzer);

            if (string.IsNullOrEmpty(Settings.Default.DefaultArguments))
            {
                Settings.Default.DefaultArguments = CppcheckSettings.DefaultArguments;
            }

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the menu item.
                {
                    CommandID   menuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck);
                    MenuCommand menuItem      = new MenuCommand(onCheckCurrentProjectRequested, menuCommandID);
                    mcs.AddCommand(menuItem);
                }

                {
                    // Create the command for the settings window
                    CommandID   settingsWndCmdId = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidSettings);
                    MenuCommand menuSettings     = new MenuCommand(onSettingsWindowRequested, settingsWndCmdId);
                    mcs.AddCommand(menuSettings);
                }

                {
                    CommandID   stopCheckMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidStopCppcheck);
                    MenuCommand stopCheckMenuItem      = new MenuCommand(onStopCheckRequested, stopCheckMenuCommandID);
                    mcs.AddCommand(stopCheckMenuItem);
                }

                {
                    CommandID   selectionsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckMultiItemCppcheck);
                    MenuCommand selectionsMenuItem      = new MenuCommand(onCheckSelectionsRequested, selectionsMenuCommandID);
                    mcs.AddCommand(selectionsMenuItem);
                }

                {
                    CommandID   projectMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck1);
                    MenuCommand projectMenuItem      = new MenuCommand(onCheckCurrentProjectRequested, projectMenuCommandID);
                    mcs.AddCommand(projectMenuItem);
                }

                {
                    CommandID   projectsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginMultiProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectsCppcheck);
                    MenuCommand projectsMenuItem      = new MenuCommand(onCheckAllProjectsRequested, projectsMenuCommandID);
                    mcs.AddCommand(projectsMenuItem);
                }

                {
                    CommandID   selectionsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginMultiItemProjectCmdSet, (int)PkgCmdIDList.cmdidCheckMultiItemCppcheck1);
                    MenuCommand selectionsMenuItem      = new MenuCommand(onCheckSelectionsRequested, selectionsMenuCommandID);
                    mcs.AddCommand(selectionsMenuItem);
                }
            }
        }