本文整理汇总了C#中Gtk.TextBuffer.GetIterAtOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextBuffer.GetIterAtOffset方法的具体用法?C# TextBuffer.GetIterAtOffset怎么用?C# TextBuffer.GetIterAtOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gtk.TextBuffer
的用法示例。
在下文中一共展示了TextBuffer.GetIterAtOffset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Redo
public override void Redo (TextBuffer buffer)
{
TextIter insertIter = buffer.GetIterAtOffset (index);
buffer.InsertRange (ref insertIter, chop.Start, chop.End);
buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (index));
buffer.MoveMark (buffer.InsertMark, buffer.GetIterAtOffset (index + chop.Length));
}
示例2: Undo
public override void Undo (TextBuffer buffer)
{
#if DEBUG
Console.WriteLine ("DEBUG: Chop Text: {0} Length: {1}", chop.Text, chop.Length);
#endif
TextIter startIter = buffer.GetIterAtOffset (index);
TextIter endIter = buffer.GetIterAtOffset (index + chop.Length);
buffer.Delete (ref startIter, ref endIter);
buffer.MoveMark (buffer.InsertMark, buffer.GetIterAtOffset (index));
buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (index));
}
示例3: AddPaddingEmpty
public static int AddPaddingEmpty (TextBuffer buffer, int offset, string suffix)
{
TextIter insertAt = buffer.GetIterAtOffset (offset);
AddPaddingEmpty (buffer, ref insertAt, suffix);
return insertAt.Offset;
}
示例4: CopyBufferToClipboard
static void CopyBufferToClipboard (TextBuffer buf)
{
//get current cursor state
TextIter s, e;
TextIter cursorIter = TextIter.Zero;
var hadSel = buf.GetSelectionBounds (out s, out e);
if (!hadSel) {
cursorIter = buf.GetIterAtOffset (buf.CursorPosition);
}
//copy text to clipboard, let the buffer handle the details
buf.SelectRange (buf.StartIter, buf.EndIter);
Clipboard clipboard = Clipboard.Get (Mono.TextEditor.ClipboardActions.CopyOperation.CLIPBOARD_ATOM);
buf.CopyClipboard (clipboard);
//restore cursor state
if (hadSel) {
buf.SelectRange (s, e);
} else {
buf.PlaceCursor (cursorIter);
}
}
示例5: AddText
public static int AddText (TextBuffer buffer, int offset, string data, TextTag tag)
{
TextIter insertAt = buffer.GetIterAtOffset (offset);
AddText (buffer, ref insertAt, data, tag);
return insertAt.Offset;
}
示例6: DeserializeAttributes
private static int DeserializeAttributes (TextBuffer buffer, int offset, XmlTextReader xmlReader, string tagSuffix)
{
string elementName, tagName;
elementName = tagName = xmlReader.Name;
DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
TextIter insertAt, applyStart, applyEnd;
insertAt = buffer.GetIterAtOffset (offset);
TextTag tagAttributes;
// Lookup Attributes tag in table, if it is not present we create one.
tagName += ":Attributes" + tagSuffix;
tagAttributes = tagTable.Lookup (tagName);
if (tagAttributes == null)
tagAttributes = tagTable.CreateDynamicTag (tagName);
switch (elementName) {
case "Type":
DeserializeAttributesType (buffer, ref insertAt, xmlReader, tagSuffix);
break;
case "TypeSignature":
DeserializeAttributesTypeSignature (buffer, ref insertAt, xmlReader, tagSuffix);
break;
case "Member":
DeserializeAttributesMember (buffer, ref insertAt, xmlReader, tagSuffix);
break;
case "MemberSignature":
DeserializeAttributesMemberSignature (buffer, ref insertAt, xmlReader, tagSuffix);
break;
default:
DeserializeAttributesNone (buffer, ref insertAt, xmlReader, tagSuffix);
break;
}
applyStart = buffer.GetIterAtOffset (offset);
applyEnd = buffer.GetIterAtOffset (insertAt.Offset);
buffer.ApplyTag (tagAttributes, applyStart, applyEnd);
#if DEBUG
Console.WriteLine ("Attributes: {0} Start: {1} End: {2}", tagName, offset, insertAt.Offset);
#endif
return insertAt.Offset;
}
示例7: AddString
public static int AddString (TextBuffer buffer, int offset, string data, string suffix)
{
TextIter insertAt = buffer.GetIterAtOffset (offset);
AddString (buffer, ref insertAt, data, suffix);
return insertAt.Offset;
}
示例8: FormatStart
private static int FormatStart (TextBuffer buffer, int offset, string suffix, string elementName)
{
TextIter insertAt = buffer.GetIterAtOffset (offset);
switch (elementName) {
case "AssemblyName":
DocumentUtils.AddString (buffer, ref insertAt, "Assembly Name: ", suffix);
break;
case "AssemblyPublicKey":
DocumentUtils.AddString (buffer, ref insertAt, "Assembly PublicKey: ", suffix);
break;
case "AssemblyVersion":
DocumentUtils.AddString (buffer, ref insertAt, "Assembly Version: ", suffix);
break;
case "MemberOfLibrary":
DocumentUtils.AddString (buffer, ref insertAt, "From Library: ", suffix);
break;
case "ThreadSafetyStatement":
DocumentUtils.AddString (buffer, ref insertAt, "Threading Safety: ", suffix);
break;
case "ThreadingSafetyStatement":
DocumentUtils.AddString (buffer, ref insertAt, "Threading Safety: ", suffix);
break;
case "summary":
DocumentUtils.AddString (buffer, ref insertAt, "Summary:\n", suffix);
break;
case "remarks":
DocumentUtils.AddString (buffer, ref insertAt, "Remarks:\n", suffix);
break;
case "Members":
DocumentUtils.AddString (buffer, ref insertAt, "Members:\n\n", suffix);
break;
case "MemberType":
DocumentUtils.AddString (buffer, ref insertAt, "Member Type: ", suffix);
break;
case "ReturnType":
DocumentUtils.AddString (buffer, ref insertAt, "Member Return Type: ", suffix);
break;
case "since":
DocumentUtils.AddString (buffer, ref insertAt, "Since version: ", suffix);
break;
default:
break;
}
return insertAt.Offset;
}
示例9: FormatEnd
private static int FormatEnd (TextBuffer buffer, int offset, string suffix, string elementName)
{
TextIter insertAt = buffer.GetIterAtOffset (offset);
switch (elementName) {
case "para":
case "Docs":
case "Base":
case "BaseTypeName":
case "Attribute":
case "AttributeName":
case "Members":
case "Member":
case "Type":
case "link":
break;
case "see":
case "since":
case "paramref":
case "Parameters":
case "MemberSignature":
break;
case "summary":
case "ThreadSafetyStatement":
case "ThreadingSafetyStatement":
DocumentUtils.AddString (buffer, ref insertAt, "\n\n", suffix);
break;
default:
DocumentUtils.AddString (buffer, ref insertAt, "\n", suffix);
break;
}
return insertAt.Offset;
}
示例10: InsertEndElement
private static int InsertEndElement (TextBuffer buffer, int offset, Stack stack, ref int depth)
{
TextIter insertAt, applyStart, applyEnd;
TagStart tagStart = (TagStart) stack.Pop ();
string suffix = '#' + depth.ToString ();
#if DEBUG
Console.WriteLine ("Element: {0}, End: {1}", tagStart.Tag.Name, offset);
#endif
if (((DocumentTag) tagStart.Tag).IsEditable) {
if (tagStart.Start + 1 == offset)
offset = DocumentUtils.AddStub (buffer, offset, "To be added test", suffix);
insertAt = buffer.GetIterAtOffset (offset);
buffer.Insert (ref insertAt, "]");
offset += 1;
} else if (tagStart.Start == offset)
offset = DocumentUtils.AddPaddingEmpty (buffer, offset, suffix);
applyStart = buffer.GetIterAtOffset (tagStart.Start);
applyEnd = buffer.GetIterAtOffset (offset);
buffer.ApplyTag (tagStart.Tag, applyStart, applyEnd);
offset = FormatEnd (buffer, offset, suffix, tagStart.Name);
depth--;
#if DEBUG
Console.WriteLine ("Applied: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
#endif
// Padding between tag regions
suffix = "#" + depth;
offset = DocumentUtils.AddPadding (buffer, offset, suffix);
return offset;
}
示例11: InsertText
private static int InsertText (TextBuffer buffer, int offset, string data, Stack stack)
{
TagStart tagStart = (TagStart) stack.Peek ();
TextIter insertAt = buffer.GetIterAtOffset (offset);
TextTag textTag = DocumentUtils.GetAssociatedTextTag (buffer, tagStart.Tag);
DocumentUtils.AddText (buffer, ref insertAt, data, textTag);
// buffer.InsertWithTags (ref insertAt, data, textTag);
#if DEBUG
Console.WriteLine ("Text: {0} Value: {1} Start: {2}", textTag.Name, data, offset);
#endif
return insertAt.Offset;
}
示例12: InsertStartElement
private static int InsertStartElement (TextBuffer buffer, int offset, XmlTextReader xmlReader, Stack stack, ref int depth, ref int count)
{
string elementName = xmlReader.Name;
string suffix = String.Empty;
DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
bool emptyElement = xmlReader.IsEmptyElement;
bool isDynamic = DocumentTagTable.IsDynamic (elementName);
TextIter insertAt, applyStart, applyEnd;
depth++;
// We define a suffix so each dynamic tag has an unique name.
// Suffix has format: #{depth level}
if (isDynamic)
suffix = "#" + depth;
// We add any needed string to give format to the document.
offset = FormatStart (buffer, offset, suffix, elementName);
TagStart tagStart = new TagStart ();
tagStart.Start = offset;
tagStart.Name = elementName;
// We first lookup the tag name, if the element is dynamic, we can
// have three scenarios.
// 1) The tag is not in the table: So we create it in the spot.
// 2) Tag is in table but it priority is wrong: We created a new
// dynamic tag with an extra suffix. Format #{depth level}.{count}
// 3) Tag is in table with right priority: We reuse it and we don't
// create a new dymamic tag.
tagStart.Tag = tagTable.Lookup (elementName + suffix);
if (isDynamic && tagStart.Tag == null)
tagStart.Tag = tagTable.CreateDynamicTag (elementName + suffix);
else if (isDynamic && tagStart.Tag != null && tagStart.Tag.Priority < ((TagStart) stack.Peek ()).Tag.Priority) {
suffix += "." + count;
tagStart.Tag = tagTable.CreateDynamicTag (elementName + suffix);
count++;
}
#if DEBUG
try {
Console.WriteLine ("Element: {0} Start: {1}", tagStart.Tag.Name, tagStart.Start);
} catch (NullReferenceException) {
Console.WriteLine ("Error: Missing {0} element", xmlReader.Name);
Environment.Exit (1);
}
#endif
// If element has attributes we have to get them and deserialize them.
if (xmlReader.HasAttributes)
offset = DeserializeAttributes (buffer, offset, xmlReader, suffix);
// Special case when an elment is empty.
// Case A: If element is editable a string stub is inserted to allow edition.
// Case B: If element is not editable then a padding is inserted to handle
// TextTag behaviour in which zero length ranges are lost.
if (emptyElement) {
if (((DocumentTag) tagStart.Tag).IsEditable) {
insertAt = buffer.GetIterAtOffset (offset);
buffer.Insert (ref insertAt, "[");
offset += 1;
offset = DocumentUtils.AddStub (buffer, offset, "Click to Add Documentation", suffix);
insertAt = buffer.GetIterAtOffset (offset);
buffer.Insert (ref insertAt, "]");
offset += 1;
} else
offset = DocumentUtils.AddPaddingEmpty (buffer, offset, suffix);
applyStart = buffer.GetIterAtOffset (tagStart.Start);
applyEnd = buffer.GetIterAtOffset (offset);
buffer.ApplyTag (tagStart.Tag, applyStart, applyEnd);
offset = FormatEnd (buffer, offset, suffix, elementName);
// Padding between tag regions
offset = DocumentUtils.AddPadding (buffer, offset, suffix);
depth--;
#if DEBUG
Console.WriteLine ("Empty Element: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
#endif
} else {
stack.Push (tagStart);
if (((DocumentTag) tagStart.Tag).IsEditable) {
insertAt = buffer.GetIterAtOffset (offset);
buffer.Insert (ref insertAt, "[");
offset += 1;
}
}
return offset;
}
示例13: GetSqlStatementAtCursor
// Execute first SQL statement at cursor
public string GetSqlStatementAtCursor(TextBuffer sqlTextBuffer, out TextIter iter)
{
TextIter start_iter, end_iter, insert_iter;
TextIter match_start1, match_end1, match_start2, match_end2;
TextIter begin_iter, finish_iter;
string text = String.Empty;
int char_count = 0;
TextMark insert_mark;
insert_mark = sqlTextBuffer.InsertMark;
insert_iter = sqlTextBuffer.GetIterAtMark (insert_mark);
start_iter = sqlTextBuffer.GetIterAtOffset (0);
char_count = sqlTextBuffer.CharCount;
end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
iter = end_iter;
match_start1 = sqlTextBuffer.GetIterAtOffset (0);
match_end1 = sqlTextBuffer.GetIterAtOffset (char_count);
match_start2 = sqlTextBuffer.GetIterAtOffset (0);
match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);
begin_iter = sqlTextBuffer.GetIterAtOffset (0);
finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);
if (start_iter.IsEnd == false)
{
if (insert_iter.BackwardSearch (";", TextSearchFlags.TextOnly,
out match_start1, out match_end1, start_iter) == true) {
begin_iter = match_start1;
begin_iter.ForwardChars (1);
}
if (insert_iter.ForwardSearch (";", TextSearchFlags.TextOnly,
out match_start2, out match_end2, end_iter) == true) {
finish_iter = match_end2;
finish_iter.BackwardChars (1);
}
iter = finish_iter;
text = sqlTextBuffer.GetText (begin_iter, finish_iter, false);
// FIXME: for this to work. GetSqlStatement has to rewritten to be line-based
if (text.Length > 0) {
// search does not work if what you are searching for is
// at the end of the buffer,
// this compensates for this
int j = text.Length;
int cont = 1;
for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
char ch = text[i];
switch(ch) {
case ' ':
case ';':
j--;
break;
default:
cont = 0;
break;
}
}
if (j != text.Length) {
string t = text.Substring(0, j);
text = t;
}
}
}
return text;
}
示例14: GetNextSqlStatement
// get next SQL statement. Requires GetSqlStatementAtCursor having been called first
public string GetNextSqlStatement(TextBuffer sqlTextBuffer, ref TextIter iter)
{
TextIter start_iter, end_iter;
TextIter match_start2, match_end2;
TextIter finish_iter;
string text = String.Empty;
int char_count = 0;
char_count = sqlTextBuffer.CharCount;
end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
if (iter.IsEnd == false) {
iter.ForwardChars (1);
if (sqlTextBuffer.GetText (iter, end_iter, false).Equals (";"))
iter.ForwardChars (1);
}
if (iter.IsEnd == true)
return "";
start_iter = iter;
match_start2 = iter;
match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);
finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);
if (start_iter.IsEnd == false) {
if (iter.ForwardSearch (";", TextSearchFlags.TextOnly,
out match_start2, out match_end2, end_iter) == true) {
finish_iter = match_end2;
finish_iter.BackwardChars (1);
}
text = sqlTextBuffer.GetText (iter, finish_iter, false);
iter = finish_iter;
if(text.Length > 0) {
// search does not work if what you are searching for is
// at the end of the buffer,
// this compensates for this
int j = text.Length;
int cont = 1;
for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
char ch = text[i];
switch(ch) {
case ' ':
case ';':
j--;
break;
default:
cont = 0;
break;
}
}
if(j != text.Length) {
string t = text.Substring(0, j);
text = t;
}
}
}
return text;
}