/// <summary>
        /// Thread function used to run the IronPython engine in a different thread.
        /// This thread will run until the IConsole implementation of this window will return
        /// null from the ReadLine method.
        /// </summary>
        private void InitializeEngine()
        {
            // Get the engine provider service to set this console window as the console
            // object associated with the shared engine.
            IPythonEngineProvider engineProvider = (IPythonEngineProvider)globalProvider.GetService(typeof(IPythonEngineProvider));

            if (null != engineProvider)
            {
                IEngine engine = engineProvider.GetSharedEngine();
                engine.StdErr = textStream;
                engine.StdOut = textStream;
                string version = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                               Resources.EngineVersionFormat,
                                               engine.Version.Major,
                                               engine.Version.Minor,
                                               engine.Version.Build);

                // Write engine version end copyright on the console.
                using (StreamWriter writer = new StreamWriter(textStream as Stream))
                {
                    writer.WriteLine(version);
                    writer.WriteLine(engine.Copyright);
                }

                // Create the buffer that will handle the commands to the engine.
                inputBuffer = new CommandBuffer(engine);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Thread function used to run the FoxPro engine in a different thread.
        /// This thread will run until the IConsole implementation of this window will return
        /// null from the ReadLine method.
        /// </summary>
        private void InitializeEngine()
        {
            // Get the engine provider service to set this console window as the console
            // object associated with the shared engine.
            IFoxProEngineProvider engineProvider = (IFoxProEngineProvider)globalProvider.GetService(typeof(IFoxProEngineProvider));

            if (null != engineProvider)
            {
                IEngine engine = engineProvider.GetSharedEngine();
                engine.StdErr = textStream;
                engine.StdOut = textStream;
                string version = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                               Resources.EngineVersionFormat,
                                               engine.Version.Major,
                                               engine.Version.Minor,
                                               engine.Version.Build);
                // Remove the read-only flag from the text buffer.
                uint flags;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    textLines.GetStateFlags(out flags));
                flags &= ~(uint)Microsoft.VisualStudio.TextManager.Interop.BUFFERSTATEFLAGS.BSF_USER_READONLY;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    textLines.SetStateFlags(flags));

                // Write engine version end copyright on the console.
                using (StreamWriter writer = new StreamWriter(textStream as Stream))
                {
                    writer.WriteLine(version);
                    writer.WriteLine(engine.Copyright);
                }

                // Create the buffer that will handle the commands to the engine.
                inputBuffer = new CommandBuffer(engine);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface.
        /// </summary>
        /// <param name="serviceProvider">A service provider.</param>
        /// <param name="hierarchy">The hierarchy whose configuration is requested.  This method calls into
        /// native code and may be called on a background thread, so make sure the IVsHierarchy passed is
        /// safe to use for that sort of interop.</param>
        /// <param name="configuration">The name of the active configuration.</param>
        /// <param name="platform">The name of the platform.</param>
        /// <returns>true if successfull.</returns>
        /// <summary>
        /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface.
        /// </summary>
        /// <param name="serviceProvider">A service provider.</param>
        /// <param name="hierarchy">The hierrachy whose configuration is requested.</param>
        /// <param name="configuration">The name of the active configuration.</param>
        /// <param name="platform">The name of the platform.</param>
        /// <returns>true if successfull.</returns>
        internal static bool TryGetActiveConfigurationAndPlatform(System.IServiceProvider serviceProvider, IVsHierarchy hierarchy, out ConfigCanonicalName configCanonicalName)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }

            IVsSolutionBuildManager2 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;

            if (solutionBuildManager == null)
            {
                configCanonicalName = new ConfigCanonicalName();
                return(false);
            }

            IVsProjectCfg[] activeConfigs = new IVsProjectCfg[1];
            ErrorHandler.ThrowOnFailure(solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, activeConfigs));

            IVsProjectCfg activeCfg = activeConfigs[0];

            // Can it be that the activeCfg is null?
            System.Diagnostics.Debug.Assert(activeCfg != null, "Cannot find the active configuration");

            string canonicalName;

            ErrorHandler.ThrowOnFailure(activeCfg.get_CanonicalName(out canonicalName));
            configCanonicalName = new ConfigCanonicalName(canonicalName);
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Retrieves Visual Studio global service from global VS service provider.
        /// This method is not thread safe and should not be called from async methods.
        /// </summary>
        /// <typeparam name="T">Service interface type such as IVsUiShell</typeparam>
        /// <param name="type">Service type if different from T, such as typeof(SVSUiShell)</param>
        /// <returns>Service instance of null if not found.</returns>
        public T GetGlobalService <T>(Type type = null) where T : class
        {
            if (IsUnitTestEnvironment)
            {
                System.IServiceProvider sp = RPackage.Current;
                return(sp.GetService(type ?? typeof(T)) as T);
            }

            return(VisualStudio.Shell.Package.GetGlobalService(type ?? typeof(T)) as T);
        }
