From 39502aacab8624c9d39fe9b0c4ced1d6ce4b0163 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 21 Jul 2009 06:58:56 +0000 Subject: [PATCH] Added history functionality to Boo Interpreter and Debugger Console git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4504 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Gui/Editor/CommandPromptControl.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CommandPromptControl.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CommandPromptControl.cs index 13fba1e49b..a56f85bb8f 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CommandPromptControl.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CommandPromptControl.cs @@ -5,9 +5,11 @@ // $Revision$ // using System; +using System.Collections.Generic; +using System.Windows.Forms; + using ICSharpCode.TextEditor; using ICSharpCode.TextEditor.Document; -using System.Windows.Forms; namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor { @@ -19,12 +21,15 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor TextMarker readOnlyMarker; int promptStartOffset; int promptEndOffset; + IList history; + int historyPointer; public CommandPromptControl() : base(false, false) { this.TextEditorProperties.SupportReadOnlySegments = true; this.TextEditorProperties.ShowLineNumbers = false; + this.history = new List(); base.contextMenuPath = null; } @@ -80,11 +85,36 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor return this.Document.GetText(promptEndOffset, this.Document.TextLength - promptEndOffset); } + /// + /// Sets the current command + /// + protected void SetCommand(string cmd) + { + this.Document.Replace(promptEndOffset, this.Document.TextLength - promptEndOffset, cmd); + this.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, this.Document.GetLineNumberForOffset(promptEndOffset))); + this.Document.CommitUpdate(); + this.ActiveTextAreaControl.Caret.Position = this.Document.OffsetToPosition(this.Document.TextLength); + } + bool HandleDialogKey(Keys keys) { - if (keys == Keys.Enter) { - AcceptCommand(GetCommand()); - return true; + switch (keys) { + case Keys.Enter: + history.Add(GetCommand()); + historyPointer = history.Count; + AcceptCommand(GetCommand()); + return true; + case Keys.Up: + historyPointer = Math.Max(historyPointer - 1, 0); + SetCommand(history[historyPointer]); + return true; + case Keys.Down: + historyPointer = Math.Min(historyPointer + 1, history.Count); + if (historyPointer == history.Count) + SetCommand(string.Empty); + else + SetCommand(history[historyPointer]); + return true; } return false; }