original commit: 6e2b0ee5bffbf12912fedfc0a0119e6a5b42dd78
This commit is contained in:
Robby Findler 2002-09-05 17:32:44 +00:00
parent 1c94dbf071
commit c9c0aefebb
3 changed files with 161 additions and 98 deletions

View File

@ -266,10 +266,14 @@
"garbage collection.")
(autosave:restore-autosave-files/gui
(-> (union false? (is-a?/c top-level-window<%>)))
(-> void?)
()
"Opens a GUI to ask the user about recovering any autosave files"
"left around from crashes and things.")
"left around from crashes and things."
""
"This function doesn't return until the user has finished"
"restoring the autosave files. (It uses yield to handle events"
"however).")
(exit:frame-exiting
(case->

View File

@ -2,6 +2,7 @@
(module autosave mzscheme
(require (lib "unitsig.ss")
(lib "class.ss")
(lib "file.ss")
"sig.ss"
(lib "mred-sig.ss" "mred")
(lib "mred.ss" "mred") ;; remove this!
@ -15,7 +16,11 @@
(import mred^
[exit : framework:exit^]
[preferences : framework:preferences^]
[frame : framework:frame^])
[frame : framework:frame^]
[scheme : framework:scheme^]
[editor : framework:editor^]
[text : framework:text^]
[finder : framework:finder^])
(define autosavable<%>
(interface ()
@ -70,7 +75,6 @@
(let* ([new-filename (send object do-autosave)]
[tmp-box (box #f)]
[filename (send object get-filename tmp-box)])
(printf "autosave ~s ~s to ~s\n" object filename new-filename)
(loop (cdr orig-objects)
(if new-filename
(cons (list (and (not (unbox tmp-box)) filename)
@ -99,21 +103,52 @@
;; restore-autosave-files/gui : -> (union #f (is-a?/c top-level-window<%>))
;; opens a frame that lists the autosave files that have changed.
(define (restore-autosave-files/gui)
(and (file-exists? autosave-toc-filename)
;; main : -> void
;; start everything going
(define (main)
(when (file-exists? autosave-toc-filename)
(let* ([table (call-with-input-file autosave-toc-filename read)]
;; assume that the autosave file was deleted due to the file being saved
[filtered-table
(filter (lambda (x) (file-exists? (cadr x))) table)])
(and (not (null? filtered-table))
(let ([f (make-object frame:basic% (string-constant recover-autosave-files-frame-title))])
(for-each (add-table-line (send f get-area-container)) filtered-table)
f)))))
(unless (null? filtered-table)
(let* ([f (make-object final-frame% (string-constant recover-autosave-files-frame-title))]
[t (instantiate text% ()
(auto-wrap #t))]
[ec (instantiate editor-canvas% ()
(parent (send f get-area-container))
(editor t)
(line-count 2)
(style '(no-hscroll)))]
[hp (make-object horizontal-panel% (send f get-area-container))]
[vp (make-object vertical-panel% hp)])
(make-object grow-box-spacer-pane% hp)
(send t insert (string-constant autosave-explanation))
(send t hide-caret #t)
(send t set-position 0 0)
(send t lock #t)
;; add-table-line : (is-a? area-container<%>)
(for-each (add-table-line vp f) filtered-table)
(send f show #t)
(yield done-semaphore)
(void))))))
(define done-semaphore (make-semaphore 0))
(define final-frame%
(class frame:basic%
(rename [super-on-close on-close])
(define/override (on-close)
(super-on-close)
(semaphore-post done-semaphore))
(super-instantiate ())))
;; add-table-line : (is-a? area-container<%>) (union #f (is-a?/c top-level-window<%>))
;; -> (list (union #f string[filename]) string[filename-file-exists?])
;; -> void
;; adds in a line to the overview table showing this pair of files.
(define (add-table-line area-container)
(define (add-table-line area-container parent)
(lambda (table-entry)
(let* ([orig-file (car table-entry)]
[backup-file (cadr table-entry)]
@ -123,14 +158,6 @@
(stretchable-height #f))]
[vp (instantiate vertical-panel% ()
(parent hp))]
[compare
(make-object button% (string-constant autosave-details) hp
(lambda (x y)
(show-differences table-entry)))]
[recover
(make-object button% (string-constant autosave-recover) hp
(lambda (x y)
(recover-file area-container hp table-entry)))]
[msg1-panel (instantiate horizontal-panel% ()
(parent vp))]
[msg1-label (instantiate message% ()
@ -148,11 +175,23 @@
[msg2 (instantiate message% ()
(label backup-file)
(stretchable-width #t)
(parent msg2-panel))])
(parent msg2-panel))]
[details
(make-object button% (string-constant autosave-details) hp
(lambda (x y)
(show-files table-entry)))]
[recover
(make-object button% (string-constant autosave-recover) hp
(lambda (recover y)
(let ([filename-result (recover-file parent table-entry)])
(when filename-result
(send recover enable #f)
(send details enable #f)
(send msg2 set-label (string-constant autosave-recovered!))
(send msg1 set-label filename-result)))))])
(let ([w (max (send msg1-label get-width) (send msg2-label get-width))])
(send msg1-label min-width w)
(send msg2-label min-width w))
(send compare enable orig-file)
(void))))
;; show-files : (list (union #f string[filename]) string) -> void
@ -169,8 +208,8 @@
(define hp (instantiate horizontal-panel% ()
(parent (send frame get-area-container))))
(when file1
(add-file-viewer file1 (string-constant autosave-original-label) hp))
(add-file-viewer file2 (string-constant autosave-autosave-label) hp)
(add-file-viewer file1 hp (string-constant autosave-original-label)))
(add-file-viewer file2 hp (string-constant autosave-autosave-label))
(send frame show #t)))
;; add-file-viewer : string[filename] -> void
@ -190,5 +229,23 @@
(editor:keymap-mixin
text:basic%)))
(define (recover-file parent child table-entry)
(void)))))
(main))
;; recover-file : (union #f (is-a?/c toplevel-window<%>))
;; (list (union #f string[filename]) string)
;; -> (union #f string)
(define (recover-file parent table-entry)
(let ([orig-name (or (car table-entry)
(parameterize ([finder:dialog-parent-parameter parent])
(finder:put-file)))])
(and orig-name
(let ([autosave-name (cadr table-entry)])
(let ([tmp-name (and (file-exists? orig-name)
(make-temporary-file "autosave-repair~a" orig-name))])
(when (file-exists? orig-name)
(delete-file orig-name))
(copy-file autosave-name orig-name)
(delete-file autosave-name)
(when tmp-name
(delete-file tmp-name))
orig-name))))))))

View File

@ -14,7 +14,9 @@
(let-values ([(base name dir?)
(if name
(split-path name)
(values (current-directory) "mredauto" #f))])
(values (find-system-path 'home-dir)
"mredauto"
#f))])
(let* ([base (if (string? base)
base
(current-directory))]