Example #1
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);
            }
        }
Example #2
0
        private bool IsDirty(IVsTextView pView)
        {
            IVsTextLines lines = null;

            pView.GetBuffer(out lines);
            if (lines != null)
            {
                uint flags;
                lines.GetStateFlags(out flags);
                bool isDirty = (flags & (uint)BUFFERSTATEFLAGS.BSF_MODIFIED) != 0;
                return(isDirty);
            }
            return(false);
        }
Example #3
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;
        }
Example #4
0
 public int GetStateFlags(out uint pdwReadOnlyFlags)
 {
     return(_textBuffer.GetStateFlags(out pdwReadOnlyFlags));
 }
        /// <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;
        }