diff --git a/clog.asd b/clog.asd index c493d1c..c966292 100644 --- a/clog.asd +++ b/clog.asd @@ -99,6 +99,7 @@ (:file "clog-builder-scope") (:file "clog-builder-repl") (:file "clog-builder-shell") + (:file "clog-builder-search") (:file "clog-builder-images") (:file "preferences-tabs") ;; clog-builder panels (post-render) @@ -108,6 +109,7 @@ (:file "panel-threads") (:file "panel-systems") (:file "panel-sys-browser") + (:file "panel-search") (:file "panel-projects") (:file "panel-project-directory") (:file "panel-clog-builder-repl") diff --git a/source/clog-element.lisp b/source/clog-element.lisp index 29ee495..8f70001 100644 --- a/source/clog-element.lisp +++ b/source/clog-element.lisp @@ -158,6 +158,18 @@ after attachment is changed to one unique to this session.")) (setf (parent child) obj) child)) +;;;;;;;;;;;;;;;;;;;;;; +;; destroy-children ;; +;;;;;;;;;;;;;;;;;;;;;; + +(defgeneric destroy-children (clog-element) + (:documentation "Destroy all children in DOM contained with in CLOG-ELEMENT +and run a BROWSER-GC")) + +(defmethod destroy-children ((obj clog-element)) + (setf (inner-html obj) "") + (browser-gc obj)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; General Properties - clog-element ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -463,7 +475,8 @@ html of an element. This will remove any Elements within Element from the DOM. If those elements were created in CLOG they are still available and can be placed in the DOM again using the placement methods. However if they were created through html writes or otherwise not assigned an ID by CLOG, they are -lost forever.")) +lost forever. If BROWSER-GC is called at any point, the elements will be +destroyed from the browser and placement methods will no longer have an affect.")) (defmethod inner-html ((obj clog-element)) (jquery-query obj "html()")) diff --git a/source/clog.lisp b/source/clog.lisp index 10c67f8..1745c5c 100644 --- a/source/clog.lisp +++ b/source/clog.lisp @@ -214,10 +214,11 @@ embedded in a native template application.)" "CLOG-Element - Class for CLOG Elements" (clog-element class) - "CLOG-Element - Low Level Creation" - (create-element generic-function) - (create-child generic-function) - (attach-as-child generic-function) + "CLOG-Element - Low Level" + (create-element generic-function) + (create-child generic-function) + (attach-as-child generic-function) + (destroy-children generic-function) "CLOG-Element - DOM Placement" (place-after generic-function) diff --git a/tools/clog-builder-dir-tree.lisp b/tools/clog-builder-dir-tree.lisp index 13bf069..94acd61 100644 --- a/tools/clog-builder-dir-tree.lisp +++ b/tools/clog-builder-dir-tree.lisp @@ -48,6 +48,7 @@ (opo (create-div menu :content "Open in os" :class *builder-menu-context-item-class*)) (opd (create-div menu :content "Open in new Tree" :class *builder-menu-context-item-class*)) (opr (create-div menu :content "Set as root" :class *builder-menu-context-item-class*)) + (grp (create-div menu :content "Search directory" :class *builder-menu-context-item-class*)) (nwd (create-div menu :content "New subdirectory" :class *builder-menu-context-item-class*)) (ren (create-div menu :content "Rename directory" :class *builder-menu-context-item-class*)) (del (create-div menu :content "Delete directory" :class *builder-menu-context-item-class*))) @@ -61,6 +62,10 @@ obj)) :cancel-event t)) *file-extensions*) + (set-on-click grp (lambda (i) + (declare (ignore i)) + (on-file-search obj :dir item)) + :cancel-event t) (set-on-click menu (lambda (i) (declare (ignore i)) (destroy menu))) @@ -124,7 +129,7 @@ (dolist (item (sort (uiop:directory-files (directory-namestring dir)) (lambda (a b) (if (equal (pathname-name a) (pathname-name b)) - (string-lessp (format nil "~A" a) (format nil "~A" b)) + (string-lessp (format nil "~A" a) (format nil "~A" b)) (string-lessp (format nil "~A" (pathname-name a)) (format nil "~A" (pathname-name b))))))) (create-clog-tree-item (tree-root node) @@ -143,6 +148,7 @@ (opt (create-div menu :content "Open new tab" :class *builder-menu-context-item-class*)) (ope (create-div menu :content "Open emacs" :class *builder-menu-context-item-class*)) (opo (create-div menu :content "Open os default" :class *builder-menu-context-item-class*)) + (grp (create-div menu :content "Search directory" :class *builder-menu-context-item-class*)) (ren (create-div menu :content "Rename" :class *builder-menu-context-item-class*)) (del (create-div menu :content "Delete" :class *builder-menu-context-item-class*))) (declare (ignore title op)) @@ -155,6 +161,9 @@ obj)) :cancel-event t)) *file-extensions*) + (set-on-click grp (lambda (i) + (declare (ignore i)) + (on-file-search obj :dir item))) (set-on-click menu (lambda (i) (declare (ignore i)) (destroy menu))) @@ -200,8 +209,8 @@ (project-tree-select obj (format nil "~A" item))) :content (file-namestring item)))) (on-change (obj) - (setf (text tree) "") - (browser-gc obj) + (declare (ignore obj)) + (destroy-children tree) (let* ((root (text-value root-dir)) (tname (truename root)) (dir (format nil "~A" (uiop:native-namestring (if tname diff --git a/tools/clog-builder-files.lisp b/tools/clog-builder-files.lisp index f1e1329..7551ffe 100644 --- a/tools/clog-builder-files.lisp +++ b/tools/clog-builder-files.lisp @@ -14,7 +14,8 @@ (error (condition) (if clog-obj (alert-toast clog-obj "File Error" (format nil "Error: ~A" condition)) - (format t "Error: ~A" condition))))) + (format t "Error: ~A" condition)) + nil))) (defun write-file (string outfile &key clog-obj (action-if-exists :rename)) "Write local file named OUTFILE" @@ -68,6 +69,7 @@ (title-class *builder-title-class*) lisp-package regex + show-find is-console left top (editor-use-console-for-evals *editor-use-console-for-evals*) @@ -82,8 +84,11 @@ (close-window pop) (window-focus win))) (when regex + (focus (window-param win)) (js-execute win (format nil "~A.find('~A',{caseSensitive:false,regExp:true})" (clog-ace::js-ace (window-param win)) regex))) + (when show-find + (clog-ace:execute-command (window-param win) "find")) win) (unless win (let* ((app (connection-data-item obj "builder-app-data")) @@ -307,7 +312,9 @@ (t (setf lisp-file nil) (setf (current-editor-is-lisp app) nil) - (setf (clog-ace:mode ace) (clog-ace:get-mode-from-extension ace fname)))) + (if (equalp (pathname-type fname) "clog") + (setf (clog-ace:mode ace) "ace/mode/html") + (setf (clog-ace:mode ace) (clog-ace:get-mode-from-extension ace fname))))) (setf (clog-ace:text-value ace) c))) (error (condition) (unless text @@ -325,8 +332,11 @@ (not (equalp open-file ""))) (open-file-name open-file)) (when regex + (focus ace) (js-execute obj (format nil "~A.find('~A',{caseSensitive:false,regExp:true})" (clog-ace::js-ace ace) regex))) + (when show-find + (clog-ace:execute-command ace "find")) (set-on-click btn-load (lambda (obj) (load-file obj))) (set-on-click m-load (lambda (obj) (load-file obj))) (set-on-click m-revert (lambda (obj) diff --git a/tools/clog-builder-project-tree.lisp b/tools/clog-builder-project-tree.lisp index 4374d82..11c1c40 100644 --- a/tools/clog-builder-project-tree.lisp +++ b/tools/clog-builder-project-tree.lisp @@ -138,7 +138,8 @@ (op (create-div menu :content "Toggle open" :class *builder-menu-context-item-class*)) (opd (create-div menu :content "Open in dir tree" :class *builder-menu-context-item-class*)) (ops (create-div menu :content "Open in pseudo shell" :class *builder-menu-context-item-class*)) - (opo (create-div menu :content "Open in os" :class *builder-menu-context-item-class*))) + (opo (create-div menu :content "Open in os" :class *builder-menu-context-item-class*)) + (grp (create-div menu :content "Search directory" :class *builder-menu-context-item-class*))) (declare (ignore title op)) (mapcar (lambda (file-extension) (set-on-click (create-div menu :content (getf file-extension :name) :class *builder-menu-context-item-class*) @@ -152,6 +153,10 @@ (set-on-click menu (lambda (i) (declare (ignore i)) (destroy menu))) + (set-on-click grp (lambda (i) + (declare (ignore i)) + (on-file-search obj :dir item)) + :cancel-event t) (set-on-click opd (lambda (i) (declare (ignore i)) (on-dir-tree obj :dir item)) @@ -289,7 +294,8 @@ (ops (create-div menu :content "Open pseudo shell" :class *builder-menu-context-item-class*)) (opa (create-div menu :content "Open in ASDF browser" :class *builder-menu-context-item-class*)) (opr (create-div menu :content "Open REPL" :class *builder-menu-context-item-class*)) - (opo (create-div menu :content "Open in os" :class *builder-menu-context-item-class*))) + (opo (create-div menu :content "Open in os" :class *builder-menu-context-item-class*)) + (grp (create-div menu :content "Search directory" :class *builder-menu-context-item-class*))) (declare (ignore title op)) (set-on-click menu (lambda (i) (declare (ignore i)) @@ -298,6 +304,10 @@ (declare (ignore i)) (on-dir-tree obj :dir item)) :cancel-event t) + (set-on-click grp (lambda (i) + (declare (ignore i)) + (on-file-search obj :dir item)) + :cancel-event t) (set-on-click ops (lambda (i) (declare (ignore i)) (on-shell obj :dir item)) diff --git a/tools/clog-builder-search.lisp b/tools/clog-builder-search.lisp new file mode 100644 index 0000000..08a44c0 --- /dev/null +++ b/tools/clog-builder-search.lisp @@ -0,0 +1,36 @@ +(in-package :clog-tools) + +(defun on-file-search (obj &key (dir "")) + "Open file search" + (let* ((*default-title-class* *builder-title-class*) + (*default-border-class* *builder-border-class*) + (win (create-gui-window obj :title (format nil "Search Dir ~A" + dir) + :width 600 :height 400 + :client-movement *client-side-movement*)) + (panel (create-panel-search (window-content win)))) + (setf (text-value (dir-input panel)) dir))) + +(defun panel-search-dir-change (panel target) + (setf (window-title (parent (parent panel))) + (format nil "Search Project Dir ~A" (text-value target)))) + +(defun panel-search-on-click (panel target) + (declare (ignore target)) + (destroy-children (result-box panel)) + (dolist (item (uiop:directory-files (text-value (dir-input panel)))) + (let* ((fname (format nil "~A" item)) + (regex (text-value (grep-input panel))) + (s (ppcre:create-scanner regex :case-insensitive-mode t)) + (c (read-file fname))) + (when (and c + (ppcre:scan s c)) + (let ((li (create-option (result-box panel) + :content (file-namestring item)))) + (flet ((do-select () + (on-open-file panel :open-file fname + :show-find t + :regex regex))) + (set-on-double-click li (lambda (obj) + (declare (ignore obj)) + (do-select))))))))) \ No newline at end of file diff --git a/tools/panel-search.clog b/tools/panel-search.clog new file mode 100644 index 0000000..eb43122 --- /dev/null +++ b/tools/panel-search.clog @@ -0,0 +1,21 @@ + +