Skip to content

Commit 9509b24

Browse files
committed
add support to reopen files from the previous session
1 parent 2d559b3 commit 9509b24

File tree

11 files changed

+96
-27
lines changed

11 files changed

+96
-27
lines changed

gui-doc/scribblings/framework/frame.scrbl

+14-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777

7878
Returns @racket[#f].
7979
}
80+
@defmethod[(get-all-open-files) (listof path?)]{
81+
Indicates the files that are currently open in this frame.
82+
83+
Returns @racket['()].
84+
85+
@history[#:added "1.74"]
86+
}
8087
@defmethod*[(((get-filename (temp (or/c #f (box boolean?)) #f)) (or/c #f path?)))]{
8188
This returns the filename that the frame is currently being saved as,
8289
or @racket[#f] if there is no appropriate filename.
@@ -607,10 +614,16 @@
607614
@method[frame:editor<%> get-editor].
608615
}
609616

610-
@defmethod*[#:mode override (((editing-this-file? (filename path?)) boolean?))]{
617+
@defmethod[#:mode override (editing-this-file? [filename path?]) boolean?]{
611618
Returns @racket[#t] if the filename is the file that this frame is editing.
612619
}
613620

621+
@defmethod[#:mode override (get-all-open-files) (listof path?)]{
622+
Returns a list of all the paths for files that are open in this frame.
623+
624+
@history[#:added "1.74"]
625+
}
626+
614627
@defmethod*[#:mode augment (((on-close) void?))]{
615628
Calls the @racket[editor:basic<%>]'s method @method[editor:basic<%>
616629
on-close].

gui-lib/framework/main.rkt

+14
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,20 @@
450450
()
451451
@{Adds a font selection preferences panel to the preferences dialog.})
452452

453+
(proc-doc/names
454+
preferences:add-boolean-option-with-ask-me
455+
(-> (or/c (is-a?/c area-container<%>) #f)
456+
string?
457+
string?
458+
string?
459+
symbol?
460+
void?)
461+
(parent label option1 option2 pref-key)
462+
463+
@{Adds a checkbox to @racket[parent] with three options; the first two are given by @racket[option1] and @racket[option2], and
464+
the third is "Ask me". The preference named by@racket[pref-key] is updated based on the selection in the checkbox.
465+
})
466+
453467
(proc-doc/names
454468
preferences:show-dialog
455469
(-> void?)

gui-lib/framework/private/editor-misc.rkt

+5-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@
213213
(file-or-directory-modify-seconds filename))))))
214214

215215
(set! can-save-file-filename #f)
216+
217+
(handler:update-currently-open-files)
216218
(inner (void) after-save-file success?))
217219

218220
(define/augment (after-load-file success?)
@@ -223,7 +225,8 @@
223225
(set! last-saved-file-time
224226
(and filename
225227
(file-exists? filename)
226-
(file-or-directory-modify-seconds filename)))))
228+
(file-or-directory-modify-seconds filename))))
229+
(handler:update-currently-open-files))
227230
(inner (void) after-load-file success?))
228231

229232
(define/public (save-file-out-of-date?)
@@ -688,6 +691,7 @@
688691

689692
(define/augment (on-close)
690693
(remove-autosave)
694+
(handler:update-currently-open-files)
691695
(set! do-autosave? #f)
692696
(inner (void) on-close))
693697
(define/augment (on-change)

gui-lib/framework/private/frame.rkt

+8-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@
186186
[(b) #f]))
187187

188188
(define/public (editing-this-file? filename) #f)
189+
190+
(define/public (get-all-open-files) '())
189191

190192
(define/override (on-superwindow-show shown?)
191193
(send (group:get-the-frame-group) frame-shown/hidden this)
@@ -510,7 +512,8 @@
510512
(define/override (on-activate on?)
511513
(super on-activate on?)
512514
(when on?
513-
(send (group:get-the-frame-group) set-active-frame this)))
515+
(send (group:get-the-frame-group) set-active-frame this))
516+
(handler:update-currently-open-files))
514517

515518
(super-new)
516519
(send (group:get-the-frame-group) insert-frame this)))
@@ -1449,6 +1452,10 @@
14491452
(let ([this-fn (get-filename)])
14501453
(and this-fn
14511454
(path-equal? filename (get-filename))))))
1455+
1456+
(define/override (get-all-open-files)
1457+
(with-handlers ((exn:fail? (λ (x) '())))
1458+
(list (normalize-path (get-filename)))))
14521459

14531460
(define/augment (on-close)
14541461
(send (get-editor) on-close)

gui-lib/framework/private/group.rkt

+7
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@
263263
(if (test-frame frame)
264264
frame
265265
(loop (cdr frames))))]))))
266+
267+
(define/public (get-all-open-files)
268+
(define the-frames (map frame-frame frames))
269+
(when (member active-frame the-frames)
270+
(set! the-frames (cons active-frame (remove active-frame the-frames))))
271+
(for/list ([frame (in-list the-frames)])
272+
(send frame get-all-open-files)))
266273

267274
(super-new)))
268275

gui-lib/framework/private/handler.rkt

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
string-constants)
1111

