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