1 /** 2 * Dialog module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.window.dialog.dialog; 8 9 /** 10 * Imports. 11 */ 12 import std.regex; 13 import tkd.element.element; 14 import tkd.window.window; 15 16 /** 17 * Abstract base class for all dialog boxes. 18 * 19 * See_Also: 20 * $(LINK2 ../../element/element.html, tkd.element.element) $(BR) 21 */ 22 abstract class Dialog : Element 23 { 24 /* 25 * The parent window of the dialog. 26 */ 27 protected Window _parent; 28 29 /* 30 * The title of the dialog. 31 */ 32 protected string _title; 33 34 /* 35 * The result of the dialog. 36 */ 37 protected string[] _results; 38 39 /** 40 * Construct the dialog. 41 * 42 * Params: 43 * parent = The parent window of the dialog. 44 * title = The title of the dialog. 45 */ 46 this(Window parent, string title) 47 { 48 this._elementId = "dialog"; 49 this._parent = parent; 50 this._title = title; 51 } 52 53 /** 54 * Get the dialog result. This varies on the type of dialog used and will 55 * reflect the overall result expected of each dialog. 56 * 57 * Returns: 58 * The result of the dialog or an empty string. 59 */ 60 public string getResult() 61 { 62 return this._results.length ? this._results[0] : ""; 63 } 64 65 /** 66 * Remove any leading or trailing braces. 67 */ 68 protected void removeBracesFromResults() 69 { 70 foreach (ref result; this._results) 71 { 72 result = result.replace(regex(r"^\{"), ""); 73 result = result.replace(regex(r"\}$"), ""); 74 } 75 } 76 77 /** 78 * Show the dialog. 79 * 80 * Returns: 81 * This dialog to aid method chaining. 82 */ 83 abstract public auto show(this T)(); 84 }