예제 #1
0
        public LanguagePreferences(PythonToolsService service, Guid languageGuid)
        {
            _service = service;
            _service.Site.AssertShellIsInitialized();

            _textMgr = (IVsTextManager)service.Site.GetService(typeof(SVsTextManager));
            if (_textMgr == null)
            {
                throw new NotSupportedException("");
            }

            var langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = languageGuid;
            ErrorHandler.ThrowOnFailure(_textMgr.GetUserPreferences(null, null, langPrefs, null));
            _preferences = langPrefs[0];

            var guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint = null;

            (_textMgr as IConnectionPointContainer)?.FindConnectionPoint(ref guid, out connectionPoint);
            if (connectionPoint != null)
            {
                connectionPoint.Advise(this, out _cookie);
            }
        }
예제 #2
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <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()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            var langService = new NodejsLanguageInfo(this);

            ((IServiceContainer)this).AddService(langService.GetType(), langService, true);

            RegisterProjectFactory(new NodejsProjectFactory(this));
            RegisterEditorFactory(new NodejsEditorFactory(this));
            RegisterEditorFactory(new NodejsEditorFactoryPromptForEncoding(this));
            RegisterEditorFactory(new JadeEditorFactory(this));

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var commands = new List <Command> {
                new OpenReplWindowCommand(),
                new OpenRemoteDebugProxyFolderCommand(),
                new OpenRemoteDebugDocumentationCommand(),
                new SurveyNewsCommand(),
                new ImportWizardCommand(),
                new DiagnosticsCommand()
            };

            try {
                commands.Add(new AzureExplorerAttachDebuggerCommand());
            } catch (NotSupportedException) {
            }
            RegisterCommands(commands, Guids.NodejsCmdSet);

            IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));

            var langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            var textManagerEvents2Guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint textManagerEvents2ConnectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref textManagerEvents2Guid, out textManagerEvents2ConnectionPoint);
            uint cookie;

            textManagerEvents2ConnectionPoint.Advise(_langPrefs, out cookie);

            var textManagerEventsGuid = typeof(IVsTextManagerEvents).GUID;
            IConnectionPoint textManagerEventsConnectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref textManagerEventsGuid, out textManagerEventsConnectionPoint);
            textManagerEventsConnectionPoint.Advise(new DataTipTextManagerEvents(this), out cookie);

            MakeDebuggerContextAvailable();

            IntellisenseOptionsPage.AnalysisLogMaximumChanged += IntellisenseOptionsPage_AnalysisLogMaximumChanged;

            InitializeLogging();
        }
예제 #3
0
        internal PythonToolsService(IServiceContainer container)
        {
            _container = container;

            var langService = new PythonLanguageInfo(container);

            _container.AddService(langService.GetType(), langService, true);

            IVsTextManager textMgr = (IVsTextManager)container.GetService(typeof(SVsTextManager));

            if (textMgr != null)
            {
                var langPrefs = new LANGPREFERENCES[1];
                langPrefs[0].guidLang = typeof(PythonLanguageInfo).GUID;
                ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
                _langPrefs = new LanguagePreferences(this, langPrefs[0]);

                Guid             guid = typeof(IVsTextManagerEvents2).GUID;
                IConnectionPoint connectionPoint;
                ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
                connectionPoint.Advise(_langPrefs, out _langPrefsTextManagerCookie);
            }

            _optionsService = (IPythonToolsOptionsService)container.GetService(typeof(IPythonToolsOptionsService));
            var compModel = (IComponentModel)container.GetService(typeof(SComponentModel));

            _interpreterRegistry = compModel.GetService <IInterpreterRegistryService>();
            if (_interpreterRegistry != null)
            {
                _interpreterRegistry.InterpretersChanged += InterpretersChanged;
            }

            _interpreterOptionsService = compModel.GetService <IInterpreterOptionsService>();
            if (_interpreterOptionsService != null)     // not available in some test cases...
            {
                _interpreterOptionsService.DefaultInterpreterChanged += UpdateDefaultAnalyzer;
                LoadInterpreterOptions();
            }

            _idleManager              = new IdleManager(container);
            _advancedOptions          = new AdvancedEditorOptions(this);
            _debuggerOptions          = new DebuggerOptions(this);
            _generalOptions           = new GeneralOptions(this);
            _surveyNews               = new SurveyNewsService(container);
            _suppressDialogOptions    = new SuppressDialogOptions(this);
            _globalInterpreterOptions = new GlobalInterpreterOptions(this, _interpreterOptionsService, _interpreterRegistry);
            _globalInterpreterOptions.Load();
            _interactiveOptions = new PythonInteractiveOptions(this, "Interactive");
            _interactiveOptions.Load();
            _debugInteractiveOptions = new PythonInteractiveOptions(this, "Debug Interactive Window");
            _debuggerOptions.Load();
            _factoryProviders = ComponentModel.DefaultExportProvider.GetExports <IPythonInterpreterFactoryProvider, Dictionary <string, object> >();
            _logger           = new PythonToolsLogger(ComponentModel.GetExtensions <IPythonToolsLogger>().ToArray());
            InitializeLogging();
        }
