home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-12 | 8.9 KB | 261 lines | [TEXT/CCL2] |
- ;;;-*- Mode: Lisp; Package: COMMON-LISP-USER -*-
-
- (in-package :cl-user)
-
- ;; file: applescript-editor.lisp
-
-
- ;; Author T. Bonura, 1994
- ;; ©Apple Computer
- ;; an applescript editor (duhh)
- ;; TO DO:
- ;; Need to check to insure that if the contents of the buffer have changed,
- ;; before closing the editor, the applescript object gets the new changes - no
- ;; big deal right now.
-
- (require :scrolling-fred-dialog-item)
-
- (DEFMACRO MAKE-LITERAL-STRING (string)
- ;;takes a string and string quotes it. e.g. "foo" ->
- ;; "\"foo\""
- `(concatenate 'string "\"" ,string "\""))
-
- (DEFUN NULL-STRING-P (STRING)
- "Return t if the string is "" otherwise nil"
- (IF (NOT (STRINGP string))
- (ERROR nil (FORMAT nil "The arg to null-string-p, ~a, is not a string.~%" string))
- (IF (EQ (LENGTH string) 0)
- t
- nil)))
- (DEFVAR *AS-SCRIPT-EDITOR* NIL "Points to the applescript editor")
- (DEFVAR *BOGUS-SCRIPT*
- (concatenate 'string "tell application " (make-literal-string "applicationName")
- (format nil "~%") (format nil "~%")
- "end tell" (format nil "~%"))
- )
-
- ;; THis is where the script is actually written
- (DEFCLASS AS-INPUT-BUFFER (ccl::scrolling-fred-dialog-item)
- ()
- (:default-initargs
- :view-size #@(450 230)
- :view-nick-name 'input-buffer
- )
- )
-
- (DEFCLASS AS-EDITOR-WINDOW (window)
- ((current.object :initarg :current-object :initform nil :accessor current-object)
- )
- (:default-initargs
- :window-type :document-with-grow
- :color-p t
- :window-title "AppleScript Editor"
- :view-position #@(50 100)
- :view-size #@(500 300)
- :close-box-p t
- )
- )
-
- (DEFCLASS RUN-SCRIPT-BTN (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'run-btn
- :default-button nil
- :dialog-item-text "Run Script"
- :view-size #@(100 20)
- :view-position #@(79 274)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD DIALOG-ITEM-ACTION ((btn run-script-btn))
- ;; enter the script into the applescript instance then compile and run the script.
- (let* ((dialog (view-container btn))
- (as-object (current-object dialog))
- (script (extract-script-text (dialog-item-text (view-named 'input-buffer dialog)))))
- ; set the script
- (setf (script as-object) script)
- (open-component as-object)
- (compile-applescript as-object)
- (execute-applescript as-object)
- (if (check-box-checked-p (view-named 'show-result (view-container btn)))
- (format t "~a~%" (show-result-as-string as-object)))
- )
- )
-
- (DEFCLASS ADD-SCRIPT-BTN (button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'add-btn
- :default-button t
- :dialog-item-text "Set Script"
- :view-size #@(100 20)
- :view-position #@(183 273)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD DIALOG-ITEM-ACTION ((btn add-script-btn))
- ;; enter the script into the applescript instance then compile it.
- (let* ((dialog (view-container btn))
- (as-object (current-object dialog))
- (script (dialog-item-text (view-named 'input-buffer dialog))))
- ; set the script
- (setf (script as-object) script)
- ;; since we want to recompile the script set the compiled script id to nil
- (setf (compiled-script-id as-object) nil)
- ))
-
- (DEFCLASS CANCEL-BTN (button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'cancel-btn
- :default-button nil
- :dialog-item-text "cancel"
- :view-size #@(60 20)
- :view-position #@(301 275)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD DIALOG-ITEM-ACTION ((btn cancel-btn))
- ;; punt
- (let ((dialog (view-container btn)))
- ; set the script
- (set-dialog-item-text (view-named 'input-buffer dialog) "")
- (setf (current-object dialog) nil)
- ))
-
-
- (DEFMETHOD SHOW-SCRIPT ((window AS-EDITOR-WINDOW) &optional (script *bogus-script*))
- ;; shove the script in the AS-INPUT-BUFFER
- (let ((input.buffer (view-named 'input-buffer window)))
- (set-dialog-item-text input.buffer script)
- )
- )
-
- (DEFUN MAKE-APPLESCRIPT-EDITOR (&optional as-object)
- (cond ((and *AS-SCRIPT-EDITOR*
- (wptr *AS-SCRIPT-EDITOR*))
- (window-select *AS-SCRIPT-EDITOR*)
- (setf (current-object *AS-SCRIPT-EDITOR*) as-object)
- )
- (t
- (setf *AS-SCRIPT-EDITOR*
- (make-instance 'as-editor-window))
- (setf (current-object *AS-SCRIPT-EDITOR*) as-object)
- (let* ((v-offset 20)
- (h-offset 15)
- (dialog-size (view-size *AS-SCRIPT-EDITOR*))
- (dialog-width (point-h dialog-size))
- (dialog-height (point-v dialog-size))
- (reserve-for-button 50)
- (button-margin (floor
- (/ (- (point-h dialog-width)
- 280 ;sum of buttons
- ) 2)))
- (run-button-position nil)
- (add-button-position nil)
- (cancel-button-position nil))
- (setf run-button-position
- (make-point button-margin
- (- dialog-height 25)))
- (setf add-button-position
- (make-point (+ 10 (point-h run-button-position)
- 100)
- (point-v run-button-position)))
- (setf cancel-button-position
- (make-point (+ 10 (point-h add-button-position) 100)
- (point-v run-button-position)))
- (add-subviews *AS-SCRIPT-EDITOR*
- (make-instance 'check-box-dialog-item
- :view-position #@(0 0)
- :dialog-item-text "Show The Result?"
- :check-box-checked-p t
- :view-nick-name 'show-result)
- (make-instance 'as-input-buffer
- :view-position (make-point 0 v-offset)
- :view-size (make-point
- (- dialog-width
- h-offset)
- (- dialog-height
- v-offset
- reserve-for-button)))
- (make-instance 'run-script-btn
- :view-position run-button-position)
- (make-instance 'add-script-btn
- :view-position add-button-position)
- (make-instance 'cancel-btn
- :view-position cancel-button-position)))))
- )
-
- ;;(make-applescript-editor)
-
- (defmethod ccl::set-view-size ((window AS-EDITOR-WINDOW) h &optional v)
- ;; do the regular thing
- (declare (ignore v))
- (call-next-method)
- ;; resize the input-buffer proportionally
-
- (let* ((v-offset 20)
- (h-offset 15)
- (dialog-width (point-h h))
- (dialog-height (point-v h))
- (reserve-for-button 50)
- (button-margin (floor
- (/ (- dialog-width
- 280 ;sum of buttons
- ) 2)))
- (run-button-position nil)
- (add-button-position nil)
- (cancel-button-position nil))
- (setf run-button-position
- (make-point button-margin
- (- dialog-height 25)))
- (setf add-button-position
- (make-point (+ 10 (point-h run-button-position)
- 100)
- (point-v run-button-position)))
- (setf cancel-button-position
- (make-point (+ 10 (point-h add-button-position) 100)
- (point-v run-button-position)))
- (set-view-size (view-named 'input-buffer window)
- (- dialog-width h-offset)
- (- dialog-height v-offset reserve-for-button))
- (set-view-position (view-named 'run-btn window) (point-h run-button-position)
- (point-v run-button-position))
- (set-view-position (view-named 'add-btn window) (point-h add-button-position)
- (point-v add-button-position))
- (set-view-position (view-named 'cancel-btn window) (point-h cancel-button-position)
- (point-v cancel-button-position))
- )
- )
-
- ;; Method for editing scripts using the applescript-editor
-
- (DEFMETHOD EDIT-SCRIPT ((ASO APPLESCRIPT-OBJECT))
- (declare (special *AS-SCRIPT-EDITOR*))
- (let ((script (script ASO))
- (theApp (application-name ASO)))
- (if (and script
- (not (null-string-p script)))
- (progn
- (make-applescript-editor ASO)
- (show-script *AS-SCRIPT-EDITOR* script))
- (progn
- (make-applescript-editor ASO)
- (if theApp
- (show-script *AS-SCRIPT-EDITOR*
- (concatenate 'string "tell application"
- (make-literal-string theApp)
- " to")))))
- )
- )
-
-
-
-
- (provide :as-edit)
-
-
-