Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1580 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
9 changed files with 196 additions and 67 deletions
@ -0,0 +1,76 @@ |
|||||||
|
// <file> |
||||||
|
// <copyright see="prj:///doc/copyright.txt"/> |
||||||
|
// <license see="prj:///doc/license.txt"/> |
||||||
|
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/> |
||||||
|
// <version>$Revision$</version> |
||||||
|
// </file> |
||||||
|
|
||||||
|
namespace Boo.InterpreterAddIn |
||||||
|
|
||||||
|
import System |
||||||
|
|
||||||
|
abstract class InterpreterContext: |
||||||
|
[property(Visible, Observable: true)] |
||||||
|
private _visible as bool = true |
||||||
|
|
||||||
|
[property(Image, Observable: true)] |
||||||
|
private _image as System.Drawing.Image |
||||||
|
|
||||||
|
[property(Title, Observable: true)] |
||||||
|
private _title as string = '${res:ICSharpCode.BooInterpreter}' |
||||||
|
|
||||||
|
[property(ToolTipText, Observable: true)] |
||||||
|
private _toolTipText as string |
||||||
|
|
||||||
|
event LinePrinted as callable(string) |
||||||
|
"""Callback when interpreter outputs a text line. |
||||||
|
You can raise the event on any thread, InterpreterAddIn takes care of invoking""" |
||||||
|
|
||||||
|
event Cleared as callable() |
||||||
|
"""Callback when interpreter clears the text box. |
||||||
|
You can raise the event on any thread, InterpreterAddIn takes care of invoking""" |
||||||
|
|
||||||
|
protected def RaiseClear(): |
||||||
|
"""Raise the Cleared event.""" |
||||||
|
Cleared() |
||||||
|
|
||||||
|
protected def PrintLine(line as string): |
||||||
|
"""Raise LinePrinted event to output a line in the interpreter""" |
||||||
|
LinePrinted(line) |
||||||
|
|
||||||
|
abstract def RunCommand(code as string) as void: |
||||||
|
"""Execute the passed code.""" |
||||||
|
pass |
||||||
|
|
||||||
|
virtual def GetGlobals() as (string): |
||||||
|
"""Gets a list of globally available types/variables. Used for Ctrl+Space completion""" |
||||||
|
return null |
||||||
|
|
||||||
|
virtual def SuggestCodeCompletion(code as string) as (string): |
||||||
|
"""Gets list of available members for completion on the passed expression. Used for '.' completion""" |
||||||
|
return null |
||||||
|
|
||||||
|
class DefaultBooInterpreterContext(InterpreterContext): |
||||||
|
_interpreter as Boo.Lang.Interpreter.InteractiveInterpreter |
||||||
|
|
||||||
|
def constructor(): |
||||||
|
self.Image = ICSharpCode.Core.ResourceService.GetBitmap("Boo.ProjectIcon") |
||||||
|
|
||||||
|
private def InitInterpreter(): |
||||||
|
_interpreter = Boo.Lang.Interpreter.InteractiveInterpreter( |
||||||
|
RememberLastValue: true, |
||||||
|
Print: self.PrintLine) |
||||||
|
_interpreter.SetValue("cls", RaiseClear) |
||||||
|
_interpreter.LoopEval(""" |
||||||
|
import System |
||||||
|
import System.IO |
||||||
|
import System.Text |
||||||
|
""") |
||||||
|
|
||||||
|
def RunCommand(code as string): |
||||||
|
InitInterpreter() if _interpreter is null |
||||||
|
_interpreter.LoopEval(code) |
||||||
|
|
||||||
|
def GetGlobals(): |
||||||
|
InitInterpreter() if _interpreter is null |
||||||
|
return _interpreter.globals() |
@ -1,43 +0,0 @@ |
|||||||
// <file> |
|
||||||
// <copyright see="prj:///doc/copyright.txt">2005 AlphaSierraPapa</copyright> |
|
||||||
// <license see="prj:///doc/license.txt">GNU General Public License</license> |
|
||||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/> |
|
||||||
// <version>$Revision$</version> |
|
||||||
// </file> |
|
||||||
|
|
||||||
namespace Boo.InterpreterAddIn |
|
||||||
|
|
||||||
import System |
|
||||||
import System.Windows.Forms |
|
||||||
|
|
||||||
class InterpreterWrapper: |
|
||||||
_interpreter as Boo.Lang.Interpreter.InteractiveInterpreter |
|
||||||
|
|
||||||
def constructor(): |
|
||||||
_interpreter = Boo.Lang.Interpreter.InteractiveInterpreter( |
|
||||||
RememberLastValue: true, |
|
||||||
Print: self.OnPrintLine) |
|
||||||
_interpreter.SetValue("cls", RaiseClear) |
|
||||||
|
|
||||||
event LinePrinted as callable(string) |
|
||||||
event Cleared as MethodInvoker |
|
||||||
|
|
||||||
private def RaiseClear(): |
|
||||||
Cleared() |
|
||||||
|
|
||||||
private def OnPrintLine(text as string): |
|
||||||
LinePrinted(text) |
|
||||||
|
|
||||||
def RunCommand(code as string): |
|
||||||
_interpreter.LoopEval(code) |
|
||||||
|
|
||||||
def SuggestCodeCompletion(code as string): |
|
||||||
// David: the code completion items have to be passed as strings; |
|
||||||
// but it's not important, you can return null if you want. |
|
||||||
return _interpreter.SuggestCodeCompletion(code) |
|
||||||
|
|
||||||
def GetGlobals(): |
|
||||||
return _interpreter.globals() |
|
||||||
|
|
||||||
def GetValue(variableName as string): |
|
||||||
return _interpreter.GetValue(variableName) |
|
Loading…
Reference in new issue