Changeset 12771


Ignore:
Timestamp:
Sep 7, 2009, 9:51:28 PM (10 years ago)
Author:
gz
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/contrib/paine/workpersistence.lisp

    r12675 r12771  
    44;;; ie. on restart of CCL re-open (and position) the last session's open files.
    55;;; 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.
    69
    7 (defvar *work-persistence-file* "ccl:.workpersistence.text")
    8 ;; perhaps use (user-homedir-pathname)?
     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")
    918;; (ed *work-persistence-file*)
    1019
    1120(defun remember-hemlock-files ()
    12    (with-open-file (*standard-output*
    13                     *work-persistence-file*
    14                     :direction :output :if-exists :supersede)
    15      (let* ((win-arr (#/orderedWindows ccl::*NSApp*)))
    16        (loop for i below (#/count win-arr)
    17          for win = (#/objectAtIndex: win-arr i)
    18          when (typep win '(and gui::hemlock-frame
    19                                (not gui::hemlock-listener-frame)))
    20          do (let* ((buffer (hi:hemlock-view-buffer
    21                             (gui::hemlock-view win)))
    22                    (path (hi:buffer-pathname buffer)))
    23               (when path
    24                 (let ((frame (slot-value win 'ns:_frame)))
     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)))
    2528                  (loop initially (format T "~&(")
    2629                    for fn in '(ns:ns-rect-x ns:ns-rect-y ns:ns-rect-width ns:ns-rect-height)
    2730                    do (format T "~5D " (floor (funcall fn frame)))
    28                     finally (format T "~S)" path)))))))))
     31                    finally (format T "~S)" path))))))))
    2932
    30 (defun find-file-buffer (path)
     33(defun find-file-buffer-window (path)
    3134   (loop with win-arr = (#/orderedWindows ccl::*NSApp*)
    3235     for i below (#/count win-arr)
     
    4750         do (destructuring-bind (posx posy width height path) item
    4851              (when (probe-file path)
    49                 (gui::execute-in-gui #'(lambda ()
    50                                          (gui::find-or-make-hemlock-view path)
    51                                          (let ((window (find-file-buffer path))) ; round about way*
    52                                            ;;* how to get from hemlock-view
    53                                            (when window
    54                                              ;; should check whether coords are still in screen bounds
    55                                              ;; (could have changed screen realestate since)
    56                                              (let ((rect (ns:make-ns-rect posx posy width height)))
    57                                                (#/setFrame:display: window rect t))))))))))))
     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))))))))))))
    5862
    5963(pushnew 'remember-hemlock-files *lisp-cleanup-functions*)
     
    6165
    6266;; (remember-hemlock-files)
    63 ;; (open-remembered-hemlock-files)
     67(open-remembered-hemlock-files)
Note: See TracChangeset for help on using the changeset viewer.