Fossil SCM
Improve the header comment on the style_copy_button() routine to be more accurate and lucid.
Commit
7404ad0b0e08b99c6652d5579085c29525b3c37380c739a31b22b16ab6005be7
Parent
5298941066616b3…
1 file changed
+29
-22
+29
-22
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -474,43 +474,50 @@ | ||
| 474 | 474 | free(zVarName); |
| 475 | 475 | free(zUrl); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /* |
| 479 | -** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js | |
| 480 | -** Javascript module, and generates HTML elements with the following IDs: | |
| 481 | -** | |
| 482 | -** TARGETID: The <span> wrapper around TEXT. | |
| 483 | -** copy-TARGETID: The <button> for the copy button. | |
| 484 | -** | |
| 485 | -** If the FLIPPED argument is non-zero, the copy button is displayed after TEXT. | |
| 486 | -** | |
| 487 | -** The COPYLENGTH argument defines the length of the substring of TEXT copied to | |
| 488 | -** clipboard: | |
| 489 | -** | |
| 490 | -** <= 0: No limit (default if the argument is omitted). | |
| 491 | -** >= 3: Truncate TEXT after COPYLENGTH (single-byte) characters. | |
| 479 | +** Output text generated from zTextFmt,... with a click-to-copy button | |
| 480 | +** next to it. This routine assures that the copybtn.js Javascript module | |
| 481 | +** is loaded. It generates HTML elements with the following IDs: | |
| 482 | +** | |
| 483 | +** zTargetId: The <span> wrapper around the generated text. | |
| 484 | +** copy-zTargetId: The <button> for the copy button. | |
| 485 | +** | |
| 486 | +** The bOutputCGI parameter is usually true, meaning that the output | |
| 487 | +** is appended to the CGI result under construction. However, if | |
| 488 | +** bOutputCGI is false, the generated HTML is written into memory | |
| 489 | +** obtained from fossil_malloc() and returned. | |
| 490 | +** | |
| 491 | +** If the bFlipped argument is non-zero, the copy button is displayed | |
| 492 | +** after the text. Normally the copy button comes before. | |
| 493 | +** | |
| 494 | +** The mxLength argument defines the length of the substring of the | |
| 495 | +** text to be copied to the clipboard: | |
| 496 | +** | |
| 497 | +** <= 0: Use all of the text | |
| 498 | +** >= 3: Truncate the text after mxLength bytes. | |
| 492 | 499 | ** 1: Use the "hash-digits" setting as the limit. |
| 493 | 500 | ** 2: Use the length appropriate for URLs as the limit (defined at |
| 494 | 501 | ** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16). |
| 495 | 502 | */ |
| 496 | 503 | char *style_copy_button( |
| 497 | 504 | int bOutputCGI, /* Don't return result, but send to cgi_printf(). */ |
| 498 | - const char *zTargetId, /* The TARGETID argument. */ | |
| 499 | - int bFlipped, /* The FLIPPED argument. */ | |
| 500 | - int cchLength, /* The COPYLENGTH argument. */ | |
| 505 | + const char *zTargetId, /* HTML id of the text */ | |
| 506 | + int bFlipped, /* True to put copy button after text */ | |
| 507 | + int mxLength, /* Length of text to copy to clipboard */ | |
| 501 | 508 | const char *zTextFmt, /* Formatting of the TEXT argument (htmlized). */ |
| 502 | 509 | ... /* Formatting parameters of the TEXT argument. */ |
| 503 | 510 | ){ |
| 504 | 511 | va_list ap; |
| 505 | 512 | char *zText; |
| 506 | 513 | char *zResult = 0; |
| 507 | 514 | va_start(ap,zTextFmt); |
| 508 | 515 | zText = vmprintf(zTextFmt/*works-like:?*/,ap); |
| 509 | 516 | va_end(ap); |
| 510 | - if( cchLength==1 ) cchLength = hash_digits(0); | |
| 511 | - else if( cchLength==2 ) cchLength = hash_digits(1); | |
| 517 | + if( mxLength==1 ) mxLength = hash_digits(0); | |
| 518 | + else if( mxLength==2 ) mxLength = hash_digits(1); | |
| 512 | 519 | if( !bFlipped ){ |
| 513 | 520 | const char *zBtnFmt = |
| 514 | 521 | "<span class=\"nobr\">" |
| 515 | 522 | "<button " |
| 516 | 523 | "class=\"copy-button\" " |
| @@ -525,15 +532,15 @@ | ||
| 525 | 532 | "</span>" |
| 526 | 533 | "</span>"; |
| 527 | 534 | if( bOutputCGI ){ |
| 528 | 535 | cgi_printf( |
| 529 | 536 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 530 | - zTargetId,zTargetId,cchLength,zTargetId,zText); | |
| 537 | + zTargetId,zTargetId,mxLength,zTargetId,zText); | |
| 531 | 538 | }else{ |
| 532 | 539 | zResult = mprintf( |
| 533 | 540 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 534 | - zTargetId,zTargetId,cchLength,zTargetId,zText); | |
| 541 | + zTargetId,zTargetId,mxLength,zTargetId,zText); | |
| 535 | 542 | } |
| 536 | 543 | }else{ |
| 537 | 544 | const char *zBtnFmt = |
| 538 | 545 | "<span class=\"nobr\">" |
| 539 | 546 | "<span id=\"%h\">" |
| @@ -549,15 +556,15 @@ | ||
| 549 | 556 | "</button>" |
| 550 | 557 | "</span>"; |
| 551 | 558 | if( bOutputCGI ){ |
| 552 | 559 | cgi_printf( |
| 553 | 560 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 554 | - zTargetId,zText,zTargetId,zTargetId,cchLength); | |
| 561 | + zTargetId,zText,zTargetId,zTargetId,mxLength); | |
| 555 | 562 | }else{ |
| 556 | 563 | zResult = mprintf( |
| 557 | 564 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 558 | - zTargetId,zText,zTargetId,zTargetId,cchLength); | |
| 565 | + zTargetId,zText,zTargetId,zTargetId,mxLength); | |
| 559 | 566 | } |
| 560 | 567 | } |
| 561 | 568 | free(zText); |
| 562 | 569 | builtin_request_js("copybtn.js"); |
| 563 | 570 | return zResult; |
| 564 | 571 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -474,43 +474,50 @@ | |
| 474 | free(zVarName); |
| 475 | free(zUrl); |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | ** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js |
| 480 | ** Javascript module, and generates HTML elements with the following IDs: |
| 481 | ** |
| 482 | ** TARGETID: The <span> wrapper around TEXT. |
| 483 | ** copy-TARGETID: The <button> for the copy button. |
| 484 | ** |
| 485 | ** If the FLIPPED argument is non-zero, the copy button is displayed after TEXT. |
| 486 | ** |
| 487 | ** The COPYLENGTH argument defines the length of the substring of TEXT copied to |
| 488 | ** clipboard: |
| 489 | ** |
| 490 | ** <= 0: No limit (default if the argument is omitted). |
| 491 | ** >= 3: Truncate TEXT after COPYLENGTH (single-byte) characters. |
| 492 | ** 1: Use the "hash-digits" setting as the limit. |
| 493 | ** 2: Use the length appropriate for URLs as the limit (defined at |
| 494 | ** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16). |
| 495 | */ |
| 496 | char *style_copy_button( |
| 497 | int bOutputCGI, /* Don't return result, but send to cgi_printf(). */ |
| 498 | const char *zTargetId, /* The TARGETID argument. */ |
| 499 | int bFlipped, /* The FLIPPED argument. */ |
| 500 | int cchLength, /* The COPYLENGTH argument. */ |
| 501 | const char *zTextFmt, /* Formatting of the TEXT argument (htmlized). */ |
| 502 | ... /* Formatting parameters of the TEXT argument. */ |
| 503 | ){ |
| 504 | va_list ap; |
| 505 | char *zText; |
| 506 | char *zResult = 0; |
| 507 | va_start(ap,zTextFmt); |
| 508 | zText = vmprintf(zTextFmt/*works-like:?*/,ap); |
| 509 | va_end(ap); |
| 510 | if( cchLength==1 ) cchLength = hash_digits(0); |
| 511 | else if( cchLength==2 ) cchLength = hash_digits(1); |
| 512 | if( !bFlipped ){ |
| 513 | const char *zBtnFmt = |
| 514 | "<span class=\"nobr\">" |
| 515 | "<button " |
| 516 | "class=\"copy-button\" " |
| @@ -525,15 +532,15 @@ | |
| 525 | "</span>" |
| 526 | "</span>"; |
| 527 | if( bOutputCGI ){ |
| 528 | cgi_printf( |
| 529 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 530 | zTargetId,zTargetId,cchLength,zTargetId,zText); |
| 531 | }else{ |
| 532 | zResult = mprintf( |
| 533 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 534 | zTargetId,zTargetId,cchLength,zTargetId,zText); |
| 535 | } |
| 536 | }else{ |
| 537 | const char *zBtnFmt = |
| 538 | "<span class=\"nobr\">" |
| 539 | "<span id=\"%h\">" |
| @@ -549,15 +556,15 @@ | |
| 549 | "</button>" |
| 550 | "</span>"; |
| 551 | if( bOutputCGI ){ |
| 552 | cgi_printf( |
| 553 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 554 | zTargetId,zText,zTargetId,zTargetId,cchLength); |
| 555 | }else{ |
| 556 | zResult = mprintf( |
| 557 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 558 | zTargetId,zText,zTargetId,zTargetId,cchLength); |
| 559 | } |
| 560 | } |
| 561 | free(zText); |
| 562 | builtin_request_js("copybtn.js"); |
| 563 | return zResult; |
| 564 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -474,43 +474,50 @@ | |
| 474 | free(zVarName); |
| 475 | free(zUrl); |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | ** Output text generated from zTextFmt,... with a click-to-copy button |
| 480 | ** next to it. This routine assures that the copybtn.js Javascript module |
| 481 | ** is loaded. It generates HTML elements with the following IDs: |
| 482 | ** |
| 483 | ** zTargetId: The <span> wrapper around the generated text. |
| 484 | ** copy-zTargetId: The <button> for the copy button. |
| 485 | ** |
| 486 | ** The bOutputCGI parameter is usually true, meaning that the output |
| 487 | ** is appended to the CGI result under construction. However, if |
| 488 | ** bOutputCGI is false, the generated HTML is written into memory |
| 489 | ** obtained from fossil_malloc() and returned. |
| 490 | ** |
| 491 | ** If the bFlipped argument is non-zero, the copy button is displayed |
| 492 | ** after the text. Normally the copy button comes before. |
| 493 | ** |
| 494 | ** The mxLength argument defines the length of the substring of the |
| 495 | ** text to be copied to the clipboard: |
| 496 | ** |
| 497 | ** <= 0: Use all of the text |
| 498 | ** >= 3: Truncate the text after mxLength bytes. |
| 499 | ** 1: Use the "hash-digits" setting as the limit. |
| 500 | ** 2: Use the length appropriate for URLs as the limit (defined at |
| 501 | ** compile-time by FOSSIL_HASH_DIGITS_URL, defaults to 16). |
| 502 | */ |
| 503 | char *style_copy_button( |
| 504 | int bOutputCGI, /* Don't return result, but send to cgi_printf(). */ |
| 505 | const char *zTargetId, /* HTML id of the text */ |
| 506 | int bFlipped, /* True to put copy button after text */ |
| 507 | int mxLength, /* Length of text to copy to clipboard */ |
| 508 | const char *zTextFmt, /* Formatting of the TEXT argument (htmlized). */ |
| 509 | ... /* Formatting parameters of the TEXT argument. */ |
| 510 | ){ |
| 511 | va_list ap; |
| 512 | char *zText; |
| 513 | char *zResult = 0; |
| 514 | va_start(ap,zTextFmt); |
| 515 | zText = vmprintf(zTextFmt/*works-like:?*/,ap); |
| 516 | va_end(ap); |
| 517 | if( mxLength==1 ) mxLength = hash_digits(0); |
| 518 | else if( mxLength==2 ) mxLength = hash_digits(1); |
| 519 | if( !bFlipped ){ |
| 520 | const char *zBtnFmt = |
| 521 | "<span class=\"nobr\">" |
| 522 | "<button " |
| 523 | "class=\"copy-button\" " |
| @@ -525,15 +532,15 @@ | |
| 532 | "</span>" |
| 533 | "</span>"; |
| 534 | if( bOutputCGI ){ |
| 535 | cgi_printf( |
| 536 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 537 | zTargetId,zTargetId,mxLength,zTargetId,zText); |
| 538 | }else{ |
| 539 | zResult = mprintf( |
| 540 | zBtnFmt/*works-like:"%h%h%d%h%s"*/, |
| 541 | zTargetId,zTargetId,mxLength,zTargetId,zText); |
| 542 | } |
| 543 | }else{ |
| 544 | const char *zBtnFmt = |
| 545 | "<span class=\"nobr\">" |
| 546 | "<span id=\"%h\">" |
| @@ -549,15 +556,15 @@ | |
| 556 | "</button>" |
| 557 | "</span>"; |
| 558 | if( bOutputCGI ){ |
| 559 | cgi_printf( |
| 560 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 561 | zTargetId,zText,zTargetId,zTargetId,mxLength); |
| 562 | }else{ |
| 563 | zResult = mprintf( |
| 564 | zBtnFmt/*works-like:"%h%s%h%h%d"*/, |
| 565 | zTargetId,zText,zTargetId,zTargetId,mxLength); |
| 566 | } |
| 567 | } |
| 568 | free(zText); |
| 569 | builtin_request_js("copybtn.js"); |
| 570 | return zResult; |
| 571 |