1212
(import mred^
13+
[prefix exit: framework:exit^]
1314
[prefix finder: framework:finder^]
1415
[prefix group: framework:group^]
1516
[prefix frame: framework:frame^])
@@ -126,6 +127,13 @@
126127
(preferences:get 'framework:recent-max-count)))
127128
(preferences:set 'framework:recently-opened-files/pos new-recent))
128129

130+
(define (update-currently-open-files)
131+
(unless (exit:exiting?)
132+
(preferences:set
133+
'framework:last-opened-files
134+
(send (group:get-the-frame-group)
135+
get-all-open-files))))
136+
129137
;; same-enough-path? : path path -> boolean
130138
;; used to determine if the open-recent-files menu item considers two paths to be the same
131139
(define (recently-opened-files-same-enough-path? p1 p2)

gui-lib/framework/private/interfaces.rkt

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
make-root-area-container
7575
close
7676
editing-this-file?
77+
get-all-open-files
7778
get-filename
7879
make-visible))
7980

gui-lib/framework/private/main.rkt

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
(application-preferences-handler (λ () (preferences:show-dialog)))
2929

30+
(preferences:set-default 'framework:last-opened-files '() (listof (listof path?)))
31+
(preferences:set-un/marshall 'framework:last-opened-files
32+
(λ (x) (map (λ (x) (map path->bytes x)) x))
33+
(λ (x) (map (λ (x) (map bytes->path x)) x)))
34+
3035
(preferences:set-default 'framework:caret-blink-disable? #f boolean?)
3136

3237
(preferences:set-default 'framework:editor-x-selection-mode #t boolean?)

gui-lib/framework/private/preferences.rkt

+31-22
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,31 @@ the state transitions / contracts are:
567567
(cadr current)))))
568568
(update-tf-bkg))
569569

570+
(define (add-boolean-option-with-ask-me parent label option1 option2 pref-key)
571+
(define rb
572+
(new radio-box%
573+
[label label]
574+
[parent parent]
575+
[choices (list option1
576+
option2
577+
(string-constant ask-me-each-time))]
578+
[callback
579+
(λ (rb evt)
580+
(preferences:set pref-key
581+
(case (send rb get-selection)
582+
[(0) #t]
583+
[(1) #f]
584+
[(2) 'ask])))]))
585+
(define (update-rb what)
586+
(send rb set-selection
587+
(case what
588+
[(#t) 0]
589+
[(#f) 1]
590+
[(ask) 2])))
591+
(update-rb (preferences:get pref-key))
592+
(preferences:add-callback pref-key (λ (p v) (update-rb v)))
593+
(void))
594+
570595
(define (add-general-checkbox-panel) (add-general-checkbox-panel/real))
571596
(define (add-general-checkbox-panel/real)
572597
(set! add-general-checkbox-panel/real void)
@@ -579,28 +604,12 @@ the state transitions / contracts are:
579604
(string-constant backup-unsaved-files))
580605
(add-check editor-panel 'framework:backup-files? (string-constant first-change-files))
581606

582-
(define auto-load-rb
583-
(new radio-box%
584-
[label (string-constant autoload-automatically-reload)]
585-
[parent editor-panel]
586-
[choices (list (string-constant autoload-when-the-editor-isnt-dirty)
587-
(string-constant autoload-never-revert)
588-
(string-constant autoload-ask-about-reverting))]
589-
[callback
590-
(λ (rb evt)
591-
(preferences:set 'framework:autoload
592-
(case (send rb get-selection)
593-
[(0) #t]
594-
[(1) #f]
595-
[(2) 'ask])))]))
596-
(define (update-auto-load-rb what)
597-
(send auto-load-rb set-selection
598-
(case what
599-
[(#t) 0]
600-
[(#f) 1]
601-
[(ask) 2])))
602-
(update-auto-load-rb (preferences:get 'framework:autoload))
603-
(preferences:add-callback 'framework:autoload (λ (p v) (update-auto-load-rb v)))
607+
(add-boolean-option-with-ask-me
608+
editor-panel
609+
(string-constant autoload-automatically-reload)
610+
(string-constant autoload-when-the-editor-isnt-dirty)
611+
(string-constant autoload-never-revert)
612+
'framework:autoload)
604613

605614
(unless (equal? (system-type) 'unix)
606615
(define (bool->pref b) (if b 'std 'common))

gui-lib/framework/private/sig.rkt

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
add-can-close-dialog-callback
112112

113113
add-check
114-
114+
add-boolean-option-with-ask-me
115115
show-dialog
116116
hide-dialog))
117117

@@ -289,6 +289,7 @@
289289
open-file
290290
install-recent-items
291291
add-to-recent
292+
update-currently-open-files ;; not provided outside of the unit
292293
set-recent-position
293294
set-recent-items-frame-superclass
294295
size-recently-opened-files))

gui-lib/info.rkt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
(define pkg-authors '(mflatt robby))
3636

37-
(define version "1.73")
37+
(define version "1.74")
3838

3939
(define license
4040
'(Apache-2.0 OR MIT))

0 commit comments

Comments
 (0)