diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2015-11-19 20:46:40 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2015-11-19 20:46:40 (GMT) |
commit | f0e7b98adcaa0890c60fdf84c8e9753f8f903a53 (patch) | |
tree | 02b9115f94d1ef5680576bf60aa762861eefc229 /generic/tkText.c | |
parent | 8c6ac85de70a9f2ce13eecd5605fb55cfde6d911 (diff) | |
download | tk-f0e7b98adcaa0890c60fdf84c8e9753f8f903a53.zip tk-f0e7b98adcaa0890c60fdf84c8e9753f8f903a53.tar.gz tk-f0e7b98adcaa0890c60fdf84c8e9753f8f903a53.tar.bz2 |
First test-implementation of "$t yupdate -command <command>". TODO: more testcases and documentation
Diffstat (limited to 'generic/tkText.c')
-rw-r--r-- | generic/tkText.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/generic/tkText.c b/generic/tkText.c index 5c7f187..2c4d54c 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -1508,14 +1508,31 @@ TextWidgetObjCmd( result = TkTextXviewCmd(textPtr, interp, objc, objv); break; case TEXT_YUPDATE: { - if (objc != 2) { - Tcl_WrongNumArgs(interp, 2, objv, NULL); - result = TCL_ERROR; - goto done; - } - TkTextUpdateLineMetrics(textPtr, 1, - TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr), -1); - break; + if ((objc == 4) && !strncmp(Tcl_GetString(objv[2]), "-command", objv[3]->length)) { + Tcl_Obj *cmd = objv[3]; + Tcl_IncrRefCount(cmd); + if (TkTextPendingyupdate(textPtr)) { + if (textPtr->linesUpdatedCmd) { + Tcl_DecrRefCount(textPtr->linesUpdatedCmd); + } + textPtr->linesUpdatedCmd = cmd; + } else { + result = Tcl_EvalObjEx(interp, cmd, TCL_EVAL_GLOBAL); + Tcl_DecrRefCount(cmd); + } + break; + } else if (objc != 2) { + Tcl_WrongNumArgs(interp, 2, objv, "?-command command?"); + result = TCL_ERROR; + goto done; + } + if (textPtr->linesUpdatedCmd) { + Tcl_DecrRefCount(textPtr->linesUpdatedCmd); + } + textPtr->linesUpdatedCmd = NULL; + TkTextUpdateLineMetrics(textPtr, 1, + TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr), -1); + break; } case TEXT_YVIEW: result = TkTextYviewCmd(textPtr, interp, objc, objv); @@ -1993,6 +2010,10 @@ DestroyText( textPtr->tkwin = NULL; textPtr->refCount--; Tcl_DeleteCommandFromToken(textPtr->interp, textPtr->widgetCmd); + if (textPtr->linesUpdatedCmd != 0){ + Tcl_DecrRefCount(textPtr->linesUpdatedCmd); + textPtr->linesUpdatedCmd = 0; + } if (textPtr->refCount == 0) { ckfree((char *) textPtr); } |