Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Move common code for running the IronRuby or IronPython console from …
…the menu to the Scripting project.
  • Loading branch information
mrward committed Sep 25, 2010
1 parent fc508ad commit c132891
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 94 deletions.
Expand Up @@ -2,11 +2,8 @@
// 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.Debugging;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util;

namespace ICSharpCode.PythonBinding
{
Expand Down
Expand Up @@ -2,63 +2,25 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Diagnostics;
using System.IO;

using ICSharpCode.Core;
using ICSharpCode.Scripting;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util;

namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Runs the Python console passing the filename of the
/// active python script open in SharpDevelop.
/// </summary>
public class RunPythonCommand : AbstractMenuCommand
public class RunPythonCommand : RunScriptingConsoleApplicationCommand
{
IDebugger debugger;
PythonAddInOptions options;
IScriptingWorkbench workbench;
PythonConsoleApplication ipy;

public RunPythonCommand()
: this(new PythonWorkbench(), new PythonAddInOptions(), DebuggerService.CurrentDebugger)
{
}

public RunPythonCommand(IScriptingWorkbench workbench, PythonAddInOptions options, IDebugger debugger)
: base(workbench, debugger, new PythonConsoleApplication(options))
{
this.workbench = workbench;
this.debugger = debugger;
this.options = options;
ipy = new PythonConsoleApplication(options);
}

public bool Debug {
get { return ipy.Debug; }
set { ipy.Debug = value; }
}

public override void Run()
{
ProcessStartInfo processStartInfo = GetProcessStartInfo();
if (Debug) {
debugger.Start(processStartInfo);
} else {
PauseCommandPromptProcessStartInfo pauseCommandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo);
debugger.StartWithoutDebugging(pauseCommandPrompt.ProcessStartInfo);
}
}

ProcessStartInfo GetProcessStartInfo()
{
string scriptFileName = workbench.ActiveViewContent.PrimaryFileName;
ipy.ScriptFileName = scriptFileName;
ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName);
return ipy.GetProcessStartInfo();
}
}
}
Expand Up @@ -51,7 +51,7 @@ public void Run_PythonFileOpen_IronPythonConsoleFileNamePassedToDebugger()
public void Run_PythonFileOpen_DebugOptionsPassedToIronPythonConsole()
{
string args = debugger.ProcessStartInfo.Arguments;
string expectedArgs = "-X:Debug \"C:\\Projects\\test.py\"";
string expectedArgs = "-X:Debug \"test.py\"";
Assert.AreEqual(expectedArgs, args);
}
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ public void Run_PythonFileOpen_CommandPromptExePassedToDebugger()
public void Run_PythonFileOpen_IronPythonConsoleAndPythonFileNameAndPausePassedAsCommandLineArguments()
{
string args = debugger.ProcessStartInfo.Arguments;
string expectedArgs = "/c \"C:\\IronPython\\ipy.exe \"C:\\Projects\\test.py\"\" & pause";
string expectedArgs = "/c \"C:\\IronPython\\ipy.exe \"test.py\"\" & pause";
Assert.AreEqual(expectedArgs, args);
}

