From 3c212c5839892c3999c97dda638600c275f2f884 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 12 Feb 2010 14:16:21 +0000 Subject: [PATCH] Improved F# interactive pad. Add InitiallyFocusedControl to pads. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5498 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/InteractiveInterpreter.cs | 2 +- .../FSharpBinding/FSharpBinding.addin | 3 +- .../FSharpBinding/FSharpInteractive.cs | 99 +++++++++---------- .../Project/Src/RecentProjectsControl.xaml | 4 +- .../Project/Src/RecentProjectsControl.xaml.cs | 1 + .../Project/Src/StartPageControl.xaml | 2 +- .../Project/Src/Gui/AbstractPadContent.cs | 8 ++ .../Project/Src/Gui/AbstractViewContent.cs | 2 +- src/Main/Base/Project/Src/Gui/IPadContent.cs | 9 +- .../Src/Gui/Pads/AbstractConsolePad.cs | 33 +++++-- .../Base/Project/Src/Gui/Pads/FileScout.cs | 6 ++ .../Gui/Workbench/Layouts/AvalonPadContent.cs | 12 +++ 12 files changed, 112 insertions(+), 69 deletions(-) diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/InteractiveInterpreter.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/InteractiveInterpreter.cs index efc56430f4..1b14872de1 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/InteractiveInterpreter.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/InteractiveInterpreter.cs @@ -95,7 +95,7 @@ namespace Grunwald.BooBinding if (processing) AppendLine(text.ToString()); else - InsertLineBeforePrompt(text.ToString()); + InsertBeforePrompt(text.ToString() + Environment.NewLine); } } diff --git a/src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin b/src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin index 7a76fb57a3..d305fa0cd9 100644 --- a/src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin +++ b/src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin @@ -101,7 +101,8 @@ category = "Main" title = "F# Interactive" icon = "F#.ProjectIcon" - class = "FSharpBinding.FSharpInteractive"/> + class = "FSharpBinding.FSharpInteractive" + defaultPosition = "Bottom, Hidden" /> diff --git a/src/AddIns/BackendBindings/FSharpBinding/FSharpInteractive.cs b/src/AddIns/BackendBindings/FSharpBinding/FSharpInteractive.cs index 7621a23ef2..5567fcb1ce 100644 --- a/src/AddIns/BackendBindings/FSharpBinding/FSharpInteractive.cs +++ b/src/AddIns/BackendBindings/FSharpBinding/FSharpInteractive.cs @@ -5,54 +5,37 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Editor; using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using System.Windows.Forms; + using ICSharpCode.Core; using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; namespace FSharpBinding { - public class FSharpInteractive : AbstractPadContent + public class FSharpInteractive : AbstractConsolePad { Queue outputQueue = new Queue(); internal readonly Process fsiProcess = new Process(); - Panel panel = new Panel(); - TextBox input, output; internal readonly bool foundCompiler; public FSharpInteractive() { - input = new TextBox { - Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, - Width = panel.Width - }; - output = new TextBox { - Multiline = true, - Top = input.Height, - Height = panel.Height - input.Height, - Width = panel.Width, - ReadOnly = true, - ScrollBars = ScrollBars.Both, - WordWrap = false, - Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom - }; - panel.Controls.Add(input); - panel.Controls.Add(output); - if (Array.Exists(ConfigurationManager.AppSettings.AllKeys, x => x == "alt_fs_bin_path")) { string path = Path.Combine(ConfigurationManager.AppSettings["alt_fs_bin_path"], "fsi.exe"); if (File.Exists(path)) { fsiProcess.StartInfo.FileName = path; foundCompiler = true; } else { - output.Text = "you are trying to use the app setting alt_fs_bin_path, but fsi.exe is not localed in the given directory"; + AppendLine("you are trying to use the app setting alt_fs_bin_path, but fsi.exe is not localed in the given directory"); foundCompiler = false; } } else { @@ -68,37 +51,26 @@ namespace FSharpBinding foundCompiler = true; } else { string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); - var possibleFiles = from fsdir in Directory.GetDirectories(programFiles, "FSharp*") - //LoggingService.Debug("Trying to find fsi in '" + fsdir + "'"); - let fileInfo = new FileInfo(Path.Combine(fsdir, "bin\\fsi.exe")) - where fileInfo.Exists - orderby fileInfo.CreationTime - select fileInfo; - FileInfo file = possibleFiles.FirstOrDefault(); - if (file != null) { - fsiProcess.StartInfo.FileName = file.FullName; + path = Path.Combine(programFiles, @"Microsoft F#\v4.0\Fsi.exe"); + if (File.Exists(path)) { + fsiProcess.StartInfo.FileName = path; foundCompiler = true; } else { - output.Text = "Can not find the fsi.exe, ensure a version of the F# compiler is installed." + Environment.NewLine + - "Please see http://research.microsoft.com/fsharp for details of how to install the compiler"; + AppendLine("Can not find the fsi.exe, ensure a version of the F# compiler is installed." + Environment.NewLine + + "Please see http://research.microsoft.com/fsharp for details of how to install the compiler"); foundCompiler = false; } } } if (foundCompiler) { - input.KeyUp += delegate(object sender, KeyEventArgs e) { - if (e.KeyData == Keys.Return) { - fsiProcess.StandardInput.WriteLine(input.Text); - input.Text = ""; - } - }; //fsiProcess.StartInfo.Arguments <- "--fsi-server sharpdevelopfsi"; fsiProcess.StartInfo.UseShellExecute = false; fsiProcess.StartInfo.CreateNoWindow = true; fsiProcess.StartInfo.RedirectStandardError = true; fsiProcess.StartInfo.RedirectStandardInput = true; fsiProcess.StartInfo.RedirectStandardOutput = true; + fsiProcess.EnableRaisingEvents = true; fsiProcess.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { lock (outputQueue) { outputQueue.Enqueue(e.Data); @@ -117,31 +89,52 @@ namespace FSharpBinding outputQueue.Enqueue("restarting ..."); } WorkbenchSingleton.SafeThreadAsyncCall(ReadAll); - fsiProcess.Start(); - }; - fsiProcess.Start(); - fsiProcess.BeginErrorReadLine(); - fsiProcess.BeginOutputReadLine(); - } else { - input.KeyUp += delegate(object sender, KeyEventArgs e) { - if (e.KeyData == Keys.Return) { - output.AppendText(Environment.NewLine + "F# not installed - could not execute command"); - input.Text = ""; - } + WorkbenchSingleton.SafeThreadAsyncCall(StartFSharp); }; + StartFSharp(); } } + void StartFSharp() + { + fsiProcess.Start(); + fsiProcess.BeginErrorReadLine(); + fsiProcess.BeginOutputReadLine(); + } + + int expectedPrompts; + void ReadAll() { + StringBuilder b = new StringBuilder(); lock (outputQueue) { while (outputQueue.Count > 0) - output.AppendText(outputQueue.Dequeue() + Environment.NewLine); + b.AppendLine(outputQueue.Dequeue()); + } + int offset = 0; + // ignore prompts inserted by fsi.exe (we only see them too late as we're reading line per line) + for (int i = 0; i < expectedPrompts; i++) { + if (offset + 1 < b.Length && b[offset] == '>' && b[offset + 1] == ' ') + offset += 2; + else + break; } + expectedPrompts = 0; + InsertBeforePrompt(b.ToString(offset, b.Length - offset)); } - public override object Control { - get { return panel; } + protected override string Prompt { + get { return "> "; } + } + + protected override bool AcceptCommand(string command) + { + if (command.TrimEnd().EndsWith(";;", StringComparison.Ordinal)) { + expectedPrompts++; + fsiProcess.StandardInput.WriteLine(command); + return true; + } + return false; } } diff --git a/src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml b/src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml index b7269d3a12..7a4661608b 100644 --- a/src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml +++ b/src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml @@ -7,6 +7,7 @@ Name="lastProjectsListView" SelectionMode="Single" core:SortableGridViewColumn.SortMode="Automatic" + Margin="0,0,0,20" MouseDoubleClick="lastProjectsDoubleClick" KeyDown="lastProjectsKeyDown"> @@ -38,8 +39,7 @@ + Orientation="Horizontal">