Browse Source

AvalonEdit: Fixed drag'n'drop when there are read-only text segments.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4669 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
04f2d7b102
  1. 59
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionMouseHandler.cs
  2. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

59
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionMouseHandler.cs

@ -144,13 +144,14 @@ namespace ICSharpCode.AvalonEdit.Editing
if (offset >= 0) { if (offset >= 0) {
textArea.Caret.Position = new TextViewPosition(textArea.Document.GetLocation(offset), visualColumn); textArea.Caret.Position = new TextViewPosition(textArea.Document.GetLocation(offset), visualColumn);
textArea.Caret.DesiredXPos = double.NaN; textArea.Caret.DesiredXPos = double.NaN;
if ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move if (textArea.ReadOnlySectionProvider.CanInsert(offset)) {
&& (e.KeyStates & DragDropKeyStates.ControlKey) != DragDropKeyStates.ControlKey if ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move
&& textArea.ReadOnlySectionProvider.CanInsert(offset)) && (e.KeyStates & DragDropKeyStates.ControlKey) != DragDropKeyStates.ControlKey)
{ {
return DragDropEffects.Move; return DragDropEffects.Move;
} else { } else {
return e.AllowedEffects & DragDropEffects.Copy; return e.AllowedEffects & DragDropEffects.Copy;
}
} }
} }
} }
@ -159,9 +160,13 @@ namespace ICSharpCode.AvalonEdit.Editing
void textArea_DragLeave(object sender, DragEventArgs e) void textArea_DragLeave(object sender, DragEventArgs e)
{ {
e.Handled = true; try {
if (!textArea.IsKeyboardFocusWithin) e.Handled = true;
textArea.Caret.Hide(); if (!textArea.IsKeyboardFocusWithin)
textArea.Caret.Hide();
} catch (Exception ex) {
OnDragException(ex);
}
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
@ -221,20 +226,28 @@ namespace ICSharpCode.AvalonEdit.Editing
void textArea_GiveFeedback(object sender, GiveFeedbackEventArgs e) void textArea_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{ {
e.UseDefaultCursors = true; try {
e.Handled = true; e.UseDefaultCursors = true;
e.Handled = true;
} catch (Exception ex) {
OnDragException(ex);
}
} }
void textArea_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) void textArea_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{ {
if (e.EscapePressed) { try {
e.Action = DragAction.Cancel; if (e.EscapePressed) {
} else if ((e.KeyStates & DragDropKeyStates.LeftMouseButton) != DragDropKeyStates.LeftMouseButton) { e.Action = DragAction.Cancel;
e.Action = DragAction.Drop; } else if ((e.KeyStates & DragDropKeyStates.LeftMouseButton) != DragDropKeyStates.LeftMouseButton) {
} else { e.Action = DragAction.Drop;
e.Action = DragAction.Continue; } else {
e.Action = DragAction.Continue;
}
e.Handled = true;
} catch (Exception ex) {
OnDragException(ex);
} }
e.Handled = true;
} }
#endregion #endregion
@ -253,6 +266,12 @@ namespace ICSharpCode.AvalonEdit.Editing
DragDropEffects allowedEffects = DragDropEffects.All; DragDropEffects allowedEffects = DragDropEffects.All;
var deleteOnMove = textArea.Selection.Segments.Select(s => new AnchorSegment(textArea.Document, s)).ToList(); var deleteOnMove = textArea.Selection.Segments.Select(s => new AnchorSegment(textArea.Document, s)).ToList();
foreach (ISegment s in deleteOnMove) {
ISegment[] result = textArea.ReadOnlySectionProvider.GetDeletableSegments(s).ToArray();
if (result.Length != 1 || result[0].Offset != s.Offset || result[0].EndOffset != s.EndOffset) {
allowedEffects &= ~DragDropEffects.Move;
}
}
object dragDescriptor = new object(); object dragDescriptor = new object();
this.currentDragDescriptor = dragDescriptor; this.currentDragDescriptor = dragDescriptor;
@ -277,7 +296,7 @@ namespace ICSharpCode.AvalonEdit.Editing
this.currentDragDescriptor = null; this.currentDragDescriptor = null;
if (deleteOnMove != null && resultEffect == DragDropEffects.Move) { if (deleteOnMove != null && resultEffect == DragDropEffects.Move && (allowedEffects & DragDropEffects.Move) == DragDropEffects.Move) {
bool draggedInsideSingleDocument = (dragDescriptor == textArea.Document.UndoStack.LastGroupDescriptor); bool draggedInsideSingleDocument = (dragDescriptor == textArea.Document.UndoStack.LastGroupDescriptor);
if (draggedInsideSingleDocument) if (draggedInsideSingleDocument)
textArea.Document.UndoStack.StartContinuedUndoGroup(null); textArea.Document.UndoStack.StartContinuedUndoGroup(null);

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

@ -667,7 +667,7 @@ namespace ICSharpCode.AvalonEdit
get { get {
TextArea textArea = this.TextArea; TextArea textArea = this.TextArea;
if (textArea != null) if (textArea != null)
return textArea.Selection.Length; return textArea.Selection.SurroundingSegment.Length;
else else
return 0; return 0;
} }

Loading…
Cancel
Save