Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4755 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
10 changed files with 466 additions and 264 deletions
After Width: | Height: | Size: 46 KiB |
@ -0,0 +1,351 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.Core.Presentation; |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
using ICSharpCode.AvalonEdit.Document; |
||||||
|
using ICSharpCode.AvalonEdit.Editing; |
||||||
|
using ICSharpCode.AvalonEdit.Highlighting; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Gui |
||||||
|
{ |
||||||
|
public abstract class AbstractConsolePad : AbstractPadContent, IEditable, IPositionable, ITextEditorProvider, IToolsHost |
||||||
|
{ |
||||||
|
const string toolBarTreePath = "/SharpDevelop/Pads/CommonConsole/ToolBar"; |
||||||
|
|
||||||
|
DockPanel panel; |
||||||
|
ConsoleControl console; |
||||||
|
ToolBar toolbar; |
||||||
|
|
||||||
|
bool cleared; |
||||||
|
IList<string> history; |
||||||
|
int historyPointer; |
||||||
|
|
||||||
|
protected AbstractConsolePad() |
||||||
|
{ |
||||||
|
this.panel = new DockPanel(); |
||||||
|
|
||||||
|
this.toolbar = ToolBarService.CreateToolBar(this, toolBarTreePath); |
||||||
|
this.toolbar.SetValue(DockPanel.DockProperty, Dock.Top); |
||||||
|
|
||||||
|
this.console = new ConsoleControl(); |
||||||
|
|
||||||
|
this.panel.Children.Add(toolbar); |
||||||
|
this.panel.Children.Add(console); |
||||||
|
|
||||||
|
this.history = new List<string>(); |
||||||
|
|
||||||
|
this.console.editor.TextArea.PreviewKeyDown += (sender, e) => { |
||||||
|
e.Handled = HandleInput(e.Key); |
||||||
|
}; |
||||||
|
|
||||||
|
this.InitializeConsole(); |
||||||
|
} |
||||||
|
|
||||||
|
public virtual ITextEditor TextEditor { |
||||||
|
get { |
||||||
|
return console.TextEditor; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override object Control { |
||||||
|
get { return panel; } |
||||||
|
} |
||||||
|
|
||||||
|
string GetText() |
||||||
|
{ |
||||||
|
return this.TextEditor.Document.Text; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a snapshot of the editor content.
|
||||||
|
/// This method is thread-safe.
|
||||||
|
/// </summary>
|
||||||
|
public ITextBuffer CreateSnapshot() |
||||||
|
{ |
||||||
|
return new StringTextBuffer(GetText()); |
||||||
|
} |
||||||
|
|
||||||
|
string IEditable.Text { |
||||||
|
get { |
||||||
|
return GetText(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public virtual ICSharpCode.SharpDevelop.Editor.IDocument GetDocumentForFile(OpenedFile file) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
#region IPositionable implementation
|
||||||
|
void IPositionable.JumpTo(int line, int column) |
||||||
|
{ |
||||||
|
this.TextEditor.JumpTo(line, column); |
||||||
|
} |
||||||
|
|
||||||
|
int IPositionable.Line { |
||||||
|
get { |
||||||
|
return this.TextEditor.Caret.Line; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int IPositionable.Column { |
||||||
|
get { |
||||||
|
return this.TextEditor.Caret.Column; |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
object IToolsHost.ToolsContent { |
||||||
|
get { return TextEditorSideBar.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual bool HandleInput(Key key) { |
||||||
|
switch (key) { |
||||||
|
case Key.Down: |
||||||
|
this.historyPointer = Math.Min(this.historyPointer + 1, this.history.Count); |
||||||
|
if (this.historyPointer == this.history.Count) |
||||||
|
console.CommandText = ""; |
||||||
|
else |
||||||
|
console.CommandText = this.history[this.historyPointer]; |
||||||
|
console.editor.ScrollToEnd(); |
||||||
|
return true; |
||||||
|
case Key.Up: |
||||||
|
this.historyPointer = Math.Max(this.historyPointer - 1, 0); |
||||||
|
if (this.historyPointer == this.history.Count) |
||||||
|
console.CommandText = ""; |
||||||
|
else |
||||||
|
console.CommandText = this.history[this.historyPointer]; |
||||||
|
console.editor.ScrollToEnd(); |
||||||
|
return true; |
||||||
|
case Key.Return: |
||||||
|
if (Keyboard.Modifiers == ModifierKeys.Shift) |
||||||
|
return false; |
||||||
|
string commandText = console.CommandText; |
||||||
|
this.console.TextEditor.Document.Insert(this.console.TextEditor.Document.TextLength, "\n"); |
||||||
|
if (!string.IsNullOrEmpty(commandText)) |
||||||
|
AcceptCommand(commandText); |
||||||
|
if (!cleared) |
||||||
|
AppendPrompt(); |
||||||
|
else |
||||||
|
console.CommandText = ""; |
||||||
|
cleared = false; |
||||||
|
this.history.Add(commandText); |
||||||
|
this.historyPointer = this.history.Count; |
||||||
|
console.editor.ScrollToEnd(); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the content of the console and prints a new prompt.
|
||||||
|
/// </summary>
|
||||||
|
public void ClearConsole() |
||||||
|
{ |
||||||
|
this.console.editor.Document.Text = ""; |
||||||
|
cleared = true; |
||||||
|
AppendPrompt(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the console history.
|
||||||
|
/// </summary>
|
||||||
|
public void DeleteHistory() |
||||||
|
{ |
||||||
|
this.history.Clear(); |
||||||
|
this.historyPointer = 0; |
||||||
|
} |
||||||
|
|
||||||
|
public void SetHighlighting(string language) |
||||||
|
{ |
||||||
|
this.console.SetHighlighting(language); |
||||||
|
} |
||||||
|
|
||||||
|
public bool WordWrap { |
||||||
|
get { return this.console.editor.WordWrap; } |
||||||
|
set { this.console.editor.WordWrap = value; } |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract string Prompt { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract void AcceptCommand(string command); |
||||||
|
|
||||||
|
protected virtual void InitializeConsole() |
||||||
|
{ |
||||||
|
AppendPrompt(); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void AppendPrompt() |
||||||
|
{ |
||||||
|
console.Append(Prompt); |
||||||
|
console.SetReadonly(); |
||||||
|
console.editor.Document.UndoStack.ClearAll(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void Append(string text) |
||||||
|
{ |
||||||
|
console.Append(text); |
||||||
|
} |
||||||
|
|
||||||
|
protected void InsertLineBeforePrompt(string text) |
||||||
|
{ |
||||||
|
text += Environment.NewLine; |
||||||
|
this.console.editor.Document.Insert(this.console.readOnlyRegion.EndOffset - Prompt.Length, text); |
||||||
|
this.console.SetReadonly(this.console.readOnlyRegion.EndOffset + text.Length); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void Clear() |
||||||
|
{ |
||||||
|
this.ClearConsole(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class ConsoleControl : Grid |
||||||
|
{ |
||||||
|
internal AvalonEdit.TextEditor editor; |
||||||
|
internal BeginReadOnlySectionProvider readOnlyRegion; |
||||||
|
|
||||||
|
public ConsoleControl() |
||||||
|
{ |
||||||
|
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); |
||||||
|
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); |
||||||
|
|
||||||
|
this.editor = new ICSharpCode.AvalonEdit.TextEditor(); |
||||||
|
this.editor.SetValue(Grid.ColumnProperty, 0); |
||||||
|
this.editor.SetValue(Grid.RowProperty, 0); |
||||||
|
|
||||||
|
this.editor.Background = Brushes.White; |
||||||
|
this.editor.FontFamily = new FontFamily("Consolas"); |
||||||
|
this.editor.FontSize = 13; |
||||||
|
this.Children.Add(editor); |
||||||
|
|
||||||
|
editor.TextArea.ReadOnlySectionProvider = readOnlyRegion = new BeginReadOnlySectionProvider(); |
||||||
|
} |
||||||
|
|
||||||
|
public ITextEditor TextEditor { |
||||||
|
get { |
||||||
|
return new AvalonEditTextEditorAdapter(editor); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SetHighlighting(string language) |
||||||
|
{ |
||||||
|
editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition(language); |
||||||
|
} |
||||||
|
|
||||||
|
public void Append(string text) |
||||||
|
{ |
||||||
|
editor.AppendText(text); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the readonly region to a specified offset.
|
||||||
|
/// </summary>
|
||||||
|
public void SetReadonly(int offset) |
||||||
|
{ |
||||||
|
readOnlyRegion.EndOffset = offset; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the readonly region to the end of the document.
|
||||||
|
/// </summary>
|
||||||
|
public void SetReadonly() |
||||||
|
{ |
||||||
|
readOnlyRegion.EndOffset = editor.Document.TextLength; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets the command text displayed at the command prompt.
|
||||||
|
/// </summary>
|
||||||
|
public string CommandText { |
||||||
|
get { |
||||||
|
return editor.Document.GetText(new TextSegment() { StartOffset = readOnlyRegion.EndOffset, EndOffset = editor.Document.TextLength }); |
||||||
|
} |
||||||
|
set { |
||||||
|
editor.Document.Replace(new TextSegment() { StartOffset = readOnlyRegion.EndOffset, EndOffset = editor.Document.TextLength }, value); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class BeginReadOnlySectionProvider : IReadOnlySectionProvider |
||||||
|
{ |
||||||
|
public int EndOffset { get; set; } |
||||||
|
|
||||||
|
public bool CanInsert(int offset) |
||||||
|
{ |
||||||
|
return offset >= EndOffset; |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<ISegment> GetDeletableSegments(ISegment segment) |
||||||
|
{ |
||||||
|
return new[] { |
||||||
|
new TextSegment() { |
||||||
|
StartOffset = Math.Max(this.EndOffset, segment.Offset), |
||||||
|
EndOffset = segment.EndOffset |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class ClearConsoleCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
var pad = this.Owner as AbstractConsolePad; |
||||||
|
if (pad != null) |
||||||
|
pad.ClearConsole(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class DeleteHistoryCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
var pad = this.Owner as AbstractConsolePad; |
||||||
|
if (pad != null) |
||||||
|
pad.DeleteHistory(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class ToggleConsoleWordWrapCommand : AbstractCheckableMenuCommand |
||||||
|
{ |
||||||
|
AbstractConsolePad pad; |
||||||
|
|
||||||
|
public override object Owner { |
||||||
|
get { return base.Owner; } |
||||||
|
set { |
||||||
|
if (!(value is AbstractConsolePad)) |
||||||
|
throw new Exception("Owner has to be a AbstractConsolePad"); |
||||||
|
pad = value as AbstractConsolePad; |
||||||
|
base.Owner = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsChecked { |
||||||
|
get { return pad.WordWrap; } |
||||||
|
set { pad.WordWrap = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
IsChecked = !IsChecked; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,186 +0,0 @@ |
|||||||
// <file>
|
|
||||||
// <copyright see="prj:///doc/copyright.txt"/>
|
|
||||||
// <license see="prj:///doc/license.txt"/>
|
|
||||||
// <author name="Daniel Grunwald"/>
|
|
||||||
// <version>$Revision$</version>
|
|
||||||
// </file>
|
|
||||||
|
|
||||||
using ICSharpCode.SharpDevelop.Editor; |
|
||||||
using System; |
|
||||||
using System.Drawing.Printing; |
|
||||||
using System.Windows.Forms; |
|
||||||
using ICSharpCode.SharpDevelop.Gui; |
|
||||||
using ICSharpCode.TextEditor; |
|
||||||
using ICSharpCode.TextEditor.Document; |
|
||||||
|
|
||||||
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 virtual ICSharpCode.SharpDevelop.Editor.ITextEditor TextEditor { |
|
||||||
get { |
|
||||||
return new TextEditorAdapter(this.TextEditorControl); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override object 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); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a snapshot of the editor content.
|
|
||||||
/// This method is thread-safe.
|
|
||||||
/// </summary>
|
|
||||||
public ITextBuffer CreateSnapshot() |
|
||||||
{ |
|
||||||
string content = WorkbenchSingleton.SafeThreadFunction<string>(GetText); |
|
||||||
return new StringTextBuffer(content); |
|
||||||
} |
|
||||||
|
|
||||||
string IEditable.Text { |
|
||||||
get { |
|
||||||
if (WorkbenchSingleton.InvokeRequired) |
|
||||||
return WorkbenchSingleton.SafeThreadFunction<string>(GetText); |
|
||||||
else |
|
||||||
return GetText(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public virtual ICSharpCode.SharpDevelop.Editor.IDocument GetDocumentForFile(OpenedFile file) |
|
||||||
{ |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
PrintDocument IPrintable.PrintDocument { |
|
||||||
get { |
|
||||||
return this.TextEditorControl.PrintDocument; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void IUndoHandler.Undo() |
|
||||||
{ |
|
||||||
this.TextEditorControl.Undo(); |
|
||||||
} |
|
||||||
|
|
||||||
void IUndoHandler.Redo() |
|
||||||
{ |
|
||||||
this.TextEditorControl.Redo(); |
|
||||||
} |
|
||||||
|
|
||||||
#region IPositionable implementation
|
|
||||||
void IPositionable.JumpTo(int line, int column) |
|
||||||
{ |
|
||||||
this.TextEditorControl.ActiveTextAreaControl.JumpTo(line - 1, column - 1); |
|
||||||
|
|
||||||
// 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 - 1, (int)(0.3 * this.TextEditorControl.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount)); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
int IPositionable.Line { |
|
||||||
get { |
|
||||||
return this.TextEditorControl.ActiveTextAreaControl.Caret.Line + 1; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
int IPositionable.Column { |
|
||||||
get { |
|
||||||
return this.TextEditorControl.ActiveTextAreaControl.Caret.Column + 1; |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
object IToolsHost.ToolsContent { |
|
||||||
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
|
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
Loading…
Reference in new issue