예제 #4
0
        public LanguageSettings()
        {
            IVsTextManager textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));

            LANGPREFERENCES[] preferences = new LANGPREFERENCES[1];
            preferences[0].guidLang = new Guid("5b6692e7-a860-4b7d-9242-a6781510dee0");

            if (textManager.GetUserPreferences(null, null, preferences, null) == 0)
            {
                _Preferences = preferences[0];
            }
        }
예제 #5
0
        public LanguageSettings()
        {
            IVsTextManager textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));

            LANGPREFERENCES[] preferences = new LANGPREFERENCES[1];
            preferences[0].guidLang = Guids.ScssLanguageService;

            if (textManager.GetUserPreferences(null, null, preferences, null) == 0)
            {
                _Preferences = preferences[0];
            }
        }
예제 #6
0
        private void SetEditorOptions(IEditorOptions options, Guid languageServiceGuid)
        {
            IVsTextManager textMgr   = (IVsTextManager)InteractiveWindowPackage.GetGlobalService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = languageServiceGuid;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));

            options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
            options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, langPrefs[0].fInsertTabs == 0);
            options.SetOptionValue(DefaultOptions.TabSizeOptionId, (int)langPrefs[0].uTabSize);
            options.SetOptionValue(DefaultOptions.IndentSizeOptionId, (int)langPrefs[0].uIndentSize);
        }
예제 #7
0
        private void InitializeLangPrefs()
        {
            IVsTextManager textMgr   = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(VSGenero4GLLanguageInfo).GUID;
            int result = textMgr.GetUserPreferences(null, null, langPrefs, null);

            _langPrefs = new Genero4GLLanguagePreferences(langPrefs[0]);

            Guid             guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
            uint cookie;

            connectionPoint.Advise(_langPrefs, out cookie);
        }
예제 #8
0
        void dteEvents_OnStartupComplete()
        {
            if (BabePackage.Setting.IsFirstInstall)
            {
                BabePackage.WindowManager.ShowSettingWindow();
                //BabePackage.Current.ShowFolderWindow(null, null);
                //BabePackage.Current.ShowOutlineWindow(null, null);
                //var props = DTE.Properties["TextEditor", "Lua"];
                //props.Item("IndentStyle").Value = EnvDTE.vsIndentStyle.vsIndentStyleDefault;
            }
            else if (!string.IsNullOrWhiteSpace(BabePackage.Setting.CurrentSetting))
            {
                IntellisenseHelper.Scan();
            }

            if (BabePackage.Setting.HideUselessViews)
            {
                HiddenVSWindows();
            }

            //打开上次关闭时打开的文件

            //启动完成。开始初始化。

            //如果是此版本第一次运行,更改缩进设置项为“块”
            if (Properties.Settings.Default.IsFirstRun)
            {
                IVsTextManager textMgr   = (IVsTextManager)BabePackage.Current.GetService(typeof(SVsTextManager));
                var            langPrefs = new LANGPREFERENCES[1];
                langPrefs[0].guidLang = typeof(LuaLanguageInfo).GUID;
                ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
                langPrefs[0].IndentStyle = Microsoft.VisualStudio.TextManager.Interop.vsIndentStyle.vsIndentStyleDefault;
                textMgr.SetUserPreferences(null, null, langPrefs, null);
                Properties.Settings.Default.IsFirstRun = false;
                Properties.Settings.Default.Save();
            }

            //注册编辑器内容变化通知
            TextViewCreationListener.FileContentChanged += TextViewCreationListener_FileContentChanged;
            Logger.UploadLog();
            Updater.CheckVersion();
        }
