Exemple #1
0
        public static IEnumerable <(string line, int index)> GetLines(this EnvDTE.Document document)
        {
            TextDocument textDoc = (TextDocument)document.Object("TextDocument");

            if (textDoc == null)
            {
                return(Enumerable.Empty <(string line, int index)>());
            }
            return(textDoc.GetLines());
        }
Exemple #2
0
 public int OnBeforeSave(uint docCookie)
 {
     if (_pkg.RemoveOnSave())
     {
         RunningDocumentInfo runningDocumentInfo = new RunningDocumentInfo(_pkg.rdt, docCookie);
         EnvDTE.Document     document            = _pkg.dte.Documents.OfType <EnvDTE.Document>().SingleOrDefault(x => x.FullName == runningDocumentInfo.Moniker);
         if (document == null)
         {
             return(VSConstants.S_OK);
         }
         if (document.Object("TextDocument") is TextDocument textDoc)
         {
             _pkg.RemoveTrailingWhiteSpaces(textDoc);
         }
     }
     return(VSConstants.S_OK);
 }
Exemple #3
0
 public int OnBeforeSave(uint docCookie)
 {
     if (_pkg.removeOnSave())
     {
         RunningDocumentInfo runningDocumentInfo = _pkg.rdt.GetDocumentInfo(docCookie);
         EnvDTE.Document     document            = _pkg.dte.Documents.OfType <EnvDTE.Document>().SingleOrDefault(x => x.FullName == runningDocumentInfo.Moniker);
         if (document == null)
         {
             return(VSConstants.S_OK);
         }
         var textDoc = document.Object("TextDocument") as TextDocument;
         if (textDoc != null)
         {
             RemoveTrailingWhitespacesPackage.removeTrailingWhiteSpaces(textDoc);
         }
     }
     return(VSConstants.S_OK);
 }
        private TextSelection GetTextSelection()
        {
            try
            {
                EnvDTE.Document objDocument = this.dteProvider.Dte.ActiveDocument;
                if (objDocument == null)
                {
                    ShowMessageBox("GetTextSelection()", "ActiveDocument not found. Are you in a code editor window ?");
                    return(null);
                }

                EnvDTE.TextDocument  objTextDocument  = (EnvDTE.TextDocument)objDocument.Object("TextDocument");
                EnvDTE.TextSelection objTextSelection = objTextDocument.Selection;
                return(objTextSelection);
            }
            catch (Exception ex)
            {
                ShowMessageBox("GetTextSelection()", ex.Message);
            }
            return(null);
        }
        public static string GetText(this EnvDTE.Document doc)
        {
            var textdoc = (TextDocument)doc.Object("TextDocument");

            return textdoc.StartPoint.CreateEditPoint().GetText(textdoc.EndPoint);
        }
 public static TextDocument ToTextDocument(this EnvDTE.Document doc)
 {
     return (TextDocument)doc.Object("TextDocument");
 }