Exemple #1
0
        /// <summary>
        /// Gets all of the currently selected items.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <VSITEMSELECTION> GetSelectedItems()
        {
            IVsMonitorSelection monitorSelection = _package.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;

            IntPtr hierarchyPtr       = IntPtr.Zero;
            IntPtr selectionContainer = IntPtr.Zero;

            try {
                uint selectionItemId;
                IVsMultiItemSelect multiItemSelect = null;
                ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out selectionItemId, out multiItemSelect, out selectionContainer));

                if (selectionItemId != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero)
                {
                    IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;

                    if (selectionItemId != VSConstants.VSITEMID_SELECTION)
                    {
                        // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid
                        if (Utilities.IsSameComObject(this, hierarchy))
                        {
                            yield return(new VSITEMSELECTION()
                            {
                                itemid = selectionItemId, pHier = hierarchy
                            });
                        }
                    }
                    else if (multiItemSelect != null)
                    {
                        // This is a multiple item selection.
                        // Get number of items selected and also determine if the items are located in more than one hierarchy

                        uint numberOfSelectedItems;
                        int  isSingleHierarchyInt;
                        ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                        bool isSingleHierarchy = (isSingleHierarchyInt != 0);

                        // Now loop all selected items and add to the list only those that are selected within this hierarchy
                        if (!isSingleHierarchy || (isSingleHierarchy && Utilities.IsSameComObject(this, hierarchy)))
                        {
                            Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd");
                            VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
                            uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
                            ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));

                            foreach (VSITEMSELECTION vsItemSelection in vsItemSelections)
                            {
                                yield return(new VSITEMSELECTION()
                                {
                                    itemid = vsItemSelection.itemid, pHier = hierarchy
                                });
                            }
                        }
                    }
                }
            } finally {
                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
                if (selectionContainer != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainer);
                }
            }
        }
Exemple #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();

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

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

            LANGPREFERENCES3[] langPrefs = GetNodejsLanguagePreferencesFromTypeScript(textMgr);
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            var textManagerEvents2Guid = typeof(IVsTextManagerEvents4).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;
            IntellisenseOptionsPage.AnalysisLevelChanged      += IntellisenseOptionsPageAnalysisLevelChanged;
            IntellisenseOptionsPage.SaveToDiskChanged         += IntellisenseOptionsPageSaveToDiskChanged;

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

            if (!_hasRequiredTypescriptVersion.Value)
            {
                MessageBox.Show(
                    Project.SR.GetString(Project.SR.TypeScriptMinVersionNotInstalled, _minRequiredTypescriptVersion.ToString()),
                    Project.SR.ProductName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            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 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),
                new SendFeedbackCommand(),
                new ShowDocumentationCommand()
            };

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

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

            LANGPREFERENCES3[] langPrefs = GetNodejsLanguagePreferencesFromTypeScript(textMgr);
            _langPrefs = new LanguagePreferences(langPrefs[0]);

            var textManagerEvents2Guid = typeof(IVsTextManagerEvents4).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();

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

#if DEV15
            var root = Environment.GetEnvironmentVariable("VsInstallRoot");
            if (!string.IsNullOrEmpty(root))
            {
                Environment.SetEnvironmentVariable(NodejsConstants.NodeToolsVsInstallRootEnvironmentVariable, root);
            }
#endif
        }