Beispiel #1
0
        /// <summary>
        /// For Actor.
        /// </summary>
        public static void ShowHistory()
        {
            var    m    = new UI.CommandHistoryMenu(string.Empty);
            string code = m.Show();

            if (code == null)
            {
                return;
            }

            // insert to command lines
            switch (Far.Api.Window.Kind)
            {
            case WindowKind.Panels:
                Far.Api.CommandLine.Text = Entry.CommandInvoke1.Prefix + ": " + code;
                return;

            case WindowKind.Editor:
                var editor = Far.Api.Editor;
                if (!(editor.Host is Interactive))
                {
                    break;
                }
                editor.GoToEnd(true);
                editor.InsertText(code);
                editor.Redraw();
                return;

            case WindowKind.Dialog:
                var dialog = Far.Api.Dialog;
                var typeId = dialog.TypeId;
                if (typeId != UI.InputDialog.TypeId)
                {
                    break;
                }
                var line = Far.Api.Line;
                if (line == null || line.IsReadOnly)
                {
                    break;
                }
                line.Text = code;
                return;
            }

            // show "Invoke commands"
            var ui = new UI.InputDialog()
            {
                Title = Res.Me, History = Res.History, Prompt = new string[] { Res.InvokeCommands }, Text = code
            };

            if (!ui.Show())
            {
                return;
            }

            // invoke input
            A.Psf.Act(ui.Text, null, true);
        }
Beispiel #2
0
        public string InputCode()
        {
            var ui = new UI.InputDialog()
            {
                Caption = Res.Me, History = Res.History, UseLastHistory = true, Prompt = new string[] { Res.InvokeCommands }
            };

            return(ui.Show() ? ui.Text : null);
        }
Beispiel #3
0
        static async void InvokeInputCode(string code)
        {
            var ui = new UI.InputDialog()
            {
                Title = Res.Me, History = Res.History, Prompt = new string[] { Res.InvokeCommands }, Text = code
            };

            code = await ui.ShowAsync();

            // invoke input
            if (!string.IsNullOrEmpty(code))
            {
                await Tasks.Job(() => A.Psf.Act(code, null, true));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Reads a string.
        /// </summary>
        public override string ReadLine()
        {
            for (;;)
            {
                var ui = new UI.InputDialog()
                {
                    History = Res.HistoryPrompt
                };
                var text = ui.Show();
                if (text != null)
                {
                    return(text);
                }

                A.AskStopPipeline();
            }
        }
Beispiel #5
0
        public static void InvokePipelineForEach(IEnumerable <PSObject> input)
        {
            List <PSObject> items = new List <PSObject>(input);

            if (items.Count == 0)
            {
                return;
            }

            // keep $_
            var dash = Psf.Engine.SessionState.PSVariable.GetValue("_");

            // set $_ to a sample for TabExpansion
            Psf.Engine.SessionState.PSVariable.Set("_", items[0]);

            try
            {
                // show the dialog, get the code
                UI.InputDialog ui = new UI.InputDialog()
                {
                    Title          = Res.Me,
                    History        = Res.HistoryApply,
                    UseLastHistory = true,
                    Prompt         = new string[] { "For each $_ in " + items.Count + " selected:" }
                };
                if (!ui.Show())
                {
                    return;
                }
                string code = ui.Text.Trim();
                if (code.Length == 0)
                {
                    return;
                }

                // invoke the pipeline using the input
                Psf.Engine.SessionState.PSVariable.Set("_", items);
                Psf.Act("$_ | .{process{ " + code + " }}", null, false);
            }
            finally
            {
                // restore $_
                Psf.Engine.SessionState.PSVariable.Set("_", dash);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Reads a string.
        /// </summary>
        public override string ReadLine()
        {
            string text;

            {
                for (;;)
                {
                    var ui = new UI.InputDialog()
                    {
                        History = Res.HistoryPrompt
                    };
                    if (ui.Show())
                    {
                        text = ui.Text;
                        break;
                    }
                    A.AskStopPipeline();
                }
            }
            return(text);
        }
Beispiel #7
0
 /// <summary>
 /// Reads a string.
 /// </summary>
 public override string ReadLine()
 {
     string text;
     if (Far.Api.UI.IsCommandMode)
     {
         for (; ; )
         {
             var ui = new UI.ReadLine() { History = Res.HistoryPrompt };
             if (ui.Show())
             {
                 text = ui.Text;
                 break;
             }
             A.AskStopPipeline();
         }
         WriteLine(text);
     }
     else
     {
         for (; ; )
         {
             var ui = new UI.InputDialog() { History = Res.HistoryPrompt };
             if (ui.Show())
             {
                 text = ui.Text;
                 break;
             }
             A.AskStopPipeline();
         }
     }
     return text;
 }
Beispiel #8
0
        public static void ShowHistory()
        {
            var m = new UI.CommandHistoryMenu(string.Empty);
            string code = m.Show();
            if (code == null)
                return;

            // insert to command lines
            switch (Far.Api.Window.Kind)
            {
                case WindowKind.Panels:
                    Far.Api.CommandLine.Text = Entry.CommandInvoke1.Prefix + ": " + code;
                    return;
                case WindowKind.Editor:
                    var editor = Far.Api.Editor;
                    if (!(editor.Host is EditorConsole))
                        break;
                    editor.GoToEnd(true);
                    editor.InsertText(code);
                    editor.Redraw();
                    return;
                case WindowKind.Dialog:
                    var dialog = Far.Api.Dialog;
                    var typeId = dialog.TypeId;
                    if (typeId != UI.InputConsole.TypeId && typeId != UI.InputDialog.TypeId)
                        break;
                    var line = Far.Api.Line;
                    if (line == null || line.IsReadOnly)
                        break;
                    line.Text = code;
                    return;
            }

            // show "Invoke commands"
            var ui = new UI.InputDialog() { Caption = Res.Me, History = Res.History, Prompt = new string[] { Res.InvokeCommands }, Text = code };
            if (!ui.Show())
                return;

            // invoke input
            A.Psf.Act(ui.Text, null, true);
        }
Beispiel #9
0
        public static void InvokePipelineForEach(IEnumerable<PSObject> input)
        {
            List<PSObject> items = new List<PSObject>(input);
            if (items.Count == 0)
                return;

            // keep $_
            var dash = Psf.Engine.SessionState.PSVariable.GetValue("_");

            // set $_ to a sample for TabExpansion
            Psf.Engine.SessionState.PSVariable.Set("_", items[0]);

            try
            {
                // show the dialog, get the code
                UI.InputDialog ui = new UI.InputDialog()
                {
                    Caption = Res.Me,
                    History = Res.HistoryApply,
                    UseLastHistory = true,
                    Prompt = new string[] { "For each $_ in " + items.Count + " selected:" }
                };
                if (!ui.Show())
                    return;
                string code = ui.Text.Trim();
                if (code.Length == 0)
                    return;

                // invoke the pipeline using the input
                Psf.Engine.SessionState.PSVariable.Set("_", items);
                Psf.Act("$_ | .{process{ " + code + " }}", null, false);
            }
            finally
            {
                // restore $_
                Psf.Engine.SessionState.PSVariable.Set("_", dash);
            }
        }
Beispiel #10
0
 public string InputCode()
 {
     var ui = new UI.InputDialog() { Caption = Res.Me, History = Res.History, UseLastHistory = true, Prompt = new string[] { Res.InvokeCommands } };
     return ui.Show() ? ui.Text : null;
 }