Changeset 14249


Ignore:
Timestamp:
Sep 11, 2010, 4:10:55 AM (9 years ago)
Author:
jaj
Message:

Clean up search files

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

Legend:

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

    r14244 r14249  
    120120  (declare (ignore sender))
    121121  (let ((w nil))
    122     (if (or (current-event-command-key-p)
     122    (if (or (current-event-modifier-p #$NSFunctionKeyMask)
    123123            (null (setf w (first-window-with-controller-type 'search-files-window-controller))))
    124124      (let* ((wc (make-instance 'search-files-window-controller)))
    125         (#/showWindow: wc self))
    126       (#/makeKeyAndOrderFront: w self))))
     125        (#/showWindow: wc self)
     126        (set-search-files-default-dir wc))
     127      (progn
     128        (#/makeKeyAndOrderFront: w self)
     129        (set-search-files-default-dir (#/windowController w))))))
    127130
    128131(objc:defmethod (#/newListener: :void) ((self lisp-application-delegate)
  • trunk/source/cocoa-ide/cocoa-editor.lisp

    r14248 r14249  
    25822582      (hemlock-buffer ts))))
    25832583
     2584(defmethod window-document ((w ns:ns-window))
     2585  (let* ((sc (#/sharedDocumentController ns:ns-document-controller))
     2586         (doc (#/documentForWindow: sc w)))
     2587    (if (%null-ptr-p doc)
     2588      nil
     2589      doc)))
     2590
     2591(defmethod window-pathname ((w ns:ns-window))
     2592  (document-pathname (window-document w)))
     2593
     2594(defmethod document-pathname ((doc NULL))
     2595  nil)
     2596
     2597(defmethod document-pathname ((doc hemlock-editor-document))
     2598  (hi:buffer-pathname (hemlock-buffer doc)))
     2599
    25842600(defmethod assume-not-editing ((doc hemlock-editor-document))
    25852601  (assume-not-editing (slot-value doc 'textstorage)))
  • trunk/source/cocoa-ide/cocoa-grep.lisp

    r12230 r14249  
    77(defvar *grep-program* "grep")
    88
    9 (defun cocoa-edit-grep-line (file line-num)
     9(defun cocoa-edit-grep-line (file line-num &optional search-string)
    1010  (assume-cocoa-thread)
    1111  (let ((view (find-or-make-hemlock-view file)))
    1212    (hi::handle-hemlock-event view #'(lambda ()
    13                                        (edit-grep-line-in-buffer line-num)))))
     13                                       (edit-grep-line-in-buffer line-num search-string)))))
    1414
    15 (defun edit-grep-line-in-buffer (line-num)
     15(defun edit-grep-line-in-buffer (line-num search-string)
    1616  (let ((point (hi::current-point-collapsing-selection)))
    1717    (hi::buffer-start point)
    18     (unless (hi::line-offset point line-num)
     18    (if (hi::line-offset point line-num)
     19      (when search-string
     20        (setf hi::*last-search-string* search-string)
     21        (hemlock::start-isearch-mode :forward)
     22        (let ((iss (hi::value hemlock::i-search-state)))
     23          (hemlock::i-search-repeat iss)))     
    1924      (hi::buffer-end point))))
    2025
  • trunk/source/cocoa-ide/cocoa-utils.lisp

    r14244 r14249  
    139139    (nreverse ret)))
    140140
     141(defun front-window ()
     142  (map-windows #'(lambda (win) (return-from front-window win))))
     143
    141144(defun first-window-satisfying-predicate (pred)
    142145  (block foo
  • trunk/source/cocoa-ide/ide-contents/Resources/English.lproj/SearchFiles.nib/classes.nib

    r12134 r14249  
    5757                                <key>searchButton</key>
    5858                                <string>id</string>
     59                                <key>searchCommentsCheckbox</key>
     60                                <string>id</string>
    5961                                <key>statusField</key>
    6062                                <string>id</string>
  • trunk/source/cocoa-ide/ide-contents/Resources/English.lproj/SearchFiles.nib/info.nib

    r12134 r14249  
    1111        <key>IBOpenObjects</key>
    1212        <array>
    13                 <integer>1</integer>
     13                <integer>2</integer>
    1414        </array>
    1515        <key>IBSystem Version</key>
    16         <string>9J61</string>
     16        <string>9L30</string>
    1717        <key>targetFramework</key>
    1818        <string>IBCocoaFramework</string>
  • trunk/source/cocoa-ide/search-files.lisp

    r13116 r14249  
    4848   (recursive-p :initform t :reader recursive-p)
    4949   (case-sensitive-p :initform nil :reader case-sensitive-p)
    50    (expand-results-p :initform nil :reader expand-results-p))
     50   (expand-results-p :initform nil :reader expand-results-p)
     51   (grep-process :initform nil :accessor grep-process))
    5152  (:metaclass ns:+ns-object))
    5253
     
    6566
    6667
    67 
    68 
    6968;;; Enable and disable the Search button according to the state of the
    7069;;; search files dialog.
     
    7675
    7776(defmethod folder-valid-p ((wc search-files-window-controller))
    78   (let* ((fm (#/defaultManager ns:ns-file-manager))
    79          (path (folder-string-value wc)))
    80     (rlet ((dir-p #>BOOL))
    81       (and
    82        (#/fileExistsAtPath:isDirectory: fm path dir-p)
    83        (plusp (%get-byte dir-p))))))
     77  (let* ((nsstr (folder-string-value wc)))
     78    (when (and (typep nsstr ns:ns-string) (#/length nsstr))
     79      (let ((lstr (lisp-string-from-nsstring nsstr)))
     80        (when (valid-host-p lstr)
     81          (probe-file (get-full-dir-string lstr)))))))
    8482
    8583(objc:defmethod (#/controlTextDidChange: :void) ((wc search-files-window-controller) notification)
     
    144142
    145143
    146 
    147 
    148144(objc:defmethod #/init ((self search-files-window-controller))
    149145  (prog1
     
    167163  (#/cascadeTopLeftFromPoint: (#/window wc) *search-files-cascade-point*))
    168164
     165(defun set-search-files-default-dir (wc)
     166  (let* ((w (first-window-satisfying-predicate #'window-pathname))
     167         (path (and w (window-pathname w)))
     168         (dir (if path
     169                (namestring (ccl::back-translate-pathname (directory-namestring path)))
     170                "ccl:"))
     171         (nsdir (#/autorelease (%make-nsstring dir))))
     172    (with-slots (folder-combo-box) wc
     173      (#/setStringValue: folder-combo-box nsdir)
     174      (#/updateFolderString: wc folder-combo-box))))
     175
    169176(objc:defmethod (#/awakeFromNib :void) ((wc search-files-window-controller))
    170177  (#/setStringValue: (status-field wc) #@"")
     
    173180    (#/setDoubleAction: outline-view (@selector #/editLine:)))
    174181  (setf (find-string-value wc) #@"")
     182  (setf (folder-string-value wc) #@"")
    175183  (with-slots (file-name-combo-box) wc
    176184    (#/setStringValue: file-name-combo-box #@"*.lisp")
    177     (#/updateFileNameString: wc file-name-combo-box))
    178   (with-slots (folder-combo-box) wc
    179     (let ((dir (ccl::native-translated-namestring (ccl:current-directory))))
    180     (#/setStringValue: folder-combo-box
    181                        (#/autorelease (%make-nsstring dir)))
    182     (#/updateFolderString: wc folder-combo-box))))
     185    (#/updateFileNameString: wc file-name-combo-box)))
    183186
    184187(defun ns-string-equal (ns1 ns2)
     
    190193  ;make sure it has a trailing slash
    191194  (let ((ret (ccl::native-untranslated-namestring str)))
    192     (unless (eql #\/ (aref str (1- (length str))))
     195    (unless (eql #\/ (aref ret (1- (length ret))))
    193196      (setf ret (concatenate 'string ret "/")))
    194197    ret))
     198
     199;;; nil host is considered valid
     200(defmethod valid-host-p ((ob t))
     201  nil)
     202
     203(defmethod valid-host-p ((str string))
     204  (let ((colon-pos (position #\: str)))
     205    (or (not colon-pos)
     206        (ccl::logical-host-p (subseq str 0 colon-pos)))))
     207
     208(defmethod valid-host-p ((p pathname))
     209  (ccl::logical-host-p (pathname-host p)))
    195210
    196211(defmethod get-full-dir-string ((nsstring ns:ns-string))
     
    204219        (file-name-string-value wc) (#/stringValue (file-name-combo-box wc)))
    205220  (let* ((find-str (lisp-string-from-nsstring (find-string-value wc)))
    206          (folder-str (lisp-string-from-nsstring (folder-string-value wc)))
     221         (folder-str (get-full-dir-string (lisp-string-from-nsstring (folder-string-value wc))))
    207222         (file-str (lisp-string-from-nsstring (file-name-string-value wc)))
    208          (grep-args (list "-I" "-s" "-c" "-e" find-str "--include" file-str
    209                           (get-full-dir-string folder-str))))
     223         (grep-args (list "-I" "-s" "-c" "-e" find-str "--include" file-str folder-str)))
    210224    (when (recursive-p wc)
    211225      (push "-r" grep-args))
     
    215229          (search-str wc) find-str)
    216230    (#/setEnabled: (search-button wc) nil)
    217     (process-run-function "grep" 'run-grep grep-args wc)
     231    (setf (grep-process wc) (process-run-function "grep" 'run-grep grep-args wc))
    218232    (#/setTitle: (#/window wc) (#/autorelease
    219233                                (%make-nsstring (format nil "Search Files: ~a"
    220234                                                        find-str))))))
     235
     236(objc:defmethod (#/windowWillClose: :void) ((wc search-files-window-controller)
     237                                            notification)
     238  (declare (ignore notification))
     239  (let* ((proc (grep-process wc)))
     240    (when proc (process-kill proc))))
    221241
    222242(defun auto-expandable-p (results)
     
    246266;;              (expand-results-p wc))
    247267;;       (expand-all-results wc))
     268    (setf (grep-process wc) nil)
    248269    (#/reloadData (outline-view wc))
    249270    (#/setEnabled: (search-button wc) t)))
     
    329350    (when line-result
    330351      (cocoa-edit-grep-line (concatenate 'string (search-dir wc) "/" (search-result-line-file line-result))
    331                       (1- (search-result-line-number line-result))))))
     352                      (1- (search-result-line-number line-result))
     353                      (search-str wc)))))
    332354
    333355(defun get-selected-item (outline-view)
     
    351373  (declare (ignore view))
    352374  (with-slots (results) wc
    353     (if (eql item +null-ptr+)
     375    (if (Eql Item +Null-Ptr+)
    354376      (let ((result (aref results child)))
    355377        (or (search-result-file-nsstr result)
Note: See TracChangeset for help on using the changeset viewer.