Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for sending selected text to Python and Ruby consoles.

  • Loading branch information...
commit a528487a500a6e411e5f8126717abad607717f97 1 parent 19c6754
@mrward mrward authored
Showing with 503 additions and 78 deletions.
  1. +12 −0 data/resources/StringResources.de.resx
  2. +3 −0  data/resources/StringResources.fr.resx
  3. +9 −0 data/resources/StringResources.nl.resx
  4. +9 −0 data/resources/StringResources.resx
  5. +10 −0 src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
  6. +1 −0  src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  7. +16 −0 src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendSelectedTextToPythonConsoleCommand.cs
  8. +10 −0 src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin
  9. +1 −0  src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj
  10. +16 −0 src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendSelectedTextToRubyConsoleCommand.cs
  11. +2 −0  src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  12. +2 −1  src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs
  13. +61 −12 src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  14. +5 −36 src/AddIns/BackendBindings/Scripting/Project/Src/SendLineToScriptingConsoleCommand.cs
  15. +38 −0 src/AddIns/BackendBindings/Scripting/Project/Src/SendSelectedTextToScriptingConsoleCommand.cs
  16. +42 −0 src/AddIns/BackendBindings/Scripting/Project/Src/SendToScriptingConsoleCommand.cs
  17. +0 −5 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
  18. +144 −0 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs
  19. +5 −0 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs
  20. +3 −10 src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs
  21. +51 −0 src/AddIns/BackendBindings/Scripting/Test/Console/SendSelectedTextToScriptingConsoleCommandTests.cs
  22. +28 −0 src/AddIns/BackendBindings/Scripting/Test/Console/SendToScriptingConsoleCommandTestsBase.cs
  23. +3 −0  src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  24. +6 −0 src/AddIns/BackendBindings/Scripting/Test/Utils/MockScriptingConsole.cs
  25. +2 −13 src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs
  26. +1 −1  src/Main/Base/Project/ICSharpCode.SharpDevelop.addin
  27. +1 −0  src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  28. +22 −0 src/Main/Base/Project/Src/Editor/AvalonEdit/TextSelectedCondition.cs
