properly use ace editor for events

This commit is contained in:
David Botton 2022-07-12 19:38:31 -04:00
parent 02e4ed8fc1
commit ea92bb20c3
3 changed files with 110 additions and 101 deletions

View file

@ -70,10 +70,11 @@ most up to date version or you can also clone the github repo into
(push #P"path/to/dir/of/projects" ql:*local-project-directories*) ]:
```
For git:
For git (you need the ace editor plug in for the builder too from git):
cd ~/common-lisp
git clone https://github.com/rabbibotton/clog.git
git clone https://github.com/rabbibotton/clog-ace.git
To add UltraLisp to QuickLisp (_RECOMMENDED_):

View file

@ -48,7 +48,7 @@
:components ((:file "clog-docs")))
(asdf:defsystem #:clog/tools
:depends-on (#:clog #:s-base64)
:depends-on (#:clog #:clog-ace #:s-base64)
:pathname "tools/"
:components ((:file "clog-db-admin")
(:file "clog-builder-settings")

View file

@ -41,7 +41,11 @@
(events-list
:accessor events-list
:initform nil
:documentation "Property list in events window")
:documentation "Event list in events window")
(event-editor
:accessor event-editor
:initform nil
:documentation "Editor in events window")
(control-events-win
:accessor control-events-win
:initform nil
@ -542,8 +546,8 @@ replaced."
;; Control selection utilities
(defun get-placer (control)
"Get placer for CONTROL. A placer is a div placed on top of the control and
prevents access to use or activate the control directylu and allows
"Get placer for CONTROL. A placer is a div placed on top of CONTROL and
prevents access to use or activate the control directy and allows
manipulation of the control's location and size."
(when control
(attach-as-child control (format nil "p-~A" (html-id control)))))
@ -759,56 +763,50 @@ not a temporary attached one when using select-control."
;; obj if current-control is nil must be content
(let* ((app (connection-data-item obj "builder-app-data"))
(event-win (control-events-win app))
(elist (events-list app))
(control (if (current-control app)
(current-control app)
obj))
(table (events-list app)))
obj)))
(when event-win
(setf (inner-html table) "")
(let ((info (control-info (attribute control "data-clog-type")))
events)
(dolist (event (reverse (getf info :events)))
(let ((attr (format nil "data-~A" (getf event :name))))
(push `(,(getf event :name)
,(let ((txt (attribute control attr)))
(setf (inner-html elist) "")
(remove-attribute elist "data-current-event")
(set-on-blur (event-editor app) nil)
(set-on-change elist nil)
(let ((info (control-info (attribute control "data-clog-type"))))
(add-select-option elist "" "Select Event")
(setf (text-value (event-editor app)) "")
(labels ((on-blur (obj)
(let ((attr (attribute elist "data-current-event")))
(unless (equalp attr "undefined")
(let ((txt (text-value (event-editor app))))
(cond ((or (equal txt "")
(equalp txt "undefined"))
(remove-attribute control attr))
(t
(setf (attribute control attr) (text-value (event-editor app))))))
(jquery-execute (get-placer control) "trigger('clog-builder-snap-shot')")))))
(set-on-change elist (lambda (obj)
(declare (ignore obj))
(let ((event (select-value elist "clog-events")))
(cond ((equal event "")
(set-on-blur (event-editor app) nil)
(setf (text-value (event-editor app)) ""))
(t
(let* ((attr (format nil "data-~A" event))
(txt (attribute control attr)))
(setf (text-value (event-editor app))
(if (equalp txt "undefined")
""
txt))
,(getf event :parameters)
,(getf event :setup)
,(lambda (obj)
(let ((txt (text-value obj)))
(if (or (equal txt "")
(equalp txt "undefined"))
(remove-attribute control attr)
(setf (attribute control attr) (text-value obj))))))
events)))
(dolist (item events)
(let* ((tr (create-table-row table))
(td1 (create-table-column tr :content (first item)))
(td2 (create-table-column tr))
(editor nil))
(setf (width td1) "30%")
(setf (width td2) "70%")
(set-border td1 "1px" :dotted :black)
(setf (advisory-title td1) (format nil "params: panel ~A" (third item)))
(cond ((fourth item)
(setf editor td2)
(setf (editablep td2) (funcall (fourth item) control td1 td2)))
(t
;; (setf editor (clog-ace:create-clog-ace-element td2))
;; (setf (clog-ace:theme editor) "ace/theme/xcode")
;; (setf (clog-ace:mode editor) "ace/mode/lisp")
;; (setf (clog-ace:tab-size editor) 2)
(setf editor (create-text-area td2))
(setf (spellcheckp editor) nil)
(setf (width editor) "95%"))) ; leave space for scroll bar
(setf (text-value editor) (second item))
(set-on-blur editor
(lambda (obj)
(declare (ignore obj))
(funcall (fifth item) obj)
(jquery-execute (get-placer control) "trigger('clog-builder-snap-shot')")))))))))
(setf (attribute elist "data-current-event") attr)
(focus (event-editor app))
(set-on-blur (event-editor app) #'on-blur))))))))
(dolist (event (getf info :events))
(add-select-option elist
(getf event :name)
(format nil "~A (panel ~A)"
(getf event :name)
(getf event :parameters))))))))
(defun on-populate-control-properties-win (obj &key win)
"Populate the control properties for the current control"
@ -1056,17 +1054,27 @@ of controls and double click to select control."
(let* ((win (create-gui-window obj :title "Control Events"
:left 225
:top 480
:height 200 :width 600
:height 200 :width 645
:has-pinner t :client-movement t))
(content (window-content win))
(control-list (create-table content)))
(content (window-content win)))
(setf (control-events-win app) win)
(setf (events-list app) control-list)
(setf (events-list app) (create-select content :name "clog-events"))
(setf (positioning (events-list app)) :absolute)
(set-geometry (events-list app) :top 5 :left 5 :right 5)
(setf (event-editor app) (clog-ace:create-clog-ace-element content))
(setf (positioning (event-editor app)) :absolute)
(setf (width (event-editor app)) "")
(setf (height (event-editor app)) "")
(set-geometry (event-editor app) :top 35 :left 5 :right 5 :bottom 5)
(clog-ace:resize (event-editor app))
(setf (clog-ace:theme (event-editor app)) "ace/theme/xcode")
(setf (clog-ace:mode (event-editor app)) "ace/mode/lisp")
(setf (clog-ace:tab-size (event-editor app)) 2)
(set-on-window-close win (lambda (obj)
(declare (ignore obj))
(setf (control-events-win app) nil)))
(setf (positioning control-list) :absolute)
(set-geometry control-list :units "" :left 0 :top 0 :bottom 0 :width "100%")))))
(setf (event-editor app) nil)
(setf (events-list app) nil)
(setf (control-events-win app) nil)))))))
(defun on-show-copy-history-win (obj)
"Create and show copy/but history"
@ -1163,7 +1171,7 @@ of controls and double click to select control."
"Open new panel"
(let* ((app (connection-data-item obj "builder-app-data"))
(win (create-gui-window obj :top 40 :left 225
:width 600 :height 430
:width 645 :height 430
:client-movement t))
(box (create-panel-box-layout (window-content win)
:left-width 0 :right-width 0