Browse Source

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

pull/1/head
mrward 16 years ago
parent
commit
a528487a50
  1. 12
      data/resources/StringResources.de.resx
  2. 3
      data/resources/StringResources.fr.resx
  3. 9
      data/resources/StringResources.nl.resx
  4. 9
      data/resources/StringResources.resx
  5. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
  6. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  7. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendSelectedTextToPythonConsoleCommand.cs
  8. 10
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin
  9. 1
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj
  10. 16
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendSelectedTextToRubyConsoleCommand.cs
  11. 2
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  12. 3
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs
  13. 73
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs
  14. 41
      src/AddIns/BackendBindings/Scripting/Project/Src/SendLineToScriptingConsoleCommand.cs
  15. 38
      src/AddIns/BackendBindings/Scripting/Project/Src/SendSelectedTextToScriptingConsoleCommand.cs
  16. 42
      src/AddIns/BackendBindings/Scripting/Project/Src/SendToScriptingConsoleCommand.cs
  17. 5
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs
  18. 144
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs
  19. 5
      src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs
  20. 13
      src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs
  21. 51
      src/AddIns/BackendBindings/Scripting/Test/Console/SendSelectedTextToScriptingConsoleCommandTests.cs
  22. 28
      src/AddIns/BackendBindings/Scripting/Test/Console/SendToScriptingConsoleCommandTestsBase.cs
  23. 3
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  24. 6
      src/AddIns/BackendBindings/Scripting/Test/Utils/MockScriptingConsole.cs
  25. 15
      src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs
  26. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.addin
  27. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  28. 22
      src/Main/Base/Project/Src/Editor/AvalonEdit/TextSelectedCondition.cs

12
data/resources/StringResources.de.resx

@ -232,6 +232,9 @@ Laden Sie ein AddIn aus dem Internet herunter, klicken Sie auf "AddIn installier @@ -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 @@ -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.< @@ -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>

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 @@ -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>

9
data/resources/StringResources.nl.resx

@ -699,6 +699,9 @@ De geselecteerde code bevat een break commando zonder de insluitende lus. Wijzig @@ -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 @@ -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>

9
data/resources/StringResources.resx

@ -701,6 +701,9 @@ Optionally you can specify a working directory and command line arguments. @@ -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 @@ -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>

10
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin

@ -83,6 +83,11 @@ @@ -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 @@ @@ -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>

1
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -119,6 +119,7 @@ @@ -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" />

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendSelectedTextToPythonConsoleCommand.cs

@ -0,0 +1,16 @@ @@ -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())
{
}
}
}

10
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin

@ -77,6 +77,11 @@ @@ -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 @@ @@ -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>

1
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.csproj

@ -126,6 +126,7 @@ @@ -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">

16
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendSelectedTextToRubyConsoleCommand.cs

@ -0,0 +1,16 @@ @@ -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())
{
}
}
}

2
src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj

@ -93,6 +93,8 @@ @@ -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>

3
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingConsole.cs

@ -7,6 +7,7 @@ namespace ICSharpCode.Scripting @@ -7,6 +7,7 @@ namespace ICSharpCode.Scripting
{
public interface IScriptingConsole
{
void SendLine(string text);
void SendLine(string line);
void SendText(string text);
}
}

73
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsole.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.Scripting @@ -19,7 +19,7 @@ namespace ICSharpCode.Scripting
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 @@ namespace ICSharpCode.Scripting @@ -67,18 +67,19 @@ namespace ICSharpCode.Scripting
{
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 @@ namespace ICSharpCode.Scripting @@ -292,14 +293,14 @@ namespace ICSharpCode.Scripting
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 @@ namespace ICSharpCode.Scripting @@ -312,12 +313,12 @@ namespace ICSharpCode.Scripting
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 @@ namespace ICSharpCode.Scripting @@ -330,5 +331,53 @@ namespace ICSharpCode.Scripting
{
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);
}
}
}
}

41
src/AddIns/BackendBindings/Scripting/Project/Src/SendLineToScriptingConsoleCommand.cs

@ -1,34 +1,18 @@ @@ -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 @@ namespace ICSharpCode.Scripting @@ -46,25 +30,10 @@ namespace ICSharpCode.Scripting
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);
}
}
}

38
src/AddIns/BackendBindings/Scripting/Project/Src/SendSelectedTextToScriptingConsoleCommand.cs

@ -0,0 +1,38 @@ @@ -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);
}
}
}

42
src/AddIns/BackendBindings/Scripting/Project/Src/SendToScriptingConsoleCommand.cs

@ -0,0 +1,42 @@ @@ -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;
}
}
}

5
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendLineTests.cs

@ -31,11 +31,6 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -31,11 +31,6 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole.SendLine(text);
}
void WritePrompt()
{
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
}
[Test]
public void SendLine_NoUnreadLines_CreatesLockForPreviousLines()
{

144
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleSendTextTests.cs

@ -0,0 +1,144 @@ @@ -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);
}
}
}

5
src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleTestsBase.cs

@ -17,5 +17,10 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -17,5 +17,10 @@ namespace ICSharpCode.Scripting.Tests.Console
TestableScriptingConsole = new TestableScriptingConsole();
MockConsoleTextEditor = TestableScriptingConsole.MockConsoleTextEditor;
}
public void WritePrompt()
{
TestableScriptingConsole.Write(">>> ", ScriptingStyle.Prompt);
}
}
}

13
src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs

@ -9,13 +9,9 @@ using NUnit.Framework; @@ -9,13 +9,9 @@ using NUnit.Framework;
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 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -32,10 +28,7 @@ namespace ICSharpCode.Scripting.Tests.Console
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 @@ namespace ICSharpCode.Scripting.Tests.Console @@ -75,7 +68,7 @@ namespace ICSharpCode.Scripting.Tests.Console
}
[Test]
public void Run_SingleLineInTextEditor_PythonConsolePadBroughtToFront()
public void Run_SingleLineInTextEditor_ScriptingConsolePadBroughtToFront()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");

51
src/AddIns/BackendBindings/Scripting/Test/Console/SendSelectedTextToScriptingConsoleCommandTests.cs

@ -0,0 +1,51 @@ @@ -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);
}
}
}

28
src/AddIns/BackendBindings/Scripting/Test/Console/SendToScriptingConsoleCommandTestsBase.cs

@ -0,0 +1,28 @@ @@ -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;
}
}
}

3
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -84,11 +84,14 @@ @@ -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" />

6
src/AddIns/BackendBindings/Scripting/Test/Utils/MockScriptingConsole.cs

@ -9,10 +9,16 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -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;
}
}
}

15
src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs

@ -62,20 +62,9 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -62,20 +62,9 @@ namespace ICSharpCode.Scripting.Tests.Utils
}
}
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 {

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.addin

@ -30,7 +30,7 @@ @@ -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"/>

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -92,6 +92,7 @@ @@ -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>

22
src/Main/Base/Project/Src/Editor/AvalonEdit/TextSelectedCondition.cs

@ -0,0 +1,22 @@ @@ -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;
}
}
}
Loading…
Cancel
Save