1 /**
2  * Insert module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.common.insert;
8 
9 /**
10  * These are common commands that apply to all widgets that have them injected.
11  */
12 mixin template Insert()
13 {
14 	import std.conv;
15 
16 	/**
17 	 * Insert text at an index.
18 	 *
19 	 * Params:
20 	 *     text = The text to insert.
21 	 *     charIndex = The index to insert the text.
22 	 *
23 	 * Returns:
24 	 *     This widget to aid method chaining.
25 	 */
26 	public auto insertTextAt(this T)(string text, int charIndex)
27 	{
28 		// String concatenation is used to build the script here instead of 
29 		// using format specifiers to enable supporting input which includes 
30 		// Tcl/Tk reserved characters and elements that could be construed as 
31 		// format specifiers.
32 		string script = std.conv.text(this.id, ` insert `, charIndex, ` "`, this._tk.escape(text), `"`);
33 		this._tk.eval(script);
34 
35 		return cast(T) this;
36 	}
37 
38 	/**
39 	 * Append text to the end.
40 	 *
41 	 * Params:
42 	 *     text = The text to insert.
43 	 *
44 	 * Returns:
45 	 *     This widget to aid method chaining.
46 	 */
47 	public auto appendText(this T)(string text)
48 	{
49 		// String concatenation is used to build the script here instead of 
50 		// using format specifiers to enable supporting input which includes 
51 		// Tcl/Tk reserved characters and elements that could be construed as 
52 		// format specifiers.
53 		string script = std.conv.text(this.id, ` insert end `, `"`, this._tk.escape(text), `"`);
54 		this._tk.eval(script);
55 
56 		return cast(T) this;
57 	}
58 
59 	/**
60 	 * Insert text at the cursor position.
61 	 *
62 	 * Params:
63 	 *     text = The text to insert.
64 	 *
65 	 * Returns:
66 	 *     This widget to aid method chaining.
67 	 *
68 	 * See_Also:
69 	 *     $(LINK2 ./cursor.html, tkd.widget.common.cursor) $(BR)
70 	 *     $(LINK2 ./index.html, tkd.widget.common.index) $(BR)
71 	 */
72 	public auto insertTextAtCursor(this T)(string text)
73 	{
74 		// String concatenation is used to build the script here instead of 
75 		// using format specifiers to enable supporting input which includes 
76 		// Tcl/Tk reserved characters and elements that could be construed as 
77 		// format specifiers.
78 		string script = std.conv.text(this.id, ` insert insert `, `"`, this._tk.escape(text), `"`);
79 		this._tk.eval(script);
80 
81 		return cast(T) this;
82 	}
83 }