예제 #9
0
        public LanguagePreferences(PythonToolsService service, Guid languageGuid) {
            _service = service;
            _service.Site.AssertShellIsInitialized();

            _textMgr = (IVsTextManager)service.Site.GetService(typeof(SVsTextManager));
            if (_textMgr == null) {
                throw new NotSupportedException("");
            }

            var langPrefs = new LANGPREFERENCES[1];
            langPrefs[0].guidLang = languageGuid;
            ErrorHandler.ThrowOnFailure(_textMgr.GetUserPreferences(null, null, langPrefs, null));
            _preferences = langPrefs[0];

            var guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint = null;
            (_textMgr as IConnectionPointContainer)?.FindConnectionPoint(ref guid, out connectionPoint);
            if (connectionPoint != null) {
                connectionPoint.Advise(this, out _cookie);
            }
        }
예제 #10
0
 private void GetLanguagePrefs()
 {
     if (this.textMgr != null)
     {
         this.prefs.guidLang = langSvc;
         LANGPREFERENCES[] langPrefs = new LANGPREFERENCES[1];
         langPrefs[0] = this.prefs;
         try {
             if (!this.user)
             {
                 textMgr.GetPerLanguagePreferences(langPrefs);
             }
             else
             {
                 textMgr.GetUserPreferences(null, null, langPrefs, null);
             }
             this.prefs = langPrefs[0];
         } catch (Exception ex) {
             Trace.WriteLine(ex.Message);
         }
     }
 }
        private bool TryGetTextManagerOptionValue(string valueName, ref int optionValue)
        {
            bool result = false;

            // Note: The CacheLanguageGuids method (used by LanguageGuids.Value) depends on
            // MainPackage.Instance, so we can't pull Value until the package instance is set.
            Guid langGuid;

            if (MainPackage.Instance != null && LanguageGuids.Value.TryGetValue(this.textManagerLanguageName, out langGuid))
            {
                IVsTextManager textManager = (IVsTextManager)MainPackage.GetGlobalService(typeof(SVsTextManager));
                if (textManager != null)
                {
                    LANGPREFERENCES[] langPrefs = new LANGPREFERENCES[1];
                    langPrefs[0].guidLang = langGuid;
                    int hr = textManager.GetUserPreferences(null, null, langPrefs, null);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        switch (valueName)
                        {
                        case InsertTabsOptionName:
                            optionValue = unchecked ((int)langPrefs[0].fInsertTabs);
                            result      = true;
                            break;

                        case TabSizeOptionName:
                            optionValue = unchecked ((int)langPrefs[0].uTabSize);
                            result      = true;
                            break;
                        }
                    }
                }
            }

            return(result);
        }
예제 #12
0
        protected override void Initialize()
        {
            base.Initialize();

            Instance = this;

            this.languageInfo = new GLSLLanguageInfo();
            ((IServiceContainer)this).AddService(typeof(GLSLLanguageInfo), this.languageInfo, true);

            this.RegisterEditorFactory(new GLSLEditorFactoryWithoutEncoding(this));

            IVsTextManager textManager = (IVsTextManager)this.GetService(typeof(SVsTextManager));

            LANGPREFERENCES[] lanaguagePreferences = new LANGPREFERENCES[1];
            lanaguagePreferences[0].guidLang = typeof(GLSLLanguageInfo).GUID;
            ErrorHandler.ThrowOnFailure(textManager.GetUserPreferences(null, null, lanaguagePreferences, null));
            this.Preferences = new GLSLPreferences(lanaguagePreferences[0]);

            Guid events2Guid = typeof(IVsTextManagerEvents2).GUID;

            ((IConnectionPointContainer)textManager).FindConnectionPoint(ref events2Guid, out this.connectionPoint);

            this.connectionPoint.Advise(this.Preferences, out this.cookie);
        }
