Changeset 16040


Ignore:
Timestamp:
Mar 3, 2014, 4:37:14 PM (6 years ago)
Author:
xach
Message:

Remove unneeded dataSource code for Search Files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/search-files.lisp

    r16038 r16040  
    366366;;; Displaying and updating the interface
    367367;;;
    368 
    369 (defstruct search-result-file
    370   name ;A lisp string that contains the full path of the file
    371   nsstr  ;An NSString that is shown in the dialog
    372   lines ;A vector of search-result-lines
    373   )
    374368
    375369
     
    665659        (cocoa-edit-grep-line (%get-cfstring (#/path url))
    666660                              (1- line-number))))))
    667 
    668 (defun map-lines (string fn)
    669   "For each line in string, fn is called with the start and end of the line"
    670   (loop with end = (length string)
    671     for start = 0 then (1+ pos)
    672     as pos = (or (position #\Newline string :start start :end end) end)
    673     when (< start pos) do (funcall fn start pos)
    674     while (< pos end)))
    675 
    676 (defun nsstring-to-file-result (wc nsstring)
    677   (find nsstring (search-results wc) :test #'ns-string-equal :key #'search-result-file-nsstr))
    678 
    679 (defun nsstring-to-line-result (wc nsstring)
    680   (loop for file-result across (search-results wc)
    681     do (loop for line-result across (search-result-file-lines file-result)
    682          while line-result
    683          do (when (ns-string-equal nsstring (search-result-line-nsstr line-result))
    684               (return-from nsstring-to-line-result line-result)))))
    685 
    686 ;;NSOutlineView data source protocol
    687 ;- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
    688 (objc:defmethod #/outlineView:child:ofItem: ((wc search-files-window-controller) view (child :<NSI>nteger) item)
    689   (declare (ignore view))
    690   (with-slots (results) wc
    691     (if (Eql Item +Null-Ptr+)
    692       (let ((result (aref results child)))
    693         (or (search-result-file-nsstr result)
    694             (setf (search-result-file-nsstr result)
    695                   (%make-nsstring (format nil "[~a] ~a"
    696                                           (length (search-result-file-lines result))
    697                                           (search-result-file-name result))))))
    698       (let* ((file-result (nsstring-to-file-result wc item))
    699              (line-result (get-line-result wc file-result child)))
    700         (if line-result
    701           (search-result-line-nsstr line-result)
    702           #@"[internal error]")))))
    703 
    704 (defun get-line-result (wc file-result index)
    705   (let ((lines (search-result-file-lines file-result)))
    706     (or (aref lines index)
    707         (progn
    708           (compute-line-results wc file-result)
    709           (aref lines index)))))
    710 
    711 (defun compute-line-results (wc file-result)
    712   (with-slots (search-str search-dir) wc
    713     (let* ((grep-args (cons "-n" (make-grep-arglist wc search-str))) ; prefix each result with line number
    714            (grep-output (call-grep (nconc grep-args
    715                                           (list (concatenate 'string search-dir (search-result-file-name file-result))))))
    716            (index -1))
    717       (map-lines grep-output
    718                  #'(lambda (start end)
    719                      (let* ((str (subseq grep-output start end))
    720                             (colon-pos (position #\: str))
    721                             (num (parse-integer str :end colon-pos)))
    722                        (setf (aref (search-result-file-lines file-result) (incf index))
    723                              (make-search-result-line :file (search-result-file-name file-result)
    724                                                       :number num
    725                                                       :nsstr (%make-nsstring str)))))))))
    726 
    727 ;- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
    728 (objc:defmethod (#/outlineView:isItemExpandable: :<BOOL>) ((wc search-files-window-controller) view item)
    729   (declare (ignore view))
    730   ;;it's expandable if it starts with #\[ (it's a file)
    731   (and (typep item 'ns:ns-string)
    732        (= (char-code #\[) (#/characterAtIndex: item 0))))
    733 
    734 ;- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
    735 (objc:defmethod (#/outlineView:numberOfChildrenOfItem: :<NSI>nteger)
    736                 ((wc search-files-window-controller) view item)
    737   (declare (ignore view))
    738   (if (eql item +null-ptr+)
    739     (length (search-results wc))
    740     (let ((file-result (nsstring-to-file-result wc item)))
    741       (if file-result
    742         (length (search-result-file-lines file-result))
    743         0))))
    744 
    745 ;- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
    746 (objc:defmethod #/outlineView:objectValueForTableColumn:byItem:
    747                 ((wc search-files-window-controller) outline-view table-column item)
    748   (declare (ignore outline-view table-column))
    749   (let ((file-result (nsstring-to-file-result wc item)))
    750     (if file-result
    751       (search-result-file-nsstr file-result)
    752       (let ((line-result (nsstring-to-line-result wc item)))
    753         (if line-result
    754           (search-result-line-nsstr line-result)
    755           #@"ERROR")))))
    756 
    757 
Note: See TracChangeset for help on using the changeset viewer.