/// <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); } }
public uint StartBufferUpdate() { // null in unit tests if (_debuggerTextLinesOpt == null) { return(0); } _debuggerTextLinesOpt.GetStateFlags(out var bufferFlags); _debuggerTextLinesOpt.SetStateFlags((uint)((BUFFERSTATEFLAGS)bufferFlags & ~BUFFERSTATEFLAGS.BSF_USER_READONLY)); return(bufferFlags); }
public static void ViewFile(string fileName, string caption) { IVsUIHierarchy hier; UInt32 itemid; IVsWindowFrame frame; IVsTextView view; VsShellUtilities.OpenDocument(RPackage.Current, fileName.FromRPath(), VSConstants.LOGVIEWID.Code_guid, out hier, out itemid, out frame, out view); IVsTextLines textBuffer = null; frame?.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption); view?.GetBuffer(out textBuffer); textBuffer?.SetStateFlags((uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); }
/// <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; }
private void ClearEditor() { if (_docData != null) { _docData.GetStateFlags(out uint oldFlags); _docData.SetStateFlags(oldFlags & ~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); _docData = null; } if (_codeWindow != null) { _codeWindow.Close(); _codeWindow = null; } if (_textView != null) { _textView.CloseView(); _textView = null; } _textViewHost = null; }
public void EndBufferUpdate(uint cookie) { // null in unit tests _debuggerTextLinesOpt?.SetStateFlags(cookie); }
public int SetStateFlags(uint dwReadOnlyFlags) { return(_textBuffer.SetStateFlags(dwReadOnlyFlags)); }
/// <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; }
private void CreateEditor(string filePath) { //IVsInvisibleEditors are in-memory represenations of typical Visual Studio editors. //Language services, highlighting and error squiggles are hooked up to these editors //for us once we convert them to WpfTextViews. IVsInvisibleEditor invisibleEditor; ErrorHandler.ThrowOnFailure(_invisibleEditorManager.RegisterInvisibleEditor( filePath , pProject: null , dwFlags: (uint)_EDITORREGFLAGS.RIEF_ENABLECACHING , pFactory: null , ppEditor: out invisibleEditor)); //Then when creating the IVsInvisibleEditor, find and lock the document IntPtr docData; IVsHierarchy hierarchy; var runningDocTable = (IVsRunningDocumentTable)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsRunningDocumentTable)); uint docCookie; ErrorHandler.ThrowOnFailure(runningDocTable.FindAndLockDocument( dwRDTLockType: (uint)_VSRDTFLAGS.RDT_ReadLock, pszMkDocument: filePath, ppHier: out hierarchy, pitemid: out uint itemId, ppunkDocData: out docData, pdwCookie: out docCookie)); IntPtr docDataPointer; var guidIVsTextLines = typeof(IVsTextLines).GUID; ErrorHandler.ThrowOnFailure(invisibleEditor.GetDocData( fEnsureWritable: 1 , riid: ref guidIVsTextLines , ppDocData: out docDataPointer)); _docData = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer); //Make Buffer Readonly _docData.GetStateFlags(out uint oldFlags); _docData.SetStateFlags(oldFlags | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); //Create a code window adapter _codeWindow = _editorAdapter.CreateVsCodeWindowAdapter(ProfilerPlugin.Instance.OLEServiceProvider); //Disable the splitter control on the editor as leaving it enabled causes a crash if the user //tries to use it here :( IVsCodeWindowEx codeWindowEx = (IVsCodeWindowEx)_codeWindow; INITVIEW[] initView = new INITVIEW[1]; codeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,// | ((uint)TextViewInitFlags2.VIF_READONLY), VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, szNameAuxUserContext: "", szValueAuxUserContext: "", InitViewFlags: 0, pInitView: initView); ErrorHandler.ThrowOnFailure(_codeWindow.SetBuffer(_docData)); //Get a text view for our editor which we will then use to get the WPF control for that editor. ErrorHandler.ThrowOnFailure(_codeWindow.GetPrimaryView(out _textView)); _textViewHost = _editorAdapter.GetWpfTextViewHost(_textView); }