Changeset 14247


Ignore:
Timestamp:
Sep 10, 2010, 8:41:33 PM (9 years ago)
Author:
rme
Message:

Add some contextual menu commands to Hemlock editor views.

There are two commands at the moment:

  • If the selection designates a file name (as determined by the the function gui::pathname-for-namestring-fragment), then the menu will contain an item that will open the said file.
  • If the selection looks like a symbol, there will be a menu item that will inspect the symbol.

This could be elaborated substantially, but it's a stake in the
ground, so to speak.

File:
1 edited

Legend:

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

    r14215 r14247  
    17991799  (text-view-context-menu))
    18001800
     1801(defun pathname-for-namestring-fragment (string)
     1802  "Return a pathname that STRING might designate."
     1803  ;; We could get fancy here, but for now just be stupid.
     1804  (let ((pathname (ignore-errors (probe-file string))))
     1805    (if (and (pathnamep pathname)
     1806             (not (directory-pathname-p pathname)))
     1807      pathname)))
     1808
     1809;;; If we get here, we've already checked that the selection represents
     1810;;; a valid pathname.
     1811(objc:defmethod (#/openSelection: :void) ((self hemlock-text-view) sender)
     1812  (declare (ignore sender))
     1813  (let* ((text (#/string self))
     1814         (selection (#/substringWithRange: text (#/selectedRange self)))
     1815         (pathname (pathname-for-namestring-fragment
     1816                    (lisp-string-from-nsstring selection))))
     1817    (ed pathname)))
     1818
     1819;;; If we get here, we've already checked that the selection represents
     1820;;; a valid symbol name.
     1821(objc:defmethod (#/inspectSelection: :void) ((self hemlock-text-view) sender)
     1822  (declare (ignore sender))
     1823  (let* ((text (#/string self))
     1824         (selection (#/substringWithRange: text (#/selectedRange self)))
     1825         (symbol-name (string-upcase (lisp-string-from-nsstring selection))))
     1826    (inspect (find-symbol symbol-name))))
     1827
    18011828;;; If we don't override this, NSTextView will start adding Google/
    18021829;;; Spotlight search options and dictionary lookup when a selection
     
    18041831(objc:defmethod #/menuForEvent: ((self hemlock-text-view) event)
    18051832  (declare (ignore event))
    1806   (#/menu self))
     1833  (let* ((text (#/string self))
     1834         (selection (#/substringWithRange: text (#/selectedRange self)))
     1835         (s (lisp-string-from-nsstring selection))
     1836         (menu (if (> (length s) 0)
     1837                 (#/copy (#/menu self))
     1838                 (#/retain (#/menu self)))))
     1839    (when (find-symbol (string-upcase s))
     1840      (let* ((title (#/stringByAppendingString: #@"Inspect " selection))
     1841             (item (make-instance 'ns:ns-menu-item :with-title title
     1842                     :action (@selector #/inspectSelection:)
     1843                     :key-equivalent #@"")))
     1844        (#/setTarget: item self)
     1845        (#/insertItem:atIndex: menu item 0)
     1846        (#/release item)))
     1847    (when (pathname-for-namestring-fragment s)
     1848      (let* ((title (#/stringByAppendingString: #@"Open " selection))
     1849             (item (make-instance 'ns:ns-menu-item :with-title title
     1850                     :action (@selector #/openSelection:)
     1851                     :key-equivalent #@"")))
     1852        (#/setTarget: item self)
     1853        (#/insertItem:atIndex: menu item 0)
     1854        (#/release item)))
     1855
     1856    (#/autorelease menu)))
    18071857
    18081858(defun make-scrolling-text-view-for-textstorage (textstorage x y width height tracks-width color style)
Note: See TracChangeset for help on using the changeset viewer.