regex dir search

This commit is contained in:
David Botton 2024-07-04 15:23:12 -04:00
parent ca417fc393
commit 0e306f6f12
9 changed files with 171 additions and 12 deletions

2
clog.asd vendored
View file

@ -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")

View file

@ -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()"))

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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))

View file

@ -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)))))))))

21
tools/panel-search.clog vendored Normal file
View file

@ -0,0 +1,21 @@
<data id="I3929109423" data-in-package="clog-tools" data-custom-slots=""
data-clog-next-id="6" data-clog-title="panel-search"></data>
<div data-clog-type="grid" data-clog-name="result-grid"
style="display: grid; box-sizing: content-box; position: absolute; inset: 5px; grid-template: &quot;a a&quot; 1fr &quot;d d&quot; 28px &quot;b c&quot; 28px / 1fr 80px; gap: 5px;"
class=""><select data-clog-type="listbox" size="4"
data-clog-name="result-box"
style="box-sizing: content-box; position: static; grid-area: a;"
class="w3-small" tabindex="2"></select><input type="TEXT" value=""
data-clog-type="input" data-clog-name="dir-input"
style="box-sizing: content-box; position: static; grid-area: d;"
data-on-change="(panel-search-dir-change panel target)"
placeholder="directory to search" tabindex="3"><input type="TEXT"
value="" data-clog-type="input" data-clog-name="grep-input"
style="box-sizing: content-box; position: static; left: 50px; top: 8px; grid-area: b;"
placeholder="search regex" tabindex="4"><button data-clog-type="button"
data-clog-name="search-button"
style="box-sizing: content-box; position: static; height: 22px; grid-area: c;"
data-on-click="(panel-search-on-click panel target)" class=""
data-on-create="(setf (attribute target &quot;autofocus&quot;) &quot;true&quot;)
(focus target)" tabindex="1">Search</button>
</div>

57
tools/panel-search.lisp Normal file
View file

@ -0,0 +1,57 @@
;;;; CLOG Builder generated code - modify original .clog file and rerender
(in-package :clog-tools)
(defclass panel-search (clog:clog-panel)
((search-button :reader search-button)
(grep-input :reader grep-input) (dir-input :reader dir-input)
(result-box :reader result-box) (result-grid :reader result-grid)))
(defun create-panel-search
(clog-obj &key hidden class style html-id (auto-place t))
(let ((panel
(change-class
(clog:create-div clog-obj :content
"<div style=\"display: grid; box-sizing: content-box; position: absolute; inset: 5px; grid-template: &quot;a a&quot; 1fr &quot;d d&quot; 28px &quot;b c&quot; 28px / 1fr 80px; gap: 5px;\"
class=\"\" id=\"CLOGB3929109399\" data-clog-name=\"result-grid\"><select size=\"4\"
style=\"box-sizing: content-box; position: static; grid-area: a;\"
class=\"w3-small\" tabindex=\"2\" id=\"CLOGB3929109400\"
data-clog-name=\"result-box\"></select><input type=\"TEXT\" value=\"\"
style=\"box-sizing: content-box; position: static; grid-area: d;\"
placeholder=\"directory to search\" tabindex=\"3\" id=\"CLOGB3929109401\"
data-clog-name=\"dir-input\"><input type=\"TEXT\" value=\"\"
style=\"box-sizing: content-box; position: static; left: 50px; top: 8px; grid-area: b;\"
placeholder=\"search regex\" tabindex=\"4\" id=\"CLOGB3929109402\"
data-clog-name=\"grep-input\"><button
style=\"box-sizing: content-box; position: static; height: 22px; grid-area: c;\"
class=\"\" tabindex=\"1\" id=\"CLOGB3929109403\"
data-clog-name=\"search-button\">Search</button>
</div>"
:hidden hidden :class class :style style :html-id
html-id :auto-place auto-place)
'panel-search)))
(setf (slot-value panel 'search-button)
(attach-as-child clog-obj "CLOGB3929109403" :clog-type
'clog:clog-button :new-id t))
(setf (slot-value panel 'grep-input)
(attach-as-child clog-obj "CLOGB3929109402" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'dir-input)
(attach-as-child clog-obj "CLOGB3929109401" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'result-box)
(attach-as-child clog-obj "CLOGB3929109400" :clog-type
'clog:clog-select :new-id t))
(setf (slot-value panel 'result-grid)
(attach-as-child clog-obj "CLOGB3929109399" :clog-type
'clog:clog-div :new-id t))
(let ((target (search-button panel)))
(declare (ignorable target))
(setf (attribute target "autofocus") "true")
(focus target))
(clog:set-on-change (dir-input panel)
(lambda (target)
(declare (ignorable target))
(panel-search-dir-change panel target)))
(clog:set-on-click (search-button panel)
(lambda (target)
(declare (ignorable target))
(panel-search-on-click panel target)))
panel))