Expand Down
Expand Up @@ -313,7 +313,7 @@
<Compile Include="Expressions\StringTextContentProviderTests.cs" />
<Compile Include="Gui\AppSettingsPanelTestFixture.cs" />
<Compile Include="Gui\CompilingOptionsPanelTestFixture.cs" />
<Compile Include="Gui\DebugPythonCommandTestFixture.cs" />
<Compile Include="Gui\DebugPythonCommandTests.cs" />
<Compile Include="Gui\FormsDesignerDisplayBindingTestFixture.cs" />
<Compile Include="Gui\PythonIndentationTests.cs" />
<Compile Include="Gui\PythonOptionsPanelTestFixture.cs" />
Expand Down
Expand Up @@ -17,61 +17,16 @@ namespace ICSharpCode.RubyBinding
/// Runs the Ruby console passing the filename of the
/// active Ruby script open in SharpDevelop.
/// </summary>
public class RunRubyCommand : AbstractMenuCommand
{
IDebugger debugger;
RubyAddInOptions options;
IScriptingWorkbench workbench;
RubyConsoleApplication rubyConsoleApplication;

public class RunRubyCommand : RunScriptingConsoleApplicationCommand
{
public RunRubyCommand()
: this(new RubyWorkbench(), new RubyAddInOptions(), DebuggerService.CurrentDebugger)
{
}

public RunRubyCommand(IScriptingWorkbench workbench, RubyAddInOptions options, IDebugger debugger)
: base(workbench, debugger, new RubyConsoleApplication(options))
{
this.workbench = workbench;
this.debugger = debugger;
this.options = options;
rubyConsoleApplication = new RubyConsoleApplication(options);
}

public bool Debug {
get { return rubyConsoleApplication.Debug; }
set { rubyConsoleApplication.Debug = value; }
}

public override void Run()
{
ProcessStartInfo processStartInfo = CreateProcessStartInfo();
if (Debug) {
debugger.Start(processStartInfo);
} else {
PauseCommandPromptProcessStartInfo commandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo);
debugger.StartWithoutDebugging(commandPrompt.ProcessStartInfo);
}
}

ProcessStartInfo CreateProcessStartInfo()
{
rubyConsoleApplication.ScriptFileName = GetRubyScriptFileName();
rubyConsoleApplication.WorkingDirectory = GetWorkingDirectory();
return rubyConsoleApplication.GetProcessStartInfo();
}

string GetWorkingDirectory()
{
return Path.GetDirectoryName(WorkbenchPrimaryFileName);
}

FileName WorkbenchPrimaryFileName {
get { return workbench.ActiveViewContent.PrimaryFileName; }
}

string GetRubyScriptFileName()
{
return Path.GetFileName(WorkbenchPrimaryFileName);
}
}
}
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Src\IScriptingFileService.cs" />
<Compile Include="Src\IScriptingWorkbench.cs" />
<Compile Include="Src\PauseCommandPromptProcessStartInfo.cs" />
<Compile Include="Src\RunScriptingConsoleApplicationCommand.cs" />
<Compile Include="Src\ScriptingCodeBuilder.cs" />
<Compile Include="Src\ScriptingCommandLineBuilder.cs" />
<Compile Include="Src\ScriptingConsole.cs" />
Expand Down
@@ -0,0 +1,65 @@
// 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 System.Diagnostics;
using System.IO;

using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;

namespace ICSharpCode.Scripting
{
public class RunScriptingConsoleApplicationCommand : AbstractMenuCommand
{
IDebugger debugger;
IScriptingWorkbench workbench;
ScriptingConsoleApplication scriptingConsoleApplication;

public RunScriptingConsoleApplicationCommand(IScriptingWorkbench workbench,
IDebugger debugger,
ScriptingConsoleApplication scriptingConsoleApplication)
{
this.workbench = workbench;
this.debugger = debugger;
this.scriptingConsoleApplication = scriptingConsoleApplication;
}

public bool Debug {
get { return scriptingConsoleApplication.Debug; }
set { scriptingConsoleApplication.Debug = value; }
}

public override void Run()
{
ProcessStartInfo processStartInfo = CreateProcessStartInfo();
if (Debug) {
debugger.Start(processStartInfo);
} else {
PauseCommandPromptProcessStartInfo commandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo);
debugger.StartWithoutDebugging(commandPrompt.ProcessStartInfo);
}
}

ProcessStartInfo CreateProcessStartInfo()
{
scriptingConsoleApplication.ScriptFileName = GetScriptFileName();
scriptingConsoleApplication.WorkingDirectory = GetWorkingDirectory();
return scriptingConsoleApplication.GetProcessStartInfo();
}

string GetWorkingDirectory()
{
return Path.GetDirectoryName(WorkbenchPrimaryFileName);
}

FileName WorkbenchPrimaryFileName {
get { return workbench.ActiveViewContent.PrimaryFileName; }
}

string GetScriptFileName()
{
return Path.GetFileName(WorkbenchPrimaryFileName);
}
}
}

0 comments on commit c132891

Please sign in to comment.