Here are the examples of the csharp api class EnvDTE.Document.Object(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
28 Examples
0
1. Example
View licenseprivate void SetCurrentText(string newText) { var dte = (DTE)GetService(typeof(DTE)); if (dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } doc.Selection.Text = newText; }
0
2. Example
View licenseprivate string GetCurrentText() { var dte = (DTE)GetService(typeof(DTE)); if (dte.ActiveDocument == null) { return null; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return null; } return doc.Selection.Text; }
0
3. Example
View licensepublic static bool TryGetSelectionPoint(IServiceProvider serviceProvider, out VirtualPoint point) { Contract.Requires(serviceProvider != null); Contract.Ensures(Contract.ValueAtReturn(out point) != null || !Contract.Result<bool>()); point = null; var dte = VsServiceProviderHelper.GetService<DTE>(serviceProvider); if (dte == null) { return false; } try { // code window supported only Document document = dte.ActiveDocument; if (document != null) { TextDocument tdoc = document.Object("TextDocument") as TextDocument; if (tdoc != null) { try { Contract.Assume(tdoc.Selection != null); point = tdoc.Selection.TopPoint; } catch (COMException) { } } } } catch (ArgumentException) { } // reported by user catch (COMException) { } return point != null; }
0
4. Example
View licenseinternal static TextDocument GetTextDocument(this Document document) { return document.Object("TextDocument") as TextDocument; }
0
5. Example
View licensepublic static void InsertIntoCurrentDocument(string str) { var textDocument = DTE.ActiveDocument.Object(null) as TextDocument; if (textDocument != null) { textDocument.Selection.Insert(str); } }
0
6. Example
View licenseprivate void BlameCommand(object sender, EventArgs e) { _currentFilePath = FileHelper.GetPath(); var currentLineIndex = ((TextDocument) Dte.ActiveDocument?.Object(string.Empty))?.Selection.CurrentLine ?? 0; if (string.IsNullOrEmpty(_currentFilePath)) return; CommandHelper.StartProcess(_tortoiseProc, $"/command:blame /path:\"{_currentFilePath}\" /line:{currentLineIndex}"); }
0
7. Example
View licensepublic static string GetText(Document document) { var text = string.Empty; try { var textDocument = (TextDocument)document.Object("TextDocument"); var startPoint = textDocument?.StartPoint?.CreateEditPoint(); if (startPoint == null) { LogHelper.Log("Error during mapping: Unable to find TextDocument StartPoint"); return null; }; text = startPoint.GetText(textDocument.EndPoint); } catch (COMException e) { // Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) // We were unable to get a start- or endpoint for the document. // This was our last resort to map this document, nothing we can do further. } catch (Exception e) { LogHelper.Log("Error getting Text for document", e); } return text; }
0
8. Example
View license[ContractVerification(false)] private static bool TrySetContent([CanBeNull] EnvDTE.Document document, [CanBeNull] XDocument value) { try { var textDocument = (EnvDTE.TextDocument)document?.Object(@"TextDocument"); if (textDocument == null) return false; var text = value.Declaration + Environment.NewLine + value; textDocument.CreateEditPoint().ReplaceText(textDocument.EndPoint, text, 0); return true; } catch (Exception) { return false; } }
0
9. Example
View license[CanBeNull] private static Selection GetSelection([NotNull] EnvDTE.Document document) { Contract.Requires(document != null); var textDocument = (EnvDTE.TextDocument)document.Object(@"TextDocument"); var topPoint = textDocument?.Selection?.TopPoint; if (topPoint == null) return null; var line = textDocument.CreateEditPoint()?.GetLines(topPoint.Line, topPoint.Line + 1); if (line == null) return null; var fileCodeModel = document.ProjectItem?.FileCodeModel; return new Selection(textDocument, line, fileCodeModel); }
0
10. Example
View license[SuppressMessage("ReSharper", "PossibleNullReferenceException")] private static void SetContent([NotNull] EnvDTE.Document document, [CanBeNull] string text) { var textDocument = (EnvDTE.TextDocument)document.Object("TextDocument"); textDocument.StartPoint.CreateEditPoint().ReplaceText(textDocument.EndPoint, text, 0); }
0
11. Example
View licenseprivate void MyDocumentEvents_DocumentOpened(Document Document) { if (Document.FullName.EndsWith(".sql")) { var textDoc = ((TextDocument)Document.Object()); textDoc.ReplacePattern("/*designTime", "-- designTime"); textDoc.ReplacePattern("endDesignTime*/", "-- endDesignTime"); // backward compatibility textDoc.ReplacePattern("--designTime", "-- designTime"); textDoc.ReplacePattern("--endDesignTime", "-- endDesignTime"); // never got close to working. cost me 50 points on stack. just saw it open the window???? //try //{ // if (_dte.Commands.Item("SQL.TSqlEditorConnect") != null && _dte.Commands.Item("SQL.TSqlEditorConnect").IsAvailable) // { // _dte.ExecuteCommand("SQL.TSqlEditorConnect"); // } // //_dte.ExecuteCommand("SQL.TSqlEditorConnect", "Data Source=not-mobility;Initial Catalog=NORTHWND;Integrated Security=SSPI;"); //} //catch (Exception ex) { } } }
0
12. Example
View license[CanBeNull] [ContractVerification(false)] private static XDocument TryGetContent([CanBeNull] EnvDTE.Document document) { try { var textDocument = (EnvDTE.TextDocument)document?.Object(@"TextDocument"); var text = textDocument?.CreateEditPoint().GetText(textDocument.EndPoint); return text == null ? null : XDocument.Parse(text); } catch (Exception) { return null; } }
0
13. Example
View licenseprivate string GetCurrentDocumentText(DTE dte) { if (dte.ActiveDocument == null) { return null; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return null; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); return ep.GetText(length); }
0
14. Example
View licensepublic static string GetText(this Document source) { if (source == null) return null; //can this even happen? var doc = source.Object("TextDocument") as TextDocument; if (null == doc) { return null; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); return ep.GetText(length); }
0
15. Example
View licenseprivate string GetCurrentDocumentText() { var dte = (DTE) GetService(typeof (DTE)); if (dte.ActiveDocument == null) { return null; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return null; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); return ep.GetText(length); }
0
16. Example
View licenseprivate void ToggleQueryCosts(object sender, EventArgs e) { try { var dte = (DTE) GetService(typeof (DTE)); if (dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); var originalText = ep.GetText(length); DocumentScriptCosters.SetDte(dte); var coster = DocumentScriptCosters.GetInstance().GetCoster(); if (coster == null) return; if (coster.ShowCosts) { coster.ShowCosts = false; } else { coster.ShowCosts = true; coster.AddCosts(originalText, dte.ActiveDocument); } } catch (Exception ee) { OutputPane.WriteMessage("ToggleQueryCosts error: {0}", ee.Message); Log.WriteInfo("ToggleQueryCosts error: {0}", ee.Message); } }
0
17. Example
View license[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] internal void Reparse() { if(isDirty) { Debug.Assert(ccu != null); CodeCompileUnit newCcu = null; TextDocument td = ((TextDocument)ProjectItem.Document.Object("TextDocument")); Debug.Assert(td != null); EditPoint ep = td.CreateEditPoint(td.StartPoint); string text = ep.GetText(td.EndPoint); try{ newCcu = provider.ParseMergable(text, ProjectItem.Document.FullName, new FileCodeMerger(parent)); MergeNewCompileUnit(newCcu); } catch { // swallow parse errors. } isDirty = false; } }
0
18. Example
View licenseprivate void SetCurrentDocumentText(string newText) { var dte = (DTE)GetService(typeof(DTE)); if (dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); ep.Delete(length); ep.Insert(newText); }
0
19. Example
View licenseprivate void CreatetSQLtTest(object sender, EventArgs e) { try { CallWrapper(); var dte = (DTE) GetService(typeof (DTE)); if (dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); var originalText = ep.GetText(length); var builder = new TestBuilder(originalText, dte.ActiveDocument.ProjectItem.ContainingProject); builder.Go(); // builder.CreateTests(); } catch (Exception ex) { OutputPane.WriteMessage("Exception creating tSQLt tests, error: {0}", ex.Message); } }
0
20. Example
View licenseprivate void CreatetSQLtSchema(object sender, EventArgs e) { try { CallWrapper(); var dte = (DTE) GetService(typeof (DTE)); if (dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); var originalText = ep.GetText(length); var builder = new SchemaBuilder(originalText); builder.CreateSchemas(); } catch (Exception ex) { OutputPane.WriteMessage("Exception creating tSQLt schema, error: {0}", ex.Message); } }
0
21. Example
View license[NotNull] public static string GetContent([NotNull] this EnvDTE.ProjectItem projectItem) { try { if (!projectItem.IsOpen) projectItem.Open(); var document = projectItem.Document; if (document != null) { // ReSharper disable once AssignNullToNotNullAttribute return GetContent((EnvDTE.TextDocument)document.Object("TextDocument")); } var fileName = projectItem.TryGetFileName(); if (string.IsNullOrEmpty(fileName)) return string.Empty; return File.ReadAllText(fileName); } catch (Exception) { return string.Empty; } }
0
22. Example
View licensevoid myDocumentEvents_DocumentSaved(Document Document) { //kludge if (!TinyIoCContainer.Current.CanResolve<IWrapperClassMaker>()) RegisterTypes(); if (Document.FullName.EndsWith(".sql")) try { var textDoc = ((TextDocument)Document.Object()); var text = textDoc.CreateEditPoint().GetText(textDoc.EndPoint); if (text.Contains("managed by QueryFirst")) { var cdctr = new Conductor(_VSOutputWindow); cdctr.ProcessOneQuery(Document); } } catch (Exception ex) { _VSOutputWindow.Write(ex.Message + ex.StackTrace); } }
0
23. Example
View licensepublic void WriteAndFormat(string code) { bool rememberToClose = false; if (!_item.IsOpen) { _item.Open(); rememberToClose = true; } var textDoc = ((TextDocument)_item.Document.Object()); var ep = textDoc.CreateEditPoint(); ep.ReplaceText(textDoc.EndPoint, code, 0); ep.SmartFormat(textDoc.EndPoint); _item.Save(); if (rememberToClose) { _item.Document.Close(); } }
0
24. Example
View licenseprivate void ProcessAllItems(ProjectItems items, VSOutputWindow vsOutputWindow) { if (items != null) { foreach (ProjectItem item in items) { try { if (item.FileNames[1].EndsWith(".sql")) { item.Open(); var textDoc = ((TextDocument)item.Document.Object()); var text = textDoc.CreateEditPoint().GetText(textDoc.EndPoint); if (text.Contains("managed by QueryFirst")) { new Conductor(vsOutputWindow).ProcessOneQuery(item.Document); } } if (item.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}") //folder ProcessAllItems(item.ProjectItems, vsOutputWindow); } catch (Exception ex) { } } } }
0
25. Example
View licenseprivate void RunCodeCleanupGeneric(Document document, ITextBuffer textBuffer) { ITextDocument textDocument; var doc = (TextDocument)document.Object("TextDocument"); textBuffer.Properties.TryGetProperty(typeof(ITextDocument), out textDocument); var path = doc.Parent.FullName; FileConfiguration settings; if (!ConfigLoader.TryLoad(path, out settings)) return; using (ITextEdit edit = textBuffer.CreateEdit()) { ITextSnapshot snapshot = edit.Snapshot; if (settings.Charset != null && textDocument != null) FixDocumentCharset(textDocument, settings.Charset.Value); if (settings.TryKeyAsBool("trim_trailing_whitespace")) TrimTrailingWhitespace(snapshot, edit); if (settings.TryKeyAsBool("insert_final_newline")) InsertFinalNewline(snapshot, edit, settings.EndOfLine()); var eol = settings.EndOfLine(); FixLineEndings(snapshot, edit, eol); edit.Apply(); } }
0
26. Example
View licenseprivate void NameConstraintsCalled(object sender, EventArgs e) { try { CallWrapper(); var dte = (DTE) GetService(typeof (DTE)); if (null == dte || dte.ActiveDocument == null) { return; } var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (null == doc) { return; } var ep = doc.StartPoint.CreateEditPoint(); ep.EndOfDocument(); var length = ep.AbsoluteCharOffset; ep.StartOfDocument(); var originalText = ep.GetText(length); var namer = new ConstraintNamer(originalText); var modifiedText = namer.Go(); if (originalText != modifiedText) { ep.Delete(length); ep.Insert(modifiedText); } } catch (Exception ex) { OutputPane.WriteMessage("Exception naming constraints, error: {0}", ex.Message); } }
0
27. Example
View licensevoid CSharpItemRenamed(ProjectItem renamedQuery, string OldName) { if (OldName./n ..... /n //View Source file for more details /n }
0
28. Example
View licensepublic void InjectPOCOFactory(CodeGenerationContext ctx, ProjectItem partialClass) { /n ..... /n //View Source file for more details /n }