예제 #1
0
        public void Dispose()
        {
            if (_errorListHelper != null)
            {
                _errorListHelper.Dispose();
                _errorListHelper = null;
            }

            if (_linter != null)
            {
                _linter.Dispose();
                _linter = null;
            }
        }
예제 #2
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 void Initialize()
        {
            OptionsProviderRegistry.PushOptionsProvider(new FileOptionsProvider("Global", GlobalOptionsPath));
            OptionsProviderRegistry.ReloadCurrent();

            _dte2            = GetService(typeof(DTE)) as DTE2;
            _solutionEvents  = _dte2.Events.SolutionEvents;
            _buildEvents     = _dte2.Events.BuildEvents;
            _docEvents       = _dte2.Events.DocumentEvents;
            _errorListHelper = new ErrorListHelper(this);

            // Add our command handlers for menu (commands must exist in the .vsct file)

            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Source Editor: JS Lint
                var sourceEditorLintCmdId    = new CommandID(GuidList.guidSourceEditorCmdSet, (int)PkgCmdIDList.lint);
                var sourceEditorLintMenuItem = new MenuCommand(LintSourceEditorCmdCallback, sourceEditorLintCmdId);
                mcs.AddCommand(sourceEditorLintMenuItem);

                // Source Editor: JS Lint Fragment
                var sourceEditorFragmentLintCmdId    = new CommandID(GuidList.guidSourceEditorFragmentCmdSet, (int)PkgCmdIDList.lint);
                var sourceEditorFragmentLintMenuItem = new OleMenuCommand(LintSourceEditorFragmentItemCmdCallback, sourceEditorFragmentLintCmdId);
                sourceEditorFragmentLintMenuItem.BeforeQueryStatus += SourceEditorFragmentLintMenuItem_BeforeQueryStatus;
                mcs.AddCommand(sourceEditorFragmentLintMenuItem);

                // Solution Explorer: JS Lint
                var solutionItemCmdId    = new CommandID(GuidList.guidSolutionItemCmdSet, (int)PkgCmdIDList.lint);
                var solutionItemMenuItem = new OleMenuCommand(LintSolutionItemCmdCallback, solutionItemCmdId);
                solutionItemMenuItem.BeforeQueryStatus += SolutionItemMenuItem_BeforeQueryStatus;
                mcs.AddCommand(solutionItemMenuItem);

                // Solution Explorer: Skip File
                var solutionItemSkipCmdId    = new CommandID(GuidList.guidSolutionItemCmdSet, (int)PkgCmdIDList.exclude);
                var solutionItemSkipMenuItem = new OleMenuCommand(LintSolutionItemSkipCmdCallback, solutionItemSkipCmdId);
                solutionItemSkipMenuItem.BeforeQueryStatus += SolutionItemSkipMenuItem_BeforeQueryStatus;
                mcs.AddCommand(solutionItemSkipMenuItem);

                // Solution Explorer: Skip Folder
                var solutionFolderNodeSkipCmdId    = new CommandID(GuidList.guidSolutionFolderNodeCmdSet, (int)PkgCmdIDList.excludeFolder);
                var solutionFolderNodeSkipMenuItem = new OleMenuCommand(LintSolutionFolderNodeSkipCmdCallback, solutionFolderNodeSkipCmdId);
                solutionFolderNodeSkipMenuItem.BeforeQueryStatus += SolutionFolderNodeSkipMenuItem_BeforeQueryStatus;
                mcs.AddCommand(solutionFolderNodeSkipMenuItem);

                // Solution Explorer: Predefined global variables
                var solutionItemGlobalsCmdId    = new CommandID(GuidList.guidSolutionItemCmdSet, (int)PkgCmdIDList.globals);
                var solutionItemGlobalsMenuItem = new OleMenuCommand(LintSolutionItemGlobalsCmdCallback, solutionItemGlobalsCmdId);
                solutionItemGlobalsMenuItem.BeforeQueryStatus += SolutionItemGlobalsMenuItem_BeforeQueryStatus;
                mcs.AddCommand(solutionItemGlobalsMenuItem);

                // Source Editor: Predefined global variables
                var sourceEditorGlobalsCmdId    = new CommandID(GuidList.guidSourceEditorCmdSet, (int)PkgCmdIDList.globals);
                var sourceEditorGlobalsMenuItem = new MenuCommand(LintSourceEditorGlobalsCmdCallback, sourceEditorGlobalsCmdId);
                mcs.AddCommand(sourceEditorGlobalsMenuItem);

                // Error List: Clear JS Lint Errors
                var errorListCmdId    = new CommandID(GuidList.guidErrorListCmdSet, (int)PkgCmdIDList.wipeerrors);
                var errorListMenuItem = new OleMenuCommand(ErrorListCmdCallback, errorListCmdId);
                errorListMenuItem.BeforeQueryStatus += ErrorListMenuItem_BeforeQueryStatus;
                mcs.AddCommand(errorListMenuItem);

                // Solution Node: Add Config
                var addConfigCmdId    = new CommandID(GuidList.guidSolutionNodeCmdSet, (int)PkgCmdIDList.addconfig);
                var addConfigMenuItem = new OleMenuCommand(AddSolutionOptionsFileCmdCallback, addConfigCmdId);
                addConfigMenuItem.BeforeQueryStatus += addConfigMenuItem_BeforeQueryStatus;
                mcs.AddCommand(addConfigMenuItem);

                // Solution Node: Edit Config
                var editConfigCmdId    = new CommandID(GuidList.guidSolutionNodeCmdSet, (int)PkgCmdIDList.editconfig);
                var editConfigMenuItem = new OleMenuCommand(EditSolutionOptionsFileCmdCallback, editConfigCmdId);
                editConfigMenuItem.BeforeQueryStatus += editOrRemoveConfigMenuItem_BeforeQueryStatus;
                mcs.AddCommand(editConfigMenuItem);

                // Solution Node: Remove Config
                var removeConfigCmdId    = new CommandID(GuidList.guidSolutionNodeCmdSet, (int)PkgCmdIDList.removeconfig);
                var removeConfigMenuItem = new OleMenuCommand(RemoveSolutionOptionsFileCmdCallback, removeConfigCmdId);
                removeConfigMenuItem.BeforeQueryStatus += editOrRemoveConfigMenuItem_BeforeQueryStatus;
                mcs.AddCommand(removeConfigMenuItem);

                // Main Menu: JSLint Options
                var optionsCmdId    = new CommandID(GuidList.guidOptionsCmdSet, (int)PkgCmdIDList.options);
                var optionsMenuItem = new MenuCommand(OptionsCmdCallback, optionsCmdId);
                mcs.AddCommand(optionsMenuItem);
            }

            //solution events
            _solutionEvents.Opened       += solutionEvents_Opened;
            _solutionEvents.AfterClosing += SolutionEvents_AfterClosing;

            // build events
            _buildEvents.OnBuildBegin           += buildEvents_OnBuildBegin;
            _buildEvents.OnBuildProjConfigBegin += buildEvents_OnBuildProjConfigBegin;

            //document events
            _docEvents.DocumentSaved += DocumentEvents_DocumentSaved;
            base.Initialize();
        }