public static Result Query(Result flags, string errormsg, string condition, string file) { var s = String.Format (condition, file); int len = Math.Min (s.Length, Application.Cols-8); var d = new Dialog (len, 8, "Error"); d.ErrorColors (); d.Add (new Label (1, 1, errormsg)); d.Add (new Label (1, 2, String.Format (condition, file.Ellipsize (len-condition.Length)))); Result result = Result.Ignore; Button b; if ((flags & Result.Retry) == Result.Retry) { b = new Button (0, 0, "Retry", true); b.Clicked += delegate { result = Result.Retry; d.Running = false; }; d.Add (b); } if ((flags & Result.Ignore) == Result.Ignore) { b = new Button (0, 0, "Ignore", true); b.Clicked += delegate { result = Result.Ignore; d.Running = false; }; d.Add (b); } if ((flags & Result.Cancel) == Result.Cancel) { b = new Button (0, 0, "Cancel", true); b.Clicked += delegate { result = Result.Cancel; d.Running = false; }; d.Add (b); } Application.Run (d); return result; }
/// <summary> /// Displays a message on a modal dialog box. /// </summary> /// <remarks> /// The error boolean indicates whether this is an /// error message box or not. /// </remarks> public static void Msg(bool error, string caption, string t) { var lines = new List<string> (); int last = 0; int max_w = 0; string x; for (int i = 0; i < t.Length; i++){ if (t [i] == '\n'){ x = t.Substring (last, i-last); lines.Add (x); last = i + 1; if (x.Length > max_w) max_w = x.Length; } } x = t.Substring (last); if (x.Length > max_w) max_w = x.Length; lines.Add (x); Dialog d = new Dialog (System.Math.Max (caption.Length + 8, max_w + 8), lines.Count + 7, caption); if (error) d.ErrorColors (); for (int i = 0; i < lines.Count; i++) d.Add (new Label (1, i + 1, (string) lines [i])); Button b = new Button (0, 0, "Ok", true); d.AddButton (b); b.Clicked += delegate { b.Container.Running = false; }; Application.Run (d); }
public static int Query(int width, int height, string title, string message, params string [] buttons) { var d = new Dialog (width, height, title); int clicked = -1, count = 0; foreach (var s in buttons){ int n = count++; var b = new Button (s); b.Clicked += delegate { clicked = n; d.Running = false; }; d.AddButton (b); } if (message != null){ var l = new Label ((width - 4 - message.Length)/2, 0, message); d.Add (l); } Application.Run (d); return clicked; }
public MainWindow() : base(0, 0, Application.Cols, Application.Lines) { //Frame layout = new Frame(0,0, Application.Cols, Application.Lines, "smuxi"); //Add(layout); // menu Button fileButton = new Button(0, 0, "File"); fileButton.Clicked += delegate { Dialog dialog = new Dialog(40, 6, "File Menu"); Button quitButton = new Button(0, 0, "Quit"); quitButton.Clicked += delegate { Frontend.Quit(); }; dialog.AddButton(quitButton); Button closeButton = new Button(0, 0, "Close"); closeButton.Clicked += delegate { dialog.Running = false; dialog.Clear(); }; dialog.AddButton(closeButton); Application.Run(dialog); }; Add(fileButton); Button helpButton = new Button(10, 0, "Help"); helpButton.Clicked += delegate { Dialog dialog = new Dialog(30, 6, "Help Menu"); Button aboutButton = new Button(0, 0, "About"); aboutButton.Clicked += delegate { Dialog aboutDialog = new Dialog(70, 10, "About smuxi"); aboutDialog.Add(new Label(0, 0, "smuxi")); aboutDialog.Add(new Label(0, 1, "Frontend: " + Frontend.UIName + " " + Frontend.Version)); aboutDialog.Add(new Label(0, 2, "Engine: " + Frontend.EngineVersion)); aboutDialog.Add(new Label(0, 4, "Copyright(C) 2005-2007 (C) Mirco Bauer <*****@*****.**>")); Button closeButton = new Button("Close"); closeButton.Clicked += delegate { aboutDialog.Running = false; aboutDialog.Clear(); }; aboutDialog.AddButton(closeButton); Application.Run(aboutDialog); }; dialog.AddButton(aboutButton); Button helpCloseButton = new Button(0, 0, "Close"); helpCloseButton.Clicked += delegate { dialog.Running = false; dialog.Clear(); }; dialog.AddButton(helpCloseButton); Application.Run(dialog); }; Add(helpButton); // output /* TextView textView = new TextView(0, 1, Application.Cols, Application.Lines -2); textView.Add("Hello World!"); textView.Add("Foo bar me!"); Add(textView); */ LogWidget log = new LogWidget(0, 1, Application.Cols, Application.Lines -2); Add(log); _UI = new CursesUI(log); // input Entry entry = new Entry(0, Application.Lines - 1, Application.Cols, String.Empty); Add(entry); _Entry = entry; // status }
public TargetExistsAction TargetExists(string file, DateTime sourceTime, long sourceSize, DateTime targetTime, long targetSize, bool multiple) { const int padding = 14; const int minEllipse = 22; const string fmt = "Target file \"{0}\" already exists"; TargetExistsAction result = TargetExistsAction.Cancel; var msg = String.Format (fmt, file); if (msg.Length > Application.Cols-padding) msg = String.Format (fmt, file.Ellipsize (Application.Cols-8-fmt.Length)); var d = new Dialog (msg.Length + padding, 13 + (multiple ? 3 : 0), "File exists"); d.ErrorColors (); d.Add (new Label (2, 1, msg)); // TODO: compute what changes actually matter (year, month, day, hour, minute) d.Add (new Label (2, 3, String.Format ("Source date: {0}, size {1}", sourceTime, sourceSize))); d.Add (new Label (2, 4, String.Format ("Target date: {0}, size {1}", targetTime, targetSize))); d.Add (new Label (2, 6, "Override this target?")); MakeButton (d, 24, 6, "Yes", () => result = TargetExistsAction.Overwrite); MakeButton (d, 32, 6, "No", () => result = TargetExistsAction.Skip); MakeButton (d, 39, 6, "Append", () => result = TargetExistsAction.Append); if (multiple){ d.Add (new Label (2, 8, "Override all targets?")); MakeButton (d, 24, 8, "aLl", () => result = TargetExistsAction.AlwaysOverwrite); MakeButton (d, 32, 8, "Update", () => result = TargetExistsAction.AlwaysUpdate); MakeButton (d, 43, 8, "None", () => result = TargetExistsAction.AlwaysSkip); MakeButton (d, 24, 9, "if Size differs", () => result = TargetExistsAction.AlwaysUpdateOnSizeMismatch); } MakeButton (d, (d.w-4-"Cancel".Length)/2, 8 + (multiple ? 3 : 0), "Cancel", () => {}); Application.Run (d); return result; }
public static void Error(string msg) { var d = new Dialog (Math.Min (Application.Cols-8, msg.Length+6), 8, "Error"); d.ErrorColors (); d.Add (new Label (1, 1, msg)); var b = new Button (0, 0, "Ok"); b.Clicked += delegate { d.Running = false; }; d.AddButton (b); Application.Run (d); }
void MakeButton(Dialog d, int x, int y, string text, System.Action action) { Button b = new Button (x, y, text); b.Clicked += delegate { action (); d.Running = false; }; d.Add (b); }