Changeset 12116


Ignore:
Timestamp:
May 24, 2009, 5:51:59 AM (10 years ago)
Author:
mikel
Message:

Added code that updates the swank port preference field from the defaults database at launch, and also shows in a label the current swank wire protocol version

Location:
trunk/source/cocoa-ide
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/ide-contents/Resources/English.lproj/preferences.nib/classes.nib

    r12115 r12116  
    3535                                <key>listenerTabViewItem</key>
    3636                                <string>id</string>
     37                                <key>swankPortField</key>
     38                                <string>id</string>
     39                                <key>swankProtocolLabel</key>
     40                                <string>id</string>
    3741                                <key>tabView</key>
    3842                                <string>id</string>
  • trunk/source/cocoa-ide/preferences.lisp

    r12115 r12116  
    5757
    5858(defclass preferences-window-controller (ns:ns-window-controller)
    59   ((tab-view :foreign-type :id :accessor tab-view)
     59  ((appearance-prefs :foreign-type :id :accessor appearance-prefs)
     60   (documentation-prefs :foreign-type :id :accessor documentation-prefs)
    6061   (editor-tab-view-item :foreign-type :id :accessor editor-tab-view-item)
     62   (encodings-prefs :foreign-type :id :accessor encodings-prefs)
     63   (general-prefs :foreign-type :id :accessor general-prefs)
     64   (hyperspec-path-button :foreign-type :id :accessor hyperspec-path-button)
    6165   (listener-tab-view-item :foreign-type :id :accessor listener-tab-view-item)
    62    (hyperspec-path-button :foreign-type :id :accessor hyperspec-path-button)
    63    (toolbar :foreign-type :id :accessor toolbar)
    64    (general-prefs :foreign-type :id :accessor general-prefs)
    65    (appearance-prefs :foreign-type :id :accessor appearance-prefs)
    66    (documentation-prefs :foreign-type :id :accessor documentation-prefs)
    67    (encodings-prefs :foreign-type :id :accessor encodings-prefs))
     66   (swank-port-field :foreign-type :id :accessor swank-port-field)
     67   (swank-protocol-label :foreign-type :id :accessor swank-protocol-label)
     68   (tab-view :foreign-type :id :accessor tab-view)
     69   (toolbar :foreign-type :id :accessor toolbar))
    6870  (:metaclass ns:+ns-object))
    6971
     
    8284  self)
    8385
     86(eval-when (:compile-toplevel :load-toplevel :execute)
     87    (require :swank))
     88
    8489(objc:defmethod (#/windowDidLoad :void) ((self preferences-window-controller))
    85   (let* ((window (#/window self)))
     90  (let* ((window (#/window self))
     91         (swank-protocol-version swank::*swank-wire-protocol-version*)
     92         (protocol-label (swank-protocol-label self))
     93         (port-field (swank-port-field self))
     94         (swank-port (or (preference-swank-port) *default-gui-swank-port*)))
    8695    (with-slots (toolbar) self
    8796      (setf toolbar (make-instance 'ns:ns-toolbar
     
    93102      (#/setShowsToolbarButton: window nil)
    94103      (#/release toolbar))
     104    (ccl::with-autoreleased-nsstring (label-str (format nil "Swank protocol version: ~a" swank-protocol-version))
     105      (#/setStringValue: protocol-label label-str))
     106    (ccl::with-autoreleased-nsstring (port-string (format nil "~A" swank-port))
     107      (#/setStringValue: port-field port-string))
    95108    (#/showAppearancePrefs: self +null-ptr+)))
    96109 
  • trunk/source/cocoa-ide/start.lisp

    r12115 r12116  
    8787(eval-when (:compile-toplevel :load-toplevel :execute)
    8888    (require :swank))
    89 
    90 (defun try-starting-swank (&key (force nil))
    91   (unless *ccl-swank-active-p*
    92     ;; try to determine the user preferences concerning the swank port number
    93     ;; and whether the swank server should be started. If the user says start
    94     ;; it, and we can determine a valid port for it, start it up
    95     (let* ((defaults (handler-case (#/values (#/sharedUserDefaultsController ns:ns-user-defaults-controller))
    96                        (serious-condition (c)
    97                          (progn (format t "~%ERROR: Unable to get preferences from the Shared User Defaults Controller")
    98                                 (force-output)
    99                                 nil))))
    100            (start-swank-pref (and defaults (#/valueForKey: defaults #@"startSwankServer")))
    101            (start-swank? (cond
    102                            ;; force is true, so we don't care about the user pref
    103                            (force t)
    104                            ;; the user default is not initialized
    105                            ((or (null start-swank-pref)
    106                                 (%null-ptr-p start-swank-pref)) nil)
    107                            ;; examine the user default
    108                            ((typep start-swank-pref 'ns:ns-number)
    109                             (case (#/intValue start-swank-pref)
    110                               ;; don't start swank
    111                               (0 nil)
    112                               ;; start swank
    113                               (1 t)
    114                               ;; the user default value is incomprehensible
    115                               (otherwise (progn
    116                                            (format t "~%ERROR: Unrecognized value in user preference 'startSwankServer': ~S"
    117                                                    start-swank-pref)
    118                                            (force-output)
    119                                            nil))))
    120                            ;; the user default value is incomprehensible
    121                            (t (progn
    122                                 (format t "~%ERROR: Unrecognized value type in user preference 'startSwankServer': ~S"
    123                                         start-swank-pref)
    124                                 (force-output)
    125                                 nil))))
    126            (swank-port-pref (and defaults (#/valueForKey: defaults #@"swankPort")))
    127            (swank-port (cond
    128                          ;; the user default is not initialized
    129                          ((or (null swank-port-pref)
    130                               (%null-ptr-p swank-port-pref)) nil)
    131                          ;; examine the user default
    132                          ((typep swank-port-pref 'ns:ns-string)
    133                           (handler-case (let* ((port-str (lisp-string-from-nsstring swank-port-pref))
    134                                                (port (parse-integer port-str :junk-allowed nil)))
    135                                           (or port *default-gui-swank-port*))
    136                             ;; parsing the port number failed
    137                             (ccl::parse-integer-not-integer-string (c)
    138                               (setf *ccl-swank-active-p* nil)
    139                               (format t "~%Error starting swank server; the swank-port user preference is not a valid port number: ~S~%"
    140                                       port-str)
    141                               (force-output)
    142                               nil)))
    143                          ;; the user default value is incomprehensible
    144                          (t (progn
    145                               (format t "~%ERROR: Unrecognized value type in user preference 'swankPort': ~S"
    146                                       swank-port-pref)
    147                               (force-output)
    148                               nil)))))
    149       (if (and start-swank? swank-port)
    150           ;; try to start the swank server
    151           (handler-case (progn
    152                           (swank:create-server :port swank-port :dont-close t)
    153                           (setf *ccl-swank-active-p* t)
    154                           (setf *active-gui-swank-port* swank-port)
    155                           swank-port)
    156             ;; swank server creation failed
    157             (serious-condition (c)
    158               (setf *ccl-swank-active-p* nil)
    159               (setf *active-gui-swank-port* nil)
    160               (format t "~%Error starting swank server: ~A~%" c)
    161               (force-output)
    162               nil))
    163           ;; don't try to start the swank server
    164           (progn
    165             (setf *ccl-swank-active-p* nil)
    166             (setf *active-gui-swank-port* nil)
    167             nil)))))
    16889
    16990(defmethod toplevel-function ((a cocoa-application) init-file)
  • trunk/source/cocoa-ide/swank.lisp

    r12104 r12116  
    88(swank-loader::load-swank)
    99
     10(defun preference-start-swank? ()
     11  (let* ((defaults (handler-case (#/values (#/sharedUserDefaultsController ns:ns-user-defaults-controller))
     12                     (serious-condition (c)
     13                       (progn (format t "~%ERROR: Unable to get preferences from the Shared User Defaults Controller")
     14                              (force-output)
     15                              nil))))
     16         (start-swank-pref (and defaults (#/valueForKey: defaults #@"startSwankServer"))))
     17    (cond
     18      ;; the user default is not initialized
     19      ((or (null start-swank-pref)
     20           (%null-ptr-p start-swank-pref)) nil)
     21      ;; examine the user default
     22      ((typep start-swank-pref 'ns:ns-number)
     23       (case (#/intValue start-swank-pref)
     24         ;; don't start swank
     25         (0 nil)
     26         ;; start swank
     27         (1 t)
     28         ;; the user default value is incomprehensible
     29         (otherwise (progn
     30                      (format t "~%ERROR: Unrecognized value in user preference 'startSwankServer': ~S"
     31                              start-swank-pref)
     32                      (force-output)
     33                      nil))))
     34      ;; the user default value is incomprehensible
     35      (t (progn
     36           (format t "~%ERROR: Unrecognized value type in user preference 'startSwankServer': ~S"
     37                   start-swank-pref)
     38           (force-output)
     39           nil)))))
     40
     41(defun preference-swank-port ()
     42  (let* ((defaults (handler-case (#/values (#/sharedUserDefaultsController ns:ns-user-defaults-controller))
     43                     (serious-condition (c)
     44                       (progn (format t "~%ERROR: Unable to get preferences from the Shared User Defaults Controller")
     45                              (force-output)
     46                              nil))))
     47         (swank-port-pref (and defaults (#/valueForKey: defaults #@"swankPort"))))
     48    (cond
     49      ;; the user default is not initialized
     50      ((or (null swank-port-pref)
     51           (%null-ptr-p swank-port-pref)) nil)
     52      ;; examine the user default
     53      ((typep swank-port-pref 'ns:ns-string)
     54       (handler-case (let* ((port-str (lisp-string-from-nsstring swank-port-pref))
     55                            (port (parse-integer port-str :junk-allowed nil)))
     56                       (or port *default-gui-swank-port*))
     57         ;; parsing the port number failed
     58         (ccl::parse-integer-not-integer-string (c)
     59           (setf *ccl-swank-active-p* nil)
     60           (format t "~%Error starting swank server; the swank-port user preference is not a valid port number: ~S~%"
     61                   port-str)
     62           (force-output)
     63           nil)))
     64      ;; the user default value is incomprehensible
     65      (t (progn
     66           (format t "~%ERROR: Unrecognized value type in user preference 'swankPort': ~S"
     67                   swank-port-pref)
     68           (force-output)
     69           nil)))))
     70
     71(defun try-starting-swank (&key (force nil))
     72  (unless *ccl-swank-active-p*
     73    ;; try to determine the user preferences concerning the swank port number
     74    ;; and whether the swank server should be started. If the user says start
     75    ;; it, and we can determine a valid port for it, start it up
     76    (let* ((start-swank? (or (preference-start-swank?) force))
     77           (swank-port (or (preference-swank-port) *default-gui-swank-port*)))
     78      (if (and start-swank? swank-port)
     79          ;; try to start the swank server
     80          (handler-case (progn
     81                          (swank:create-server :port swank-port :dont-close t)
     82                          (setf *ccl-swank-active-p* t)
     83                          (setf *active-gui-swank-port* swank-port)
     84                          swank-port)
     85            ;; swank server creation failed
     86            (serious-condition (c)
     87              (setf *ccl-swank-active-p* nil)
     88              (setf *active-gui-swank-port* nil)
     89              (format t "~%Error starting swank server: ~A~%" c)
     90              (force-output)
     91              nil))
     92          ;; don't try to start the swank server
     93          (progn
     94            (setf *ccl-swank-active-p* nil)
     95            (setf *active-gui-swank-port* nil)
     96            nil)))))
     97
    1098(provide :swank)
Note: See TracChangeset for help on using the changeset viewer.