Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3209 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
19 changed files with 478 additions and 882 deletions
@ -1,26 +0,0 @@ |
|||||||
<AddIn name = "Boo Interpreter Console" |
|
||||||
author = "Daniel Grunwald" |
|
||||||
url = "http://www.icsharpcode.net" |
|
||||||
description = "Interactive interpreter for boo"> |
|
||||||
|
|
||||||
<Manifest> |
|
||||||
<Identity name = "ICSharpCode.BooInterpreter"/> |
|
||||||
</Manifest> |
|
||||||
|
|
||||||
<Runtime> |
|
||||||
<Import assembly = "Boo.InterpreterAddIn.dll"/> |
|
||||||
</Runtime> |
|
||||||
|
|
||||||
<Path name = "/SharpDevelop/Workbench/Pads"> |
|
||||||
<Pad id = "BooIshPad" |
|
||||||
category = "Main" |
|
||||||
title = "${res:ICSharpCode.BooInterpreter}" |
|
||||||
icon = "Boo.ProjectIcon" |
|
||||||
shortcut = "Control|Shift|B" |
|
||||||
class = "Boo.InterpreterAddIn.InterpreterPad"/> |
|
||||||
</Path> |
|
||||||
|
|
||||||
<Path name="/AddIns/InterpreterAddIn/InterpreterContexts"> |
|
||||||
<Class id="Default" class="Boo.InterpreterAddIn.DefaultBooInterpreterContext"/> |
|
||||||
</Path> |
|
||||||
</AddIn> |
|
||||||
@ -1,69 +0,0 @@ |
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
||||||
<PropertyGroup> |
|
||||||
<OutputType>Library</OutputType> |
|
||||||
<RootNamespace>Boo.InterpreterAddIn</RootNamespace> |
|
||||||
<AssemblyName>Boo.InterpreterAddIn</AssemblyName> |
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
||||||
<ProjectGuid>{928E34B2-5E46-4A4D-8E4D-2CA2CCDB905A}</ProjectGuid> |
|
||||||
<OutputPath>..\..\..\..\..\..\AddIns\AddIns\BackendBindings\BooBinding\</OutputPath> |
|
||||||
</PropertyGroup> |
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
|
||||||
<Optimize>False</Optimize> |
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|
||||||
<DebugSymbols>True</DebugSymbols> |
|
||||||
<DebugType>Full</DebugType> |
|
||||||
</PropertyGroup> |
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
|
||||||
<Optimize>True</Optimize> |
|
||||||
<DefineConstants>TRACE</DefineConstants> |
|
||||||
<DebugSymbols>False</DebugSymbols> |
|
||||||
<DebugType>None</DebugType> |
|
||||||
</PropertyGroup> |
|
||||||
<ItemGroup> |
|
||||||
<Reference Include="System.Xml" /> |
|
||||||
<Reference Include="System.Drawing" /> |
|
||||||
<Reference Include="System.Windows.Forms" /> |
|
||||||
<Reference Include="Boo.Lang.Interpreter"> |
|
||||||
<HintPath>..\..\RequiredLibraries\Boo.Lang.Interpreter.dll</HintPath> |
|
||||||
<SpecificVersion>False</SpecificVersion> |
|
||||||
</Reference> |
|
||||||
<Reference Include="Boo.Lang.Compiler"> |
|
||||||
<HintPath>..\..\RequiredLibraries\Boo.Lang.Compiler.dll</HintPath> |
|
||||||
<SpecificVersion>False</SpecificVersion> |
|
||||||
<Private>True</Private> |
|
||||||
</Reference> |
|
||||||
</ItemGroup> |
|
||||||
<ItemGroup> |
|
||||||
<Compile Include="CodeCompletionData.boo" /> |
|
||||||
<Compile Include="InteractiveInterpreterControl.boo" /> |
|
||||||
<Compile Include="InterpreterPad.boo" /> |
|
||||||
<Compile Include="InterpreterContext.boo" /> |
|
||||||
<Compile Include="ContextEntry.boo" /> |
|
||||||
<Compile Include="DefaultBooInterpreterContext.boo" /> |
|
||||||
</ItemGroup> |
|
||||||
<ItemGroup> |
|
||||||
<ProjectReference Include="..\..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> |
|
||||||
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> |
|
||||||
<Name>ICSharpCode.TextEditor</Name> |
|
||||||
<Private>False</Private> |
|
||||||
<SpecificVersion>False</SpecificVersion> |
|
||||||
</ProjectReference> |
|
||||||
<Content Include="Boo.Interpreter.addin"> |
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
|
||||||
</Content> |
|
||||||
<ProjectReference Include="..\..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> |
|
||||||
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> |
|
||||||
<Name>ICSharpCode.SharpDevelop</Name> |
|
||||||
<Private>False</Private> |
|
||||||
</ProjectReference> |
|
||||||
<ProjectReference Include="..\..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> |
|
||||||
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> |
|
||||||
<Name>ICSharpCode.Core</Name> |
|
||||||
<Private>False</Private> |
|
||||||
</ProjectReference> |
|
||||||
<Content Include="PostBuildEvent.proj" /> |
|
||||||
</ItemGroup> |
|
||||||
<Import Project="$(BooBinPath)\Boo.Microsoft.Build.targets" /> |
|
||||||
<Import Project="PostBuildEvent.proj" /> |
|
||||||
</Project> |
|
||||||
@ -1,159 +0,0 @@ |
|||||||
// <file> |
|
||||||
// <copyright see="prj:///doc/copyright.txt">2004 Rodrigo B. de Oliveira; 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 ICSharpCode.Core |
|
||||||
import ICSharpCode.TextEditor |
|
||||||
import ICSharpCode.TextEditor.Document |
|
||||||
import ICSharpCode.TextEditor.Actions |
|
||||||
import ICSharpCode.TextEditor.Gui.CompletionWindow |
|
||||||
import Boo.Lang.Interpreter |
|
||||||
import Boo.Lang.Compiler.TypeSystem |
|
||||||
import ICSharpCode.SharpDevelop |
|
||||||
|
|
||||||
internal class AbstractCompletionData(ICompletionData, IComparable): |
|
||||||
Priority as double: |
|
||||||
get: |
|
||||||
return 0 |
|
||||||
|
|
||||||
_name as string |
|
||||||
|
|
||||||
def constructor(name): |
|
||||||
_name = name |
|
||||||
|
|
||||||
Text as string: |
|
||||||
get: |
|
||||||
return _name |
|
||||||
set: |
|
||||||
_name = value |
|
||||||
|
|
||||||
abstract ImageIndex as int: |
|
||||||
get: |
|
||||||
pass |
|
||||||
|
|
||||||
abstract Description as string: |
|
||||||
get: |
|
||||||
pass |
|
||||||
|
|
||||||
def InsertAction(textArea as TextArea, ch as char): |
|
||||||
textArea.InsertString(_name) |
|
||||||
return false |
|
||||||
|
|
||||||
public def CompareTo(obj) as int: |
|
||||||
if obj is null or not obj isa CodeCompletionData: |
|
||||||
return -1 |
|
||||||
|
|
||||||
other = obj as CodeCompletionData |
|
||||||
return _name.CompareTo(other._name) |
|
||||||
|
|
||||||
internal class CodeCompletionData(AbstractCompletionData): |
|
||||||
|
|
||||||
_entities as List = [] |
|
||||||
|
|
||||||
def constructor(name): |
|
||||||
super(name) |
|
||||||
|
|
||||||
Description: |
|
||||||
get: |
|
||||||
description = InteractiveInterpreter.DescribeEntity(_entities[0]) |
|
||||||
return description if 1 == len(_entities) |
|
||||||
return "${description} (+${len(_entities)-1} overloads)" |
|
||||||
|
|
||||||
ImageIndex as int: |
|
||||||
get: |
|
||||||
entity = _entities[0] as IEntity |
|
||||||
entityType = entity.EntityType |
|
||||||
if EntityType.Type == entityType: |
|
||||||
type as IType = entity |
|
||||||
if type.IsInterface: |
|
||||||
return ClassBrowserIconService.InterfaceIndex |
|
||||||
elif type.IsEnum: |
|
||||||
return ClassBrowserIconService.EnumIndex |
|
||||||
elif type.IsValueType: |
|
||||||
return ClassBrowserIconService.StructIndex |
|
||||||
elif type isa ICallableType: |
|
||||||
return ClassBrowserIconService.DelegateIndex |
|
||||||
else: |
|
||||||
return ClassBrowserIconService.ClassIndex |
|
||||||
elif EntityType.Method == entityType: |
|
||||||
return ClassBrowserIconService.MethodIndex |
|
||||||
elif EntityType.Field == entityType: |
|
||||||
if (entity as IField).IsLiteral: |
|
||||||
return ClassBrowserIconService.ConstIndex |
|
||||||
else: |
|
||||||
return ClassBrowserIconService.FieldIndex |
|
||||||
elif EntityType.Property == entityType: |
|
||||||
return ClassBrowserIconService.PropertyIndex |
|
||||||
elif EntityType.Event == entityType: |
|
||||||
return ClassBrowserIconService.EventIndex |
|
||||||
return ClassBrowserIconService.NamespaceIndex |
|
||||||
|
|
||||||
def AddEntity(entity as IEntity): |
|
||||||
_entities.Add(entity) |
|
||||||
|
|
||||||
internal class GlobalsCompletionDataProvider(ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.AbstractCompletionDataProvider): |
|
||||||
_interpreter as InterpreterContext |
|
||||||
|
|
||||||
class GlobalCompletionData(AbstractCompletionData): |
|
||||||
|
|
||||||
[getter(ImageIndex)] |
|
||||||
_imageIndex as int |
|
||||||
|
|
||||||
[getter(Description)] |
|
||||||
_description as string |
|
||||||
|
|
||||||
def constructor(name as string, imageIndex as int, description as string): |
|
||||||
super(name) |
|
||||||
_imageIndex = imageIndex |
|
||||||
_description = description |
|
||||||
|
|
||||||
def constructor(interpreter as InterpreterContext): |
|
||||||
_interpreter = interpreter |
|
||||||
super.preSelection = "" |
|
||||||
|
|
||||||
override def GenerateCompletionData(fileName as string, textArea as TextArea, charTyped as System.Char) as (ICompletionData): |
|
||||||
globals = _interpreter.GetGlobals() |
|
||||||
return array(ICompletionData, 0) if globals is null |
|
||||||
data = array(ICompletionData, len(globals)) |
|
||||||
for index, key in enumerate(globals): |
|
||||||
value = null #_interpreter.GetValue(key) TODO |
|
||||||
delegate = value as System.Delegate |
|
||||||
if delegate is null: |
|
||||||
if value is not null: |
|
||||||
description = "${key} as ${InteractiveInterpreter.GetBooTypeName(value.GetType())}" |
|
||||||
else: |
|
||||||
description = "null" |
|
||||||
item = GlobalCompletionData(key, ClassBrowserIconService.FieldIndex, description) |
|
||||||
else: |
|
||||||
item = GlobalCompletionData(key, ClassBrowserIconService.MethodIndex, InteractiveInterpreter.DescribeMethod(delegate.Method)) |
|
||||||
data[index] = item |
|
||||||
return data |
|
||||||
|
|
||||||
|
|
||||||
internal class CodeCompletionDataProvider(ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.AbstractCompletionDataProvider): |
|
||||||
|
|
||||||
_codeCompletion as (IEntity) |
|
||||||
|
|
||||||
def constructor([required] codeCompletion): |
|
||||||
_codeCompletion = codeCompletion |
|
||||||
|
|
||||||
override def GenerateCompletionData(fileName as string, textArea as TextArea, charTyped as System.Char) as (ICompletionData): |
|
||||||
values = {} |
|
||||||
for item in _codeCompletion: |
|
||||||
data as CodeCompletionData |
|
||||||
data = values[item.Name] |
|
||||||
if data is null: |
|
||||||
name = item.Name |
|
||||||
if "." in name: |
|
||||||
name = /\./.Split(name)[-1] |
|
||||||
data = CodeCompletionData(name) |
|
||||||
values[item.Name] = data |
|
||||||
data.AddEntity(item) |
|
||||||
return array(ICompletionData, values.Values) |
|
||||||
|
|
||||||
@ -1,55 +0,0 @@ |
|||||||
// <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 |
|
||||||
import System.Windows.Forms |
|
||||||
import ICSharpCode.Core |
|
||||||
import ICSharpCode.SharpDevelop.Gui |
|
||||||
|
|
||||||
class ContextEntry: |
|
||||||
[getter(InterpreterControl)] |
|
||||||
_ctl as InteractiveInterpreterControl |
|
||||||
|
|
||||||
[getter(Context)] |
|
||||||
_context as InterpreterContext |
|
||||||
|
|
||||||
[getter(ToolBarItem)] |
|
||||||
_item as ToolStripButton |
|
||||||
|
|
||||||
_parentPad as InterpreterPad |
|
||||||
|
|
||||||
def constructor([required] context as InterpreterContext, [required] parentPad as InterpreterPad): |
|
||||||
_context = context |
|
||||||
_parentPad = parentPad |
|
||||||
|
|
||||||
_ctl = InteractiveInterpreterControl(context) |
|
||||||
_ctl.Dock = DockStyle.Fill |
|
||||||
|
|
||||||
_item = ToolStripButton(StringParser.Parse(context.Title), context.Image) |
|
||||||
_item.ToolTipText = StringParser.Parse(context.ToolTipText) |
|
||||||
_item.Visible = context.Visible |
|
||||||
_item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText |
|
||||||
|
|
||||||
context.ImageChanged += AutoInvoke() do: |
|
||||||
_item.Image = _context.Image |
|
||||||
context.TitleChanged += AutoInvoke() do: |
|
||||||
_item.Text = StringParser.Parse(_context.Title) |
|
||||||
context.ToolTipTextChanged += AutoInvoke() do: |
|
||||||
_item.ToolTipText = StringParser.Parse(_context.ToolTipText) |
|
||||||
context.VisibleChanged += AutoInvoke() do: |
|
||||||
_item.Visible = _context.Visible |
|
||||||
_parentPad.UpdateToolBarVisible() |
|
||||||
if _parentPad.CurrentContext is self and _context.Visible == false: |
|
||||||
_parentPad.ActivateFirstVisibleContext() |
|
||||||
_item.Click += def: |
|
||||||
_parentPad.CurrentContext = self |
|
||||||
|
|
||||||
private static def AutoInvoke(what as callable()) as EventHandler: |
|
||||||
return def(sender as object, e as EventArgs): |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(what) |
|
||||||
@ -1,61 +0,0 @@ |
|||||||
// <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 |
|
||||||
import System.Reflection |
|
||||||
|
|
||||||
class DefaultBooInterpreterContext(InterpreterContext): |
|
||||||
_interpreter as Boo.Lang.Interpreter.InteractiveInterpreter |
|
||||||
_isAdditionalTab as bool |
|
||||||
|
|
||||||
def constructor(): |
|
||||||
self.Image = ICSharpCode.Core.ResourceService.GetBitmap("Boo.ProjectIcon") |
|
||||||
|
|
||||||
def constructor(isAdditionalTab as bool): |
|
||||||
self() |
|
||||||
if isAdditionalTab: |
|
||||||
self.Title = "New " + self.Title |
|
||||||
_isAdditionalTab = true |
|
||||||
|
|
||||||
private def AddAssemblies(main as Assembly): |
|
||||||
_interpreter.References.Add(main) |
|
||||||
for reference in main.GetReferencedAssemblies(): |
|
||||||
_interpreter.References.Add(Assembly.Load(reference.FullName)) |
|
||||||
|
|
||||||
private def InitInterpreter(): |
|
||||||
_interpreter = Boo.Lang.Interpreter.InteractiveInterpreter( |
|
||||||
RememberLastValue: true, |
|
||||||
Print: self.PrintLine) |
|
||||||
AddAssemblies(typeof(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton).Assembly) |
|
||||||
_interpreter.SetValue("cls", RaiseClear) |
|
||||||
_interpreter.SetValue("newTab") do(): |
|
||||||
InterpreterPad.Instance.AddInterpreterContext(c = DefaultBooInterpreterContext(true)) |
|
||||||
return c |
|
||||||
if _isAdditionalTab: |
|
||||||
_interpreter.SetValue("thisTab", self) |
|
||||||
|
|
||||||
_interpreter.LoopEval(""" |
|
||||||
import System |
|
||||||
import System.IO |
|
||||||
import System.Text |
|
||||||
""") |
|
||||||
|
|
||||||
def RunCommand(code as string): |
|
||||||
InitInterpreter() if _interpreter is null |
|
||||||
try: |
|
||||||
_interpreter.LoopEval(code) |
|
||||||
except x as System.Reflection.TargetInvocationException: |
|
||||||
PrintLine(x.InnerException.ToString()) |
|
||||||
|
|
||||||
def GetGlobals(): |
|
||||||
InitInterpreter() if _interpreter is null |
|
||||||
return _interpreter.globals() |
|
||||||
|
|
||||||
def CloseTab(): |
|
||||||
InterpreterPad.Instance.RemoveInterpreterContext(self) |
|
||||||
@ -1,261 +0,0 @@ |
|||||||
// <file> |
|
||||||
// <copyright see="prj:///doc/copyright.txt">2004 Rodrigo B. de Oliveira; 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> |
|
||||||
|
|
||||||
""" |
|
||||||
Interactive Forms-based Console |
|
||||||
""" |
|
||||||
namespace Boo.InterpreterAddIn |
|
||||||
|
|
||||||
import System |
|
||||||
import System.Drawing |
|
||||||
import System.IO |
|
||||||
import System.Windows.Forms |
|
||||||
import ICSharpCode.SharpDevelop.Gui |
|
||||||
import ICSharpCode.TextEditor |
|
||||||
import ICSharpCode.TextEditor.Document |
|
||||||
import ICSharpCode.TextEditor.Actions |
|
||||||
import ICSharpCode.TextEditor.Gui.CompletionWindow |
|
||||||
import Boo.Lang.Compiler.TypeSystem |
|
||||||
|
|
||||||
class InteractiveInterpreterControl(TextEditorControl): |
|
||||||
|
|
||||||
enum InputState: |
|
||||||
SingleLine = 0 |
|
||||||
Block = 1 |
|
||||||
|
|
||||||
class LineHistory: |
|
||||||
|
|
||||||
_lines = [] |
|
||||||
_current = 0 |
|
||||||
|
|
||||||
event CurrentLineChanged as EventHandler |
|
||||||
|
|
||||||
def Add([required] line as string): |
|
||||||
if len(line) > 0 and line != LastLine: |
|
||||||
_lines.Add(line) |
|
||||||
_current = len(_lines) |
|
||||||
|
|
||||||
LastLine as string: |
|
||||||
get: |
|
||||||
return null if 0 == len(_lines) |
|
||||||
return _lines[-1] |
|
||||||
|
|
||||||
CurrentLine as string: |
|
||||||
get: |
|
||||||
return null if 0 == len(_lines) |
|
||||||
return _lines[_current] |
|
||||||
|
|
||||||
def Up(): |
|
||||||
MoveTo(_current - 1) |
|
||||||
|
|
||||||
def Down(): |
|
||||||
MoveTo(_current + 1) |
|
||||||
|
|
||||||
def MoveTo(index as int): |
|
||||||
return if 0 == len(_lines) |
|
||||||
old = _current |
|
||||||
_current = index % len(_lines) |
|
||||||
if old != _current: |
|
||||||
CurrentLineChanged(self, EventArgs.Empty) |
|
||||||
|
|
||||||
_state = InputState.SingleLine |
|
||||||
|
|
||||||
_block = System.IO.StringWriter() |
|
||||||
|
|
||||||
[getter(Interpreter)] |
|
||||||
_interpreter as InterpreterContext |
|
||||||
|
|
||||||
_codeCompletionWindow as CodeCompletionWindow |
|
||||||
|
|
||||||
_lineHistory as LineHistory |
|
||||||
|
|
||||||
def constructor([required] interpreter as InterpreterContext): |
|
||||||
self._interpreter = interpreter |
|
||||||
|
|
||||||
self._interpreter.LinePrinted += def(line as string): |
|
||||||
if WorkbenchSingleton.InvokeRequired: |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall({ self.print(line) }) |
|
||||||
else: |
|
||||||
self.print(line) |
|
||||||
self._interpreter.Cleared += def(): |
|
||||||
if WorkbenchSingleton.InvokeRequired: |
|
||||||
WorkbenchSingleton.SafeThreadAsyncCall(self.cls) |
|
||||||
else: |
|
||||||
self.cls() |
|
||||||
self._lineHistory = LineHistory(CurrentLineChanged: _lineHistory_CurrentLineChanged) |
|
||||||
self.Document.HighlightingStrategy = GetBooHighlighting() |
|
||||||
self.EnableFolding = false |
|
||||||
self.ShowLineNumbers = false |
|
||||||
self.ShowSpaces = false |
|
||||||
self.ShowTabs = true |
|
||||||
self.ShowEOLMarkers = false |
|
||||||
self.AllowCaretBeyondEOL = false |
|
||||||
self.ShowInvalidLines = false |
|
||||||
self.Dock = DockStyle.Fill |
|
||||||
|
|
||||||
CaretColumn: |
|
||||||
get: |
|
||||||
return self.ActiveTextAreaControl.Caret.Column |
|
||||||
|
|
||||||
CurrentLineText: |
|
||||||
get: |
|
||||||
segment = GetLastLineSegment() |
|
||||||
return self.Document.GetText(segment)[4:] |
|
||||||
|
|
||||||
override def OnLoad(args as EventArgs): |
|
||||||
super(args) |
|
||||||
prompt() |
|
||||||
|
|
||||||
def Eval(code as string): |
|
||||||
try: |
|
||||||
_interpreter.RunCommand(code) |
|
||||||
ensure: |
|
||||||
_state = InputState.SingleLine |
|
||||||
|
|
||||||
private def ConsumeCurrentLine(): |
|
||||||
text as string = CurrentLineText # was accessing Control.text member |
|
||||||
_lineHistory.Add(text) |
|
||||||
print("") |
|
||||||
return text |
|
||||||
|
|
||||||
private def GetLastLineSegment(): |
|
||||||
return self.Document.GetLineSegment(self.Document.LineSegmentCollection.Count) |
|
||||||
|
|
||||||
private def SingleLineInputState(): |
|
||||||
code = ConsumeCurrentLine() |
|
||||||
if code[-1:] in (":", "\\"): |
|
||||||
_state = InputState.Block |
|
||||||
_block.GetStringBuilder().Length = 0 |
|
||||||
_block.WriteLine(code) |
|
||||||
else: |
|
||||||
Eval(code) |
|
||||||
|
|
||||||
private def BlockInputState(): |
|
||||||
code = ConsumeCurrentLine() |
|
||||||
if 0 == len(code): |
|
||||||
Eval(_block.ToString()) |
|
||||||
else: |
|
||||||
_block.WriteLine(code) |
|
||||||
|
|
||||||
def print(msg as string): |
|
||||||
AppendText(msg + "\r\n") |
|
||||||
|
|
||||||
def prompt(): |
|
||||||
AppendText((">>> ", "... ")[_state]) |
|
||||||
|
|
||||||
def ClearLine(): |
|
||||||
segment = GetLastLineSegment() |
|
||||||
self.Document.Replace(segment.Offset + 4, |
|
||||||
self.CurrentLineText.Length, |
|
||||||
"") |
|
||||||
|
|
||||||
def AppendText(text as string): |
|
||||||
segment = GetLastLineSegment() |
|
||||||
self.Document.Insert(segment.Offset + segment.TotalLength, text) |
|
||||||
MoveCaretToEnd() |
|
||||||
|
|
||||||
def MoveCaretToEnd(): |
|
||||||
segment = GetLastLineSegment() |
|
||||||
newOffset = segment.Offset + segment.TotalLength |
|
||||||
MoveCaretToOffset(newOffset) |
|
||||||
|
|
||||||
def MoveCaretToOffset(offset as int): |
|
||||||
self.ActiveTextAreaControl.Caret.Position = self.Document.OffsetToPosition(offset) |
|
||||||
|
|
||||||
override def InitializeTextAreaControl(newControl as TextAreaControl): |
|
||||||
super(newControl) |
|
||||||
newControl.TextArea.DoProcessDialogKey += HandleDialogKey |
|
||||||
newControl.TextArea.KeyEventHandler += HandleKeyPress |
|
||||||
|
|
||||||
InCodeCompletion: |
|
||||||
get: |
|
||||||
return _codeCompletionWindow is not null and not _codeCompletionWindow.IsDisposed |
|
||||||
|
|
||||||
private def DotComplete(ch as System.Char): |
|
||||||
suggestions = GetSuggestions() |
|
||||||
if suggestions is not null: |
|
||||||
ShowCompletionWindow(CodeCompletionDataProvider(suggestions), ch) |
|
||||||
|
|
||||||
private def ShowCompletionWindow(completionDataProvider, ch as System.Char): |
|
||||||
_codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( |
|
||||||
self.ParentForm, |
|
||||||
self, |
|
||||||
"<code>", |
|
||||||
completionDataProvider, |
|
||||||
ch) |
|
||||||
if _codeCompletionWindow is not null: |
|
||||||
_codeCompletionWindow.Closed += def(): |
|
||||||
_codeCompletionWindow = null |
|
||||||
|
|
||||||
private def CtrlSpaceComplete(): |
|
||||||
ShowCompletionWindow(GlobalsCompletionDataProvider(self._interpreter), char('\0')) |
|
||||||
|
|
||||||
private def GetSuggestions(): |
|
||||||
code = CurrentLineText.Insert(self.CaretColumn-4, ".__codecomplete__") |
|
||||||
code = code.Insert(0, _block.ToString()) if InputState.Block == _state |
|
||||||
return _interpreter.SuggestCodeCompletion(code) |
|
||||||
|
|
||||||
private def HandleDialogKey(key as Keys): |
|
||||||
return false if InCodeCompletion |
|
||||||
|
|
||||||
if key == Keys.Enter: |
|
||||||
try: |
|
||||||
(SingleLineInputState, BlockInputState)[_state]() |
|
||||||
except x: |
|
||||||
print(x.ToString()) |
|
||||||
prompt() |
|
||||||
return true |
|
||||||
|
|
||||||
if key == Keys.Up: |
|
||||||
_lineHistory.Up() |
|
||||||
return true |
|
||||||
if key == Keys.Down: |
|
||||||
_lineHistory.Down() |
|
||||||
return true |
|
||||||
|
|
||||||
if key == (Keys.Control | Keys.Space): |
|
||||||
CtrlSpaceComplete() |
|
||||||
return true |
|
||||||
|
|
||||||
if key in (Keys.Home, Keys.Shift|Keys.Home, Keys.Control|Keys.Home): |
|
||||||
MoveCaretToOffset(GetLastLineSegment().Offset + 4) |
|
||||||
return true |
|
||||||
|
|
||||||
if key == Keys.Escape: |
|
||||||
ClearLine() |
|
||||||
return true |
|
||||||
|
|
||||||
if key in (Keys.Back, Keys.Left): |
|
||||||
if self.CaretColumn < 5: |
|
||||||
return true |
|
||||||
else: |
|
||||||
if self.CaretColumn < 4: |
|
||||||
MoveCaretToEnd() |
|
||||||
|
|
||||||
return false |
|
||||||
|
|
||||||
private def HandleKeyPress(ch as System.Char) as bool: |
|
||||||
if InCodeCompletion: |
|
||||||
_codeCompletionWindow.ProcessKeyEvent(ch) |
|
||||||
|
|
||||||
if ch == "."[0]: |
|
||||||
DotComplete(ch) |
|
||||||
|
|
||||||
return false |
|
||||||
|
|
||||||
private def cls(): |
|
||||||
self.Document.TextContent = "" |
|
||||||
self.ActiveTextAreaControl.Refresh() |
|
||||||
|
|
||||||
private def _lineHistory_CurrentLineChanged(): |
|
||||||
segment = GetLastLineSegment() |
|
||||||
self.Document.Replace(segment.Offset + 4, |
|
||||||
self.CurrentLineText.Length, |
|
||||||
_lineHistory.CurrentLine) |
|
||||||
|
|
||||||
def GetBooHighlighting(): |
|
||||||
return HighlightingManager.Manager.FindHighlighter("Boo") |
|
||||||
@ -1,51 +0,0 @@ |
|||||||
// <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 |
|
||||||
@ -1,125 +0,0 @@ |
|||||||
// <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 |
|
||||||
import System.Windows.Forms |
|
||||||
import ICSharpCode.Core |
|
||||||
import ICSharpCode.SharpDevelop.Gui |
|
||||||
|
|
||||||
class InterpreterPad(AbstractPadContent, IClipboardHandler): |
|
||||||
public static Instance as InterpreterPad: |
|
||||||
get: |
|
||||||
return WorkbenchSingleton.Workbench.GetPad(InterpreterPad).PadContent |
|
||||||
|
|
||||||
_contexts = [] |
|
||||||
_currentContext as ContextEntry |
|
||||||
_toolStrip = ToolStrip(GripStyle: ToolStripGripStyle.Hidden) |
|
||||||
_panel = Panel() |
|
||||||
_initDone |
|
||||||
|
|
||||||
def constructor(): |
|
||||||
_panel.Controls.Add(_toolStrip) |
|
||||||
for context as InterpreterContext in AddInTree.GetTreeNode("/AddIns/InterpreterAddIn/InterpreterContexts").BuildChildItemsArrayList(self): |
|
||||||
AddInterpreterContext(context) |
|
||||||
ActivateFirstVisibleContext() |
|
||||||
UpdateToolBarVisible() |
|
||||||
_initDone = true |
|
||||||
|
|
||||||
def AddInterpreterContext([required] context as InterpreterContext): |
|
||||||
newContext = ContextEntry(context, self) |
|
||||||
_toolStrip.Items.Add(newContext.ToolBarItem) |
|
||||||
_contexts.Add(newContext) |
|
||||||
UpdateToolBarVisible() if _initDone |
|
||||||
return newContext |
|
||||||
|
|
||||||
def RemoveInterpreterContext([required] context as InterpreterContext): |
|
||||||
for c as ContextEntry in _contexts: |
|
||||||
if c.Context is context: |
|
||||||
RemoveInterpreterContext(c) |
|
||||||
return |
|
||||||
|
|
||||||
def RemoveInterpreterContext([required] context as ContextEntry): |
|
||||||
_contexts.Remove(context) |
|
||||||
_toolStrip.Items.Remove(context.ToolBarItem) |
|
||||||
ActivateFirstVisibleContext() if self.CurrentContext is context |
|
||||||
UpdateToolBarVisible() |
|
||||||
|
|
||||||
def UpdateToolBarVisible(): |
|
||||||
count = 0 |
|
||||||
for c as ContextEntry in _contexts: |
|
||||||
count += 1 if c.Context.Visible |
|
||||||
_toolStrip.Visible = (count > 1) |
|
||||||
|
|
||||||
def ActivateFirstVisibleContext(): |
|
||||||
for c as ContextEntry in _contexts: |
|
||||||
if c.Context.Visible: |
|
||||||
self.CurrentContext = c |
|
||||||
return |
|
||||||
self.CurrentContext = null |
|
||||||
|
|
||||||
Control as Control: |
|
||||||
get: |
|
||||||
return _panel |
|
||||||
|
|
||||||
public Contexts: |
|
||||||
get: |
|
||||||
return System.Collections.ArrayList.ReadOnly(_contexts) |
|
||||||
|
|
||||||
CurrentContext: |
|
||||||
get: |
|
||||||
return _currentContext |
|
||||||
set: |
|
||||||
return if _currentContext is value |
|
||||||
if _currentContext is not null: |
|
||||||
_panel.Controls.Remove(_currentContext.InterpreterControl) |
|
||||||
if value is not null: |
|
||||||
_panel.Controls.Add(value.InterpreterControl) |
|
||||||
_panel.Controls.SetChildIndex(_toolStrip, 1) |
|
||||||
_currentContext = value |
|
||||||
for c as ContextEntry in _contexts: |
|
||||||
c.ToolBarItem.Checked = c is value |
|
||||||
|
|
||||||
CurrentTextArea: |
|
||||||
get: |
|
||||||
return _currentContext.InterpreterControl.ActiveTextAreaControl.TextArea |
|
||||||
|
|
||||||
EnableCut: |
|
||||||
get: |
|
||||||
return CurrentTextArea.ClipboardHandler.EnableCut |
|
||||||
|
|
||||||
EnableCopy: |
|
||||||
get: |
|
||||||
return CurrentTextArea.ClipboardHandler.EnableCopy |
|
||||||
|
|
||||||
EnablePaste: |
|
||||||
get: |
|
||||||
return CurrentTextArea.ClipboardHandler.EnablePaste |
|
||||||
|
|
||||||
EnableDelete: |
|
||||||
get: |
|
||||||
return CurrentTextArea.ClipboardHandler.EnableDelete |
|
||||||
|
|
||||||
EnableSelectAll: |
|
||||||
get: |
|
||||||
return CurrentTextArea.ClipboardHandler.EnableSelectAll |
|
||||||
|
|
||||||
def Cut(): |
|
||||||
CurrentTextArea.ClipboardHandler.Cut(null, null) |
|
||||||
|
|
||||||
def Copy(): |
|
||||||
CurrentTextArea.ClipboardHandler.Copy(null, null) |
|
||||||
|
|
||||||
def Paste(): |
|
||||||
CurrentTextArea.ClipboardHandler.Paste(null, null) |
|
||||||
|
|
||||||
def Delete(): |
|
||||||
CurrentTextArea.ClipboardHandler.Delete(null, null) |
|
||||||
|
|
||||||
def SelectAll(): |
|
||||||
CurrentTextArea.ClipboardHandler.SelectAll(null, null) |
|
||||||
@ -1,11 +0,0 @@ |
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
||||||
<PropertyGroup> |
|
||||||
<PrepareForRunDependsOn>$(PrepareForRunDependsOn);MyPostBuildTarget</PrepareForRunDependsOn> |
|
||||||
</PropertyGroup> |
|
||||||
<ItemGroup> |
|
||||||
<MyCopyItem Include="$(MSBuildProjectDirectory)\*.addin" /> |
|
||||||
</ItemGroup> |
|
||||||
<Target Name="MyPostBuildTarget"> |
|
||||||
<Copy SourceFiles="@(MyCopyItem)" DestinationFolder="$(OutputPath)" /> |
|
||||||
</Target> |
|
||||||
</Project> |
|
||||||
@ -0,0 +1,123 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Reflection; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using Boo.Lang.Interpreter; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace Grunwald.BooBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interactive Boo interpreter.
|
||||||
|
/// </summary>
|
||||||
|
public class InteractiveInterpreterPad : TextEditorBasedPad |
||||||
|
{ |
||||||
|
InteractiveInterpreterControl ctl = new InteractiveInterpreterControl(); |
||||||
|
|
||||||
|
public override ICSharpCode.TextEditor.TextEditorControl TextEditorControl { |
||||||
|
get { |
||||||
|
return ctl; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
sealed class InteractiveInterpreterControl : CommandPromptControl |
||||||
|
{ |
||||||
|
InteractiveInterpreter interpreter; |
||||||
|
|
||||||
|
public InteractiveInterpreterControl() |
||||||
|
{ |
||||||
|
SetHighlighting("Boo"); |
||||||
|
PrintPrompt(); |
||||||
|
} |
||||||
|
|
||||||
|
void PrintLine(object text) |
||||||
|
{ |
||||||
|
if (text == null) |
||||||
|
return; |
||||||
|
if (WorkbenchSingleton.InvokeRequired) { |
||||||
|
WorkbenchSingleton.SafeThreadAsyncCall(PrintLine, text); |
||||||
|
} else { |
||||||
|
if (processing) |
||||||
|
Append(Environment.NewLine + text.ToString()); |
||||||
|
else |
||||||
|
InsertLineBeforePrompt(text.ToString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void PrintPromptInternal() |
||||||
|
{ |
||||||
|
Append(">>> "); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void AcceptCommand(string command) |
||||||
|
{ |
||||||
|
if (command.EndsWith("\n")) { |
||||||
|
ProcessCommand(command); |
||||||
|
} else if (!command.Contains("\n") && !command.EndsWith(":")) { |
||||||
|
ProcessCommand(command); |
||||||
|
} else { |
||||||
|
Append(Environment.NewLine); |
||||||
|
ActiveTextAreaControl.Caret.Position = this.Document.OffsetToPosition(this.Document.TextLength); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool processing; |
||||||
|
|
||||||
|
void AddReference(Assembly asm) |
||||||
|
{ |
||||||
|
if (!interpreter.References.Contains(asm)) { |
||||||
|
interpreter.References.Add(asm); |
||||||
|
foreach (AssemblyName an in asm.GetReferencedAssemblies()) { |
||||||
|
AddReference(Assembly.Load(an.FullName)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ProcessCommand(string command) |
||||||
|
{ |
||||||
|
if (interpreter == null) { |
||||||
|
interpreter = new InteractiveInterpreter(); |
||||||
|
interpreter.RememberLastValue = true; |
||||||
|
interpreter.Print = PrintLine; |
||||||
|
interpreter.SetValue("cls", new Action(Clear)); |
||||||
|
|
||||||
|
AddReference(typeof(WorkbenchSingleton).Assembly); |
||||||
|
|
||||||
|
interpreter.LoopEval("import System\n" + |
||||||
|
"import System.Collections.Generic\n" + |
||||||
|
"import System.IO\n" + |
||||||
|
"import System.Text"); |
||||||
|
} |
||||||
|
processing = true; |
||||||
|
try { |
||||||
|
interpreter.LoopEval(command); |
||||||
|
} catch (System.Reflection.TargetInvocationException ex) { |
||||||
|
PrintLine(ex.InnerException); |
||||||
|
} |
||||||
|
processing = false; |
||||||
|
if (this.Document.TextLength != 0) { |
||||||
|
Append(Environment.NewLine); |
||||||
|
} |
||||||
|
PrintPrompt(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void Clear() |
||||||
|
{ |
||||||
|
if (WorkbenchSingleton.InvokeRequired) { |
||||||
|
WorkbenchSingleton.SafeThreadAsyncCall(Clear); |
||||||
|
} else { |
||||||
|
base.Clear(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,118 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
using System; |
||||||
|
using ICSharpCode.TextEditor; |
||||||
|
using ICSharpCode.TextEditor.Document; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// A text area used for an interactive command prompt.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class CommandPromptControl : SharpDevelopTextAreaControl |
||||||
|
{ |
||||||
|
TextMarker readOnlyMarker; |
||||||
|
int promptStartOffset; |
||||||
|
int promptEndOffset; |
||||||
|
|
||||||
|
public CommandPromptControl() |
||||||
|
: base(false, false) |
||||||
|
{ |
||||||
|
this.TextEditorProperties.SupportReadOnlySegments = true; |
||||||
|
this.TextEditorProperties.ShowLineNumbers = false; |
||||||
|
base.contextMenuPath = null; |
||||||
|
} |
||||||
|
|
||||||
|
protected void PrintPrompt() |
||||||
|
{ |
||||||
|
promptStartOffset = this.Document.TextLength; |
||||||
|
PrintPromptInternal(); |
||||||
|
promptEndOffset = this.Document.TextLength; |
||||||
|
MakeReadOnly(); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void Clear() |
||||||
|
{ |
||||||
|
if (readOnlyMarker != null) |
||||||
|
this.Document.MarkerStrategy.RemoveMarker(readOnlyMarker); |
||||||
|
this.Document.Remove(0, this.Document.TextLength); |
||||||
|
this.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); |
||||||
|
this.Document.CommitUpdate(); |
||||||
|
readOnlyMarker = null; |
||||||
|
promptStartOffset = 0; |
||||||
|
promptEndOffset = 0; |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract void PrintPromptInternal(); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the current control content read-only (but still allows appending more content at the end).
|
||||||
|
/// </summary>
|
||||||
|
protected void MakeReadOnly() |
||||||
|
{ |
||||||
|
if (this.Document.TextLength == 0) |
||||||
|
return; |
||||||
|
this.ActiveTextAreaControl.Caret.Position = this.Document.OffsetToPosition(this.Document.TextLength); |
||||||
|
if (readOnlyMarker == null) { |
||||||
|
readOnlyMarker = new TextMarker(0, this.Document.TextLength, TextMarkerType.Invisible) { IsReadOnly = true }; |
||||||
|
this.Document.MarkerStrategy.AddMarker(readOnlyMarker); |
||||||
|
} |
||||||
|
readOnlyMarker.Offset = 0; |
||||||
|
readOnlyMarker.Length = this.Document.TextLength; |
||||||
|
this.Document.UndoStack.ClearAll(); // prevent user from undoing the prompt insertion
|
||||||
|
} |
||||||
|
|
||||||
|
protected override void InitializeTextAreaControl(TextAreaControl newControl) |
||||||
|
{ |
||||||
|
newControl.TextArea.DoProcessDialogKey += HandleDialogKey; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current command (text from end of prompt to end of document)
|
||||||
|
/// </summary>
|
||||||
|
protected string GetCommand() |
||||||
|
{ |
||||||
|
return this.Document.GetText(promptEndOffset, this.Document.TextLength - promptEndOffset); |
||||||
|
} |
||||||
|
|
||||||
|
bool HandleDialogKey(Keys keys) |
||||||
|
{ |
||||||
|
if (keys == Keys.Enter) { |
||||||
|
AcceptCommand(GetCommand()); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Causes evaluation of a command when the user presses Enter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">The command to evaluate.</param>
|
||||||
|
protected abstract void AcceptCommand(string command); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends text at the end of the document.
|
||||||
|
/// </summary>
|
||||||
|
protected void Append(string text) |
||||||
|
{ |
||||||
|
this.Document.Insert(this.Document.TextLength, text); |
||||||
|
} |
||||||
|
|
||||||
|
protected void InsertLineBeforePrompt(string text) |
||||||
|
{ |
||||||
|
text += Environment.NewLine; |
||||||
|
this.Document.Insert(promptStartOffset, text); |
||||||
|
promptStartOffset += text.Length; |
||||||
|
promptEndOffset += text.Length; |
||||||
|
if (readOnlyMarker != null) { |
||||||
|
readOnlyMarker.Offset = 0; |
||||||
|
readOnlyMarker.Length = promptEndOffset; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,176 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Drawing.Printing; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.TextEditor; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of TextEditorBasedPad.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class TextEditorBasedPad : AbstractPadContent, IEditable, IUndoHandler, IPositionable, ITextEditorControlProvider, IPrintable, IToolsHost, IClipboardHandler |
||||||
|
{ |
||||||
|
public abstract TextEditorControl TextEditorControl { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
public override System.Windows.Forms.Control Control { |
||||||
|
get { return this.TextEditorControl; } |
||||||
|
} |
||||||
|
|
||||||
|
bool IUndoHandler.EnableUndo { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.EnableUndo; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool IUndoHandler.EnableRedo { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.EnableRedo; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
string GetText() |
||||||
|
{ |
||||||
|
return this.TextEditorControl.Document.TextContent; |
||||||
|
} |
||||||
|
|
||||||
|
void SetText(string value) |
||||||
|
{ |
||||||
|
this.TextEditorControl.Document.Replace(0, this.TextEditorControl.Document.TextLength, value); |
||||||
|
} |
||||||
|
|
||||||
|
string IEditable.Text { |
||||||
|
get { |
||||||
|
if (WorkbenchSingleton.InvokeRequired) |
||||||
|
return WorkbenchSingleton.SafeThreadFunction<string>(GetText); |
||||||
|
else |
||||||
|
return GetText(); |
||||||
|
} |
||||||
|
set { |
||||||
|
if (WorkbenchSingleton.InvokeRequired) |
||||||
|
WorkbenchSingleton.SafeThreadCall(SetText, value); |
||||||
|
else |
||||||
|
SetText(value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
PrintDocument IPrintable.PrintDocument { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.PrintDocument; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void IUndoHandler.Undo() |
||||||
|
{ |
||||||
|
this.TextEditorControl.Undo(); |
||||||
|
} |
||||||
|
|
||||||
|
void IUndoHandler.Redo() |
||||||
|
{ |
||||||
|
this.TextEditorControl.Redo(); |
||||||
|
} |
||||||
|
|
||||||
|
public override void RedrawContent() |
||||||
|
{ |
||||||
|
this.TextEditorControl.OptionsChanged(); |
||||||
|
this.TextEditorControl.Refresh(); |
||||||
|
} |
||||||
|
|
||||||
|
#region IPositionable implementation
|
||||||
|
void IPositionable.JumpTo(int line, int column) |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.JumpTo(line, column); |
||||||
|
|
||||||
|
// we need to delay this call here because the text editor does not know its height if it was just created
|
||||||
|
WorkbenchSingleton.SafeThreadAsyncCall( |
||||||
|
delegate { |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.CenterViewOn( |
||||||
|
line, (int)(0.3 * this.TextEditorControl.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount)); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
int IPositionable.Line { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.Caret.Line; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int IPositionable.Column { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.Caret.Column; |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
Control IToolsHost.ToolsControl { |
||||||
|
get { return TextEditorSideBar.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
#region ICSharpCode.SharpDevelop.Gui.IClipboardHandler interface implementation
|
||||||
|
public bool EnableCut { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCut; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableCopy { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCopy; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnablePaste { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnablePaste; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableDelete { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableDelete; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableSelectAll { |
||||||
|
get { |
||||||
|
return this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableSelectAll; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SelectAll() |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.SelectAll(null, null); |
||||||
|
} |
||||||
|
|
||||||
|
public void Delete() |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Delete(null, null); |
||||||
|
} |
||||||
|
|
||||||
|
public void Paste() |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Paste(null, null); |
||||||
|
} |
||||||
|
|
||||||
|
public void Copy() |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Copy(null, null); |
||||||
|
} |
||||||
|
|
||||||
|
public void Cut() |
||||||
|
{ |
||||||
|
this.TextEditorControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Cut(null, null); |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue