custom inspectors

This commit is contained in:
David Botton 2024-05-28 20:23:08 -04:00
parent 13077e6928
commit cc0555b35f
3 changed files with 43 additions and 10 deletions

View file

@ -9,19 +9,21 @@
(cl:in-package :clog) (cl:in-package :clog)
(defpackage #:clog-user
(:use #:cl #:clog #:clog-gui #:clog-web)
(:export :*body* :clog-repl))
(defpackage #:clog-tools (defpackage #:clog-tools
(:use #:cl #:clog #:clog-gui #:clog-web) (:use #:cl #:clog #:clog-gui #:clog-web)
(:export :clog-builder (:export :clog-builder
:clog-open :clog-open
:add-supported-controls :add-supported-controls
:control-info :control-info
:add-inspector
:clog-builder-probe :clog-builder-probe
:clog-db-admin)) :clog-db-admin))
(defpackage #:clog-user
(:use #:cl #:clog #:clog-gui #:clog-web)
(:import-from :clog-tools #:clog-builder-probe)
(:export :*body* :clog-repl))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - CLOG Utilities ;; Implementation - CLOG Utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -1,6 +1,6 @@
(in-package :clog-tools) (in-package :clog-tools)
;; Control Record Utilities / Plugin API for controls ;; Control Record Utilities / Plugin APIs
(defun control-info (control-type-name) (defun control-info (control-type-name)
"Return the control-record for CONTROL-TYPE-NAME from supported controls. (Exported)" "Return the control-record for CONTROL-TYPE-NAME from supported controls. (Exported)"
@ -33,6 +33,10 @@ replaced. (Exported)"
*supported-controls*) *supported-controls*)
(list r))))) (list r)))))
(defun add-inspector (name func)
"Add a custom inspector with NAME and (FUNC symbol title value clog-obj)"
(push (list :name name :func func) *inspectors*))
(defun reset-control-pallete (panel) (defun reset-control-pallete (panel)
(let* ((app (connection-data-item panel "builder-app-data")) (let* ((app (connection-data-item panel "builder-app-data"))
(pallete (select-tool app))) (pallete (select-tool app)))
@ -42,4 +46,3 @@ replaced. (Exported)"
(if (equal (getf control :name) "group") (if (equal (getf control :name) "group")
(add-select-optgroup pallete (getf control :description)) (add-select-optgroup pallete (getf control :description))
(add-select-option pallete (getf control :name) (getf control :description))))))) (add-select-option pallete (getf control :name) (getf control :description)))))))

View file

@ -1,5 +1,21 @@
(in-package :clog-tools) (in-package :clog-tools)
(defparameter *inspectors*
`((:name "Print to Console"
:func ,(lambda (symbol title value clog-obj)
(declare (ignore symbol))
(on-open-console clog-obj)
(print title)
(print value)))
(:name "Console Inspector"
:func ,(lambda (symbol title value clog-obj)
(declare (ignore title value))
(on-open-console clog-obj)
(let ((*default-title-class* *builder-title-class*)
(*default-border-class* *builder-border-class*)
(*standard-input* (make-instance 'console-in-stream :clog-obj clog-obj)))
(inspect symbol))))))
(defun on-probe-panel (obj) (defun on-probe-panel (obj)
(let ((app (connection-data-item obj "builder-app-data"))) (let ((app (connection-data-item obj "builder-app-data")))
(let* ((*default-title-class* *builder-title-class*) (let* ((*default-title-class* *builder-title-class*)
@ -71,9 +87,21 @@ used for title."
(set-on-click (create-button probe :content "Inspect") (set-on-click (create-button probe :content "Inspect")
(lambda (obj) (lambda (obj)
(declare (ignore obj)) (declare (ignore obj))
(on-open-console body) (let* ((menu (create-panel probe
(let ((*standard-input* (make-instance 'console-in-stream :clog-obj body))) :left (left probe) :top (top probe)
(inspect ,symbol)))) :width (width probe)
:class *builder-window-desktop-class*
:auto-place :bottom)))
(set-on-mouse-leave menu (lambda (obj) (destroy obj)))
(mapcar (lambda (inspector)
(set-on-click (create-div menu :content (getf inspector :name) :class *builder-menu-context-item-class*)
(lambda (obj)
(declare (ignore obj))
(destroy menu)
(funcall (getf inspector :func)
,symbol title (format nil "~A" ,symbol)
body))))
*inspectors*))))
(set-on-click (create-button probe :content "Remove") (set-on-click (create-button probe :content "Remove")
(lambda (obj) (lambda (obj)
(declare (ignore obj)) (declare (ignore obj))