public EditorConsole(IEditor editor, int mode) { Editor = editor; Editor.KeyDown += OnKeyDown; switch (mode) { case 0: OpenMainSession(); break; case 1: OpenLocalSession(); break; case 2: OpenRemoteSession(); break; } }
public void Show() { // active editor if (Far.Api.Window.Kind == WindowKind.Editor) _editor = Far.Api.Editor; // menu loop for (_toStop = false; ; _menu.Items.Clear()) { // new breakpoint by types _menu.Add("&Line breakpoint...", OnLineBreakpoint); _menu.Add("&Command breakpoint...", OnCommandBreakpoint); _menu.Add("&Variable breakpoint...", OnVariableBreakpoint); // breakpoint collection _breakpoints = A.InvokeCode("Get-PSBreakpoint"); if (_breakpoints.Count > 0) { // separator _menu.Add("Breakpoints").IsSeparator = true; // breakpoints int n = 0; foreach (PSObject o in _breakpoints) { Breakpoint bp = (Breakpoint)o.BaseObject; ++n; string text = bp.ToString(); if (n <= 9) text = "&" + Kit.ToString(n) + " " + text; FarItem mi = _menu.Add(text); mi.Checked = bp.Enabled; mi.Data = bp; } } // go if (!_menu.Show() || _toStop) return; } }
public EditorOutputWriter2(IEditor editor) : base(editor) { }
public EditorOutputWriter1(IEditor editor) { Editor = editor; }
// true if there is a solid char anywhere before the caret internal static bool NeedsTabExpansion(IEditor editor) { ILine line = editor.Line; string text = line.Text; int pos = line.Caret; while (--pos >= 0) if (text[pos] > ' ') return true; return false; }
// PSF sets the current directory and location to the script directory. // This is often useful and consistent with invoking from panels. // NOTE: ISE [F5] does not. public static void InvokeScriptBeingEdited(IEditor editor) { // editor if (editor == null) editor = A.Psf.Editor(); // commit editor.Save(); // sync the directory and location to the script directory // maybe it is questionable but it is very handy too often string dir0, dir1; // save/set the directory, allow failures (e.g. a long path) // note: GetDirectoryName fails on a long path, too try { dir1 = Path.GetDirectoryName(editor.FileName); dir0 = Environment.CurrentDirectory; Environment.CurrentDirectory = dir1; } catch (PathTooLongException) { // PowerShell is not able to invoke this script anyway, almost for sure Far.Api.Message("The script path is too long.\rInvoking is not supported."); return; } try { Far.Api.UI.WindowTitle = "Running..."; // push/set the location; let's ignore issues A.Psf.Engine.SessionState.Path.PushCurrentLocation(null); A.Psf.Engine.SessionState.Path.SetLocation(Kit.EscapeWildcard(dir1)); // invoke the script A.Psf.Act("& '" + editor.FileName.Replace("'", "''") + "'", null, false); Far.Api.UI.WindowTitle = "Done " + DateTime.Now; } catch { Far.Api.UI.WindowTitle = "Failed"; throw; } finally { // restore the directory first Environment.CurrentDirectory = dir0; // then pop the location, it may fail perhaps A.Psf.Engine.SessionState.Path.PopLocation(null); } }
/// <summary> /// Instructs the host to exit the currently running input loop. /// </summary> public override void ExitNestedPrompt() { if (Far.Api.UI.IsCommandMode) { PowerShellFar.UI.InputConsole.Exit = true; } else if (_nested != null) { var nested = _nested; _nested = null; if (nested.IsOpened) nested.Close(); } }
/// <summary> /// Instructs the host to interrupt the currently running pipeline and start a new nested input loop. /// An input loop is the cycle of prompt, input, and execute. /// </summary> public override void EnterNestedPrompt() { if (Far.Api.UI.IsCommandMode) { PowerShellFar.UI.InputConsole.Loop(true); return; } // push the last IEditor keepNested = _nested; try { //! Far used to crash: Test-CallStack-.ps1 \ suspend \ type exit + enter //! This exception from Open() was removed, so don't try\catch all in here. //! SVN tag 4.2.26 EditorConsole console = EditorConsole.CreateConsole(false); _nested = console.Editor; // Enter the modal editor. There are two ways to exit. // 1) User exits the editor ([Esc]/[F10]). _nested should be this editor, not null. // But PowerShell nested prompt is not yet exited, call 'exit', it triggers // ExitNestedPrompt(), it sets _nested to null. // 2) User types 'exit' in the editor. Then ExitNestedPrompt() is called first, // it sets _nested to null and closes the editor. Control gets here with null // _nested, so we do nothing but restoring the very first _nested. _nested.Open(OpenMode.Modal); // If _nested is not null then a user has closed the editor via UI, not by 'exit'. // Thus, we have to exit the nested prompt. IsRunning check is added for V3 CTP2. // It works fine in V2, too. Meaning: if there is no running pipeline (stepper) // then there is nothing to exit, so do not exit. Exit nothing hangs in V3 CTP2. if (_nested != null && A.Psf.IsRunning) { using (var ps = A.Psf.NewPowerShell()) ps.AddScript("exit").Invoke(); } } finally { // pop the last _nested = keepNested; } }
public EditorConsole(IEditor editor) : this(editor, 0) { }
/// <summary> /// Gets colors for the specified editor lines. /// </summary> /// <param name="editor">The editor.</param> /// <param name="e">The arguments.</param> public abstract void Invoke(IEditor editor, ModuleDrawerEventArgs e);