From ebecb2269e6d14b4e50ced6c9a6552de29537917 Mon Sep 17 00:00:00 2001 From: David Botton Date: Tue, 19 Jul 2022 16:54:43 -0400 Subject: [PATCH] source editor --- demos/03-demo.lisp | 2 +- tools/clog-builder.lisp | 89 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/demos/03-demo.lisp b/demos/03-demo.lisp index f657f0b..5693127 100644 --- a/demos/03-demo.lisp +++ b/demos/03-demo.lisp @@ -52,7 +52,7 @@ var editor_~A = ace.edit('~A-body'); editor_~A.setTheme('ace/theme/xcode'); editor_~A.session.setMode('ace/mode/lisp'); - editor_~A.session.setTabSize(3); + editor_~A.session.setTabSize(2); editor_~A.focus(); " (html-id win) (html-id win) diff --git a/tools/clog-builder.lisp b/tools/clog-builder.lisp index 6dab54c..6d20799 100644 --- a/tools/clog-builder.lisp +++ b/tools/clog-builder.lisp @@ -1991,6 +1991,93 @@ of controls and double click to select control." :client-movement t))) (create-quick-start (window-content win)))) +(defun on-open-file (obj) + (let* ((win (create-gui-window obj :title "New Source Editor" + :top 40 :left 225 + :width 645 :height 430 + :client-movement t)) + (box (create-panel-box-layout (window-content win) + :left-width 0 :right-width 0 + :top-height 33 :bottom-height 0)) + (tool-bar (create-div (top-panel box) :class "w3-center")) + (btn-class "w3-button w3-white w3-border w3-border-black w3-ripple") + (btn-copy (create-img tool-bar :alt-text "copy" :url-src img-btn-copy :class btn-class)) + (btn-paste (create-img tool-bar :alt-text "paste" :url-src img-btn-paste :class btn-class)) + (btn-cut (create-img tool-bar :alt-text "cut" :url-src img-btn-cut :class btn-class)) + (btn-del (create-img tool-bar :alt-text "delete" :url-src img-btn-del :class btn-class)) + (btn-undo (create-img tool-bar :alt-text "undo" :url-src img-btn-undo :class btn-class)) + (btn-redo (create-img tool-bar :alt-text "redo" :url-src img-btn-redo :class btn-class)) + (btn-test (create-img tool-bar :alt-text "eval" :url-src img-btn-test :class btn-class)) + (btn-save (create-img tool-bar :alt-text "save" :url-src img-btn-save :class btn-class)) + (btn-load (create-img tool-bar :alt-text "load" :url-src img-btn-load :class btn-class)) + (content (center-panel box)) + (ace (clog-ace:create-clog-ace-element content)) + (file-name "")) + (setf (background-color tool-bar) :black) + (setf (advisory-title btn-paste) "paste") + (setf (advisory-title btn-cut) "cut") + (setf (advisory-title btn-del) "delete") + (setf (advisory-title btn-undo) "undo") + (setf (advisory-title btn-redo) "redo") + (setf (advisory-title btn-test) "evaluate") + (setf (advisory-title btn-save) "save") + (setf (advisory-title btn-load) "load") + (setf (height btn-copy) "12px") + (setf (height btn-paste) "12px") + (setf (height btn-cut) "12px") + (setf (height btn-del) "12px") + (setf (height btn-undo) "12px") + (setf (height btn-redo) "12px") + (setf (height btn-test) "12px") + (setf (height btn-save) "12px") + (setf (height btn-load) "12px") + (set-geometry ace :units "" :width "100%" :height "100%" :top 0 :bottom 0) + (clog-ace:resize ace) + (set-on-window-size-done win + (lambda (obj) + (declare (ignore obj)) + (clog-ace:resize ace))) + (set-on-click btn-load (lambda (obj) + (server-file-dialog obj "Load Source" (directory-namestring file-name) + (lambda (fname) + (window-focus win) + (when fname + (setf file-name fname) + (setf (window-title win) fname) + (setf (clog-ace:text-value ace) + (read-file fname))))))) + (set-on-click btn-save (lambda (obj) + (server-file-dialog obj "Save Source As.." file-name + (lambda (fname) + (window-focus win) + (when fname + (setf file-name fname) + (setf (window-title win) fname) + (write-file (text-value ace) fname))) + :initial-filename file-name))) + (set-on-click btn-copy (lambda (obj) + (declare (ignore obj)) + (clog-ace:clipboard-copy ace))) + (set-on-click btn-cut (lambda (obj) + (declare (ignore obj)) + (clog-ace:clipboard-cut ace))) + (set-on-click btn-paste (lambda (obj) + (declare (ignore obj)) + (clog-ace:clipboard-paste ace))) + (set-on-click btn-del (lambda (obj) + (declare (ignore obj)) + (clog-ace:execute-command ace "del"))) + (set-on-click btn-undo (lambda (obj) + (declare (ignore obj)) + (clog-ace:execute-command ace "undo"))) + (set-on-click btn-redo (lambda (obj) + (declare (ignore obj)) + (clog-ace:execute-command ace "redo"))) + (set-on-click btn-test (lambda (obj) + (alert-dialog obj + (capture-eval (text-value ace)) + :title "Eval Result"))))) + (defun on-new-builder (body) "Launch instance of the CLOG Builder" (set-html-on-close body "Connection Lost") @@ -2007,6 +2094,7 @@ of controls and double click to select control." (icon (create-gui-menu-icon menu :image-url img-clog-icon :on-click #'on-help-about-builder)) (file (create-gui-menu-drop-down menu :content "Builder")) + (src (create-gui-menu-drop-down menu :content "Project")) (tools (create-gui-menu-drop-down menu :content "Tools")) (win (create-gui-menu-drop-down menu :content "Window")) (help (create-gui-menu-drop-down menu :content "Help"))) @@ -2018,6 +2106,7 @@ of controls and double click to select control." (create-gui-menu-item file :content "New CLOG-WEB Delay Launch" :on-click 'on-new-builder-launch-page) (create-gui-menu-item file :content "New Custom Boot Page" :on-click 'on-new-builder-custom) (create-gui-menu-item file :content "New Application Template" :on-click 'on-new-app-template) + (create-gui-menu-item src :content "New Source Editor" :on-click 'on-open-file) (create-gui-menu-item tools :content "Control Events" :on-click 'on-show-control-events-win) (create-gui-menu-item tools :content "Copy/Cut History" :on-click 'on-show-copy-history-win) (create-gui-menu-item tools :content "Image to Data" :on-click 'on-image-to-data)