Browse Source

PythonConsole now uses a read-only text marker for the read-only region and stops the undo action affecting text before the prompt.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3443 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
6997465bff
  1. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs
  2. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs
  3. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs
  4. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs
  5. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs
  6. 32
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TextEditorTestFixture.cs

5
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs

@ -87,5 +87,10 @@ namespace ICSharpCode.PythonBinding @@ -87,5 +87,10 @@ namespace ICSharpCode.PythonBinding
/// Shows the code completion window.
/// </summary>
void ShowCompletionWindow();
/// <summary>
/// Makes the current text content read only. Text can be entered at the end.
/// </summary>
void MakeCurrentContentReadOnly();
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs

@ -97,6 +97,7 @@ namespace ICSharpCode.PythonBinding @@ -97,6 +97,7 @@ namespace ICSharpCode.PythonBinding
if (style == Style.Prompt) {
promptLength = text.Length;
textEditor.MakeCurrentContentReadOnly();
}
}

33
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs

@ -20,11 +20,11 @@ namespace ICSharpCode.PythonBinding @@ -20,11 +20,11 @@ namespace ICSharpCode.PythonBinding
TextEditorControl textEditorControl;
TextArea textArea;
Color customLineColour = Color.LightGray;
TextMarker readOnlyMarker;
public TextEditor(TextEditorControl textEditorControl)
{
this.textEditorControl = textEditorControl;
this.textEditorControl.Document.LineCountChanged += LineCountChanged;
this.textArea = textEditorControl.ActiveTextAreaControl.TextArea;
textEditorControl.TextEditorProperties.SupportReadOnlySegments = true;
}
@ -70,11 +70,6 @@ namespace ICSharpCode.PythonBinding @@ -70,11 +70,6 @@ namespace ICSharpCode.PythonBinding
}
}
void AddCustomLine(int line)
{
//textEditorControl.Document.CustomLineManager.AddCustomLine(line, customLineColour, false);
}
public int Column {
get { return textEditorControl.ActiveTextAreaControl.Caret.Column; }
set { textEditorControl.ActiveTextAreaControl.Caret.Column = value; }
@ -125,6 +120,22 @@ namespace ICSharpCode.PythonBinding @@ -125,6 +120,22 @@ namespace ICSharpCode.PythonBinding
}
}
/// <summary>
/// Makes the current text read only. Text can still be entered at the end.
/// </summary>
public void MakeCurrentContentReadOnly()
{
IDocument doc = textEditorControl.Document;
if (readOnlyMarker == null) {
readOnlyMarker = new TextMarker(0, doc.TextLength, TextMarkerType.Invisible);
readOnlyMarker.IsReadOnly = true;
doc.MarkerStrategy.AddMarker(readOnlyMarker);
}
readOnlyMarker.Offset = 0;
readOnlyMarker.Length = doc.TextLength;
doc.UndoStack.ClearAll();
}
public void ShowCompletionWindow()
{
}
@ -146,15 +157,5 @@ namespace ICSharpCode.PythonBinding @@ -146,15 +157,5 @@ namespace ICSharpCode.PythonBinding
textEditorControl.IndentStyle = style;
}
}
void LineCountChanged(object source, LineCountChangeEventArgs e)
{
IDocument doc = textEditorControl.Document;
int totalLines = doc.TotalNumberOfLines;
//doc.CustomLineManager.Clear();
for (int line = 0; line < totalLines - 1; ++line) {
// doc.CustomLineManager.AddCustomLine(line, customLineColour, false);
}
}
}
}

10
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs

@ -30,6 +30,7 @@ namespace PythonBinding.Tests.Console @@ -30,6 +30,7 @@ namespace PythonBinding.Tests.Console
int totalLines = 1;
List<Color> textColors = new List<Color>();
bool showCompletionWindowCalled;
bool makeReadOnlyCalled;
public MockTextEditor()
{
@ -65,6 +66,10 @@ namespace PythonBinding.Tests.Console @@ -65,6 +66,10 @@ namespace PythonBinding.Tests.Console
get { return showCompletionWindowCalled; }
}
public bool IsMakeCurrentContentReadOnlyCalled {
get { return makeReadOnlyCalled; }
}
public string Text {
get { return previousLines.ToString() + lineBuilder.ToString(); }
set {
@ -192,6 +197,11 @@ namespace PythonBinding.Tests.Console @@ -192,6 +197,11 @@ namespace PythonBinding.Tests.Console
showCompletionWindowCalled = true;
}
public void MakeCurrentContentReadOnly()
{
makeReadOnlyCalled = true;
}
public List<Color> WrittenTextColors {
get { return textColors; }
}

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/PythonConsoleReadOnlyRegionsTestFixture.cs

@ -33,6 +33,12 @@ namespace PythonBinding.Tests.Console @@ -33,6 +33,12 @@ namespace PythonBinding.Tests.Console
console.Write(prompt, Style.Prompt);
}
[Test]
public void MakeCurrentContentReadOnlyIsCalled()
{
Assert.IsTrue(textEditor.IsMakeCurrentContentReadOnlyCalled);
}
[Test]
public void LeftArrowThenInsertNewCharacterInsertsText()
{

32
src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/TextEditorTestFixture.cs

@ -121,15 +121,17 @@ namespace PythonBinding.Tests.Console @@ -121,15 +121,17 @@ namespace PythonBinding.Tests.Console
}
[Test]
[Ignore("Change to use read-only marker.")]
public void AfterEnterKeyPreviousLineIsCustomLine()
public void MakeCurrentTextEditorContent()
{
//textEditorControl.Document.CustomLineManager.Clear();
textEditorControl.Text = String.Empty;
textEditor.Write("abc" + Environment.NewLine);
//Assert.AreEqual(1, textEditorControl.Document.CustomLineManager.CustomLines.Count);
//Assert.AreEqual(textEditor.CustomLineColour, textEditorControl.Document.CustomLineManager.GetCustomColor(0, Color.Empty));
Assert.Fail("Implement...");
textEditor.MakeCurrentContentReadOnly();
TextMarker readOnlyTextMarker = GetReadOnlyTextMarker(textEditorControl);
Assert.IsNotNull(readOnlyTextMarker);
Assert.AreEqual(0, readOnlyTextMarker.Offset);
Assert.AreEqual(textEditorControl.Text.Length, readOnlyTextMarker.Length);
Assert.IsFalse(textEditorControl.Document.UndoStack.CanUndo);
}
[Test]
@ -368,5 +370,23 @@ namespace PythonBinding.Tests.Console @@ -368,5 +370,23 @@ namespace PythonBinding.Tests.Console
keyPressed = ch;
return false;
}
/// <summary>
/// Used to remove all text markers from the text editor.
/// </summary>
bool AllMarkersMatch(TextMarker marker)
{
return true;
}
TextMarker GetReadOnlyTextMarker(TextEditorControl textEditorControl)
{
foreach (TextMarker marker in textEditorControl.Document.MarkerStrategy.TextMarker) {
if (marker.IsReadOnly) {
return marker;
}
}
return null;
}
}
}

Loading…
Cancel
Save