예제 #13
0
        public PowerShellLanguageInfo(IServiceContainer serviceContainer)
        {
            _serviceContainer             = serviceContainer;
            _componentModel               = serviceContainer.GetService(typeof(SComponentModel)) as IComponentModel;
            _editorAdaptersFactoryService = _componentModel.GetService <IVsEditorAdaptersFactoryService>();

            IVsTextManager textMgr = (IVsTextManager)serviceContainer.GetService(typeof(SVsTextManager));

            if (textMgr != null)
            {
                // Load the initial settings
                var langPrefs = new LANGPREFERENCES[1];
                langPrefs[0].guidLang = typeof(PowerShellLanguageInfo).GUID;
                ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
                _langPrefs = new PowerShellLanguagePreferences(langPrefs[0]);

                // Hook up to the setting change
                Guid guid = typeof(IVsTextManagerEvents2).GUID;
                Microsoft.VisualStudio.OLE.Interop.IConnectionPoint connectionPoint;
                ((Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
                uint cookie;
                connectionPoint.Advise(_langPrefs, out cookie);
            }
        }
예제 #14
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <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()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            SubscribeToVsCommandEvents(
                (int)VSConstants.VSStd97CmdID.AddNewProject,
                delegate { NewProjectFromExistingWizard.IsAddNewProjectCmd = true; },
                delegate { NewProjectFromExistingWizard.IsAddNewProjectCmd = false; }
                );

            var langService = new NodejsLanguageInfo(this);

            ((IServiceContainer)this).AddService(langService.GetType(), langService, true);

            ((IServiceContainer)this).AddService(typeof(ClipboardServiceBase), new ClipboardService(), true);

            RegisterProjectFactory(new NodejsProjectFactory(this));
            RegisterEditorFactory(new NodejsEditorFactory(this));
            RegisterEditorFactory(new NodejsEditorFactoryPromptForEncoding(this));
            RegisterEditorFactory(new JadeEditorFactory(this));

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var commands = new List <Command> {
                new OpenReplWindowCommand(),
                new OpenRemoteDebugProxyFolderCommand(),
                new OpenRemoteDebugDocumentationCommand(),
                new SurveyNewsCommand(),
                new ImportWizardCommand(),
                new DiagnosticsCommand(this)
            };

            try {
                commands.Add(new AzureExplorerAttachDebuggerCommand());
            } catch (NotSupportedException) {
            }
            RegisterCommands(commands, Guids.NodejsCmdSet);

            IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));

            var langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            var textManagerEvents2Guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint textManagerEvents2ConnectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref textManagerEvents2Guid, out textManagerEvents2ConnectionPoint);
            uint cookie;

            textManagerEvents2ConnectionPoint.Advise(_langPrefs, out cookie);

            var textManagerEventsGuid = typeof(IVsTextManagerEvents).GUID;
            IConnectionPoint textManagerEventsConnectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref textManagerEventsGuid, out textManagerEventsConnectionPoint);
            textManagerEventsConnectionPoint.Advise(new DataTipTextManagerEvents(this), out cookie);

            MakeDebuggerContextAvailable();

            IntellisenseOptionsPage.AnalysisLogMaximumChanged += IntellisenseOptionsPage_AnalysisLogMaximumChanged;

            InitializeLogging();

            InitializeTelemetry();

            // The variable is inherited by child processes backing Test Explorer, and is used in
            // the NTVS test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable(NodejsConstants.NodeToolsProcessIdEnvironmentVariable, Process.GetCurrentProcess().Id.ToString());
        }
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

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

            if (null != mcs)
            {
                foreach (var command in Commands.CommandTable.Commands)
                {
                    var       beforeQueryStatus = command.BeforeQueryStatus;
                    CommandID toolwndCommandID  = new CommandID(GuidList.guidIronPythonToolsCmdSet, command.CommandId);
                    if (beforeQueryStatus == null)
                    {
                        MenuCommand menuToolWin = new MenuCommand(command.DoCommand, toolwndCommandID);
                        mcs.AddCommand(menuToolWin);
                    }
                    else
                    {
                        OleMenuCommand menuToolWin = new OleMenuCommand(command.DoCommand, toolwndCommandID);
                        menuToolWin.BeforeQueryStatus += beforeQueryStatus;
                        mcs.AddCommand(menuToolWin);
                    }
                }
            }

            // This is just to force the MEF creation of the DLR runtime hosting layer, including the content type and runtime.
            if (RuntimeHost == null)
            {
                throw new InvalidOperationException("Unable to obtain the DLR Runtime hosting component");
            }

            RuntimeHost.EnterOutliningModeOnOpen = OptionsPage.EnterOutliningModeOnOpen;

            // register our language service so that we can support features like the navigation bar
            var langService = new PythonLanguageInfo(this);

            ((IServiceContainer)this).AddService(langService.GetType(), langService, true);

            var  solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
            uint cookie;

            ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(new SolutionAdvisor(), out cookie));

            IVsTextManager textMgr   = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(PythonLanguageInfo).GUID;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            Guid             guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
            connectionPoint.Advise(_langPrefs, out cookie);

            // propagate options to our runtime host
            RuntimeHost.IntersectMembers         = IntellisenseOptionsPage.IntersectMembers;
            RuntimeHost.EnterOutliningModeOnOpen = OptionsPage.EnterOutliningModeOnOpen;
            RuntimeHost.HideAdvancedMembers      = Instance.LangPrefs.HideAdvancedMembers;
        }
