source: trunk/source/contrib/paine/workpersistence.lisp @ 12771

Last change on this file since 12771 was 12771, checked in by gz, 10 years ago

Update from Peter Paine: fix not saving closed windows, fix resizing in gui thread, save in home dir.

File size: 3.1 KB
Line 
1(in-package :cl-user)
2
3;;; Clozure CL Hemlock editor windows persistence
4;;; ie. on restart of CCL re-open (and position) the last session's open files.
5;;; LGPL   c/o Peter Paine 20080611
6;;; Update 20090906: fix not saving closed windows, fix resizing in gui thread, save in home dir.
7;;; ToDo: how to read window from buffer (without external search via path)?
8;;; To use: add (load ~this-file~) to your home:ccl-init.lisp file.
9
10;; Allows separation of working file sets for different CLZ versions.
11(defvar *separate-ccl-working-file-sets-p* T)
12
13(defvar *work-persistence-file*
14  (if *separate-ccl-working-file-sets-p*
15    (format nil "home:.ccl-workpersistence-~A.text" (ccl::platform-description))
16    "home:.ccl-workpersistence.text")
17  "per user")
18;; (ed *work-persistence-file*)
19
20(defun remember-hemlock-files ()
21    (with-open-file (*standard-output*
22                     *work-persistence-file*
23                     :direction :output :if-exists :supersede)
24      (loop for buffer in (hi::all-buffers)
25         do (let* ((path (hi:buffer-pathname buffer)))
26              (when path 
27                (let ((frame (slot-value (find-file-buffer-window path) 'ns:_frame)))
28                  (loop initially (format T "~&(")
29                    for fn in '(ns:ns-rect-x ns:ns-rect-y ns:ns-rect-width ns:ns-rect-height)
30                    do (format T "~5D " (floor (funcall fn frame)))
31                    finally (format T "~S)" path))))))))
32
33(defun find-file-buffer-window (path)
34   (loop with win-arr = (#/orderedWindows ccl::*NSApp*)
35     for i below (#/count win-arr)
36     for win = (#/objectAtIndex: win-arr i)
37     when (and (typep win '(and gui::hemlock-frame
38                                (not gui::hemlock-listener-frame)))
39               (equalp path (hi:buffer-pathname (hi:hemlock-view-buffer
40                                                 (gui::hemlock-view win)))))
41     return win))
42
43(defun open-remembered-hemlock-files ()
44   (with-open-file (buffer-persistence-stream
45                    *work-persistence-file*
46                    :direction :input :if-does-not-exist nil)
47     (when buffer-persistence-stream
48       (loop for item = (read buffer-persistence-stream nil)
49         while item
50         do (destructuring-bind (posx posy width height path) item
51              (when (probe-file path)
52                (gui::execute-in-gui #'(lambda () (gui::find-or-make-hemlock-view path)))
53                (let ((window (find-file-buffer-window path))) ; round about way*
54                  ;;* how to get from hemlock-view
55                  (when window
56                    ;; should check whether coords are still in screen bounds
57                    ;; (could have changed screen realestate since)
58                    (let ((rect (ns:make-ns-rect posx posy width height)))
59                      (gui::execute-in-gui 
60                       #'(lambda () 
61                           (#/setFrame:display: window rect t))))))))))))
62
63(pushnew 'remember-hemlock-files *lisp-cleanup-functions*)
64(pushnew 'open-remembered-hemlock-files *lisp-startup-functions*)
65
66;; (remember-hemlock-files)
67(open-remembered-hemlock-files)
Note: See TracBrowser for help on using the repository browser.