1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using ICSharpCode.Core;
6
using ICSharpCode.Scripting;
7
using ICSharpCode.SharpDevelop;
8
using ICSharpCode.SharpDevelop.Gui;
10
namespace ICSharpCode.PythonBinding
13
/// Converts VB.NET or C# code to Python.
15
public class ConvertToPythonMenuCommand : AbstractMenuCommand
17
ScriptingTextEditorViewContent view;
19
public override void Run()
21
Run(new PythonWorkbench());
24
protected void Run(IScriptingWorkbench workbench)
26
view = new ScriptingTextEditorViewContent(workbench);
27
string code = GeneratePythonCode();
28
ShowPythonCodeInNewWindow(code);
31
string GeneratePythonCode()
33
NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(view.PrimaryFileName);
34
converter.IndentString = view.TextEditorOptions.IndentationString;
35
return converter.Convert(view.EditableView.Text);
38
void ShowPythonCodeInNewWindow(string code)
40
NewFile("Generated.py", "Python", code);
44
/// Creates a new file using the FileService by default.
46
protected virtual void NewFile(string defaultName, string language, string content)
48
FileService.NewFile(defaultName, content);