View
12 data/resources/StringResources.de.resx
@@ -232,6 +232,9 @@ Laden Sie ein AddIn aus dem Internet herunter, klicken Sie auf "AddIn installier
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Klassendiagramm anzeigen</value>
</data>
+ <data name="AddIns.Git.TortoiseGitRequired" xml:space="preserve">
+ <value>TortoiseGit muss installiert sein, um diese Aktion auszuführen.</value>
+ </data>
<data name="AddIns.HelpViewer.ContentsPadTitle" xml:space="preserve">
<value>Inhalt</value>
</data>
@@ -696,6 +699,9 @@ Optional können Sie auch ein Arbeitsverzeichnis und Kommandozeilen-Argumente an
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOperatorOverloads" xml:space="preserve">
<value>Operatoren überladen</value>
</data>
+ <data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod" xml:space="preserve">
+ <value>${otherMethod}-Override hinzufügen</value>
+ </data>
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.SurroundWithRegion" xml:space="preserve">
<value>Mit #region umschließen</value>
</data>
@@ -4033,9 +4039,15 @@ Bitte stellen Sie den Pfad zur NAnt-Anwendung in den SharpDevelop-Optionen ein.<
<data name="ICSharpCode.PythonBinding.PythonProjectFiles" xml:space="preserve">
<value>Python-Projektdateien</value>
</data>
+ <data name="ICSharpCode.PythonBinding.SendLineToPythonConsole" xml:space="preserve">
+ <value>Zeile an Python Konsole senden</value>
+ </data>
<data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve">
<value>Konnte Typ '{0}' nicht finden. Fehlt eine Assembly-Referenz?</value>
</data>
+ <data name="ICSharpCode.RubyBinding.SendLineToRubyConsole" xml:space="preserve">
+ <value>Zeile an Ruby Konsole senden</value>
+ </data>
<data name="ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText" xml:space="preserve">
<value>Konnte Datei ${FileNameWithoutPath} im Verzeichns ${Path} nicht laden.
Überprüfen Sie ob die Datei existiert und das Sie Leserecht für dir Datei besitzen.</value>
View
3  data/resources/StringResources.fr.resx
@@ -698,6 +698,9 @@ En option, vous pouvez spécifer un répertoire de travail et des arguments en l
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOperatorOverloads" xml:space="preserve">
<value>Ajouter des surcharges d'opérateur</value>
</data>
+ <data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod" xml:space="preserve">
+ <value>Surcharger ${otherMethod}</value>
+ </data>
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.SurroundWithRegion" xml:space="preserve">
<value>Entourer par #region</value>
</data>
View
9 data/resources/StringResources.nl.resx
@@ -699,6 +699,9 @@ De geselecteerde code bevat een break commando zonder de insluitende lus. Wijzig
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOperatorOverloads" xml:space="preserve">
<value>Voeg operator overladingen toe</value>
</data>
+ <data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod" xml:space="preserve">
+ <value>Voeg overschreven $(otherMethod} toe</value>
+ </data>
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.SurroundWithRegion" xml:space="preserve">
<value>Insluiten met #region</value>
</data>
@@ -4038,12 +4041,18 @@ Configureer a.u.b. in SharpDevelop opties de locatie van NAnt's uitvoerend besta
<data name="ICSharpCode.PythonBinding.SendLineToPythonConsole" xml:space="preserve">
<value>Stuur regel naar Python console</value>
</data>
+ <data name="ICSharpCode.PythonBinding.SendSelectedTextToPythonConsole" xml:space="preserve">
+ <value>Naar Python Console leiden</value>
+ </data>
<data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve">
<value>Kan type {0} niet vinden. Ontbreekt er een assembly referentie?</value>
</data>
<data name="ICSharpCode.RubyBinding.SendLineToRubyConsole" xml:space="preserve">
<value>Stuur regel naar Ruby console</value>
</data>
+ <data name="ICSharpCode.RubyBinding.SendSelectedTextToRubyConsole" xml:space="preserve">
+ <value>Naar Ruby Console leiden</value>
+ </data>
<data name="ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText" xml:space="preserve">
<value>Kan het bestand ${FileNameWithoutPath} in de map ${Path} niet laden. Controleer de beveiliging en het bestaan van het bestand.</value>
</data>
View
9 data/resources/StringResources.resx
@@ -701,6 +701,9 @@ Optionally you can specify a working directory and command line arguments.
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOperatorOverloads" xml:space="preserve">
<value>Add operator overloads</value>
</data>
+ <data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod" xml:space="preserve">
+ <value>Add ${otherMethod} override</value>
+ </data>
<data name="AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.SurroundWithRegion" xml:space="preserve">
<value>Surround with #region</value>
</data>
@@ -4044,12 +4047,18 @@ Please configure the NAnt executable's location in the SharpDevelop Options.</va
<data name="ICSharpCode.PythonBinding.SendLineToPythonConsole" xml:space="preserve">
<value>Send Line to Python Console</value>
</data>
+ <data name="ICSharpCode.PythonBinding.SendSelectedTextToPythonConsole" xml:space="preserve">
+ <value>Send to Python Console</value>
+ </data>
<data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve">
<value>Could not find type '{0}'. Are you missing an assembly reference?</value>
</data>
<data name="ICSharpCode.RubyBinding.SendLineToRubyConsole" xml:space="preserve">
<value>Send Line to Ruby Console</value>
</data>
+ <data name="ICSharpCode.RubyBinding.SendSelectedTextToRubyConsole" xml:space="preserve">
+ <value>Send to Ruby Console</value>
+ </data>
<data name="ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText" xml:space="preserve">
<value>Can't load file ${FileNameWithoutPath} under ${Path}.
Check the file permission and the existence of that file.</value>
View
10 src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
@@ -83,6 +83,11 @@
<MenuItem id="SendLineToPythonConsole"
class="ICSharpCode.PythonBinding.SendLineToPythonConsoleCommand"
label="${res:ICSharpCode.PythonBinding.SendLineToPythonConsole}"/>
+ <Condition name="IsTextSelected" action="Disable">
+ <MenuItem id="SendSelectedTextToPythonConsole"
+ class="ICSharpCode.PythonBinding.SendSelectedTextToPythonConsoleCommand"
+ label="${res:ICSharpCode.PythonBinding.SendSelectedTextToPythonConsole}"/>
+ </Condition>
</MenuItem>
</Condition>
</Path>
@@ -211,6 +216,11 @@
<MenuItem id="SendLineToPythonConsole"
class="ICSharpCode.PythonBinding.SendLineToPythonConsoleCommand"
label="${res:ICSharpCode.PythonBinding.SendLineToPythonConsole}"/>
+ <Condition name="IsTextSelected" action="Disable">
+ <MenuItem id="SendSelectedTextToPythonConsole"
+ class="ICSharpCode.PythonBinding.SendSelectedTextToPythonConsoleCommand"
+ label="${res:ICSharpCode.PythonBinding.SendSelectedTextToPythonConsole}"/>
+ </Condition>
</Condition>
</Path>
</AddIn>
View
1  src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
@@ -119,6 +119,7 @@
<Compile Include="Src\PythonTestRunnerResponseFile.cs" />
<Compile Include="Src\PythonWorkbench.cs" />
<Compile Include="Src\SendLineToPythonConsoleCommand.cs" />
+ <Compile Include="Src\SendSelectedTextToPythonConsoleCommand.cs" />
<Compile Include="Src\SysModuleCompletionItems.cs" />
<Compile Include="Src\NRefactoryToPythonConverter.cs" />
<Compile Include="Src\PythonAstWalker.cs" />
View
16 src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendSelectedTextToPythonConsoleCommand.cs
@@ -0,0 +1,16 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Scripting;
+
+namespace ICSharpCode.PythonBinding
+{
+ public class SendSelectedTextToPythonConsoleCommand : SendSelectedTextToScriptingConsoleCommand
+ {
+ public SendSelectedTextToPythonConsoleCommand()
+ : base(new PythonWorkbench())
+ {
+ }
+ }
+}
View
10 src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin
@@ -77,6 +77,11 @@
<MenuItem id="SendLineToRubyConsole"
class="ICSharpCode.RubyBinding.SendLineToRubyConsoleCommand"
label="${res:ICSharpCode.RubyBinding.SendLineToRubyConsole}"/>
+ <Condition name="IsTextSelected" action="Disable">
+ <MenuItem id="SendSelectedTextToRubyConsole"
+ class="ICSharpCode.RubyBinding.SendSelectedTextToRubyConsoleCommand"
+ label="${res:ICSharpCode.RubyBinding.SendSelectedTextToRubyConsole}"/>
+ </Condition>
</MenuItem>
</Condition>
</Path>
@@ -198,6 +203,11 @@
<MenuItem id="SendLineToRubyConsole"
class="ICSharpCode.RubyBinding.SendLineToRubyConsoleCommand"
label="${res:ICSharpCode.RubyBinding.SendLineToRubyConsole}"/>
+ <Condition name="IsTextSelected" action="Disable">
+ <MenuItem id="SendSelectedTextToRubyConsole"
+ class="ICSharpCode.RubyBinding.SendSelectedTextToRubyConsoleCommand"
+ label="${res:ICSharpCode.RubyBinding.SendSelectedTextToRubyConsole}"/>
+ </Condition>
</Condition>
</Path>
</AddIn>
View
1  src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj
@@ -126,6 +126,7 @@
<Compile Include="Src\RunDebugRubyCommand.cs" />
<Compile Include="Src\RunRubyCommand.cs" />
<Compile Include="Src\SendLineToRubyConsoleCommand.cs" />
+ <Compile Include="Src\SendSelectedTextToRubyConsoleCommand.cs" />
<EmbeddedResource Include="Resources\Ruby.xshd" />
<EmbeddedResource Include="Resources\RubyOptionsPanel.xfrm" />
<None Include="..\..\IronRuby\bin\Chiron.exe.config">
View
16 src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendSelectedTextToRubyConsoleCommand.cs
@@ -0,0 +1,16 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Scripting;
+
+namespace ICSharpCode.RubyBinding
+{
+ public class SendSelectedTextToRubyConsoleCommand : SendSelectedTextToScriptingConsoleCommand
+ {
+ public SendSelectedTextToRubyConsoleCommand()
+ : base(new RubyWorkbench())
+ {
+ }
+ }
+}
View
2  src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
@@ -93,6 +93,8 @@
<Compile Include="Src\ScriptingTextEditorViewContent.cs" />
<Compile Include="Src\ScriptingWorkbench.cs" />
<Compile Include="Src\SendLineToScriptingConsoleCommand.cs" />
+ <Compile Include="Src\SendSelectedTextToScriptingConsoleCommand.cs" />
+ <Compile Include="Src\SendToScriptingConsoleCommand.cs" />
<Compile Include="Src\StringListLock.cs" />
<Compile Include="Src\ThreadSafeScriptingConsoleTextEditor.cs" />
</ItemGroup>
View
3  src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs
@@ -7,6 +7,7 @@ namespace ICSharpCode.Scripting
{
public interface IScriptingConsole
{
- void SendLine(string text);
+ void SendLine(string line);
+ void SendText(string text);
}
}
View
73 src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
@@ -19,7 +19,7 @@ public class ScriptingConsole : IDisposable, IMemberProvider, IScriptingConsole
WaitHandle[] waitHandles;
int promptLength;
bool firstPromptDisplayed;
- string savedSendLineText;
+ List<string> savedTextLines = new List<string>();
CommandLineHistory commandLineHistory = new CommandLineHistory();
protected List<string> unreadLines = new List<string>();
@@ -67,18 +67,19 @@ public void Write(string text, ScriptingStyle style)
{
textEditor.Write(text);
if (style == ScriptingStyle.Prompt) {
- WriteSavedLineTextAfterFirstPrompt(text);
+ WriteSavedTextAfterFirstPrompt();
promptLength = text.Length;
textEditor.MakeCurrentContentReadOnly();
}
}
- void WriteSavedLineTextAfterFirstPrompt(string promptText)
+ void WriteSavedTextAfterFirstPrompt()
{
firstPromptDisplayed = true;
- if (savedSendLineText != null) {
- textEditor.Write(savedSendLineText + "\r\n");
- savedSendLineText = null;
+ if (savedTextLines.Count > 0) {
+ string line = GetFirstLineOfText(savedTextLines);
+ savedTextLines.RemoveAt(0);
+ textEditor.Write(line);
}
}
@@ -292,14 +293,14 @@ void ReplaceCurrentLineTextAfterPrompt(string text)
textEditor.Column = promptLength + text.Length;
}
- public void SendLine(string text)
+ public void SendLine(string line)
{
using (ILock linesLock = CreateLock(unreadLines)) {
- unreadLines.Add(text);
+ unreadLines.Add(line);
}
FireLineReceivedEvent();
MoveCursorToEndOfLastTextEditorLine();
- WriteLineIfFirstPromptHasBeenDisplayed(text);
+ WriteTextIfFirstPromptHasBeenDisplayed(line + "\r\n");
}
protected virtual ILock CreateLock(List<string> lines)
@@ -312,12 +313,12 @@ protected virtual void FireLineReceivedEvent()
lineReceivedEvent.Set();
}
- void WriteLineIfFirstPromptHasBeenDisplayed(string text)
+ void WriteTextIfFirstPromptHasBeenDisplayed(string text)
{
if (firstPromptDisplayed) {
- WriteLine(text, ScriptingStyle.Out);
+ Write(text, ScriptingStyle.Out);
} else {
- savedSendLineText = text;
+ savedTextLines = GetLines(text);
}
}
@@ -330,5 +331,53 @@ public virtual IList<string> GetGlobals(string name)
{
return new string[0];
}
+
+ public void SendText(string text)
+ {
+ MoveCursorToEndOfLastTextEditorLine();
+ WriteFirstLineOfTextIfFirstPromptHasBeenDisplayed(text);
+ }
+
+ void WriteFirstLineOfTextIfFirstPromptHasBeenDisplayed(string text)
+ {
+ List<string> lines = GetLines(text);
+ string firstLine = GetFirstLineOfText(lines);
+
+ if (lines.Count > 1) {
+ using (ILock linesLock = CreateLock(unreadLines)) {
+ AddAllLinesButLastToUnreadLines(lines);
+ }
+ FireLineReceivedEvent();
+ }
+ lines.RemoveAt(0);
+ savedTextLines = lines;
+
+ WriteTextIfFirstPromptHasBeenDisplayed(firstLine);
+ }
+
+ List<string> GetLines(string text)
+ {
+ text = text.Replace("\r\n", "\n");
+ string[] lines = text.Split('\n');
+ return new List<string>(lines);
+ }
+
+ string GetFirstLineOfText(List<string> lines)
+ {
+ if (lines.Count > 1) {
+ string firstLine = lines[0] + "\r\n";
+ return firstLine;
+ }
+ return lines[0];
+ }
+
+ void AddAllLinesButLastToUnreadLines(List<string> lines)
+ {
+ int howMany = lines.Count - 1;
+ for (int i = 0; i < howMany; ++i) {
+ string line = lines[i];
+ unreadLines.Add(line);
+ }
+ }
}
}
View
41 src/AddIns/BackendBindings/Scripting/Project/Src/SendLineToScriptingConsoleCommand.cs
@@ -1,34 +1,18 @@
-// <file>
-// <copyright see="prj:///doc/copyright.txt"/>
-// <license see="prj:///doc/license.txt"/>
-// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
-// <version>$Revision$</version>
-// </file>
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
-using ICSharpCode.Core;
-using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Editor;
-using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.Scripting
{
- public class SendLineToScriptingConsoleCommand : AbstractCommand
+ public class SendLineToScriptingConsoleCommand : SendToScriptingConsoleCommand
{
- IScriptingWorkbench workbench;
-
- IScriptingConsolePad consolePad;
- ScriptingTextEditorViewContent textEditorView;
- ITextEditor activeTextEditor;
- IScriptingConsole pythonConsole;
string lineFromActiveTextEditor;
public SendLineToScriptingConsoleCommand(IScriptingWorkbench workbench)
+ : base(workbench)
{
- this.workbench = workbench;
-
- textEditorView = new ScriptingTextEditorViewContent(workbench);
- activeTextEditor = textEditorView.TextEditor;
}
public override void Run()
@@ -46,25 +30,10 @@ void GetLineFromActiveTextEditor()
lineFromActiveTextEditor = documentLine.Text;
}
- void GetScriptingConsolePad()
- {
- consolePad = workbench.GetScriptingConsolePad();
- }
-
- void ShowScriptingConsolePad()
- {
- consolePad.BringToFront();
- }
-
void AppendLineToScriptingConsole()
{
GetScriptingConsole();
- pythonConsole.SendLine(lineFromActiveTextEditor);
- }
-
- void GetScriptingConsole()
- {
- pythonConsole = consolePad.ScriptingConsole;
+ scriptingConsole.SendLine(lineFromActiveTextEditor);
}
}
}
View
38 src/AddIns/BackendBindings/Scripting/Project/Src/SendSelectedTextToScriptingConsoleCommand.cs
@@ -0,0 +1,38 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Editor;
+
+namespace ICSharpCode.Scripting
+{
+ public class SendSelectedTextToScriptingConsoleCommand : SendToScriptingConsoleCommand
+ {
+ string selectedText;
+
+ public SendSelectedTextToScriptingConsoleCommand(IScriptingWorkbench workbench)
+ : base(workbench)
+ {
+ }
+
+ public override void Run()
+ {
+ GetSelectedTextInActiveTextEditor();
+ GetScriptingConsolePad();
+ ShowScriptingConsolePad();
+ SendTextToScriptingConsole();
+ }
+
+ void GetSelectedTextInActiveTextEditor()
+ {
+ selectedText = activeTextEditor.SelectedText;
+ }
+
+ void SendTextToScriptingConsole()
+ {
+ GetScriptingConsole();
+ scriptingConsole.SendText(selectedText);
+ }
+ }
+}
View
42 src/AddIns/BackendBindings/Scripting/Project/Src/SendToScriptingConsoleCommand.cs
@@ -0,0 +1,42 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Editor;
+
+namespace ICSharpCode.Scripting
+{
+ public abstract class SendToScriptingConsoleCommand : AbstractMenuCommand
+ {
+ protected IScriptingWorkbench workbench;
+
+ protected IScriptingConsolePad consolePad;
+ protected ScriptingTextEditorViewContent textEditorView;
+ protected ITextEditor activeTextEditor;
+ protected IScriptingConsole scriptingConsole;
+
+ public SendToScriptingConsoleCommand(IScriptingWorkbench workbench)
+ {
+ this.workbench = workbench;
+
+ textEditorView = new ScriptingTextEditorViewContent(workbench);
+ activeTextEditor = textEditorView.TextEditor;
+ }
+
+ protected void GetScriptingConsolePad()
+ {
+ consolePad = workbench.GetScriptingConsolePad();
+ }
+
+ protected void ShowScriptingConsolePad()
+ {
+ consolePad.BringToFront();
+ }
+
+ protected void GetScriptingConsole()
+ {
+ scriptingConsole = consolePad.ScriptingConsole;
+ }
+ }
+}
View
5 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
@@ -31,11 +31,6 @@ void SendLineToConsole(string text)
TestableScriptingConsole.SendLine(text);
}
- void WritePrompt()
- {
- TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
- }
-
[Test]
public void SendLine_NoUnreadLines_CreatesLockForPreviousLines()
{
View
144 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs
@@ -0,0 +1,144 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.NRefactory;
+using ICSharpCode.Scripting;
+using NUnit.Framework;
+
+namespace ICSharpCode.Scripting.Tests.Console
+{
+ [TestFixture]
+ public class ScriptingConsoleSendTextTests : ScriptingConsoleTestsBase
+ {
+ [Test]
+ public void SendText_NoNewLineInText_AppendTextToEndOfActiveConsoleInputLine()
+ {
+ SendTextToConsole("test");
+
+ string text = base.MockConsoleTextEditor.TextPassedToWrite;
+ string expectedText = "test";
+ Assert.AreEqual(expectedText, text);
+ }
+
+ void SendTextToConsole(string text)
+ {
+ base.CreateConsole();
+ WritePrompt();
+ TestableScriptingConsole.SendText(text);
+ }
+
+ [Test]
+ public void SendText_TextEditorHasTextAfterPrompt_CursorMovedToEndOfLastLineBeforeTextWritten()
+ {
+ base.CreateConsole();
+ WritePrompt();
+ MockConsoleTextEditor.Text = ">>> first";
+
+ MockConsoleTextEditor.Line = -1;
+ MockConsoleTextEditor.Column = -1;
+ TestableScriptingConsole.SendText("test");
+
+ int expectedLine = 0;
+ int expectedColumn = 9;
+ Location expectedLocation = new Location(expectedColumn, expectedLine);
+
+ Location location = MockConsoleTextEditor.CursorLocationWhenWriteTextCalled;
+
+ Assert.AreEqual(expectedLocation, location);
+ }
+
+ [Test]
+ public void SendText_FirstPromptNotYetWrittenToConsole_NoTextWrittenToConsoleTextEditor()
+ {
+ base.CreateConsole();
+ TestableScriptingConsole.SendText("test");
+ string text = MockConsoleTextEditor.TextPassedToWrite;
+
+ Assert.IsNull(text);
+ }
+
+ [Test]
+ public void Write_SendTextCalledButNoPromptWritten_WritesOutSavedText()
+ {
+ base.CreateConsole();
+ TestableScriptingConsole.SendText("test");
+
+ TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
+ string text = MockConsoleTextEditor.Text;
+
+ string expectedText = ">>> test";
+ Assert.AreEqual(expectedText, text);
+ }
+
+ [Test]
+ public void SendText_TwoLinesSelected_FirstLineOfTextWrittenToTextEditor()
+ {
+ string selectedText =
+ "first\r\n" +
+ "second";
+
+ SendTextToConsole(selectedText);
+
+ string text = base.MockConsoleTextEditor.TextPassedToWrite;
+ string expectedText = "first\r\n";
+ Assert.AreEqual(expectedText, text);
+ }
+
+ [Test]
+ public void Write_TwoLinesSelectedAndFirstLineOfTextWrittenToTextEditor_SecondLineWrittenAfterPrompt()
+ {
+ string selectedText =
+ "first\r\n" +
+ "second";
+
+ SendTextToConsole(selectedText);
+ WritePrompt();
+
+ string text = base.MockConsoleTextEditor.TextPassedToWrite;
+ string expectedText = "second";
+ Assert.AreEqual(expectedText, text);
+ }
+
+ [Test]
+ public void SendText_TwoLinesSelected_UnreadLinesContainsFirstLineOnly()
+ {
+ string selectedText =
+ "first\r\n" +
+ "second";
+
+ SendTextToConsole(selectedText);
+
+ string[] unreadLines = base.TestableScriptingConsole.GetUnreadLines();
+ string[] expectedUnreadLines = new string[] { "first" };
+ Assert.AreEqual(expectedUnreadLines, unreadLines);
+ }
+
+ [Test]
+ public void SendText_TwoLinesSelected_LineReceivedEventIsFired()
+ {
+ string selectedText =
+ "first\r\n" +
+ "second";
+
+ SendTextToConsole(selectedText);
+ bool fired = TestableScriptingConsole.IsLineReceivedEventFired;
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void SendText_ThreeLinesSelected_UnreadLinesContainsFirstTwoLines()
+ {
+ string selectedText =
+ "first\r\n" +
+ "second\r\n" +
+ "third";
+
+ SendTextToConsole(selectedText);
+
+ string[] unreadLines = base.TestableScriptingConsole.GetUnreadLines();
+ string[] expectedUnreadLines = new string[] { "first", "second" };
+ Assert.AreEqual(expectedUnreadLines, unreadLines);
+ }
+ }
+}
View
5 src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs
@@ -17,5 +17,10 @@ public void CreateConsole()
TestableScriptingConsole = new TestableScriptingConsole();
MockConsoleTextEditor = TestableScriptingConsole.MockConsoleTextEditor;
}
+
+ public void WritePrompt()
+ {
+ TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
+ }
}
}
View
13 src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs
@@ -9,13 +9,9 @@
namespace ICSharpCode.Scripting.Tests.Console
{
[TestFixture]
- public class SendLineToScriptingConsoleCommandTests
+ public class SendLineToScriptingConsoleCommandTests : SendToScriptingConsoleCommandTestsBase
{
SendLineToScriptingConsoleCommand sendLineToConsoleCommand;
- MockConsoleTextEditor fakeConsoleTextEditor;
- MockTextEditor fakeTextEditor;
- MockWorkbench workbench;
- MockScriptingConsole fakeConsole;
[Test]
public void Run_SingleLineInTextEditor_FirstLineSentToPythonConsole()
@@ -32,10 +28,7 @@ public void Run_SingleLineInTextEditor_FirstLineSentToPythonConsole()
void CreateSendLineToConsoleCommand()
{
- workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.py");
- fakeConsoleTextEditor = workbench.MockScriptingConsolePad.MockConsoleTextEditor;
- fakeConsole = workbench.MockScriptingConsolePad.MockScriptingConsole;
- fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor;
+ base.CreateFakeWorkbench();
sendLineToConsoleCommand = new SendLineToScriptingConsoleCommand(workbench);
}
@@ -75,7 +68,7 @@ public void Run_TwoLinesInTextEditorCursorOnFirstLine_FirstLineSentToPythonConso
}
[Test]
- public void Run_SingleLineInTextEditor_PythonConsolePadBroughtToFront()
+ public void Run_SingleLineInTextEditor_ScriptingConsolePadBroughtToFront()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");
View
51 src/AddIns/BackendBindings/Scripting/Test/Console/SendSelectedTextToScriptingConsoleCommandTests.cs
@@ -0,0 +1,51 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Scripting;
+using ICSharpCode.Scripting.Tests.Utils;
+using NUnit.Framework;
+
+namespace ICSharpCode.Scripting.Tests.Console
+{
+ [TestFixture]
+ public class SendSelectedTextToScriptingConsoleCommandTests : SendToScriptingConsoleCommandTestsBase
+ {
+ SendSelectedTextToScriptingConsoleCommand sendSelectedTextToConsoleCommand;
+
+ [Test]
+ public void Run_TwoLinesSelectedInTextEditor_TextSentToPythonConsole()
+ {
+ CreateSendSelectedTextToConsoleCommand();
+
+ string selectedText =
+ "print 'a'\r\n" +
+ "print 'b'\r\n";
+
+ fakeTextEditor.SelectedText = selectedText;
+ sendSelectedTextToConsoleCommand.Run();
+
+ string text = fakeConsole.TextPassedToSendText;
+
+ Assert.AreEqual(selectedText, text);
+ }
+
+ void CreateSendSelectedTextToConsoleCommand()
+ {
+ base.CreateFakeWorkbench();
+ sendSelectedTextToConsoleCommand = new SendSelectedTextToScriptingConsoleCommand(workbench);
+ }
+
+ [Test]
+ public void Run_SingleLineSelectedInTextEditor_ScriptingConsolePadBroughtToFront()
+ {
+ CreateSendSelectedTextToConsoleCommand();
+ fakeTextEditor.SelectedText = "test";
+
+ sendSelectedTextToConsoleCommand.Run();
+
+ bool broughtToFront = workbench.MockScriptingConsolePad.BringToFrontCalled;
+ Assert.IsTrue(broughtToFront);
+ }
+ }
+}
View
28 src/AddIns/BackendBindings/Scripting/Test/Console/SendToScriptingConsoleCommandTestsBase.cs
@@ -0,0 +1,28 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
+// <version>$Revision$</version>
+// </file>
+
+using System;
+using ICSharpCode.Scripting.Tests.Utils;
+
+namespace ICSharpCode.Scripting.Tests.Console
+{
+ public abstract class SendToScriptingConsoleCommandTestsBase
+ {
+ protected MockConsoleTextEditor fakeConsoleTextEditor;
+ protected MockTextEditor fakeTextEditor;
+ protected MockWorkbench workbench;
+ protected MockScriptingConsole fakeConsole;
+
+ public void CreateFakeWorkbench()
+ {
+ workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.py");
+ fakeConsoleTextEditor = workbench.MockScriptingConsolePad.MockConsoleTextEditor;
+ fakeConsole = workbench.MockScriptingConsolePad.MockScriptingConsole;
+ fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor;
+ }
+ }
+}
View
3  src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
@@ -84,11 +84,14 @@
<Compile Include="Console\ScriptingConsoleReadOnlyRegionsTests.cs" />
<Compile Include="Console\ScriptingConsoleReadTests.cs" />
<Compile Include="Console\ScriptingConsoleSendLineTests.cs" />
+ <Compile Include="Console\ScriptingConsoleSendTextTests.cs" />
<Compile Include="Console\ScriptingConsoleTestsBase.cs" />
<Compile Include="Console\ScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\ScriptingConsoleUnreadLinesTests.cs" />
<Compile Include="Console\ScriptingConsoleWriteTests.cs" />
<Compile Include="Console\SendLineToScriptingConsoleCommandTests.cs" />
+ <Compile Include="Console\SendSelectedTextToScriptingConsoleCommandTests.cs" />
+ <Compile Include="Console\SendToScriptingConsoleCommandTestsBase.cs" />
<Compile Include="Console\ThreadSafeScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoConsoleLinesWaitingTests.cs" />
<Compile Include="Designer\CallBeginInitOnLoadTests.cs" />
View
6 src/AddIns/BackendBindings/Scripting/Test/Utils/MockScriptingConsole.cs
@@ -9,10 +9,16 @@ namespace ICSharpCode.Scripting.Tests.Utils
public class MockScriptingConsole : IScriptingConsole
{
public string TextPassedToSendLine;
+ public string TextPassedToSendText;
public void SendLine(string text)
{
TextPassedToSendLine = text;
}
+
+ public void SendText(string text)
+ {
+ TextPassedToSendText = text;
+ }
}
}
View
15 src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs
@@ -62,20 +62,9 @@ protected virtual void OnKeyPress(KeyEventArgs e)
}
}
- public int SelectionLength {
- get {
- throw new NotImplementedException();
- }
- }
+ public int SelectionLength { get; set; }
- public string SelectedText {
- get {
- throw new NotImplementedException();
- }
- set {
- throw new NotImplementedException();
- }
- }
+ public string SelectedText { get; set; }
public ICSharpCode.Core.FileName FileName {
get {
View
2  src/Main/Base/Project/ICSharpCode.SharpDevelop.addin
@@ -30,7 +30,7 @@
<ConditionEvaluator name="CanNavigateForward" class="ICSharpCode.SharpDevelop.CanNavigateForwardConditionEvaluator"/>
<ConditionEvaluator name="CompareProjectProperty" class="ICSharpCode.SharpDevelop.CompareProjectPropertyConditionEvaluator"/>
<ConditionEvaluator name="ProjectItem" class="ICSharpCode.SharpDevelop.Project.ProjectItemConditionEvaluator"/>
-
+ <ConditionEvaluator name="IsTextSelected" class="ICSharpCode.SharpDevelop.Editor.AvalonEdit.TextSelectedCondition"/>
<Doozer name="CustomTool" class="ICSharpCode.SharpDevelop.Project.CustomToolDoozer"/>
<Doozer name="CustomProperty" class="ICSharpCode.SharpDevelop.Project.CustomPropertyDoozer"/>
View
1  src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
@@ -92,6 +92,7 @@
<Compile Include="Src\Editor\AvalonEdit\IndentationStrategyAdapter.cs" />
<Compile Include="Src\Editor\AvalonEdit\ISnippetElementProvider.cs" />
<Compile Include="Src\Editor\AvalonEdit\TextContentCondition.cs" />
+ <Compile Include="Src\Editor\AvalonEdit\TextSelectedCondition.cs" />
<Compile Include="Src\Editor\CodeCompletion\CodeCompletionPanel.cs">
<SubType>UserControl</SubType>
</Compile>
View
22 src/Main/Base/Project/Src/Editor/AvalonEdit/TextSelectedCondition.cs
@@ -0,0 +1,22 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Gui;
+
+namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
+{
+ public class TextSelectedCondition : IConditionEvaluator
+ {
+ public bool IsValid(object owner, Condition condition)
+ {
+ ITextEditorProvider textEditorProvider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
+ if (textEditorProvider != null) {
+ ITextEditor textEditor = textEditorProvider.TextEditor;
+ return textEditor.SelectionLength > 0;
+ }
+ return false;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.