public override int SetTextBuffer(VSTextManagerInterop.IVsTextLines pTextBuffer) { var hr = VSConstants.S_OK; _underlyingBuffer = pTextBuffer; return(hr); }
/// <summary> /// Open the file in invisible editor in RDT, and get text buffer from it. /// </summary> /// <remarks> /// This method created for refactoring usage, refactoring will work on all kinds of /// docdata, not only SqlEditorDocData. If change this method, please get let LiangZ /// know. /// </remarks> /// <param name="fullPathFileName">File name with full path.</param> /// <param name="project">the hierarchy for the document</param> /// <param name="spEditor">The result invisible editor.</param> /// <param name="textLines">The result text buffer.</param> /// <returns>True, if the file is opened correctly in invisible editor.</returns> public bool TryGetTextLinesAndInvisibleEditor( string fullPathFileName, VsShell.IVsProject project, out VsShell.IVsInvisibleEditor spEditor, out VsTextMgr.IVsTextLines textLines) { spEditor = null; textLines = null; // Need to open this file. Use the invisible editor manager to do so. VsShell.IVsInvisibleEditorManager invisibleEditorMgr; var ppDocData = IntPtr.Zero; bool result; var iidIVsTextLines = typeof(VsTextMgr.IVsTextLines).GUID; try { invisibleEditorMgr = _invisibleEditorManager; NativeMethods.ThrowOnFailure( invisibleEditorMgr.RegisterInvisibleEditor( fullPathFileName, project, (uint)VsShell._EDITORREGFLAGS.RIEF_ENABLECACHING, null, out spEditor)); if (spEditor != null) { var hr = spEditor.GetDocData(0, ref iidIVsTextLines, out ppDocData); if (hr == VSConstants.S_OK && ppDocData != IntPtr.Zero) { textLines = Marshal.GetTypedObjectForIUnknown(ppDocData, typeof(VsTextMgr.IVsTextLines)) as VsTextMgr.IVsTextLines; result = true; } else { result = false; } } else { result = false; } } finally { if (ppDocData != IntPtr.Zero) { Marshal.Release(ppDocData); } } return(result); }
// this function is fired only for top most transactions //private bool CanCommitTransaction(Transaction tx) //{ // Debug.Assert(tx != null, "tx should not be null"); // if (tx.Context.ContextInfo.ContainsKey(EntityDesignerViewModel.TransactionCancelledGuid)) // { // return false; // } // return true; //} /// <summary> /// Loads the text into the buffer. This method will allocate a VSTextManagerInterop::IVsTextLines will be created /// and loaded with the model /// </summary> /// <param name="ppTextBuffer">newly created buffer loaded with the model file (in XML string form)</param> /// <returns>VSConstants.S_OK if operation successful</returns> public override int GetTextBuffer(out VSTextManagerInterop.IVsTextLines ppTextBuffer) { if (VsBuffer == null) { if (!CreateAndLoadBuffer()) { ppTextBuffer = null; return(VSConstants.E_FAIL); } } ppTextBuffer = VsBuffer; return(VSConstants.S_OK); }
public override IScanner GetScanner(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer) { /* EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); * SolutionBuild sb = dte.Solution.SolutionBuild; * * * //config = proj.ConfigurationManager.ActiveConfiguration; * * //object o = dte.Application.C; * * if (dte != null) * { * * * * EnvDTE.Project proj = (EnvDTE.Project)dte.Solution.Projects.Item(1); * * EnvDTE.ProjectItem pi = proj.ParentProjectItem; * //EnvDTE.Project proj = (EnvDTE.Project)((object[])projs)[0]; * * //object o = proj.Object; * * //EnvDTE.ConfigurationManager cfgs = proj.ConfigurationManager; * //EnvDTE.Configuration cfg = cfgs.ActiveConfiguration; * * * * * //foreach (EnvDTE.Configuration cfg in cfgs) * { * * foreach (EnvDTE.Property temp in proj.Properties) * { * string name = temp.Name; * object val = temp.Value; * Console.WriteLine(name); * } * } * * * * * //EnvDTE.Property prop = cfg.Properties.Item("SquirrelVersion"); * //OAProject * * }*/ return(new Squirrel3Lexer()); }
public static string GetAllTextFromTextLines(VsTextMgr.IVsTextLines textLines) { string content = null; if (textLines != null) { var result = textLines.GetLastLineIndex(out int line, out int column); if (result == VSConstants.S_OK) { result = textLines.GetLineText(0, 0, line, column, out content); if (result != VSConstants.S_OK) { content = null; } } } return(content); }
public override void OnSetBuffer(Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer) { base.OnSetBuffer(view, buffer); }
public bool WriteToFile(string fullPathFileName, string content, bool saveFile, bool createIfNotExist) { var succeed = true; VsShell.IVsInvisibleEditor invisibleEditor = null; VsTextMgr.IVsTextLines textLines = null; var fileDidNotExistAndShouldBeCreated = false; try { if (IsFileInRdt(fullPathFileName)) { // File is in RDT textLines = GetTextLines(fullPathFileName); } else { if (createIfNotExist && File.Exists(fullPathFileName) == false) { fileDidNotExistAndShouldBeCreated = true; FileStream fileStream = null; StreamWriter writer = null; try { fileStream = File.Create(fullPathFileName); // Make the newly created file unicode writer = new StreamWriter(fileStream, Encoding.UTF8); writer.Write(content); } catch (IOException e) { throw new InvalidOperationException(e.Message); } catch (ArgumentException e) { throw new InvalidOperationException(e.Message); } finally { if (writer != null) { writer.Close(); } if (fileStream != null) { fileStream.Close(); } } } // File is not in RDT, open it in invisible editor. if (fileDidNotExistAndShouldBeCreated == false && !TryGetTextLinesAndInvisibleEditor(fullPathFileName, out invisibleEditor, out textLines)) { // Failed to get text lines or invisible editor. textLines = null; } } if (fileDidNotExistAndShouldBeCreated == false) { if (textLines != null) { int line, column; var result = textLines.GetLastLineIndex(out line, out column); if (result == VSConstants.S_OK) { var pContent = IntPtr.Zero; try { // Copy the content to textLines. pContent = Marshal.StringToHGlobalAuto(content); result = textLines.ReloadLines( 0, 0, line, column, pContent, content.Length, new[] { new VsTextMgr.TextSpan() }); if (result != VSConstants.S_OK) { succeed = false; } } finally { if (pContent != IntPtr.Zero) { Marshal.FreeHGlobal(pContent); } } if (saveFile) { var list = new List <string> { fullPathFileName }; Instance.SaveDirtyFiles(list); } } else { succeed = false; } } else { succeed = false; } } } finally { // Close invisible editor from RDT if (invisibleEditor != null) { Marshal.ReleaseComObject(invisibleEditor); } } return(succeed); }
public bool TryGetTextLinesAndInvisibleEditor( string fullPathFileName, out VsShell.IVsInvisibleEditor spEditor, out VsTextMgr.IVsTextLines textLines) { return(TryGetTextLinesAndInvisibleEditor(fullPathFileName, null, out spEditor, out textLines)); }
/// <summary> /// Get IVsTextLines from a file. If that file is in RDT, get text buffer from it. /// If the file is not in RDT, open that file in invisible editor and get text buffer /// from it. /// If failed to get text buffer, it will return null. /// </summary> /// <remarks> /// This method created for refactoring usage, refactoring will work on all kinds of /// docdata, not only SqlEditorDocData. If change this method, please get let LiangZ /// know. /// </remarks> /// <param name="fullPathFileName">File name with full path.</param> /// <returns>Text buffer for that file.</returns> public VsTextMgr.IVsTextLines GetTextLines(string fullPathFileName) { VsTextMgr.IVsTextLines textLines = null; var rdt = Instance.GetRunningDocumentTable(); if (rdt != null) { VsShell.IVsHierarchy ppHier; uint pitemid, pdwCookie; var ppunkDocData = IntPtr.Zero; try { NativeMethods.ThrowOnFailure( FindAndLockDocument( (uint)(VsShell._VSRDTFLAGS.RDT_NoLock), fullPathFileName, out ppHier, out pitemid, out ppunkDocData, out pdwCookie)); if (pdwCookie != 0) { if (ppunkDocData != IntPtr.Zero) { try { // Get text lines from the doc data textLines = Marshal.GetObjectForIUnknown(ppunkDocData) as VsTextMgr.IVsTextLines; } catch (ArgumentException) { // Do nothing here, it will return null stream at the end. } } } else { // The file is not in RDT, open it in invisible editor and get the text lines from it. VsShell.IVsInvisibleEditor invisibleEditor = null; try { TryGetTextLinesAndInvisibleEditor(fullPathFileName, out invisibleEditor, out textLines); } finally { if (invisibleEditor != null) { Marshal.ReleaseComObject(invisibleEditor); } } } } finally { if (ppunkDocData != IntPtr.Zero) { Marshal.Release(ppunkDocData); } } } return(textLines); }
public int UpdateLanguageContext(uint dwHint, Microsoft.VisualStudio.TextManager.Interop.IVsTextLines pBuffer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsSelection, object pUC) { // This called for the online help return(VSConstants.S_OK); }
public override IScanner GetScanner(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer) { return(new AphidScanner()); }
public override IScanner GetScanner(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer) { throw new NotImplementedException(); }