예제 #16
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // register our language service so that we can support features like the navigation bar
            var langService = new PythonLanguageInfo(this);

            ((IServiceContainer)this).AddService(langService.GetType(), langService, true);

            var solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
            //ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(new SolutionAdvisor(), out cookie));

            IVsTextManager textMgr   = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(PythonLanguageInfo).GUID;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            Guid             guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
            uint cookie;

            connectionPoint.Advise(_langPrefs, out cookie);

            var model = GetService(typeof(SComponentModel)) as IComponentModel;

            //new SendToDefiningModuleCommand(),
            List <Command> commands = new List <Command>()
            {
                new ExecuteInReplCommand(), new SendToReplCommand(), new FillParagraphCommand(), new SendToDefiningModuleCommand()
            };

            var factories      = model.GetAllPythonInterpreterFactories();
            var defaultFactory = GetDefaultInterpreter(factories);

            // sort so default always comes first, and otherwise in sorted order
            Array.Sort(factories, (x, y) => {
                if (x == y)
                {
                    return(0);
                }
                else if (x == defaultFactory)
                {
                    return(-1);
                }
                else if (y == defaultFactory)
                {
                    return(1);
                }
                else
                {
                    return(String.Compare(x.GetInterpreterDisplay(), y.GetInterpreterDisplay()));
                }
            });

            for (int i = 0; i < (PkgCmdIDList.cmdidReplWindowF - PkgCmdIDList.cmdidReplWindow); i++)
            {
                var factory = i < factories.Length ? factories[i] : null;

                commands.Add(new OpenReplCommand((int)PkgCmdIDList.cmdidReplWindow + i, factory));
            }
            _commands = commands.ToArray();

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

            if (null != mcs)
            {
                foreach (var command in Commands)
                {
                    var       beforeQueryStatus = command.BeforeQueryStatus;
                    CommandID toolwndCommandID  = new CommandID(GuidList.guidPythonToolsCmdSet, command.CommandId);
                    if (beforeQueryStatus == null)
                    {
                        MenuCommand menuToolWin = new MenuCommand(command.DoCommand, toolwndCommandID);
                        mcs.AddCommand(menuToolWin);
                    }
                    else
                    {
                        OleMenuCommand menuToolWin = new OleMenuCommand(command.DoCommand, toolwndCommandID);
                        menuToolWin.BeforeQueryStatus += beforeQueryStatus;
                        mcs.AddCommand(menuToolWin);
                    }
                }
            }
        }
예제 #17
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation
        #region Package Members

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            var services = (IServiceContainer)this;

            var langService4GL = new VSGenero4GLLanguageInfo(this);

            services.AddService(langService4GL.GetType(), langService4GL, true);
            var langServicePER = new VSGeneroPERLanguageInfo(this);

            services.AddService(langServicePER.GetType(), langServicePER, true);

            services.AddService(
                typeof(ErrorTaskProvider),
                (container, serviceType) =>
            {
                var errorList     = GetService(typeof(SVsErrorList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new ErrorTaskProvider(this, errorList, errorProvider));
            },
                promote: true);

            services.AddService(
                typeof(CommentTaskProvider),
                (container, serviceType) =>
            {
                var taskList      = GetService(typeof(SVsTaskList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new CommentTaskProvider(this, taskList, errorProvider));
            },
                promote: true);

            IVsTextManager textMgr   = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = typeof(VSGenero4GLLanguageInfo).GUID;
            int result = textMgr.GetUserPreferences(null, null, langPrefs, null);

            _langPrefs = new Genero4GLLanguagePreferences(langPrefs[0]);

            Guid             guid = typeof(IVsTextManagerEvents2).GUID;
            IConnectionPoint connectionPoint;

            ((IConnectionPointContainer)textMgr).FindConnectionPoint(ref guid, out connectionPoint);
            uint cookie;

            connectionPoint.Advise(_langPrefs, out cookie);

            // TODO: not sure if this is needed...need to test
            DTE dte = (DTE)GetService(typeof(DTE));

            if (dte != null)
            {
                GeneroEditorFactory = new EditorFactory(this);
                this.RegisterEditorFactory(GeneroEditorFactory);
            }

            RegisterCommands(new CommonCommand[]
            {
                new ExtractSqlStatementsCommand()
            }, GuidList.guidVSGeneroCmdSet);

            var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
            var sp   = new ServiceProvider(dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            try
            {
                var mefContainer = sp.GetService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel))
                                   as Microsoft.VisualStudio.ComponentModelHost.IComponentModel;
                var exportSpec = mefContainer?.DefaultExportProvider.GetExport <IBuildTaskProvider>();
                if (exportSpec != null)
                {
                    _BuildTaskProvider = exportSpec.Value;
                }
                if (DefaultAnalyzer != null)
                {
                }
            }
            catch (Exception)
            { }
        }