Beispiel #5
0
        /// <summary>
        /// Retrieves Visual Studio global service from global VS service provider.
        /// This method is not thread safe and should not be called from async methods.
        /// </summary>
        /// <typeparam name="T">Service interface type such as IVsUiShell</typeparam>
        /// <param name="type">Service type if different from T, such as typeof(SVSUiShell)</param>
        /// <returns>Service instance of null if not found.</returns>
        public T GetGlobalService <T>(Type type = null) where T : class
        {
            this.AssertIsOnMainThread();
            if (IsUnitTestEnvironment)
            {
                System.IServiceProvider sp = RPackage.Current;
                return(sp.GetService(type ?? typeof(T)) as T);
            }

            return(VsPackage.GetGlobalService(type ?? typeof(T)) as T);
        }
Beispiel #6
0
        private void OpenVsHierarchy()
        {
            CheckOnDispatchThread();
            if (_vsHierarchyActive)
            {
                return;
            }
            var vsSolution2 = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution2;

            if (vsSolution2 == null)
            {
                return;
            }
            Open();
            int hr = 0;

            if (ErrorHandler.Succeeded(hr))
            {
                __VSADDVPFLAGS flags =
                    __VSADDVPFLAGS.ADDVP_AddToProjectWindow |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromBuild |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromCfgUI |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromDebugLaunch |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromDeploy |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromEnumOutputs |
                    __VSADDVPFLAGS.ADDVP_ExcludeFromSCC;
                hr = vsSolution2.AddVirtualProject(this, (uint)flags);
                if (hr == VSConstants.VS_E_SOLUTIONNOTOPEN)
                {
                    hr = 0;
                }
            }

            if (!ErrorHandler.Succeeded(hr))
            {
                return;
            }
            _vsHierarchyActive = true;
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new ConsoleWindow object.
        /// This constructor uses the service provider passed as an argument to create and initialize
        /// the text buffer.
        /// </summary>
        public ConsoleWindow(IServiceProvider provider) :
            base(null)
        {
            if (null == provider)
            {
                throw new ArgumentNullException("provider");
            }
            globalProvider = provider;

            // Create the text buffer.
            textLines = (IVsTextLines)CreateObject(typeof(VsTextBufferClass), typeof(IVsTextLines));
            // Get a reference to the global service provider.
            IOleServiceProvider nativeProvider = (IOleServiceProvider)globalProvider.GetService(typeof(IOleServiceProvider));

            // The text buffer must be sited with the global service provider.
            ((IObjectWithSite)textLines).SetSite(nativeProvider);
            // Set the buffer as read-only. The user should be able to change the content of the
            // buffer only if the engine is started.
            uint flags;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.GetStateFlags(out flags));
            flags |= (uint)Microsoft.VisualStudio.TextManager.Interop.BUFFERSTATEFLAGS.BSF_USER_READONLY;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.SetStateFlags(flags));

            // Set the GUID of the language service that will handle this text buffer
            Guid languageGuid = typeof(FoxProLanguage).GUID;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.SetLanguageServiceID(ref languageGuid));

            // Initialize the history
            history = new HistoryBuffer();

            // Create the stream on top of the text buffer.
            textStream = new TextBufferStream(textLines);

            // Initialize the engine.
            InitializeEngine();

            // Set the title of the window.
            this.Caption = Resources.ToolWindowTitle;

            // Set the icon of the toolwindow.
            this.BitmapResourceID = 301;
            this.BitmapIndex      = 0;
        }
