/// <summary> /// Shows a dialog with a number of input fields. /// </summary> public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions) { if (descriptions == null) throw new ArgumentNullException("descriptions"); var r = new Dictionary<string, PSObject>(); if (Far.Api.UI.IsCommandMode) { if (!string.IsNullOrEmpty(caption)) WriteLine(PromptColor, BackgroundColor, caption); if (!string.IsNullOrEmpty(message)) WriteLine(message); } foreach (var current in descriptions) { var prompt = current.Name; var type = Type.GetType(current.ParameterAssemblyFullName); if (type.GetInterface(typeof(IList).FullName) != null) { var arrayList = new ArrayList(); for (; ; ) { var prompt2 = string.Format(null, "{0}[{1}]", prompt, arrayList.Count); string text; if (Far.Api.UI.IsCommandMode) { WriteLine(prompt2); //TODO HelpMessage - is fine by [F1]? for (; ; ) { var ui = new UI.ReadLine() { Prompt = TextPrompt, HelpMessage = current.HelpMessage, History = Res.HistoryPrompt }; if (!ui.Show()) { A.AskStopPipeline(); continue; } text = ui.Text; break; } WriteLine(TextPrompt + text); } else { //TODO HelpMessage - not done for (; ; ) { var ui = new UI.InputBoxEx() { Title = caption, Prompt = string.IsNullOrEmpty(message) ? prompt2 : message + "\r" + prompt2, History = Res.HistoryPrompt }; if (!ui.Show()) { A.AskStopPipeline(); continue; } text = ui.Text; break; } } if (text.Length == 0) break; arrayList.Add(text); } r.Add(prompt, new PSObject(arrayList)); } else { var safe = type == typeof(SecureString); string text; if (Far.Api.UI.IsCommandMode) { WriteLine(prompt); //TODO HelpMessage - [F1] - really? for (; ; ) { var ui = new UI.ReadLine() { Prompt = TextPrompt, HelpMessage = current.HelpMessage, History = Res.HistoryPrompt, Password = safe }; if (!ui.Show()) { A.AskStopPipeline(); continue; } text = ui.Text; WriteLine(TextPrompt + (safe ? "*" : text)); break; } } else { //TODO HelpMessage - not done for (; ; ) { var ui = new UI.InputBoxEx() { Title = caption, Prompt = string.IsNullOrEmpty(message) ? prompt : message + "\r" + prompt, History = Res.HistoryPrompt, Password = safe }; if (!ui.Show()) { A.AskStopPipeline(); continue; } text = ui.Text; break; } } r.Add(prompt, ValueToResult(text, safe)); } } return r; }
/// <summary> /// Shows a dialog with a number of choices. /// </summary> public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice) { if (choices == null || choices.Count == 0) throw new ArgumentOutOfRangeException("choices"); if (defaultChoice < -1 || defaultChoice >= choices.Count) throw new ArgumentOutOfRangeException("defaultChoice"); //! DON'T Check(): crash on pressed CTRL-C and an error in 'Inquire' mode //! 090211 The above is obsolete, perhaps. if (!Far.Api.UI.IsCommandMode) return UI.ChoiceMsg.Show(caption, message, choices); WriteLine(); if (!string.IsNullOrEmpty(caption)) WriteLine(PromptColor, BackgroundColor, caption); if (!string.IsNullOrEmpty(message)) WriteLine(message); string[,] hotkeysAndPlainLabels = null; BuildHotkeysAndPlainLabels(choices, out hotkeysAndPlainLabels); Dictionary<int, bool> dictionary = new Dictionary<int, bool>(); if (defaultChoice >= 0) dictionary.Add(defaultChoice, true); for (; ; ) { WriteChoicePrompt(hotkeysAndPlainLabels, dictionary, false); var ui = new UI.ReadLine() { Prompt = TextPrompt }; if (!ui.Show()) { A.AskStopPipeline(); continue; } var text = ui.Text; // echo WriteLine(TextPrompt + ui.Text); if (text.Length == 0) { if (defaultChoice >= 0) return defaultChoice; } else { if (text.Trim() == "?") { ShowChoiceHelp(choices, hotkeysAndPlainLabels); } else { var num = DetermineChoicePicked(text.Trim(), choices, hotkeysAndPlainLabels); if (num >= 0) return num; } } } }
/// <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; }
public override SecureString ReadLineAsSecureString() { if (Far.Api.UI.IsCommandMode) { for (; ; ) { var ui = new UI.ReadLine() { Password = true }; if (!ui.Show()) { A.AskStopPipeline(); continue; } WriteLine("*"); return (SecureString)ValueToResult(ui.Text, true).BaseObject; } } const string name = " "; var field = new FieldDescription(name); field.SetParameterType(typeof(SecureString)); var fields = new Collection<FieldDescription>() { field }; var r = Prompt("", "", fields); if (r == null) return null; return (SecureString)r[name].BaseObject; }