Changeset 15949


Ignore:
Timestamp:
Oct 14, 2013, 9:31:43 PM (7 years ago)
Author:
rme
Message:

Create preferences panel in code rather than using a nib file.
Also remove unimplemented bits of the preferences panel.

Remove unused file cocoa-prefs.lisp.

Location:
trunk/source/cocoa-ide
Files:
1 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/app-delegate.lisp

    r15941 r15949  
    7575  (when (null *preferences-window-controller*)
    7676    (setf *preferences-window-controller*
    77           (make-instance 'preferences-window-controller)))
     77          (make-instance 'ccl-preferences-window-controller)))
    7878  (#/showWindow: *preferences-window-controller* self))
    7979
  • trunk/source/cocoa-ide/defsystem.lisp

    r15362 r15949  
    6565  '("libdispatch"
    6666    "event-process"
     67    "cg"
    6768    "cf-utils"))
    6869
     
    7273    "cocoa-utils"
    7374    "cocoa-defaults"
    74     "cocoa-prefs"
    7575    "cocoa-typeout"
    7676    "console-window"
     
    8686    "project"
    8787    "cocoa-remote-lisp"
     88    "preferences-views"
    8889    "preferences"
    8990    "processes-window"
  • trunk/source/cocoa-ide/preferences.lisp

    r15188 r15949  
    22;;;
    33;;;   Copyright (C) 2007 Clozure Associates
    4 ;;;
    5 ;;; How to add a new preference pane:
    6 ;;;
    7 ;;; 1. Open preferences.nib with IB.  Drag a Custom View instance from
    8 ;;;    the palette.  Use the inpector to set its class to PreferencesView.
    9 ;;; 2. Inspect File's Owner (which represents an instance of
    10 ;;;    PreferencesWindowController).  Add an outlet for the new
    11 ;;;    preferences view you just made.  Hook up the outlet.  You can
    12 ;;;    add actions here too, if your preferences view will need them.
    13 ;;; 3. Add controls to your view, binding them to the defaults controller.
    14 ;;; 4. Save the nib file.
    15 ;;; 5. In preferences.lisp (this file), edit the defclass form for
    16 ;;;    preferences-window-controller and add a slot that matches the outlet
    17 ;;;    you created in step 2.
    18 ;;; 6. Edit the toolbar delegate methods to add a toolbar item for your
    19 ;;;    new preference view.
    20 ;;; 7. Implement a #/showFooPrefs: method to swap in the view when
    21 ;;;    the toolbar item is clicked.  (See #/showGeneralPrefs: for an
    22 ;;;    example.
    23 ;;; 8. Implement actions, if needed.
    24 
    254
    265(in-package "GUI")
    27 
    28 ;;; A view that keeps track of its initial size.
    29 (defclass preferences-view (ns:ns-view)
    30   ((width :accessor width)
    31    (height :accessor height))
    32   (:metaclass ns:+ns-object))
    33 
    34 (objc:defmethod (#/awakeFromNib :void) ((self preferences-view))
    35   (let* ((frame (#/frame self)))
    36     (setf (width self) (ns-width frame)
    37           (height self) (ns-height frame))))
    386
    397(defclass font-to-name-transformer (ns:ns-value-transformer)
     
    5624    (#/stringWithFormat: ns:ns-string #@"%@ %.0f" :id name :double-float size)))
    5725
    58 (defclass preferences-window-controller (ns:ns-window-controller)
    59   ((appearance-prefs :foreign-type :id :accessor appearance-prefs)
    60    (documentation-prefs :foreign-type :id :accessor documentation-prefs)
    61    (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)
    65    (listener-tab-view-item :foreign-type :id :accessor listener-tab-view-item)
    66    (tab-view :foreign-type :id :accessor tab-view)
    67    (toolbar :foreign-type :id :accessor toolbar))
     26(defclass ccl-preferences-window-controller (ns:ns-window-controller)
     27  ((general-view :foreign-type :id)
     28   (appearance-view :foreign-type :id))
    6829  (:metaclass ns:+ns-object))
    6930
    70 (objc:defmethod #/init ((self preferences-window-controller))
     31(objc:defmethod (#/dealloc :void) ((self ccl-preferences-window-controller))
     32  (#/release (slot-value self 'general-view))
     33  (#/release (slot-value self 'appearance-view))
     34  (call-next-method))
     35
     36(objc:defmethod #/init ((self ccl-preferences-window-controller))
    7137  (#/setValueTransformer:forName: ns:ns-value-transformer
    7238                                  (make-instance 'font-to-name-transformer)
    7339                                  #@"FontToName")
    74 
    75   (#/initWithWindowNibName: self #@"preferences")
     40  (setf (slot-value self 'general-view) (%preferences-general-view)
     41        (slot-value self 'appearance-view) (%preferences-appearance-view))
     42  (let* ((window (%preferences-panel))
     43         (toolbar (#/initWithIdentifier: (#/alloc ns:ns-toolbar)
     44                                         #@"ccl-preferences")))
     45    (#/initWithWindow: self window)
     46    (#/release window)
     47    (#/setDelegate: toolbar self)
     48    (#/setToolbar: window toolbar)
     49    (#/release toolbar)
     50    (#/setSelectedItemIdentifier: toolbar #@"appearance")
     51    (#/showAppearancePrefs: self +null-ptr+))
    7652  (#/addObserver:selector:name:object: (#/defaultCenter ns:ns-notification-center)
    7753                                       self
     
    8258  self)
    8359
    84 (objc:defmethod (#/windowDidLoad :void) ((self preferences-window-controller))
    85   (let* ((window (#/window self)))
    86     (with-slots (toolbar) self
    87       (setf toolbar (make-instance 'ns:ns-toolbar
    88                                    :with-identifier #@"preferences-window-toolbar"))
    89       (#/setDelegate: toolbar self)
    90       (#/setSelectedItemIdentifier: toolbar #@"appearance")
    91       (#/setToolbar: window toolbar)
    92       ;; for some reason, setting this in IB doesn't work on Tiger/PPC32
    93       (#/setShowsToolbarButton: window nil)
    94       (#/release toolbar))
    95     (#/showAppearancePrefs: self +null-ptr+)))
    96  
    97 (objc:defmethod (#/showWindow: :void) ((self preferences-window-controller)
     60(objc:defmethod (#/showWindow: :void) ((self ccl-preferences-window-controller)
    9861                                       sender)
    9962  (#/center (#/window self))
    10063  (call-next-method sender))
    10164
    102 (objc:defmethod (#/defaultsDidChange: :void) ((self preferences-window-controller)
     65(objc:defmethod (#/defaultsDidChange: :void) ((self ccl-preferences-window-controller)
    10366                                              notification)
    10467  (declare (ignore notification))
     
    11275(defvar *listener-or-editor* nil)
    11376
    114 (objc:defmethod (#/showFontPanel: :void) ((self preferences-window-controller)
     77(objc:defmethod (#/showFontPanel: :void) ((self ccl-preferences-window-controller)
    11578                                         sender)
    11679  (let* ((tag (#/tag sender))
     
    13497;;; This message is sent to the first responder, which is why
    13598;;; we do the *listener-or-editor* thing.
    136 (objc:defmethod (#/changeFont: :void) ((self preferences-window-controller)
     99(objc:defmethod (#/changeFont: :void) ((self ccl-preferences-window-controller)
    137100                                            font-manager)
    138101  (let* ((defaults (#/standardUserDefaults ns:ns-user-defaults))
     
    159122
    160123(objc:defmethod #/toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
    161                 ((self preferences-window-controller)
     124                ((self ccl-preferences-window-controller)
    162125                 toolbar itemIdentifier (flag :<BOOL>))
    163126  (declare (ignore toolbar))
     
    168131                                :with-item-identifier itemIdentifier))
    169132      (#/setLabel: item #@"General")
    170       (#/setImage: item (#/imageNamed: ns:ns-image #@"General"))
     133      (#/setImage: item (#/imageNamed: ns:ns-image
     134                                       #&NSImageNamePreferencesGeneral))
    171135      (#/setTarget: item self)
    172136      (#/setAction: item (@selector #/showGeneralPrefs:)))
     
    177141      (#/setImage: item (#/imageNamed: ns:ns-image #@"Appearance"))
    178142      (#/setTarget: item self)
    179       (#/setAction: item (@selector #/showAppearancePrefs:)))
    180      ((#/isEqualToString: itemIdentifier #@"documentation")
    181       (setf item (make-instance 'ns:ns-toolbar-item
    182                                 :with-item-identifier itemIdentifier))
    183       (#/setLabel: item #@"Documentation")
    184       (#/setImage: item (#/imageNamed: ns:ns-image #@"Documentation"))
    185       (#/setTarget: item self)
    186       (#/setAction: item (@selector #/showDocumentationPrefs:)))
    187      ((#/isEqualToString: itemIdentifier #@"encodings")
    188       (setf item (make-instance 'ns:ns-toolbar-item
    189                                 :with-item-identifier itemIdentifier))
    190       (#/setLabel: item #@"Encodings")
    191       (#/setImage: item (#/imageNamed: ns:ns-image #@"Encodings"))
    192       (#/setTarget: item self)
    193       (#/setAction: item (@selector #/showEncodingsPrefs:))))
     143      (#/setAction: item (@selector #/showAppearancePrefs:))))
    194144    (#/autorelease item)))
    195145
    196146(objc:defmethod #/toolbarDefaultItemIdentifiers:
    197                 ((self preferences-window-controller) toolbar)
     147                ((self ccl-preferences-window-controller) toolbar)
    198148  (declare (ignore toolbar))
    199149  (#/arrayWithObjects: ns:ns-array #@"general"
    200150                       #@"appearance"
    201                        #@"documentation"
    202                        #@"encodings"
    203                        +null-ptr+)) ; don't even think about putting nil here
     151                       +null-ptr+))
    204152
    205153(objc:defmethod #/toolbarAllowedItemIdentifiers:
    206                 ((self preferences-window-controller) toolbar)
     154                ((self ccl-preferences-window-controller) toolbar)
    207155  (declare (ignore toolbar))
    208156  (#/arrayWithObjects: ns:ns-array #@"general"
    209157                       #@"appearance"
    210                        #@"documentation"
    211                        #@"encodings"
    212158                       +null-ptr+))
    213159
    214160(objc:defmethod #/toolbarSelectableItemIdentifiers:
    215                 ((self preferences-window-controller) toolbar)
     161                ((self ccl-preferences-window-controller) toolbar)
    216162  (declare (ignore toolbar))
    217163  (#/arrayWithObjects: ns:ns-array #@"general"
    218164                       #@"appearance"
    219                        #@"documentation"
    220                        #@"encodings"
    221165                       +null-ptr+))
    222166
    223 (defun switch-content-view (window view)
    224   (#/setContentView: window view)
     167(defun switch-preference-view (window view)
     168  (#/setSubviews: (#/contentView window)
     169                  (#/array ns:ns-array))
    225170  (let* ((frame (#/frame window))
    226171         (min-size (#/minSize window))
    227172         (new-frame nil)
     173         (view-frame (#/frame view))
     174         (view-height (ns:ns-rect-height view-frame))
     175         (view-width (ns:ns-rect-width view-frame))
    228176         (content-rect (#/contentRectForFrameRect: window frame))
    229          (dy (- (height view)
     177         (dy (- view-height
    230178                (ns-height content-rect))))
    231179    (decf (ns:ns-rect-y content-rect) dy)
    232180    (incf (ns:ns-rect-height content-rect) dy)
    233     (setf (ns:ns-rect-width content-rect) (max (width view)
     181    (setf (ns:ns-rect-width content-rect) (max view-width
    234182                                               (ns:ns-size-width min-size)))
    235183    (setq new-frame (#/frameRectForContentRect: window content-rect))
    236     (#/setFrame:display:animate: window new-frame t t)))
     184    (#/setFrame:display:animate: window new-frame t t))
     185  (#/setSubviews: (#/contentView window)
     186                  (#/arrayWithObject: ns:ns-array view)))
    237187
    238188;;; toolbar actions
    239189
    240 (objc:defmethod (#/showGeneralPrefs: :void) ((self preferences-window-controller)
     190(objc:defmethod (#/showGeneralPrefs: :void) ((self ccl-preferences-window-controller)
    241191                                                sender)
    242192  (declare (ignore sender))
    243193  (#/setTitle: (#/window self) #@"General")
    244   (switch-content-view (#/window self) (general-prefs self)))
    245 
    246 (objc:defmethod (#/showAppearancePrefs: :void) ((self preferences-window-controller)
     194  (switch-preference-view (#/window self) (slot-value self 'general-view)))
     195
     196(objc:defmethod (#/showAppearancePrefs: :void) ((self ccl-preferences-window-controller)
    247197                                                sender)
    248198  (declare (ignore sender))
    249199  (#/setTitle: (#/window self) #@"Appearance")
    250   (switch-content-view (#/window self) (appearance-prefs self)))
    251 
    252 (objc:defmethod (#/showDocumentationPrefs: :void) ((self preferences-window-controller)
    253                                                 sender)
    254   (declare (ignore sender))
    255   (#/setTitle: (#/window self) #@"Documentation")
    256   (switch-content-view (#/window self) (documentation-prefs self)))
    257 
    258 (objc:defmethod (#/showEncodingsPrefs: :void) ((self preferences-window-controller)
    259                                                 sender)
    260   (declare (ignore sender))
    261   (#/setTitle: (#/window self) #@"Encodings")
    262   (switch-content-view (#/window self) (encodings-prefs self)))
     200  (switch-preference-view (#/window self) (slot-value self 'appearance-view)))
Note: See TracChangeset for help on using the changeset viewer.