|
|
|
@ -17,10 +17,10 @@ namespace ICSharpCode.TextEditor.Document
@@ -17,10 +17,10 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SelectionManager : IDisposable |
|
|
|
|
{ |
|
|
|
|
public Point selectionStart; |
|
|
|
|
internal Point selectionStart; |
|
|
|
|
IDocument document; |
|
|
|
|
TextArea textArea; |
|
|
|
|
public SelectFrom selectFrom = new SelectFrom(); |
|
|
|
|
TextArea textArea; |
|
|
|
|
internal SelectFrom selectFrom = new SelectFrom(); |
|
|
|
|
|
|
|
|
|
List<ISelection> selectionCollection = new List<ISelection>(); |
|
|
|
|
|
|
|
|
@ -42,6 +42,20 @@ namespace ICSharpCode.TextEditor.Document
@@ -42,6 +42,20 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool SelectionIsReadonly { |
|
|
|
|
get { |
|
|
|
|
if (document.ReadOnly) |
|
|
|
|
return true; |
|
|
|
|
if (document.TextEditorProperties.UseCustomLine) { |
|
|
|
|
foreach (ISelection sel in selectionCollection) { |
|
|
|
|
if (document.CustomLineManager.IsReadOnly(sel, false)) |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <value>
|
|
|
|
|
/// The text that is currently selected.
|
|
|
|
|
/// </value>
|
|
|
|
@ -74,17 +88,17 @@ namespace ICSharpCode.TextEditor.Document
@@ -74,17 +88,17 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of <see cref="SelectionManager"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SelectionManager(IDocument document, TextArea textArea) |
|
|
|
|
{ |
|
|
|
|
this.document = document; |
|
|
|
|
this.textArea = textArea; |
|
|
|
|
document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of <see cref="SelectionManager"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SelectionManager(IDocument document, TextArea textArea) |
|
|
|
|
{ |
|
|
|
|
this.document = document; |
|
|
|
|
this.textArea = textArea; |
|
|
|
|
document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
if (this.document != null) { |
|
|
|
|
document.DocumentChanged -= new DocumentEventHandler(DocumentChanged); |
|
|
|
@ -167,14 +181,14 @@ namespace ICSharpCode.TextEditor.Document
@@ -167,14 +181,14 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (selection.StartPosition != newPosition) { |
|
|
|
|
// we're back to the line we started from and it was a gutter selection
|
|
|
|
|
if (selectFrom.where == WhereFrom.Gutter && newPosition.Y >= selectionStart.Y) |
|
|
|
|
{ |
|
|
|
|
selection.StartPosition = selectionStart; |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
// we're back to the line we started from and it was a gutter selection
|
|
|
|
|
if (selectFrom.where == WhereFrom.Gutter && newPosition.Y >= selectionStart.Y) |
|
|
|
|
{ |
|
|
|
|
selection.StartPosition = selectionStart; |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
changed = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -199,30 +213,30 @@ namespace ICSharpCode.TextEditor.Document
@@ -199,30 +213,30 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
selection.StartPosition != newPosition) { |
|
|
|
|
changed = true; |
|
|
|
|
} |
|
|
|
|
if (selectFrom.where == WhereFrom.Gutter) |
|
|
|
|
{ |
|
|
|
|
if (selectFrom.first == WhereFrom.Gutter) |
|
|
|
|
{ |
|
|
|
|
if(newPosition.Y == selectionStart.Y) { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = new Point(0, newPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if(newPosition.Y == selectionStart.Y) { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = new Point(selectionStart.X, newPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = new Point(selectionStart.X, selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = selection.StartPosition; |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
if (selectFrom.where == WhereFrom.Gutter) |
|
|
|
|
{ |
|
|
|
|
if (selectFrom.first == WhereFrom.Gutter) |
|
|
|
|
{ |
|
|
|
|
if(newPosition.Y == selectionStart.Y) { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = new Point(0, newPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if(newPosition.Y == selectionStart.Y) { |
|
|
|
|
selection.EndPosition = NextValidPosition(selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = new Point(selectionStart.X, newPosition.Y); |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = new Point(selectionStart.X, selection.StartPosition.Y); |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
selection.EndPosition = selection.StartPosition; |
|
|
|
|
selection.StartPosition = newPosition; |
|
|
|
|
} |
|
|
|
|
changed = true; |
|
|
|
|
} else { |
|
|
|
|
if (selection.EndPosition != newPosition) { |
|
|
|
@ -253,19 +267,19 @@ namespace ICSharpCode.TextEditor.Document
@@ -253,19 +267,19 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// retrieve the next available line
|
|
|
|
|
// - checks that there are more lines available after the current one
|
|
|
|
|
// - if there are then the next line is returned
|
|
|
|
|
// - if there are NOT then the last position on the given line is returned
|
|
|
|
|
public Point NextValidPosition(int line) |
|
|
|
|
{ |
|
|
|
|
if (line < document.TotalNumberOfLines - 1) |
|
|
|
|
return new Point(0, line + 1); |
|
|
|
|
else |
|
|
|
|
return new Point(document.GetLineSegment(document.TotalNumberOfLines - 1).Length + 1, line); |
|
|
|
|
} |
|
|
|
|
// retrieve the next available line
|
|
|
|
|
// - checks that there are more lines available after the current one
|
|
|
|
|
// - if there are then the next line is returned
|
|
|
|
|
// - if there are NOT then the last position on the given line is returned
|
|
|
|
|
public Point NextValidPosition(int line) |
|
|
|
|
{ |
|
|
|
|
if (line < document.TotalNumberOfLines - 1) |
|
|
|
|
return new Point(0, line + 1); |
|
|
|
|
else |
|
|
|
|
return new Point(document.GetLineSegment(document.TotalNumberOfLines - 1).Length + 1, line); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ClearWithoutUpdate() |
|
|
|
|
void ClearWithoutUpdate() |
|
|
|
|
{ |
|
|
|
|
while (selectionCollection.Count > 0) { |
|
|
|
|
ISelection selection = selectionCollection[selectionCollection.Count - 1]; |
|
|
|
@ -279,16 +293,16 @@ namespace ICSharpCode.TextEditor.Document
@@ -279,16 +293,16 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void ClearSelection() |
|
|
|
|
{ |
|
|
|
|
Point mousepos; |
|
|
|
|
mousepos = textArea.mousepos; |
|
|
|
|
// this is the most logical place to reset selection starting
|
|
|
|
|
// positions because it is always called before a new selection
|
|
|
|
|
selectFrom.first = selectFrom.where; |
|
|
|
|
selectionStart = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); |
|
|
|
|
if(selectFrom.where == WhereFrom.Gutter) |
|
|
|
|
selectionStart.X = 0; |
|
|
|
|
Point mousepos; |
|
|
|
|
mousepos = textArea.mousepos; |
|
|
|
|
// this is the most logical place to reset selection starting
|
|
|
|
|
// positions because it is always called before a new selection
|
|
|
|
|
selectFrom.first = selectFrom.where; |
|
|
|
|
selectionStart = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); |
|
|
|
|
if(selectFrom.where == WhereFrom.Gutter) |
|
|
|
|
selectionStart.X = 0; |
|
|
|
|
|
|
|
|
|
ClearWithoutUpdate(); |
|
|
|
|
ClearWithoutUpdate(); |
|
|
|
|
document.CommitUpdate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -371,7 +385,7 @@ namespace ICSharpCode.TextEditor.Document
@@ -371,7 +385,7 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Used internally, do not call.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void Insert(int offset, string text) |
|
|
|
|
internal void Insert(int offset, string text) |
|
|
|
|
{ |
|
|
|
|
// foreach (ISelection selection in SelectionCollection) {
|
|
|
|
|
// if (selection.Offset > offset) {
|
|
|
|
@ -385,7 +399,7 @@ namespace ICSharpCode.TextEditor.Document
@@ -385,7 +399,7 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Used internally, do not call.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void Remove(int offset, int length) |
|
|
|
|
internal void Remove(int offset, int length) |
|
|
|
|
{ |
|
|
|
|
// foreach (ISelection selection in selectionCollection) {
|
|
|
|
|
// if (selection.Offset > offset) {
|
|
|
|
@ -399,7 +413,7 @@ namespace ICSharpCode.TextEditor.Document
@@ -399,7 +413,7 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Used internally, do not call.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void Replace(int offset, int length, string text) |
|
|
|
|
internal void Replace(int offset, int length, string text) |
|
|
|
|
{ |
|
|
|
|
// foreach (ISelection selection in selectionCollection) {
|
|
|
|
|
// if (selection.Offset > offset) {
|
|
|
|
@ -449,20 +463,20 @@ namespace ICSharpCode.TextEditor.Document
@@ -449,20 +463,20 @@ namespace ICSharpCode.TextEditor.Document
|
|
|
|
|
public event EventHandler SelectionChanged; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// selection initiated from...
|
|
|
|
|
public class SelectFrom { |
|
|
|
|
public int where = WhereFrom.None; // last selection initiator
|
|
|
|
|
public int first = WhereFrom.None; // first selection initiator
|
|
|
|
|
// selection initiated from...
|
|
|
|
|
internal class SelectFrom { |
|
|
|
|
public int where = WhereFrom.None; // last selection initiator
|
|
|
|
|
public int first = WhereFrom.None; // first selection initiator
|
|
|
|
|
|
|
|
|
|
public SelectFrom() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public SelectFrom() |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// selection initiated from type...
|
|
|
|
|
public class WhereFrom { |
|
|
|
|
public const int None = 0; |
|
|
|
|
public const int Gutter = 1; |
|
|
|
|
public const int TArea = 2; |
|
|
|
|
} |
|
|
|
|
// selection initiated from type...
|
|
|
|
|
internal class WhereFrom { |
|
|
|
|
public const int None = 0; |
|
|
|
|
public const int Gutter = 1; |
|
|
|
|
public const int TArea = 2; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|