Author: mkrueger
Date: 2008-02-18 18:15:35 -0500 (Mon, 18 Feb 2008)
New Revision: 96108
Removed:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/SelectionMarker.cs
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
Log:
* Mono.TextEditor/DefaultEditActions.cs,
Mono.TextEditor/TextViewMargin.cs, Mono.TextEditor/Document.cs,
Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/IMargin.cs,
Mono.TextEditor/SelectionMarker.cs, Mono.TextEditor/TextEditor.cs,
Mono.TextEditor/GutterMargin.cs: Worked on selection.
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-18
22:56:07 UTC (rev 96107)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-18
23:15:35 UTC (rev 96108)
@@ -1,3 +1,11 @@
+2008-02-19 Mike Krüger <[EMAIL PROTECTED]>
+
+ * Mono.TextEditor/DefaultEditActions.cs,
Mono.TextEditor/TextViewMargin.cs,
+ Mono.TextEditor/Document.cs, Mono.TextEditor/TextEditorData.cs,
+ Mono.TextEditor/IMargin.cs, Mono.TextEditor/SelectionMarker.cs,
+ Mono.TextEditor/TextEditor.cs, Mono.TextEditor/GutterMargin.cs: Worked
+ on selection.
+
2008-02-18 Mike Krüger <[EMAIL PROTECTED]>
* Mono.TextEditor/DefaultEditActions.cs: fixed Bug 322763 - Ctrl +
Backspace
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
2008-02-18 22:56:07 UTC (rev 96107)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/Makefile.am
2008-02-18 23:15:35 UTC (rev 96108)
@@ -47,7 +47,6 @@
Mono.TextEditor/ReplaceEventArgs.cs \
Mono.TextEditor/SearchOptions.cs \
Mono.TextEditor/Segment.cs \
- Mono.TextEditor/SelectionMarker.cs \
Mono.TextEditor/TextEditor.cs \
Mono.TextEditor/TextEditorData.cs \
Mono.TextEditor/TextEditorOptions.cs \
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/DefaultEditActions.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -314,9 +314,9 @@
{
data.Caret.AutoScrollToCaret = false;
data.Caret.PreserveSelection = true;
- data.SelectionStart = new SelectionMarker
(data.Document.GetLine (0), 0);
+ data.SelectionAnchor = 0;
new CaretMoveToDocumentEnd ().Run (data);
- SelectionMoveLeft.EndSelection (data);
+ data.ExtendSelectionTo (data.Document.Length);
data.Caret.AutoScrollToCaret = true;
}
}
@@ -326,14 +326,13 @@
public static void StartSelection (TextEditorData data)
{
data.Caret.PreserveSelection = true;
- if (data.SelectionStart == null) {
- data.SelectionStart = new SelectionMarker
(data.Document.GetLine (data.Caret.Line), data.Caret.Column);
- }
+ if (!data.IsSomethingSelected)
+ data.SelectionAnchor = data.Caret.Offset;
}
public static void EndSelection (TextEditorData data)
{
- data.SelectionEnd = new SelectionMarker
(data.Document.GetLine (data.Caret.Line), data.Caret.Column);
+ data.ExtendSelectionTo (data.Caret.Offset);
data.Caret.PreserveSelection = false;
}
@@ -561,11 +560,15 @@
if (first < 0)
first = last;
}
- if (data.IsSomethingSelected)
- data.SelectionStart.Column = System.Math.Max
(0, data.SelectionStart.Column - first);
- if (!data.IsSomethingSelected
|| data.SelectionEnd.Column != 0) {
- if (data.IsSomethingSelected)
- data.SelectionEnd.Column =
System.Math.Max (0, data.SelectionEnd.Column - last);
+ if (data.IsSomethingSelected) {
+ data.SelectionAnchor = System.Math.Max (0,
data.SelectionAnchor - first);
+ data.SelectionRange = new Segment
(data.SelectionRange.Offset - first, data.SelectionRange.Length + first);
+ }
+ DocumentLocation selectionEnd =
data.IsSomethingSelected ? data.Document.OffsetToLocation
(data.SelectionRange.EndOffset) : DocumentLocation.Empty;
+ if (!data.IsSomethingSelected || selectionEnd.Column !=
0) {
+ if (data.IsSomethingSelected) {
+ data.SelectionRange = new Segment
(data.SelectionRange.Offset, data.SelectionRange.Length -last);
+ }
data.Caret.PreserveSelection = true;
data.Caret.Column = System.Math.Max (0,
data.Caret.Column - last);
data.Caret.PreserveSelection = false;
@@ -577,7 +580,7 @@
public override void Run (TextEditorData data)
{
- if (data.IsSomethingSelected &&
data.SelectionStart.Segment != data.SelectionEnd.Segment) {
+ if (data.IsMultiLineSelection) {
RemoveIndentSelection (data);
return;
} else {
@@ -612,13 +615,15 @@
foreach (LineSegment line in data.SelectedLines) {
data.Document.Insert (line.Offset,
TextEditorOptions.Options.IndentationString);
}
- if (data.IsSomethingSelected)
- data.SelectionStart.Column++;
- if (!data.IsSomethingSelected
|| data.SelectionEnd.Column != 0) {
- if (data.IsSomethingSelected)
- data.SelectionEnd.Column++;
+ if (data.IsSomethingSelected) {
+ data.SelectionAnchor++;
+ }
+ DocumentLocation selectionEnd =
data.IsSomethingSelected ? data.Document.OffsetToLocation
(data.SelectionRange.EndOffset) : DocumentLocation.Empty;
+ if (selectionEnd.Column != 0) {
data.Caret.PreserveSelection = true;
data.Caret.Column++;
+ if (data.IsSomethingSelected)
+ data.ExtendSelectionTo
(data.Caret.Offset);
data.Caret.PreserveSelection = false;
}
data.Document.EndAtomicUndo ();
@@ -628,7 +633,7 @@
public override void Run (TextEditorData data)
{
- if (data.IsSomethingSelected &&
data.SelectionStart.Segment != data.SelectionEnd.Segment) {
+ if (data.IsMultiLineSelection) {
IndentSelection (data);
return;
}
@@ -636,7 +641,6 @@
if (data.IsSomethingSelected) {
data.DeleteSelectedText ();
}
-
data.Document.Insert (data.Caret.Offset,
TextEditorOptions.Options.IndentationString);
data.Caret.Column +=
TextEditorOptions.Options.IndentationString.Length;
data.Document.EndAtomicUndo ();
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -391,7 +391,7 @@
public bool CanUndo {
get {
- return this.undoStack.Count > 0;
+ return this.undoStack.Count > 0 ||
currentAtomicOperation != null;
}
}
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/GutterMargin.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -42,6 +42,7 @@
{
this.editor = editor;
layout = new Pango.Layout (editor.PangoContext);
+ base.cursor = new Gdk.Cursor (Gdk.CursorType.RightPtr);
}
void CalculateWidth ()
@@ -69,22 +70,59 @@
public override void MousePressed (int button, int x, int y,
Gdk.EventType type, Gdk.ModifierType modifierState)
{
- int lineNumber = editor.Document.VisualToLogicalLine
((int)(y + editor.VAdjustment.Value) / editor.LineHeight);
+ int lineNumber =
editor.Document.VisualToLogicalLine ((int)(y + editor.VAdjustment.Value) /
editor.LineHeight);
+ bool extendSelection = (modifierState &
Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask;
if (lineNumber < editor.Document.LineCount) {
DocumentLocation loc = new DocumentLocation
(lineNumber, 0);
- if (loc != editor.Caret.Location) {
- editor.Caret.Location = loc;
- } else if (editor.IsSomethingSelected) {
+ LineSegment line = editor.Document.GetLine
(lineNumber);
+ if (type == EventType.TwoButtonPress) {
+ editor.SelectionRange = line;
+ editor.SelectionAnchor =
editor.Document.LocationToOffset (loc);
+ } else if (extendSelection) {
+ if (!editor.IsSomethingSelected) {
+ editor.SelectionAnchor =
editor.Caret.Offset;
+ }
+ editor.SetSelectLines
(editor.SelectionAnchorLocation.Line, lineNumber);
+ } else {
editor.ClearSelection ();
- editor.QueueDraw ();
- } else {
- LineSegment line =
editor.Document.GetLine (lineNumber);
- editor.SelectionRange = new Segment
(line.Offset, line.EditableLength);
- editor.QueueDraw ();
}
+ editor.Caret.PreserveSelection = true;
+ editor.Caret.Location = loc;
+ editor.Caret.PreserveSelection = false;
+
+
+// if (loc != editor.Caret.Location) {
+//
+// } else if (editor.IsSomethingSelected) {
+// editor.ClearSelection ();
+// editor.QueueDraw ();
+// } else {
+// LineSegment line =
editor.Document.GetLine (lineNumber);
+// editor.SelectionRange = new Segment
(line.Offset, line.EditableLength);
+// editor.QueueDraw ();
+// }
}
}
+ public override void MouseHover (int x, int y, bool
buttonPressed)
+ {
+ if (buttonPressed) {
+ if (!editor.IsSomethingSelected) {
+ editor.SelectionAnchor =
editor.Caret.Offset;
+ }
+ int lineNumber =
editor.Document.VisualToLogicalLine ((int)(y + editor.VAdjustment.Value) /
editor.LineHeight);
+ editor.SetSelectLines
(editor.SelectionAnchorLocation.Line, lineNumber);
+ editor.Caret.PreserveSelection = true;
+ editor.Caret.Location = new DocumentLocation
(lineNumber, 0);
+ editor.Caret.PreserveSelection = false;
+ }
+ }
+
+
+ public override void MouseReleased (int button, int x, int y,
Gdk.ModifierType modifierState)
+ {
+ }
+
public override void Dispose ()
{
if (layout != null) {
@@ -92,6 +130,7 @@
layout = null;
}
DisposeGCs ();
+ base.Dispose ();
}
void DisposeGCs ()
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/IMargin.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -44,11 +44,16 @@
set;
}
+ Gdk.Cursor MarginCursor {
+ get;
+ }
+
void OptionsChanged ();
void Draw (Gdk.Drawable drawable, Gdk.Rectangle area, int line,
int x, int y);
void MousePressed (int button, int x, int y, Gdk.EventType
type, Gdk.ModifierType modifierState);
+ void MouseReleased (int button, int x, int y, Gdk.ModifierType
modifierState);
void MouseHover (int x, int y, bool buttonPressed);
void MouseLeft ();
}
@@ -79,6 +84,13 @@
}
}
+ protected Gdk.Cursor cursor = null;
+ public Gdk.Cursor MarginCursor {
+ get {
+ return cursor;
+ }
+ }
+
public abstract void Draw (Gdk.Drawable drawable, Gdk.Rectangle
area, int line, int x, int y);
public virtual void OptionsChanged ()
@@ -88,6 +100,9 @@
public virtual void MousePressed (int button, int x, int y,
Gdk.EventType type, Gdk.ModifierType modifierState)
{
}
+ public virtual void MouseReleased (int button, int x, int y,
Gdk.ModifierType modifierState)
+ {
+ }
public virtual void MouseHover (int x, int y, bool
buttonPressed)
{
@@ -98,6 +113,10 @@
}
public virtual void Dispose ()
{
+ if (cursor != null) {
+ cursor.Dispose ();
+ cursor = null;
+ }
}
}
Deleted:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/SelectionMarker.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/SelectionMarker.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/SelectionMarker.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -1,61 +0,0 @@
-// SelectionMarker.cs
-//
-// Author:
-// Mike Krüger <[EMAIL PROTECTED]>
-//
-// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to
deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-//
-
-using System;
-
-namespace Mono.TextEditor
-{
- public class SelectionMarker
- {
- LineSegment segment;
- int column;
-
- public int Column {
- get {
- return column;
- }
- set {
- column = value;
- }
- }
-
- public Mono.TextEditor.LineSegment Segment {
- get {
- return segment;
- }
- set {
- segment = value;
- }
- }
-
- public SelectionMarker (LineSegment segment, int column)
- {
- this.segment = segment;
- this.column = column;
- }
- }
-}
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -266,7 +266,7 @@
margins.Add (textViewMargin);
ISegment oldSelection = null;
this.textEditorData.SelectionChanged += delegate {
- if (IsSomethingSelected &&
SelectionRange.Offset > 0)
+ if (IsSomethingSelected &&
SelectionRange.Offset >= 0 && SelectionRange.EndOffset < Document.Length)
new CopyAction ().CopyToPrimary
(this.textEditorData);
// Handle redraw
@@ -300,7 +300,7 @@
to = endLine;
}
}
- oldSelection = selection;
+ oldSelection = selection != null ? new Segment
(selection.Offset, selection.Length) : null;
this.RedrawLines (System.Math.Min (from, to),
System.Math.Max (from, to));
OnSelectionChanged (EventArgs.Empty);
};
@@ -591,6 +591,12 @@
{
if (textViewMargin.inDrag)
Caret.Location = textViewMargin.clickLocation;
+ int startPos;
+ IMargin margin = GetMarginAtX ((int)e.X, out startPos);
+ if (margin != null) {
+ margin.MouseReleased ((int)e.Button, (int)(e.X
- startPos), (int)e.Y, e.State);
+ }
+
mousePressed = false;
textViewMargin.inDrag = false;
textViewMargin.inSelectionDrag = false;
@@ -678,6 +684,8 @@
{
int startPos;
IMargin margin = GetMarginAtX ((int)e.X, out startPos);
+ GdkWindow.Cursor = margin.MarginCursor;
+
if (textViewMargin.inSelectionDrag) {
margin = textViewMargin;
startPos = textViewMargin.XOffset;
@@ -700,6 +708,8 @@
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing e)
{
+ GdkWindow.Cursor = null;
+
if (e.Mode == CrossingMode.Normal) {
if (oldMargin != null)
oldMargin.MouseLeft ();
@@ -775,7 +785,6 @@
}
return base.OnScrollEvent (evnt);
}
-
internal void SetAdjustments (Gdk.Rectangle allocation)
{
@@ -861,6 +870,24 @@
}
}
+ public int SelectionAnchor {
+ get {
+ return this.textEditorData.SelectionAnchor;
+ }
+ set {
+ this.textEditorData.SelectionAnchor = value;
+ }
+ }
+
+ public DocumentLocation SelectionAnchorLocation {
+ get {
+ return Document.OffsetToLocation
(SelectionAnchor);
+ }
+ set {
+ SelectionAnchor = Document.LocationToOffset
(value);
+ }
+ }
+
public ISegment SelectionRange {
get {
return this.textEditorData.SelectionRange;
@@ -911,9 +938,20 @@
{
action.Run (this.textEditorData);
}
+ public void ExtendSelectionTo (DocumentLocation location)
+ {
+ this.textEditorData.ExtendSelectionTo (location);
+ }
+ public void ExtendSelectionTo (int offset)
+ {
+ this.textEditorData.ExtendSelectionTo (offset);
+ }
+ public void SetSelectLines (int from, int to)
+ {
+ this.textEditorData.SetSelectLines (from, to);
+ }
-
/// <summary>
/// Use with care.
/// </summary>
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -31,14 +31,39 @@
{
public class TextEditorData
{
- SelectionMarker selectionStart;
- SelectionMarker selectionEnd;
- Adjustment hadjustment = new Adjustment (0, 0, 0, 0, 0, 0);
- Adjustment vadjustment = new Adjustment (0, 0, 0, 0, 0, 0);
Document document;
Caret caret;
+ Adjustment hadjustment = new Adjustment (0, 0, 0, 0, 0, 0);
+ public Adjustment HAdjustment {
+ get {
+ return hadjustment;
+ }
+ set {
+ hadjustment = value;
+ }
+ }
+
+ Adjustment vadjustment = new Adjustment (0, 0, 0, 0, 0, 0);
+ public Adjustment VAdjustment {
+ get {
+ return vadjustment;
+ }
+ set {
+ vadjustment = value;
+ }
+ }
+
+
string searchPattern = "";
+ public string SearchPattern {
+ get {
+ return searchPattern;
+ }
+ set {
+ searchPattern = value;
+ }
+ }
public TextEditorData ()
{
@@ -75,51 +100,68 @@
}
}
+ #region Selection management
+ int selectionAnchor = -1;
+ ISegment selectionRange = null;
+
public bool IsSomethingSelected {
get {
- return SelectionStart != null && SelectionEnd
!= null;
+ return selectionRange != null;
}
}
+ public bool IsMultiLineSelection {
+ get {
+ return IsSomethingSelected &&
document.OffsetToLineNumber (selectionRange.Offset) !=
document.OffsetToLineNumber (selectionRange.EndOffset);
+ }
+ }
+
public ISegment SelectionRange {
get {
- if (!IsSomethingSelected)
- return null;
- SelectionMarker start;
- SelectionMarker end;
-
- if (SelectionStart.Segment.Offset <
SelectionEnd.Segment.Offset || SelectionStart.Segment.Offset ==
SelectionEnd.Segment.Offset && SelectionStart.Column < SelectionEnd.Column) {
- start = SelectionStart;
- end = SelectionEnd;
- } else {
- start = SelectionEnd;
- end = SelectionStart;
- }
-
- int startOffset = start.Segment.Offset +
start.Column;
- int endOffset = end.Segment.Offset +
end.Column;
- return new Segment (startOffset, endOffset -
startOffset);
+ return selectionRange;
}
set {
- if (value == null) {
- ClearSelection ();
- return;
- }
- int start, end;
- if (value.Offset < value.EndOffset) {
- start = value.Offset;
- end = value.EndOffset;
- } else {
- start = value.EndOffset;
- end = value.Offset;
- }
- LineSegment startLine =
Document.GetLineByOffset (start);
- LineSegment endLine =
Document.GetLineByOffset (end);
- this.Caret.Offset = end;
- selectionStart = new SelectionMarker
(startLine, start - startLine.Offset);
- selectionEnd = new SelectionMarker (endLine,
end - endLine.Offset);
- OnSelectionChanged (EventArgs.Empty);
+ selectionRange = value;
+ OnSelectionChanged (EventArgs.Empty);
}
+// get {
+// if (!IsSomethingSelected)
+// return null;
+// SelectionMarker start;
+// SelectionMarker end;
+//
+// if (SelectionAnchor.Segment.Offset <
SelectionEnd.Segment.Offset || SelectionAnchor.Segment.Offset ==
SelectionEnd.Segment.Offset && SelectionAnchor.Column < SelectionEnd.Column) {
+// start = SelectionAnchor;
+// end = SelectionEnd;
+// } else {
+// start = SelectionEnd;
+// end = SelectionAnchor;
+// }
+//
+// int startOffset = start.Segment.Offset +
start.Column;
+// int endOffset = end.Segment.Offset +
end.Column;
+// return new Segment (startOffset, endOffset -
startOffset);
+// }
+// set {
+// if (value == null) {
+// ClearSelection ();
+// return;
+// }
+// int start, end;
+// if (value.Offset < value.EndOffset) {
+// start = value.Offset;
+// end = value.EndOffset;
+// } else {
+// start = value.EndOffset;
+// end = value.Offset;
+// }
+// LineSegment startLine =
Document.GetLineByOffset (start);
+// LineSegment endLine =
Document.GetLineByOffset (end);
+// this.Caret.Offset = end;
+// selectionStart = new SelectionMarker
(startLine, start - startLine.Offset);
+// selectionEnd = new SelectionMarker (endLine,
end - endLine.Offset);
+// OnSelectionChanged (EventArgs.Empty);
+// }
}
public string SelectedText {
@@ -158,66 +200,62 @@
}
}
- public Adjustment HAdjustment {
+ public int SelectionAnchor {
get {
- return hadjustment;
+ return selectionAnchor;
}
set {
- hadjustment = value;
+ selectionAnchor = value;
}
}
- public Adjustment VAdjustment {
- get {
- return vadjustment;
- }
- set {
- vadjustment = value;
- }
+ public void ClearSelection ()
+ {
+ this.selectionAnchor = -1;
+ this.selectionRange = null;
+ OnSelectionChanged (EventArgs.Empty);
}
- public SelectionMarker SelectionStart {
- get {
- return selectionStart;
- }
- set {
- selectionStart = value;
- OnSelectionChanged (EventArgs.Empty);
- }
+ public void ExtendSelectionTo (DocumentLocation location)
+ {
+ ExtendSelectionTo (document.LocationToOffset
(location));
}
- public SelectionMarker SelectionEnd {
- get {
- return selectionEnd;
+ public void ExtendSelectionTo (int offset)
+ {
+ if (selectionAnchor < 0)
+ selectionAnchor = offset;
+ int from, to;
+ if (offset < selectionAnchor) {
+ from = offset;
+ to = selectionAnchor;
+ } else {
+ to = offset;
+ from = selectionAnchor;
}
- set {
- selectionEnd = value;
- OnSelectionChanged (EventArgs.Empty);
- }
+ this.SelectionRange = new Segment (from, to - from);
}
- public string SearchPattern {
- get {
- return searchPattern;
+ public void SetSelectLines (int from, int to)
+ {
+ if (to < from) {
+ int tmp = from;
+ from = to;
+ to = tmp;
}
- set {
- searchPattern = value;
- }
+ LineSegment fromLine =Document.GetLine (from);
+ LineSegment toLine = Document.GetLine (to);
+ SelectionRange = new Segment (fromLine.Offset,
toLine.EndOffset - fromLine.Offset);
}
+
- public void ClearSelection ()
- {
- this.selectionStart = this.selectionEnd = null;
- OnSelectionChanged (EventArgs.Empty);
- }
-
public void DeleteSelectedText ()
{
if (!IsSomethingSelected)
return;
document.BeginAtomicUndo ();
ISegment selection = SelectionRange;
- bool needUpdate = this.selectionStart.Segment !=
this.selectionEnd.Segment;
+ bool needUpdate = Document.OffsetToLineNumber
(selection.Offset) != Document.OffsetToLineNumber (selection.EndOffset);
if (Caret.Offset > selection.Offset)
Caret.Offset -= selection.Length;
@@ -229,7 +267,7 @@
if (needUpdate)
Document.CommitDocumentUpdate ();
}
-
+#endregion
public event EventHandler SelectionChanged;
protected virtual void OnSelectionChanged (EventArgs args)
{
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
2008-02-18 22:56:07 UTC (rev 96107)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextViewMargin.cs
2008-02-18 23:15:35 UTC (rev 96108)
@@ -49,9 +49,6 @@
uint caretBlinkTimeoutId = 0;
const int CaretBlinkTime = 800;
- Gdk.Cursor defaultCursor;
- Gdk.Cursor textCursor;
-
int lineHeight = 16;
int highlightBracketOffset = -1;
@@ -152,9 +149,7 @@
textEditor.RedrawLine (line2);
}
};
-
- defaultCursor = null;
- textCursor = new Gdk.Cursor (Gdk.CursorType.Xterm);
+ base.cursor = new Gdk.Cursor (Gdk.CursorType.Xterm);
}
public override void OptionsChanged ()
@@ -205,6 +200,7 @@
invalidLineMarker.Dispose ();
invalidLineMarker = null;
}
+ base.Dispose ();
}
public void ResetCaretBlink ()
@@ -477,6 +473,12 @@
public DocumentLocation clickLocation;
DocumentLocation selectionStartLocation;
ISegment minimalSelection = null;
+ enum MouseSelectionMode {
+ SingleChar,
+ Word,
+ WholeLine
+ };
+ MouseSelectionMode mouseSelectionMode =
MouseSelectionMode.SingleChar;
public override void MousePressed (int button, int x, int y,
Gdk.EventType type, Gdk.ModifierType modifierState)
{
@@ -484,25 +486,31 @@
inDrag = false;
if (button == 1 || button == 2) {
clickLocation = VisualToDocumentLocation (x, y);
+ if (!textEditor.IsSomethingSelected) {
+ textEditor.SelectionAnchorLocation =
clickLocation;
+ }
+
int offset = Document.LocationToOffset
(clickLocation);
if (offset < 0) {
textEditor.RunAction (new
CaretMoveToDocumentEnd ());
return;
}
-
if (type == EventType.TwoButtonPress) {
int start = ScanWord (offset, false);
int end = ScanWord (offset, true);
textEditor.SelectionRange =
minimalSelection = new Segment (start, end - start);
selectionStartLocation =
Document.OffsetToLocation (start);
inSelectionDrag = true;
+ mouseSelectionMode =
MouseSelectionMode.Word;
return;
} else if (type == EventType.ThreeButtonPress) {
textEditor.SelectionRange =
minimalSelection = Document.GetLineByOffset (offset);
selectionStartLocation =
Document.OffsetToLocation (minimalSelection.Offset);
inSelectionDrag = true;
+ mouseSelectionMode =
MouseSelectionMode.WholeLine;
return;
}
+ mouseSelectionMode =
MouseSelectionMode.SingleChar;
selectionStartLocation = clickLocation;
minimalSelection = null;
@@ -510,15 +518,13 @@
inDrag = true;
} else {
inSelectionDrag = true;
- textEditor.ClearSelection ();
if ((modifierState &
Gdk.ModifierType.ShiftMask) == ModifierType.ShiftMask) {
- if
(!textEditor.IsSomethingSelected)
-
SelectionMoveLeft.StartSelection (textEditor.GetTextEditorData ());
Caret.PreserveSelection = true;
Caret.Location = clickLocation;
Caret.PreserveSelection = false;
- SelectionMoveLeft.EndSelection
(textEditor.GetTextEditorData ());
+ textEditor.ExtendSelectionTo
(clickLocation);
} else {
+ textEditor.ClearSelection ();
Caret.Location = clickLocation;
}
this.caretBlink = false;
@@ -531,37 +537,49 @@
int ScanWord (int offset, bool forwardDirection)
{
LineSegment line = Document.GetLineByOffset (offset);
- while (offset >= line.Offset && offset < line.Offset +
line.EditableLength && char.IsWhiteSpace (Document.GetCharAt (offset))) {
+ while (offset >= line.Offset && offset < line.Offset +
line.EditableLength && !char.IsLetterOrDigit (Document.GetCharAt (offset))) {
offset = forwardDirection ? offset + 1 : offset
- 1;
}
while (offset >= line.Offset && offset < line.Offset +
line.EditableLength && (char.IsLetterOrDigit (Document.GetCharAt (offset))
|| Document.GetCharAt (offset) == '_')) {
offset = forwardDirection ? offset + 1 : offset
- 1;
}
- return offset + (forwardDirection ? 0 : 1);
+ return System.Math.Min (line.EndOffset - 1,
System.Math.Max (line.Offset, offset + (forwardDirection ? 0 : 1)));
}
public override void MouseHover (int x, int y, bool
buttonPressed)
{
- textEditor.GdkWindow.Cursor = textCursor;
if (!buttonPressed)
return;
if (inSelectionDrag) {
DocumentLocation loc = VisualToDocumentLocation
(x, y);
- int offset1 = Document.LocationToOffset
(this.selectionStartLocation);
- int offset2 = Document.LocationToOffset (loc);
- ISegment requestedSelection = offset1 < offset2
? new Segment (offset1, offset2 - offset1) : new Segment (offset2, offset1 -
offset2);
- if (this.minimalSelection != null) {
- if (requestedSelection.EndOffset <
minimalSelection.EndOffset) {
- requestedSelection = new
Segment (requestedSelection.Offset, minimalSelection.EndOffset -
requestedSelection.Offset);
+ Caret.PreserveSelection = true;
+ switch (this.mouseSelectionMode) {
+ case MouseSelectionMode.SingleChar:
+ textEditor.ExtendSelectionTo (loc);
+ Caret.Location = loc;
+ break;
+ case MouseSelectionMode.Word:
+ int offset =
textEditor.Document.LocationToOffset (loc);
+ int start;
+ int end;
+ if (offset <
textEditor.SelectionAnchor) {
+ start = ScanWord (offset,
false);
+ end = ScanWord
(textEditor.SelectionAnchor, true);
+ Caret.Offset = start;
+ } else {
+ start = ScanWord
(textEditor.SelectionAnchor, false);
+ end = ScanWord (offset, true);
+ Caret.Offset = end;
}
-
- if (requestedSelection.Offset >
minimalSelection.Offset) {
- requestedSelection = new
Segment (minimalSelection.Offset, requestedSelection.EndOffset -
minimalSelection.Offset);
- }
+ textEditor.SelectionRange = new Segment
(start, end - start);
+ break;
+ case MouseSelectionMode.WholeLine:
+ textEditor.SetSelectLines (loc.Line,
textEditor.SelectionAnchorLocation.Line);
+ LineSegment line1 =
textEditor.Document.GetLine (loc.Line);
+ LineSegment line2 =
textEditor.Document.GetLineByOffset (textEditor.SelectionAnchor);
+ Caret.Offset = line1.Offset <
line2.Offset ? line1.Offset : line1.EndOffset;
+ break;
}
- Caret.PreserveSelection = true;
- textEditor.SelectionRange = requestedSelection;
- Caret.Location = loc;
Caret.PreserveSelection = false;
// textEditor.RedrawLines (System.Math.Min
(oldLine, Caret.Line), System.Math.Max (oldLine, Caret.Line));
}
@@ -745,7 +763,6 @@
public override void MouseLeft ()
{
- textEditor.GdkWindow.Cursor = defaultCursor;
}
public DocumentLocation VisualToDocumentLocation (int x, int y)
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp
2008-02-18 22:56:07 UTC (rev 96107)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor.mdp
2008-02-18 23:15:35 UTC (rev 96108)
@@ -38,7 +38,6 @@
<File name="Mono.TextEditor/FoldMarkerMargin.cs" subtype="Code"
buildaction="Compile" />
<File name="Mono.TextEditor/IMargin.cs" subtype="Code"
buildaction="Compile" />
<File name="Mono.TextEditor.Highlighting/Chunk.cs" subtype="Code"
buildaction="Compile" />
- <File name="Mono.TextEditor/SelectionMarker.cs" subtype="Code"
buildaction="Compile" />
<File name="Mono.TextEditor/ISegment.cs" subtype="Code"
buildaction="Compile" />
<File name="Mono.TextEditor/TextEditorOptions.cs" subtype="Code"
buildaction="Compile" />
<File name="C64Style.xml" subtype="Code" buildaction="EmbedAsResource" />
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
2008-02-18 22:56:07 UTC (rev 96107)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/gtk-gui/objects.xml
2008-02-18 23:15:35 UTC (rev 96108)
@@ -5,6 +5,7 @@
<property name="SearchPattern" />
<property name="HighlightSearchPattern" />
<property name="SelectedText" />
+ <property name="SelectionAnchor" />
</itemgroup>
</itemgroups>
<signals>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches