|
535 | 535 | @{Opens a dialog that queries the user about exiting. Returns the user's |
536 | 536 | decision.}) |
537 | 537 |
|
| 538 | + (proc-doc/names |
| 539 | + path-utils:generate-backup-name |
| 540 | + (path? . -> . path?) |
| 541 | + (filename) |
| 542 | + @{ |
| 543 | + Generates a path for a backup file based on @racket[filename]. |
| 544 | + |
| 545 | + @index{'path-utils:backup-dir} |
| 546 | + The value of @racket[(preferences:get 'path-utils:backup-dir)] |
| 547 | + determines the directory of the resulting path. |
| 548 | + The value of this preference must be either a path |
| 549 | + satisfying @racket[complete-path?] and @racket[directory-exists?], |
| 550 | + in which case it is additionally checked to ensure that the |
| 551 | + directory has not been deleted since the preference was set, |
| 552 | + or @racket[#f] (the default). |
| 553 | + When the preference contains a valid path, |
| 554 | + the resulting path will use that directory; |
| 555 | + otherwise, and by default, |
| 556 | + the result will use the same directory as @racket[filename]. |
| 557 | + |
| 558 | + The final element of the resulting path is derived from @racket[filename]. |
| 559 | + When @racket[(preferences:get 'path-utils:backup-dir)] does not specify |
| 560 | + an extant directory, the final element of @racket[filename] is |
| 561 | + used directly as the base for the new element. |
| 562 | + Otherwise, the base is formed by transforming the complete path to @racket[filename] |
| 563 | + (resolved, if necessary, relative to @racket[(current-directory)]) |
| 564 | + according to the following @deftech{encoding scheme}: |
| 565 | + @itemlist[#:style 'ordered |
| 566 | + @item{A @racket[separator-byte] is selected: @litchar{!} by default, |
| 567 | + but a list of visually-appealing one-byte characters are |
| 568 | + tried if @litchar{!} occurs in the complete path to |
| 569 | + @racket[filename].} |
| 570 | + @item{Every seperator between path elements is replaced with |
| 571 | + @racket[separator-byte], as are any other occurances of the |
| 572 | + reserved separator character (@litchar{\} on Windows or |
| 573 | + @litchar{/} on Unix or Mac OS), e.g. in the name of the root directory.} |
| 574 | + @item{A single @racket[separator-byte] is added at the beginning |
| 575 | + so that the seperator can be unambiguously identified.} |
| 576 | + @item{If the result of the previous step is excessively long, it |
| 577 | + may be shortened by replacing some bytes in the middle with |
| 578 | + @racket[(bytes-append separator-byte #"..." separator-byte)] |
| 579 | + (i.e. @litchar{!...!} with @litchar{!} as the @racket[separator-byte]).}] |
| 580 | + |
| 581 | + In either case, the final path element is formed from the base |
| 582 | + in a platform-specific manner: |
| 583 | + @itemlist[ |
| 584 | + @item{On Unix and Mac OS, a @litchar{~} is added to the end.} |
| 585 | + @item{On Windows, the extension (in the sense of @racket[path-replace-extension]) |
| 586 | + is replaced with @litchar{.bak}.}] |
| 587 | + }) |
| 588 | + |
538 | 589 | (proc-doc/names |
539 | 590 | path-utils:generate-autosave-name |
540 | 591 | (-> (or/c #f path-string? path-for-some-system?) path?) |
|
544 | 595 |
|
545 | 596 | @index{'path-utils:autosave-dir} |
546 | 597 | The value of @racket[(preferences:get 'path-utils:autosave-dir)] |
547 | | - determines the directory of the resulting path. |
548 | | - When the preference value is @racket[#f] (the default), |
549 | | - result will use the same directory as the @racket[filename] |
| 598 | + determines the directory of the resulting path |
| 599 | + in much the same way as @racket[path-utils:generate-backup-name] |
| 600 | + with @racket['path-utils:backup-dir]. |
| 601 | + When the preference value is @racket[#f] (the default) or a |
| 602 | + directory that no longer exists, the |
| 603 | + result will use the same directory as @racket[filename] |
550 | 604 | (or, when @racket[filename] is @racket[#f], the directory determined by |
551 | 605 | @racket[(find-system-path 'doc-dir)]). |
552 | | - Otherwise, when @racket[(preferences:get 'path-utils:autosave-dir)] |
553 | | - returns a path satisfying @racket[complete-path?] and |
554 | | - @racket[directory-exists?], the autosave file will be saved in |
555 | | - that directory. |
556 | | - A relative @racket[filename] will be resolved based on |
557 | | - the value of @racket[(current-directory)]. |
| 606 | + Otherwise, the resulting path will use the directory specified by the preference. |
558 | 607 |
|
559 | 608 | When @racket[filename] is @racket[#f], the final element of the |
560 | 609 | resulting path will be an automatically-generated unique name. |
| 610 | + |
561 | 611 | Otherwise, the final path element will be derived from @racket[filename]. |
562 | | - When @racket[(preferences:get 'path-utils:autosave-dir)] returns |
563 | | - @racket[#f], the original file name will be used directly as the base; |
564 | | - otherwise, base will be the complete path to @racket[filename], |
565 | | - encoded by replacing each seperator (@litchar{\} on Windows or |
566 | | - @litchar{/} on Unix or Mac OS) with @litchar{!}. |
567 | | - This base is transformed into the final path element in a |
568 | | - platform-specific manner: |
| 612 | + When @racket[(preferences:get 'path-utils:autosave-dir)] does not return |
| 613 | + an extant directory, the last element of @racket[filename] will be |
| 614 | + used directly as the base for the new element. |
| 615 | + When a valid autosave directory is specified, the base will be |
| 616 | + the complete path to @racket[filename], |
| 617 | + transformed according to the same @tech{encoding scheme} as |
| 618 | + with @racket[path-utils:generate-backup-name]. |
| 619 | + In either case, the final path element is formed from the base |
| 620 | + in a platform-specific manner: |
569 | 621 | @itemlist[ |
570 | 622 | @item{On Unix and Mac OS, a @litchar{#} is added to the start |
571 | | - and end of the file’s name, then a number is added after the |
| 623 | + and end, then a number is added after the |
572 | 624 | ending @litchar{#}, and then one more @litchar{#} is appended |
573 | 625 | after the number. |
574 | 626 | The number is selected to make the autosave filename unique.} |
575 | | - @item{On Windows, the file’s extension is replaced with a number |
576 | | - to make the autosave filename unique.} |
| 627 | + @item{On Windows, the file’s extension (in the sense of @racket[path-replace-extension]) |
| 628 | + is replaced with a number to make the autosave filename unique.} |
577 | 629 | ]}) |
578 | 630 |
|
579 | | - (proc-doc/names |
580 | | - path-utils:generate-backup-name |
581 | | - (path? . -> . path?) |
582 | | - (filename) |
583 | | - @{ |
584 | | - Generates a path for a backup file based on @racket[filename]. |
585 | | - |
586 | | - @index{'path-utils:backup-dir} |
587 | | - The value of @racket[(preferences:get 'path-utils:backup-dir)] |
588 | | - determines the directory of the resulting path in much the same |
589 | | - way as @racket[path-utils:generate-autosave-name] responds to |
590 | | - the preference @racket['path-utils:autosave-dir]: |
591 | | - when the value is @racket[#f] (the default), the directory of |
592 | | - @racket[filename] is used, and otherwise the directory from the |
593 | | - preference is used. |
594 | | - |
595 | | - The final element of the resulting path is generated from |
596 | | - @racket[filename] in a platform-specific manner: |
597 | | - @itemlist[ |
598 | | - @item{On Unix and Mac OS, a @litchar{~} is added to the end |
599 | | - of the file’s name.} |
600 | | - @item{On Windows, the file’s extension is replaced |
601 | | - with @litchar{.bak}.}] |
602 | | - In either case, when @racket[(preferences:get 'path-utils:backup-dir)] |
603 | | - returns a non-false value, the result of the above transformation |
604 | | - is combined with the complete path of @racket[filename], |
605 | | - encoded by replacing seperators with @litchar{!} as with |
606 | | - @racket[path-utils:generate-autosave-name], to form the final |
607 | | - path element. |
608 | | - }) |
609 | | - |
610 | 631 | (parameter-doc |
611 | 632 | finder:dialog-parent-parameter |
612 | 633 | (parameter/c (or/c false/c (is-a?/c dialog%) (is-a?/c frame%))) |
|
0 commit comments