(in-package :clim-listener)

(define-mime-type (text x-gsharp-score)
  (:extensions "gsh"))

(defmethod mime-type-to-command ((mime-type text/x-gsharp-score) pathname)
  (values `(com-load-in-gsharp ,pathname)
          "Load in GSharp"
          (format nil "Load ~A in GSharp" pathname)))

(defun load-in-gsharp (thing)
  (let ((frame-manager (find-frame-manager)))
    (when frame-manager
      (let ((gsharp-frame (find-if (lambda (x) (typep x 'gsharp:gsharp))
                                    (frame-manager-frames frame-manager))))
        (when gsharp-frame
          (typecase thing
            ((or pathname string)
             (execute-frame-command 
              gsharp-frame `(esa-io::com-find-file ,(pathname thing)))
             t)))))))

(define-listener-command (com-load-in-gsharp :name t)
    ((pathname 'pathname))
  (load-in-gsharp pathname))
