regex for filenames

This commit is contained in:
David Botton 2024-07-05 16:37:02 -04:00
parent 8ebc9e1ec9
commit 8647c998ca
3 changed files with 70 additions and 54 deletions

View file

@ -6,8 +6,8 @@
(*default-border-class* *builder-border-class*)
(win (create-gui-window obj :title (format nil "Search in ~A"
dir)
:width 600 :height 400
:client-movement *client-side-movement*))
:width 600 :height 400
:client-movement *client-side-movement*))
(panel (create-panel-search (window-content win))))
(setf (text-value (dir-input panel)) dir)))
@ -19,23 +19,26 @@
(declare (ignore target))
(destroy-children (result-box panel))
(let* ((subdirs (checkedp (subdir-check panel)))
(nregex (text-value (name-regex-input panel)))
(sn (ppcre:create-scanner nregex :case-insensitive-mode t))
(regex (text-value (grep-input panel)))
(s (ppcre:create-scanner regex :case-insensitive-mode t)))
(labels ((do-search (dir prefix)
(dolist (item (uiop:directory-files dir))
(let* ((fname (format nil "~A" item))
(c (read-file fname :report-errors nil)))
(when (and c
(ppcre:scan s c))
(let ((li (create-option (result-box panel)
:content (format nil "~A~A" prefix (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))))))))
(let ((fname (format nil "~A" item)))
(when (ppcre:scan sn fname)
(let ((c (read-file fname :report-errors nil)))
(when (and c
(ppcre:scan s c))
(let ((li (create-option (result-box panel)
:content (format nil "~A~A" prefix (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))))))))))
(when subdirs
(dolist (item (uiop:subdirectories dir))
(do-search item (format nil "~A~A/" prefix (first (last (pathname-directory item)))))))))

View file

@ -1,31 +1,35 @@
<data id="I3929129042" data-in-package="clog-tools" data-custom-slots=""
data-clog-next-id="8" data-clog-title="panel-search"></data>
<data id="I3929200389" data-in-package="clog-tools" data-custom-slots=""
data-clog-next-id="9" data-clog-title="panel-search"></data>
<form action="#" onsubmit="return false;" data-clog-name="search-form"
data-clog-type="form">
<div data-clog-type="grid" data-clog-name="result-grid"
style="display: grid; box-sizing: content-box; position: absolute; inset: 5px; gap: 5px; grid-template: &quot;a a a a&quot; 1fr &quot;d d d d&quot; 28px &quot;b o l c&quot; 28px / 1fr 20px 70px 80px;"
style="display: grid; box-sizing: content-box; position: absolute; inset: 5px; gap: 5px; grid-template: &quot;a a a a a&quot; 1fr &quot;d d d d d&quot; 28px &quot;b n o l c&quot; 28px / 1fr 100px 20px 70px 80px;"
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=""
class="w3-small" tabindex="1"></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"
placeholder="directory to search" tabindex="2"><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" data-on-create="(setf (attribute target &quot;autofocus&quot;) &quot;true&quot;)
placeholder="search regex" tabindex="3" data-on-create="(setf (attribute target &quot;autofocus&quot;) &quot;true&quot;)
(focus target)">
<input type="CHECKBOX" value="" data-clog-type="checkbox"
data-clog-name="subdir-check"
style="box-sizing: content-box; position: static; left: 68px; top: 5px; grid-area: o;"><label
for="undefined" data-clog-type="label" data-clog-for="sundir-check"
<input type="TEXT" value="(.*\\.lisp$)" data-clog-type="input"
data-clog-name="name-regex-input"
style="box-sizing: content-box; position: static; left: 43px; top: 11px; grid-area: n;"
placeholder="file regex" tabindex="4"><input type="CHECKBOX"
value="" data-clog-type="checkbox" data-clog-name="subdir-check"
style="box-sizing: content-box; position: static; left: 68px; top: 5px; grid-area: o;"
tabindex="5" checked="checked"><label for="CLOGB3929199716"
data-clog-type="label" data-clog-for="subdir-check"
data-clog-name="subdir-label"
style="box-sizing: content-box; position: static; left: 70px; top: 11px; grid-area: l;"
class="">sub dirs</label><input type="submit" value="Search"
data-clog-type="input" data-clog-name="search-button"
style="box-sizing: content-box; position: static; left: 70px; top: 11px; grid-area: l; font: 15px / 22.5px sans-serif; visibility: visible; vertical-align: middle; text-align: center;"
class="w3-tiny">subdirectories</label><input type="submit"
value="Search" data-clog-type="input" 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=""
tabindex="1">
class="" tabindex="6"
data-on-click="(panel-search-on-click panel target)">
</div>
</form>

View file

@ -3,37 +3,43 @@
(defclass panel-search (clog:clog-panel)
((search-button :reader search-button)
(subdir-label :reader subdir-label)
(subdir-check :reader subdir-check) (grep-input :reader grep-input)
(dir-input :reader dir-input) (result-box :reader result-box)
(result-grid :reader result-grid) (search-form :reader search-form)))
(subdir-check :reader subdir-check)
(name-regex-input :reader name-regex-input)
(grep-input :reader grep-input) (dir-input :reader dir-input)
(result-box :reader result-box) (result-grid :reader result-grid)
(search-form :reader search-form)))
(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
"<form action=\"#\" onsubmit=\"return false;\" id=\"CLOGB3929127594\"
"<form action=\"#\" onsubmit=\"return false;\" id=\"CLOGB3929199710\"
data-clog-name=\"search-form\">
<div style=\"display: grid; box-sizing: content-box; position: absolute; inset: 5px; gap: 5px; grid-template: &quot;a a a a&quot; 1fr &quot;d d d d&quot; 28px &quot;b o l c&quot; 28px / 1fr 20px 70px 80px;\"
class=\"\" id=\"CLOGB3929127595\" data-clog-name=\"result-grid\"><select
<div style=\"display: grid; box-sizing: content-box; position: absolute; inset: 5px; gap: 5px; grid-template: &quot;a a a a a&quot; 1fr &quot;d d d d d&quot; 28px &quot;b n o l c&quot; 28px / 1fr 100px 20px 70px 80px;\"
class=\"\" id=\"CLOGB3929199711\" data-clog-name=\"result-grid\"><select
size=\"4\"
style=\"box-sizing: content-box; position: static; grid-area: a;\"
class=\"w3-small\" tabindex=\"2\" id=\"CLOGB3929127596\"
class=\"w3-small\" tabindex=\"1\" id=\"CLOGB3929199712\"
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=\"CLOGB3929127597\"
placeholder=\"directory to search\" tabindex=\"2\" id=\"CLOGB3929199713\"
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=\"CLOGB3929127598\"
placeholder=\"search regex\" tabindex=\"3\" id=\"CLOGB3929199714\"
data-clog-name=\"grep-input\">
<input type=\"CHECKBOX\" value=\"\" id=\"CLOGB39291277016\"
<input type=\"TEXT\" value=\"(.*\\.lisp$)\"
style=\"box-sizing: content-box; position: static; left: 43px; top: 11px; grid-area: n;\"
placeholder=\"file regex\" id=\"CLOGB3929199715\" tabindex=\"4\"
data-clog-name=\"name-regex-input\"><input type=\"CHECKBOX\" value=\"\"
style=\"box-sizing: content-box; position: static; left: 68px; top: 5px; grid-area: o;\"
data-clog-name=\"subdir-check\"><label for=\"undefined\"
id=\"CLOGB39291277397\"
style=\"box-sizing: content-box; position: static; left: 70px; top: 11px; grid-area: l;\"
class=\"\" data-clog-name=\"subdir-label\">sub dirs</label><input
id=\"CLOGB3929199716\" tabindex=\"5\" checked=\"checked\"
data-clog-name=\"subdir-check\"><label for=\"CLOGB3929199716\"
style=\"box-sizing: content-box; position: static; left: 70px; top: 11px; grid-area: l; font: 15px / 22.5px sans-serif; visibility: visible; vertical-align: middle; text-align: center;\"
class=\"w3-tiny\" id=\"CLOGB3929199717\"
data-clog-name=\"subdir-label\">subdirectories</label><input
type=\"submit\" value=\"Search\"
style=\"box-sizing: content-box; position: static; height: 22px; grid-area: c;\"
class=\"\" tabindex=\"1\" id=\"CLOGB3929127599\"
class=\"\" tabindex=\"6\" id=\"CLOGB3929199718\"
data-clog-name=\"search-button\">
</div>
</form>"
@ -41,28 +47,31 @@
html-id :auto-place auto-place)
'panel-search)))
(setf (slot-value panel 'search-button)
(attach-as-child clog-obj "CLOGB3929127599" :clog-type
(attach-as-child clog-obj "CLOGB3929199718" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'subdir-label)
(attach-as-child clog-obj "CLOGB39291277397" :clog-type
(attach-as-child clog-obj "CLOGB3929199717" :clog-type
'clog:clog-label :new-id t))
(setf (slot-value panel 'subdir-check)
(attach-as-child clog-obj "CLOGB39291277016" :clog-type
(attach-as-child clog-obj "CLOGB3929199716" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'name-regex-input)
(attach-as-child clog-obj "CLOGB3929199715" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'grep-input)
(attach-as-child clog-obj "CLOGB3929127598" :clog-type
(attach-as-child clog-obj "CLOGB3929199714" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'dir-input)
(attach-as-child clog-obj "CLOGB3929127597" :clog-type
(attach-as-child clog-obj "CLOGB3929199713" :clog-type
'clog:clog-form-element :new-id t))
(setf (slot-value panel 'result-box)
(attach-as-child clog-obj "CLOGB3929127596" :clog-type
(attach-as-child clog-obj "CLOGB3929199712" :clog-type
'clog:clog-select :new-id t))
(setf (slot-value panel 'result-grid)
(attach-as-child clog-obj "CLOGB3929127595" :clog-type
(attach-as-child clog-obj "CLOGB3929199711" :clog-type
'clog:clog-div :new-id t))
(setf (slot-value panel 'search-form)
(attach-as-child clog-obj "CLOGB3929127594" :clog-type
(attach-as-child clog-obj "CLOGB3929199710" :clog-type
'clog:clog-form :new-id t))
(let ((target (grep-input panel)))
(declare (ignorable target))
@ -72,7 +81,7 @@
(declare (ignorable target))
(setf (attribute target "for")
(clog:js-query target
"$('[data-clog-name=\\'sundir-check\\']').attr('id')")))
"$('[data-clog-name=\\'subdir-check\\']').attr('id')")))
(clog:set-on-change (dir-input panel)
(lambda (target)
(declare (ignorable target))