From dd315fcf543db060e6751de33d379232cb37be48 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Wed, 18 Feb 2009 19:33:40 +0000 Subject: [PATCH] Pressing the up key in the Python Console no longer closes the completion window if there is command history. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3816 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../PythonBinding/Project/Src/ITextEditor.cs | 5 ++ .../Project/Src/PythonConsole.cs | 4 ++ .../PythonBinding/Project/Src/TextEditor.cs | 4 ++ ...ssedWhenCompletionWindowOpenTestFixture.cs | 57 +++++++++++++++++++ .../Test/Console/MockTextEditor.cs | 7 +++ .../Test/PythonBinding.Tests.csproj | 1 + 6 files changed, 78 insertions(+) create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs index f11c3e6117..e5fb1235e0 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ITextEditor.cs @@ -93,6 +93,11 @@ namespace ICSharpCode.PythonBinding /// Shows the code completion window. /// void ShowCompletionWindow(ICompletionDataProvider completionDataProvider); + + /// + /// Indicates whether the completion window is currently being displayed. + /// + bool IsCompletionWindowDisplayed {get;} /// /// Makes the current text content read only. Text can be entered at the end. diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs index f8901c027b..434394315b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs @@ -212,6 +212,10 @@ namespace ICSharpCode.PythonBinding /// bool ProcessDialogKeyPress(Keys keyData) { + if (textEditor.IsCompletionWindowDisplayed) { + return false; + } + if (IsInReadOnlyRegion) { switch (keyData) { case Keys.Left: diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs index e5b0b324ed..f63e3be68b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/TextEditor.cs @@ -158,6 +158,10 @@ namespace ICSharpCode.PythonBinding } } + public bool IsCompletionWindowDisplayed { + get { return completionWindow != null; } + } + /// /// Gets the range of the currently selected text. /// diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs new file mode 100644 index 0000000000..1a64744be0 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/KeysPressedWhenCompletionWindowOpenTestFixture.cs @@ -0,0 +1,57 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows.Forms; + +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop; +using ICSharpCode.TextEditor.Gui.CompletionWindow; +using Microsoft.Scripting.Hosting.Shell; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Console +{ + /// + /// Pressing the up key closes the completion window when it should not. This fixture tests + /// that the up, down, home and end key do not close this window. + /// + [TestFixture] + public class KeysPressedWhenCompletionWindowOpenTestFixture + { + PythonConsole pythonConsole; + MockTextEditor textEditor; + string prompt = ">>> "; + + [SetUp] + public void Init() + { + textEditor = new MockTextEditor(); + pythonConsole = new PythonConsole(textEditor, null); + pythonConsole.Write(prompt, Style.Prompt); + + textEditor.RaiseKeyPressEvent('a'); + textEditor.RaiseDialogKeyPressEvent(Keys.Enter); + pythonConsole.Write(prompt, Style.Prompt); + textEditor.RaiseKeyPressEvent('b'); + textEditor.RaiseKeyPressEvent('.'); + } + + [Test] + public void UpKeyDoesNothing() + { + Assert.IsFalse(textEditor.RaiseDialogKeyPressEvent(Keys.Up)); + } + + [Test] + public void DownKeyDoesNothing() + { + Assert.IsFalse(textEditor.RaiseDialogKeyPressEvent(Keys.Down)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs index ee1c9a2bd2..13b3b6bccf 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Console/MockTextEditor.cs @@ -33,6 +33,7 @@ namespace PythonBinding.Tests.Console bool showCompletionWindowCalled; bool makeReadOnlyCalled; ICompletionDataProvider completionProvider; + bool completionWindowDisplayed; public MockTextEditor() { @@ -210,9 +211,15 @@ namespace PythonBinding.Tests.Console public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider) { showCompletionWindowCalled = true; + completionWindowDisplayed = true; this.completionProvider = completionDataProvider; } + public bool IsCompletionWindowDisplayed { + get { return completionWindowDisplayed; } + set { completionWindowDisplayed = value; } + } + public void MakeCurrentContentReadOnly() { makeReadOnlyCalled = true; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 215a716856..2e18bcd4d4 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -70,6 +70,7 @@ +