1 /** 2 * Post command module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.common.postcommand; 8 9 /** 10 * These are common commands that apply to all widgets that have them injected. 11 */ 12 mixin template PostCommand() 13 { 14 import std..string; 15 import tkd.element.element; 16 17 /** 18 * Add a post command to a widget. This is usually to modify the widget after creation. 19 * 20 * Params: 21 * callback = The delegate callback to execute when invoking the post command. 22 * 23 * Returns: 24 * This widget to aid method chaining. 25 * 26 * Callback_Arguments: 27 * These are the fields within the callback's $(LINK2 28 * ../../element/element.html#CommandArgs, CommandArgs) parameter which 29 * are populated by this method when the callback is executed. 30 * $(P 31 * $(PARAM_TABLE 32 * $(PARAM_ROW CommandArgs.element, The element that executed the callback.) 33 * $(PARAM_ROW CommandArgs.uniqueData, The string 'postcommand'.) 34 * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) 35 * ) 36 * ) 37 * 38 * See_Also: 39 * $(LINK2 ../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) 40 */ 41 public auto setPostCommand(this T)(CommandCallback callback) 42 { 43 string command = this.createCommand(callback, "postcommand"); 44 this._tk.eval("%s configure -postcommand %s", this.id, command); 45 46 return cast(T) this; 47 } 48 49 /** 50 * Remove a previously set post command. 51 * 52 * Returns: 53 * This widget to aid method chaining. 54 */ 55 public auto removePostCommand(this T)() 56 { 57 this._tk.deleteCommand(this.getCommandName("postcommand")); 58 this._tk.eval("%s configure -postcommand {}", this.id); 59 60 return cast(T) this; 61 } 62 }