Beispiel #8
0
        internal static bool IsShellInCommandLineMode(System.IServiceProvider serviceProvider)
        {
            Utilities.ArgumentNotNull("serviceProvider", serviceProvider);

            IVsShell shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell == null)
            {
                throw new InvalidOperationException();
            }

            object isInCommandLineModeAsObject;

            ErrorHandler.ThrowOnFailure(shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out isInCommandLineModeAsObject));

            return((bool)isInCommandLineModeAsObject);
        }
        /// <summary>
        /// Determines whether the shell is in command line mode.
        /// </summary>
        /// <param name="serviceProvider">A reference to a Service Provider.</param>
        /// <returns>true if the shell is in command line mode. false otherwise.</returns>
        /*internal, but public for FSharp.Project.dll*/ public static bool IsShellInCommandLineMode(System.IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            IVsShell shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell == null)
            {
                throw new InvalidOperationException();
            }

            object isInCommandLineModeAsObject;

            ErrorHandler.ThrowOnFailure(shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out isInCommandLineModeAsObject));

            return((bool)isInCommandLineModeAsObject);
        }
        void ShowContextMenu(object sender, EventArgs args)
        {
            // Get a reference to the UIShell.
            IVsUIShell uiShell = globalProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (null == uiShell)
            {
                return;
            }

            // Get the position of the cursor.
            System.Drawing.Point pt   = System.Windows.Forms.Cursor.Position;
            POINTS[]             pnts = new POINTS[1];
            pnts[0].x = (short)pt.X;
            pnts[0].y = (short)pt.Y;

            // Show the menu.
            Guid menuGuid = ConsoleGuidList.guidIronSchemeConsoleCmdSet;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                uiShell.ShowContextMenu(0, ref menuGuid, (int)PkgCmdIDList.ISConsoleContextMenu, pnts, textView as IOleCommandTarget));
        }
Beispiel #11
0
        /// <summary>
        /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface.
        /// </summary>
        /// <param name="serviceProvider">A service provider.</param>
        /// <param name="hierarchy">The hierrachy whose configuration is requested.</param>
        /// <returns>true if successfull.</returns>
        public static bool TryGetActiveConfigurationAndPlatform(System.IServiceProvider serviceProvider, Guid projectId, out ConfigCanonicalName configCanonicalName)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            IVsSolutionBuildManager5 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager5;

            if (solutionBuildManager == null)
            {
                configCanonicalName = new ConfigCanonicalName();
                return false;
            }

            string canonicalName;
            ErrorHandler.ThrowOnFailure(solutionBuildManager.FindActiveProjectCfgName(projectId, out canonicalName));

            configCanonicalName = new ConfigCanonicalName(canonicalName);

            return true;
        }
        /// <summary>
        /// Creates a new ConsoleWindow object.
        /// This constructor uses the service provider passed as an argument to create and initialize
        /// the text buffer.
        /// </summary>
        public ConsoleWindow(IServiceProvider provider)
            : base(null)
        {
            if (null == provider)
                throw new ArgumentNullException("provider");
            globalProvider = provider;

            // Create the text buffer.
            textLines = (IVsTextLines)CreateObject(typeof(VsTextBufferClass), typeof(IVsTextLines));
            // Get a reference to the global service provider.
            IOleServiceProvider nativeProvider = (IOleServiceProvider)globalProvider.GetService(typeof(IOleServiceProvider));
            // The text buffer must be sited with the global service provider.
            ((IObjectWithSite)textLines).SetSite(nativeProvider);
            // Set the buffer as read-only. The user should be able to change the content of the
            // buffer only if the engine is started.
            uint flags;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.GetStateFlags(out flags));
            flags |= (uint)Microsoft.VisualStudio.TextManager.Interop.BUFFERSTATEFLAGS.BSF_USER_READONLY;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.SetStateFlags(flags));

            // Set the GUID of the language service that will handle this text buffer
            Guid languageGuid = typeof(PythonLanguage).GUID;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                textLines.SetLanguageServiceID(ref languageGuid));

            // Initialize the history
            history = new HistoryBuffer();

            // Create the stream on top of the text buffer.
            textStream = new TextBufferStream(textLines);

            // Initialize the engine.
            InitializeEngine();

            // Set the title of the window.
            this.Caption = Resources.ToolWindowTitle;

            // Set the icon of the toolwindow.
            this.BitmapResourceID = 301;
            this.BitmapIndex = 0;
        }