本文整理汇总了C#中Document.GetContent方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetContent方法的具体用法?C# Document.GetContent怎么用?C# Document.GetContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.GetContent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertEntry
private void InsertEntry(Document document)
{
IEditableTextBuffer textBuffer = document.GetContent<IEditableTextBuffer>();
if (textBuffer == null) return;
string changeLogFileName = document.FileName;
string changeLogFileNameDirectory = Path.GetDirectoryName(changeLogFileName);
string selectedFileName = GetSelectedFile();
string selectedFileNameDirectory = Path.GetDirectoryName(selectedFileName);
string eol = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;
int pos = GetHeaderEndPosition (document);
if (pos > 0 && selectedFileNameDirectory.StartsWith(changeLogFileNameDirectory)) {
string text = "\t* "
+ selectedFileName.Substring(changeLogFileNameDirectory.Length + 1) + ": "
+ eol + eol;
int insertPos = Math.Min (pos + 2, textBuffer.Length);
textBuffer.InsertText (insertPos, text);
insertPos += text.Length;
textBuffer.Select (insertPos, insertPos);
textBuffer.CursorPosition = insertPos;
document.Select ();
}
}
示例2: GetResolveResult
public static ResolveResult GetResolveResult (Document doc, ITextBuffer editor)
{
ITextEditorResolver textEditorResolver = doc.GetContent<ITextEditorResolver> ();
if (textEditorResolver != null)
return textEditorResolver.GetLanguageItem (editor.CursorPosition);
/* Fallback (currently not needed)
// Look for an identifier at the cursor position
IParser parser = ProjectDomService.GetParserByFileName (editor.Name);
if (parser == null)
return;
ExpressionResult id = new ExpressionResult (editor.SelectedText);
if (String.IsNullOrEmpty (id.Expression)) {
IExpressionFinder finder = parser.CreateExpressionFinder (ctx);
if (finder == null)
return;
id = finder.FindFullExpression (editor.Text, editor.CursorPosition);
if (id == null)
return;
}
IResolver resolver = parser.CreateResolver (ctx, doc, editor.Name);
if (resolver == null)
return;
return resolver.Resolve (id, new DomLocation (line, column));
**/
return null;
}
示例3: InsertEntry
static void InsertEntry(Document document)
{
var textBuffer = document.GetContent<TextEditor>();
if (textBuffer == null) return;
string changeLogFileName = document.FileName;
string changeLogFileNameDirectory = Path.GetDirectoryName(changeLogFileName);
string selectedFileName = GetSelectedFile();
string selectedFileNameDirectory = Path.GetDirectoryName(selectedFileName);
string eol = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;
int pos = GetHeaderEndPosition (document);
if (pos > 0 && selectedFileNameDirectory.StartsWith (changeLogFileNameDirectory, StringComparison.Ordinal)) {
string text = "\t* "
+ selectedFileName.Substring(changeLogFileNameDirectory.Length + 1) + ": "
+ eol + eol;
int insertPos = Math.Min (pos + 2, textBuffer.Length);
textBuffer.InsertText (insertPos, text);
insertPos += text.Length;
textBuffer.CaretOffset = insertPos;
textBuffer.SetSelection (insertPos, insertPos);
document.Select ();
}
}
示例4: GetNavPointForDoc
static NavigationPoint GetNavPointForDoc (Document doc)
{
if (doc == null)
return null;
NavigationPoint point = null;
INavigable navigable = doc.GetContent<INavigable> ();
if (navigable != null) {
point = navigable.BuildNavigationPoint ();
if (point != null)
return point;
}
IEditableTextBuffer editBuf = doc.GetContent<IEditableTextBuffer> ();
if (editBuf != null) {
point = new TextFileNavigationPoint (doc, editBuf);
if (point != null)
return point;
}
return new DocumentNavigationPoint (doc);
}
示例5: GetFixes
public static bool GetFixes (out Document document, out IList<FixableResult> results)
{
results = null;
document = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;
if (document == null)
return false;
var ext = document.GetContent<ResultsEditorExtension> ();
if (ext == null)
return false;
var list = ext.GetResultsAtOffset (document.Editor.Caret.Offset).OfType<FixableResult> ().ToList ();
list.Sort (ResultCompareImportanceDesc);
results = list;
return results.Count > 0;
}
示例6: GetHeaderEndPosition
private int GetHeaderEndPosition(Document document)
{
IEditableTextBuffer textBuffer = document.GetContent<IEditableTextBuffer>();
if (textBuffer == null) return 0;
// This is less than optimal, we simply read 1024 chars hoping to
// find a newline there: if we don't find it we just return 0.
string text = textBuffer.GetText (0, Math.Min (textBuffer.Length, 1023));
string eol = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;
return text.IndexOf (eol + eol);
}
示例7: InsertHeader
private bool InsertHeader (Document document)
{
IEditableTextBuffer textBuffer = document.GetContent<IEditableTextBuffer>();
if (textBuffer == null) return false;
AuthorInformation userInfo = document.Project != null ? document.Project.AuthorInformation : AuthorInformation.Default;
if (!userInfo.IsValid) {
string title = GettextCatalog.GetString ("ChangeLog entries can't be generated");
string detail = GettextCatalog.GetString ("The name or e-mail of the user has not been configured.");
MessageService.ShowError (title, detail);
return false;
}
string eol = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;
string date = DateTime.Now.ToString("yyyy-MM-dd");
string text = date + " " + userInfo.Name + " <" + userInfo.Email + ">"
+ eol + eol;
// Read the first line and compare it with the header: if they are
// the same don't insert a new header.
int pos = GetHeaderEndPosition(document);
if (pos < 0 || (pos + 2 > textBuffer.Length) || textBuffer.GetText (0, pos + 2) != text)
textBuffer.InsertText (0, text);
return true;
}
示例8: PopulateInfos
public static void PopulateInfos (CommandArrayInfo infos, Document doc, IEnumerable<FixableResult> results)
{
//FIXME: ellipsize long messages
int mnemonic = 1;
var codeActionExtension = doc.GetContent <CodeActionEditorExtension> ();
var fixes = codeActionExtension.GetCurrentFixes ();
if (fixes != null) {
foreach (var _fix in fixes.Where (CodeActionEditorExtension.IsAnalysisOrErrorFix)) {
var fix = _fix;
if (fix is AnalysisContextActionProvider.AnalysisCodeAction)
continue;
var escapedLabel = fix.Title.Replace ("_", "__");
var label = (mnemonic <= 10)
? "_" + (mnemonic++ % 10).ToString () + " " + escapedLabel
: " " + escapedLabel;
infos.Add (label, fix);
}
}
foreach (var result in results) {
bool firstAction = true;
foreach (var action in GetActions (doc, result)) {
if (firstAction) {
//FIXME: make this header item insensitive but not greyed out
infos.Add (new CommandInfo (result.Message.Replace ("_", "__"), false, false) {
Icon = GetIcon (result.Level)
}, null);
firstAction = false;
}
var escapedLabel = action.Label.Replace ("_", "__");
var label = (mnemonic <= 10)
? "_" + (mnemonic++ % 10).ToString () + " " + escapedLabel
: " " + escapedLabel;
infos.Add (label, action);
}
if (result.HasOptionsDialog) {
var declSet = new CommandInfoSet ();
declSet.Text = GettextCatalog.GetString ("_Options for \"{0}\"", result.OptionsTitle);
bool hasBatchFix = false;
foreach (var fix in result.Fixes.OfType<IAnalysisFixAction> ().Where (f => f.SupportsBatchFix)) {
hasBatchFix = true;
var title = string.Format (GettextCatalog.GetString ("Apply in file: {0}"), fix.Label);
declSet.CommandInfos.Add (title, new System.Action(fix.BatchFix));
}
if (hasBatchFix)
declSet.CommandInfos.AddSeparator ();
var ir = result as InspectorResults;
if (ir != null) {
var inspector = ir.Inspector;
if (inspector.CanSuppressWithAttribute) {
declSet.CommandInfos.Add (GettextCatalog.GetString ("_Suppress with attribute"), new System.Action(delegate {
inspector.SuppressWithAttribute (doc, ir.Region);
}));
}
if (inspector.CanDisableWithPragma) {
declSet.CommandInfos.Add (GettextCatalog.GetString ("_Suppress with #pragma"), new System.Action(delegate {
inspector.DisableWithPragma (doc, ir.Region);
}));
}
if (inspector.CanDisableOnce) {
declSet.CommandInfos.Add (GettextCatalog.GetString ("_Disable Once"), new System.Action(delegate {
inspector.DisableOnce (doc, ir.Region);
}));
}
if (inspector.CanDisableAndRestore) {
declSet.CommandInfos.Add (GettextCatalog.GetString ("Disable _and Restore"), new System.Action(delegate {
inspector.DisableAndRestore (doc, ir.Region);
}));
}
}
declSet.CommandInfos.Add (GettextCatalog.GetString ("_Configure Rule"), result);
infos.Add (declSet);
}
}
}
示例9: GetFixes
public static bool GetFixes (out Document document, out IList<FixableResult> results)
{
results = null;
document = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;
if (document == null)
return false;
var ext = document.GetContent<ResultsEditorExtension> ();
if (ext == null)
return false;
var list = ext.GetResultsAtOffset (document.Editor.Caret.Offset).OfType<FixableResult> ().ToList ();
list.Sort (ResultCompareImportanceDesc);
results = list;
if (results.Count > 0)
return true;
var codeActionExtension = document.GetContent <CodeActionEditorExtension> ();
if (codeActionExtension != null) {
var fixes = codeActionExtension.GetCurrentFixes ();
if (fixes != null)
return fixes.Any (CodeActionEditorExtension.IsAnalysisOrErrorFix);
}
return false;
}
示例10: GetResolveResultAtCaret
public static ResolveResult GetResolveResultAtCaret(Document document)
{
var textEditorResolver = document.GetContent<ITextEditorResolver>();
if (textEditorResolver != null)
{
return textEditorResolver.GetLanguageItem(document.Editor.Caret.Offset);
}
return null;
}
示例11: GetData
protected ITextBuffer GetData(Document doc)
{
return data ?? doc.GetContent<ITextBuffer> ();
}