28 changed files with 503 additions and 78 deletions
@ -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()) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
@ -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()) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
@ -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); |
||||
} |
||||
} |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
} |
||||
@ -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…
Reference in new issue