Browse Source

Move common IronPython and IronRuby send line to console code to Scripting project.

pull/1/head
mrward 15 years ago
parent
commit
540a255548
  1. 59
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendLineToPythonConsoleCommand.cs
  2. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  3. 60
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendLineToRubyConsoleCommand.cs
  4. 90
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/SendLineToRubyConsoleCommandTests.cs
  5. 1
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj
  6. 1
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  7. 70
      src/AddIns/BackendBindings/Scripting/Project/Src/SendLineToScriptingConsoleCommand.cs
  8. 11
      src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs
  9. 1
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

59
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/SendLineToPythonConsoleCommand.cs

@ -4,67 +4,14 @@ @@ -4,67 +4,14 @@
using System;
using ICSharpCode.Core;
using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PythonBinding
{
public class SendLineToPythonConsoleCommand : AbstractCommand
{
IScriptingWorkbench workbench;
IScriptingConsolePad consolePad;
ScriptingTextEditorViewContent textEditorView;
ITextEditor activeTextEditor;
IScriptingConsole pythonConsole;
string lineFromActiveTextEditor;
public class SendLineToPythonConsoleCommand : SendLineToScriptingConsoleCommand
{
public SendLineToPythonConsoleCommand()
: this(new PythonWorkbench())
: base(new PythonWorkbench())
{
}
public SendLineToPythonConsoleCommand(IScriptingWorkbench workbench)
{
this.workbench = workbench;
textEditorView = new ScriptingTextEditorViewContent(workbench);
activeTextEditor = textEditorView.TextEditor;
}
public override void Run()
{
GetLineFromActiveTextEditor();
GetPythonConsolePad();
ShowPythonConsolePad();
AppendLineToPythonConsole();
}
void GetLineFromActiveTextEditor()
{
int lineNumber = activeTextEditor.Caret.Line;
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber);
lineFromActiveTextEditor = documentLine.Text;
}
void GetPythonConsolePad()
{
consolePad = workbench.GetScriptingConsolePad();
}
void ShowPythonConsolePad()
{
consolePad.BringToFront();
}
void AppendLineToPythonConsole()
{
GetPythonConsole();
pythonConsole.SendLine(lineFromActiveTextEditor);
}
void GetPythonConsole()
{
pythonConsole = consolePad.ScriptingConsole;
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -316,7 +316,6 @@ @@ -316,7 +316,6 @@
<Compile Include="Gui\PythonIndentationTests.cs" />
<Compile Include="Gui\PythonOptionsPanelTestFixture.cs" />
<Compile Include="Gui\RunPythonCommandTests.cs" />
<Compile Include="Gui\SendLineToPythonConsoleCommandTests.cs" />
<Compile Include="Parsing\ClassWithBaseClassTestFixture.cs" />
<Compile Include="Parsing\InvalidCastInPythonParserTestFixture.cs" />
<Compile Include="Parsing\MethodWithParametersTestFixture.cs" />

60
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/SendLineToRubyConsoleCommand.cs

@ -2,69 +2,15 @@ @@ -2,69 +2,15 @@
// 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.RubyBinding
{
public class SendLineToRubyConsoleCommand : AbstractCommand
{
IScriptingWorkbench workbench;
IScriptingConsolePad consolePad;
ScriptingTextEditorViewContent textEditorView;
ITextEditor activeTextEditor;
IScriptingConsole RubyConsole;
string lineFromActiveTextEditor;
public class SendLineToRubyConsoleCommand : SendLineToScriptingConsoleCommand
{
public SendLineToRubyConsoleCommand()
: this(new RubyWorkbench())
: base(new RubyWorkbench())
{
}
public SendLineToRubyConsoleCommand(IScriptingWorkbench workbench)
{
this.workbench = workbench;
textEditorView = new ScriptingTextEditorViewContent(workbench);
activeTextEditor = textEditorView.TextEditor;
}
public override void Run()
{
GetLineFromActiveTextEditor();
GetRubyConsolePad();
ShowRubyConsolePad();
AppendLineToRubyConsole();
}
void GetLineFromActiveTextEditor()
{
int lineNumber = activeTextEditor.Caret.Line;
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber);
lineFromActiveTextEditor = documentLine.Text;
}
void GetRubyConsolePad()
{
consolePad = workbench.GetScriptingConsolePad();
}
void ShowRubyConsolePad()
{
consolePad.BringToFront();
}
void AppendLineToRubyConsole()
{
GetRubyConsole();
RubyConsole.SendLine(lineFromActiveTextEditor);
}
void GetRubyConsole()
{
RubyConsole = consolePad.ScriptingConsole;
}
}
}

90
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/SendLineToRubyConsoleCommandTests.cs

@ -1,90 +0,0 @@ @@ -1,90 +0,0 @@
// 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.RubyBinding;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
using RubyBinding.Tests.Utils;
namespace RubyBinding.Tests.Gui
{
[TestFixture]
public class SendLineToRubyConsoleCommandTests
{
SendLineToRubyConsoleCommand sendLineToConsoleCommand;
MockConsoleTextEditor fakeConsoleTextEditor;
MockTextEditor fakeTextEditor;
MockWorkbench workbench;
MockScriptingConsole fakeConsole;
[Test]
public void Run_SingleLineInTextEditor_FirstLineSentToRubyConsole()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");
sendLineToConsoleCommand.Run();
string text = fakeConsole.TextPassedToSendLine;
string expectedText = "print 'hello'";
Assert.AreEqual(expectedText, text);
}
void CreateSendLineToConsoleCommand()
{
workbench = MockWorkbench.CreateWorkbenchWithOneViewContent("test.rb");
fakeConsoleTextEditor = workbench.MockScriptingConsolePad.MockConsoleTextEditor;
fakeConsole = workbench.MockScriptingConsolePad.MockScriptingConsole;
fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor;
sendLineToConsoleCommand = new SendLineToRubyConsoleCommand(workbench);
}
void AddSingleLineToTextEditor(string line)
{
fakeTextEditor.Document.Text = line;
fakeTextEditor.Caret.Line = 1;
SetTextToReturnFromTextEditorGetLine(line);
}
void SetTextToReturnFromTextEditorGetLine(string line)
{
FakeDocumentLine documentLine = new FakeDocumentLine();
documentLine.Text = line;
fakeTextEditor.FakeDocument.DocumentLineToReturnFromGetLine = documentLine;
}
[Test]
public void Run_TwoLinesInTextEditorCursorOnFirstLine_FirstLineSentToRubyConsole()
{
CreateSendLineToConsoleCommand();
fakeTextEditor.Document.Text =
"print 'hello'\r\n" +
"print 'world'\r\n";
fakeTextEditor.Caret.Line = 1;
SetTextToReturnFromTextEditorGetLine("print 'hello'");
sendLineToConsoleCommand.Run();
string text = fakeConsole.TextPassedToSendLine;
string expectedText = "print 'hello'";
Assert.AreEqual(expectedText, text);
}
[Test]
public void Run_SingleLineInTextEditor_RubyConsolePadBroughtToFront()
{
CreateSendLineToConsoleCommand();
AddSingleLineToTextEditor("print 'hello'");
sendLineToConsoleCommand.Run();
bool broughtToFront = workbench.MockScriptingConsolePad.BringToFrontCalled;
Assert.IsTrue(broughtToFront);
}
}
}

1
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -270,7 +270,6 @@ @@ -270,7 +270,6 @@
<Compile Include="Gui\RubyIndentationTests.cs" />
<Compile Include="Gui\RubyOptionsPanelTestFixture.cs" />
<Compile Include="Gui\RunRubyCommandTests.cs" />
<Compile Include="Gui\SendLineToRubyConsoleCommandTests.cs" />
<Compile Include="Parsing\ParseClassWithBaseClassTestFixture.cs" />
<Compile Include="Parsing\ParseMethodWithOptionalParametersTestFixture.cs" />
<Compile Include="Parsing\ParseMethodWithParametersTestFixture.cs" />

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

@ -92,6 +92,7 @@ @@ -92,6 +92,7 @@
<Compile Include="Src\ScriptingStyle.cs" />
<Compile Include="Src\ScriptingTextEditorViewContent.cs" />
<Compile Include="Src\ScriptingWorkbench.cs" />
<Compile Include="Src\SendLineToScriptingConsoleCommand.cs" />
<Compile Include="Src\StringListLock.cs" />
<Compile Include="Src\ThreadSafeScriptingConsoleTextEditor.cs" />
</ItemGroup>

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

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
// <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.Core;
using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.Scripting
{
public class SendLineToScriptingConsoleCommand : AbstractCommand
{
IScriptingWorkbench workbench;
IScriptingConsolePad consolePad;
ScriptingTextEditorViewContent textEditorView;
ITextEditor activeTextEditor;
IScriptingConsole pythonConsole;
string lineFromActiveTextEditor;
public SendLineToScriptingConsoleCommand(IScriptingWorkbench workbench)
{
this.workbench = workbench;
textEditorView = new ScriptingTextEditorViewContent(workbench);
activeTextEditor = textEditorView.TextEditor;
}
public override void Run()
{
GetLineFromActiveTextEditor();
GetScriptingConsolePad();
ShowScriptingConsolePad();
AppendLineToScriptingConsole();
}
void GetLineFromActiveTextEditor()
{
int lineNumber = activeTextEditor.Caret.Line;
IDocumentLine documentLine = activeTextEditor.Document.GetLine(lineNumber);
lineFromActiveTextEditor = documentLine.Text;
}
void GetScriptingConsolePad()
{
consolePad = workbench.GetScriptingConsolePad();
}
void ShowScriptingConsolePad()
{
consolePad.BringToFront();
}
void AppendLineToScriptingConsole()
{
GetScriptingConsole();
pythonConsole.SendLine(lineFromActiveTextEditor);
}
void GetScriptingConsole()
{
pythonConsole = consolePad.ScriptingConsole;
}
}
}

11
src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/SendLineToPythonConsoleCommandTests.cs → src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.cs

@ -2,17 +2,16 @@ @@ -2,17 +2,16 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting;
using ICSharpCode.Scripting.Tests.Utils;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Gui
namespace ICSharpCode.Scripting.Tests.Console
{
[TestFixture]
public class SendLineToPythonConsoleCommandTests
public class SendLineToScriptingConsoleCommandTests
{
SendLineToPythonConsoleCommand sendLineToConsoleCommand;
SendLineToScriptingConsoleCommand sendLineToConsoleCommand;
MockConsoleTextEditor fakeConsoleTextEditor;
MockTextEditor fakeTextEditor;
MockWorkbench workbench;
@ -37,7 +36,7 @@ namespace PythonBinding.Tests.Gui @@ -37,7 +36,7 @@ namespace PythonBinding.Tests.Gui
fakeConsoleTextEditor = workbench.MockScriptingConsolePad.MockConsoleTextEditor;
fakeConsole = workbench.MockScriptingConsolePad.MockScriptingConsole;
fakeTextEditor = workbench.ActiveMockEditableViewContent.MockTextEditor;
sendLineToConsoleCommand = new SendLineToPythonConsoleCommand(workbench);
sendLineToConsoleCommand = new SendLineToScriptingConsoleCommand(workbench);
}
void AddSingleLineToTextEditor(string line)

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

@ -88,6 +88,7 @@ @@ -88,6 +88,7 @@
<Compile Include="Console\ScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\ScriptingConsoleUnreadLinesTests.cs" />
<Compile Include="Console\ScriptingConsoleWriteTests.cs" />
<Compile Include="Console\SendLineToScriptingConsoleCommandTests.cs" />
<Compile Include="Console\ThreadSafeScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\TwoConsoleLinesWaitingTests.cs" />
<Compile Include="Designer\CallBeginInitOnLoadTests.cs" />

Loading…
Cancel
Save