本文整理汇总了C#中Mono.TextEditor.TextEditorData.CanEdit方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.CanEdit方法的具体用法?C# TextEditorData.CanEdit怎么用?C# TextEditorData.CanEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.CanEdit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NextWord
static void NextWord (TextEditorData data, bool subword)
{
int oldLine = data.Caret.Line;
int offset = subword? data.FindNextSubwordOffset (data.Caret.Offset) : data.FindNextWordOffset (data.Caret.Offset);
if (data.Caret.Offset != offset && data.CanEdit (oldLine) && data.CanEdit (data.Caret.Line)) {
data.Remove (data.Caret.Offset, offset - data.Caret.Offset);
data.Document.CommitLineToEndUpdate (data.Caret.Line);
}
}
示例2: NextWord
static void NextWord (TextEditorData data, bool subword)
{
int oldLine = data.Caret.Line;
int caretOffset = data.Caret.Offset;
int offset = subword? data.FindNextSubwordOffset (caretOffset) : data.FindNextWordOffset (caretOffset);
if (caretOffset != offset && data.CanEdit (oldLine) && data.CanEdit (data.Caret.Line)) {
data.Remove (caretOffset, offset - caretOffset);
}
}
示例3: PreviousWord
static void PreviousWord (TextEditorData data, bool subword)
{
int oldLine = data.Caret.Line;
int offset = subword? data.FindPrevSubwordOffset (data.Caret.Offset) : data.FindPrevWordOffset (data.Caret.Offset);
if (data.Caret.Offset != offset && data.CanEdit (oldLine) && data.CanEdit (data.Caret.Line)) {
data.Remove (offset, data.Caret.Offset - offset);
data.Caret.Offset = offset;
if (oldLine != data.Caret.Line)
data.Document.CommitLineToEndUpdate (data.Caret.Line);
}
}
示例4: PreviousWord
static void PreviousWord (TextEditorData data, bool subword)
{
using (var undo = data.OpenUndoGroup ()) {
int oldLine = data.Caret.Line;
int caretOffset = data.Caret.Offset;
int offset = subword ? data.FindPrevSubwordOffset (caretOffset) : data.FindPrevWordOffset (caretOffset);
if (caretOffset != offset && data.CanEdit (oldLine) && data.CanEdit (data.Caret.Line)) {
data.Remove (offset, caretOffset - offset);
}
}
}
示例5: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes [0] & 1) == 1;
bool pasteLine = (selBytes [0] & 2) == 2;
// var clearSelection = data.IsSomethingSelected ? data.MainSelection.SelectionMode != SelectionMode.Block : true;
if (pasteBlock) {
using (var undo = data.OpenUndoGroup ()) {
var version = data.Document.Version;
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
insertionOffset = version.MoveOffsetTo (data.Document.Version, insertionOffset);
data.Caret.PreserveSelection = true;
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
DocumentLine curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.TextLength, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines [i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
}
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
}
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
} else if (pasteLine) {
using (var undo = data.OpenUndoGroup ()) {
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
data.Caret.PreserveSelection = true;
result = text.Length;
DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
data.Insert (curLine.Offset, text + data.EolMarker);
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
} else {
result = PastePlainText (data, insertionOffset, text);
}
}
});
// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
return result;
}
if (result < 0 && clipboard.WaitIsTextAvailable ()) {
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
using (var undo = data.OpenUndoGroup ()) {
result = PastePlainText (data, insertionOffset, text);
}
});
}
return result;
}
示例6: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes [0] & 1) == 1;
bool pasteLine = (selBytes [0] & 2) == 2;
using (var undo = data.OpenUndoGroup ()) {
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
if (pasteBlock) {
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
DocumentLine curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.TextLength, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines [i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
}
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
}
} else if (pasteLine) {
result = text.Length;
DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
data.Insert (curLine.Offset, text + data.EolMarker);
} else {
int offset = data.Caret.Offset;
data.InsertAtCaret (text);
data.PasteText (offset, text, data.Caret.Offset - offset);
}
/* data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
data.Caret.Location,
lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
}
}
});
// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
return result;
}
if (result < 0 && clipboard.WaitIsTextAvailable ()) {
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
using (var undo = data.OpenUndoGroup ()) {
int caretPos = data.Caret.Offset;
if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
data.Caret.PreserveSelection = true;
data.DeleteSelectedText (false);
int textLength = 0;
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
var visualInsertLocation = data.LogicalToVisualLocation (data.Caret.Location);
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
DocumentLine lineSegment = data.GetLine (lineNumber);
int insertOffset = lineSegment.GetLogicalColumn (data, visualInsertLocation.Column) - 1;
if (lineSegment.Length < insertOffset) {
int visualLastColumn = lineSegment.GetVisualColumn (data, lineSegment.Length + 1);
int charsToInsert = visualInsertLocation.Column - visualLastColumn;
int spaceCount = charsToInsert % data.Options.TabSize;
string textToInsert = new string ('\t', (charsToInsert - spaceCount) / data.Options.TabSize) + new string (' ', spaceCount) + text;
insertOffset = lineSegment.Length;
int insertedChars = data.Insert (lineSegment.Offset + insertOffset, textToInsert);
data.PasteText (lineSegment.Offset + insertOffset, textToInsert, insertedChars);
} else {
textLength = data.Insert (lineSegment.Offset + insertOffset, text);
data.PasteText (lineSegment.Offset + insertOffset, text, textLength);
}
}
data.MainSelection.Anchor = new DocumentLocation (System.Math.Max (DocumentLocation.MinLine, data.Caret.Line == minLine ? maxLine : minLine), System.Math.Max (DocumentLocation.MinColumn, data.Caret.Column - textLength));
data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
data.Caret.PreserveSelection = false;
//.........这里部分代码省略.........
示例7: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
bool pasteBlock = (selBytes[0] & 1) == 1;
bool pasteLine = (selBytes[0] & 2) == 2;
if (!pasteBlock && !pasteLine)
return;
data.Document.BeginAtomicUndo ();
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
if (pasteBlock) {
string[] lines = text.Split ('\r');
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
LineSegment curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Length; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.Length, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines[i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.EditableLength + 1 < lineCol) {
result += lineCol - curLine.EditableLength;
data.Insert (curLine.Offset + curLine.EditableLength, new string (' ', lineCol - curLine.EditableLength));
}
data.Insert (curLine.Offset + lineCol, lines[i]);
result += lines[i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines[i].Length;
}
} else if (pasteLine) {
result += text.Length;
LineSegment curLine = data.Document.GetLine (data.Caret.Line);
data.Insert (curLine.Offset, text + data.EolMarker);
if (!preserveState)
data.Caret.Offset += text.Length + data.EolMarker.Length;
}
/* data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
data.Caret.Location,
lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
data.Document.EndAtomicUndo ();
}
});
if (result < 0) {
clipboard.WaitIsTextAvailable ();
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
data.Document.BeginAtomicUndo ();
int caretPos = data.Caret.Offset;
if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
data.Caret.PreserveSelection = true;
if (!data.MainSelection.IsDirty) {
data.DeleteSelectedText (false);
data.MainSelection.IsDirty = true;
}
int textLength = 0;
int column = data.Caret.Column;
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
int offset = data.Document.GetLine (lineNumber).Offset + column;
textLength = data.Insert (offset, text);
data.PasteText (offset, text);
}
data.Caret.Offset += textLength;
data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, data.Caret.Column - textLength);
data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
data.Caret.PreserveSelection = false;
data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
} else {
ISegment selection = data.SelectionRange;
if (preserveSelection && data.IsSomethingSelected)
data.DeleteSelectedText ();
data.Caret.PreserveSelection = true;
//int oldLine = data.Caret.Line;
int textLength = data.Insert (insertionOffset, text);
result = textLength;
//.........这里部分代码省略.........
示例8: CaretLine
public static void CaretLine (TextEditorData data)
{
if (data.Document.LineCount <= 1 || !data.CanEdit (data.Caret.Line))
return;
LineSegment line = data.Document.GetLine (data.Caret.Line);
data.Remove (line.Offset, line.Length);
data.Document.CommitLineToEndUpdate (data.Caret.Line);
data.Caret.CheckCaretPosition ();
}
示例9: CaretLineToEnd
public static void CaretLineToEnd (TextEditorData data)
{
if (!data.CanEdit (data.Caret.Line))
return;
LineSegment line = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column == line.EditableLength) {
// Nothing after the cursor, delete the end-of-line sequence
data.Remove (line.Offset + data.Caret.Column, line.Length - data.Caret.Column);
} else {
// Delete from cursor position to the end of the line
data.Remove (line.Offset + data.Caret.Column, line.EditableLength - data.Caret.Column);
}
data.Document.CommitLineUpdate (data.Caret.Line);
}
示例10: CaretLineToEnd
public static void CaretLineToEnd (TextEditorData data)
{
if (!data.CanEdit (data.Caret.Line))
return;
var line = data.Document.GetLine (data.Caret.Line);
using (var undo = data.OpenUndoGroup ()) {
data.EnsureCaretIsNotVirtual ();
int physColumn = data.Caret.Column - 1;
if (physColumn == line.Length) {
// Nothing after the cursor, delete the end-of-line sequence
data.Remove (line.Offset + physColumn, line.LengthIncludingDelimiter - physColumn);
} else {
// Delete from cursor position to the end of the line
var end = GetEndOfLineOffset (data, data.Caret.Location, false);
data.Remove (line.Offset + physColumn, end - (line.Offset + physColumn));
}
}
data.Document.CommitLineUpdate (data.Caret.Line);
}
示例11: CaretLine
public static void CaretLine (TextEditorData data)
{
if (data.Document.LineCount <= 1 || !data.CanEdit (data.Caret.Line))
return;
using (var undo = data.OpenUndoGroup ()) {
if (data.IsSomethingSelected) {
var startLine = data.GetLine (data.MainSelection.Start.Line);
var endLine = data.GetLine (data.MainSelection.End.Line);
data.Remove (startLine.Offset, endLine.EndOffsetIncludingDelimiter - startLine.Offset);
return;
}
var start = GetStartOfLineOffset (data, data.Caret.Location);
var end = GetEndOfLineOffset (data, data.Caret.Location);
data.Remove (start, end - start);
data.Caret.Column = DocumentLocation.MinColumn;
}
}
示例12: CaretLine
public static void CaretLine (TextEditorData data)
{
if (data.Document.LineCount <= 1 || !data.CanEdit (data.Caret.Line))
return;
var start = GetStartOfLineOffset (data, data.Caret.Location);
var end = GetEndOfLineOffset (data, data.Caret.Location);
data.Remove (start, end - start);
data.Caret.Column = DocumentLocation.MinColumn;
}
示例13: CaretLineToStart
public static void CaretLineToStart (TextEditorData data)
{
if (!data.CanEdit (data.Caret.Line))
return;
var line = data.Document.GetLine (data.Caret.Line);
using (var undo = data.OpenUndoGroup ()) {
data.EnsureCaretIsNotVirtual ();
int physColumn = data.Caret.Column - 1;
var startLine = GetStartOfLineOffset (data, data.Caret.Location);
data.Remove (startLine, (line.Offset + physColumn) - startLine);
}
data.Document.CommitLineUpdate (data.Caret.Line);
}
示例14: PasteFrom
static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
{
int result = -1;
if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
return result;
if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
if (selectionData.Length > 0) {
byte[] selBytes = selectionData.Data;
var upperBound = System.Math.Max (0, System.Math.Min (selBytes [1], selBytes.Length - 2));
byte[] copyData = new byte[upperBound];
Array.Copy (selBytes, 2, copyData, 0, copyData.Length);
var rawTextOffset = 1 + 1 + copyData.Length;
string text = Encoding.UTF8.GetString (selBytes, rawTextOffset, selBytes.Length - rawTextOffset);
bool pasteBlock = (selBytes [0] & 1) == 1;
bool pasteLine = (selBytes [0] & 2) == 2;
if (pasteBlock) {
using (var undo = data.OpenUndoGroup ()) {
var version = data.Document.Version;
if (!preserveSelection)
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
int startLine = data.Caret.Line;
data.EnsureCaretIsNotVirtual ();
insertionOffset = version.MoveOffsetTo (data.Document.Version, insertionOffset);
data.Caret.PreserveSelection = true;
var lines = new List<string> ();
int offset = 0;
while (true) {
var delimiter = LineSplitter.NextDelimiter (text, offset);
if (delimiter.IsInvalid)
break;
int delimiterEndOffset = delimiter.EndOffset;
lines.Add (text.Substring (offset, delimiter.Offset - offset));
offset = delimiterEndOffset;
}
if (offset < text.Length)
lines.Add (text.Substring (offset, text.Length - offset));
int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
DocumentLine curLine;
int lineCol = col;
result = 0;
for (int i = 0; i < lines.Count; i++) {
while (data.Document.LineCount <= lineNr + i) {
data.Insert (data.Document.TextLength, Environment.NewLine);
result += Environment.NewLine.Length;
}
curLine = data.Document.GetLine (lineNr + i);
if (lines [i].Length > 0) {
lineCol = curLine.GetLogicalColumn (data, visCol);
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
}
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
}
if (!preserveState)
data.ClearSelection ();
data.FixVirtualIndentation (startLine);
data.Caret.PreserveSelection = false;
}
} else if (pasteLine) {
using (var undo = data.OpenUndoGroup ()) {
if (!preserveSelection)
data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
data.EnsureCaretIsNotVirtual ();
data.Caret.PreserveSelection = true;
result = text.Length;
DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
result = PastePlainText (data, curLine.Offset, text + data.EolMarker, preserveSelection, copyData);
if (!preserveState)
data.ClearSelection ();
data.Caret.PreserveSelection = false;
data.FixVirtualIndentation (curLine.LineNumber);
}
} else {
result = PastePlainText (data, insertionOffset, text, preserveSelection, copyData);
}
}
});
// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
return result;
}
if (result < 0 && clipboard.WaitIsTextAvailable ()) {
clipboard.RequestText (delegate(Clipboard clp, string text) {
if (string.IsNullOrEmpty (text))
return;
result = PastePlainText (data, insertionOffset, text, preserveSelection);
});
//.........这里部分代码省略.........
示例15: ToggleCase
public static void ToggleCase(TextEditorData data)
{
if (data.IsSomethingSelected) {
if (!data.CanEditSelection)
return;
StringBuilder sb = new StringBuilder (data.SelectedText);
for (int i = 0; i < sb.Length; i++) {
char ch = sb [i];
if (Char.IsLower (ch))
sb [i] = Char.ToUpper (ch);
else if (Char.IsUpper (ch))
sb [i] = Char.ToLower (ch);
}
data.Replace (data.SelectionRange.Offset, data.SelectionRange.Length, sb.ToString ());
} else if (data.CanEdit (data.Caret.Line)) {
char ch = data.Document.GetCharAt (data.Caret.Offset);
if (Char.IsLower (ch))
ch = Char.ToUpper (ch);
else if (Char.IsUpper (ch))
ch = Char.ToLower (ch);
var caretOffset = data.Caret.Offset;
int length = data.Replace (caretOffset, 1, new string (ch, 1));
DocumentLine seg = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column < seg.Length)
data.Caret.Offset = caretOffset + length;
}
}