mirror of
https://codeberg.org/cage/tinmop/
synced 2025-02-14 07:40:38 +01:00
- implemented creating paths in filesystem window.
This commit is contained in:
parent
af48cde4a8
commit
9fa4b72548
@ -604,10 +604,14 @@
|
|||||||
|
|
||||||
(define-key "d" #'file-explorer-delete-path *filesystem-explorer-keymap*)
|
(define-key "d" #'file-explorer-delete-path *filesystem-explorer-keymap*)
|
||||||
|
|
||||||
|
(define-key "a" #'file-explorer-create-path *filesystem-explorer-keymap*)
|
||||||
|
|
||||||
(define-key "up" #'file-explorer-go-up *filesystem-explorer-keymap*)
|
(define-key "up" #'file-explorer-go-up *filesystem-explorer-keymap*)
|
||||||
|
|
||||||
(define-key "down" #'file-explorer-go-down *filesystem-explorer-keymap*)
|
(define-key "down" #'file-explorer-go-down *filesystem-explorer-keymap*)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;;; hooks
|
;;;; hooks
|
||||||
|
|
||||||
;; this module will install an hook to rewrite urls; By default it
|
;; this module will install an hook to rewrite urls; By default it
|
||||||
|
@ -47,13 +47,17 @@
|
|||||||
:initform #'expand-local-filesystem-node
|
:initform #'expand-local-filesystem-node
|
||||||
:accessor filesystem-expand-function
|
:accessor filesystem-expand-function
|
||||||
:type function)
|
:type function)
|
||||||
(filesystem-rename-function
|
(filesystem-rename-function
|
||||||
:initform #'rename-local-filesystem-node
|
:initform #'rename-local-filesystem-node
|
||||||
:accessor filesystem-rename-function
|
:accessor filesystem-rename-function
|
||||||
:type function)
|
:type function)
|
||||||
(filesystem-delete-function
|
(filesystem-delete-function
|
||||||
:initform #'delete-local-filesystem-node
|
:initform #'delete-local-filesystem-node
|
||||||
:accessor filesystem-delete-function
|
:accessor filesystem-delete-function
|
||||||
|
:type function)
|
||||||
|
(filesystem-create-function
|
||||||
|
:initform #'create-local-filesystem-node
|
||||||
|
:accessor filesystem-create-function
|
||||||
:type function))
|
:type function))
|
||||||
(:documentation "A window that shows and allow intercating with a hierarchical filesystem"))
|
(:documentation "A window that shows and allow intercating with a hierarchical filesystem"))
|
||||||
|
|
||||||
@ -116,6 +120,12 @@
|
|||||||
(make-instance 'm-tree :data (make-node-data file nil)))))
|
(make-instance 'm-tree :data (make-node-data file nil)))))
|
||||||
matching-node)))
|
matching-node)))
|
||||||
|
|
||||||
|
(defun create-local-filesystem-node (path dirp)
|
||||||
|
(assert path)
|
||||||
|
(if dirp
|
||||||
|
(fs:make-directory path)
|
||||||
|
(fs:create-a-file path)))
|
||||||
|
|
||||||
(defun rename-local-filesystem-node (matching-node new-path)
|
(defun rename-local-filesystem-node (matching-node new-path)
|
||||||
(let ((path (tree-path (data matching-node))))
|
(let ((path (tree-path (data matching-node))))
|
||||||
(assert path)
|
(assert path)
|
||||||
@ -270,6 +280,15 @@
|
|||||||
(win-clear window :redraw nil)
|
(win-clear window :redraw nil)
|
||||||
(resync-rows-db window :redraw t :selected-path path)))
|
(resync-rows-db window :redraw t :selected-path path)))
|
||||||
|
|
||||||
|
(defun create-treenode (window path dirp)
|
||||||
|
(when-let* ((root-node (filesystem-root window))
|
||||||
|
(parent-node (find-node root-node (fs:parent-dir-path path))))
|
||||||
|
(funcall (filesystem-create-function window) path dirp)
|
||||||
|
(remove-all-children parent-node)
|
||||||
|
(expand-treenode window (tree-path (data parent-node)))
|
||||||
|
(win-clear window :redraw nil)
|
||||||
|
(resync-rows-db window :redraw t :selected-path path)))
|
||||||
|
|
||||||
(defmethod draw :after ((object filesystem-tree-window))
|
(defmethod draw :after ((object filesystem-tree-window))
|
||||||
(when-window-shown (object)
|
(when-window-shown (object)
|
||||||
(let* ((window-width (usable-window-width object))
|
(let* ((window-width (usable-window-width object))
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
out)
|
out)
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
|
(defun create-a-file (path)
|
||||||
|
(open path :direction :probe :if-does-not-exist :create))
|
||||||
|
|
||||||
(defun rename-a-file (old new)
|
(defun rename-a-file (old new)
|
||||||
(nix:rename old new))
|
(nix:rename old new))
|
||||||
|
|
||||||
@ -95,6 +98,10 @@
|
|||||||
(let ((re (concatenate 'string ext "$")))
|
(let ((re (concatenate 'string ext "$")))
|
||||||
(cl-ppcre:scan re path)))
|
(cl-ppcre:scan re path)))
|
||||||
|
|
||||||
|
(defun extension-dir-p (path)
|
||||||
|
(let ((re (concatenate 'string *directory-sep-regexp* "$")))
|
||||||
|
(cl-ppcre:scan re path)))
|
||||||
|
|
||||||
(defun strip-extension (file &key (strip-all nil))
|
(defun strip-extension (file &key (strip-all nil))
|
||||||
(let ((new (cl-ppcre:regex-replace "(?i)[a-z0-9]\\.[^.]+$" file "")))
|
(let ((new (cl-ppcre:regex-replace "(?i)[a-z0-9]\\.[^.]+$" file "")))
|
||||||
(if (string= file new)
|
(if (string= file new)
|
||||||
|
@ -272,6 +272,7 @@
|
|||||||
:+s-isgid+
|
:+s-isgid+
|
||||||
:*directory-sep-regexp*
|
:*directory-sep-regexp*
|
||||||
:*directory-sep*
|
:*directory-sep*
|
||||||
|
:create-a-file
|
||||||
:copy-a-file
|
:copy-a-file
|
||||||
:rename-a-file
|
:rename-a-file
|
||||||
:file-size
|
:file-size
|
||||||
@ -281,6 +282,7 @@
|
|||||||
:cat-parent-dir
|
:cat-parent-dir
|
||||||
:has-extension
|
:has-extension
|
||||||
:get-extension
|
:get-extension
|
||||||
|
:extension-dir-p
|
||||||
:strip-extension
|
:strip-extension
|
||||||
:add-extension
|
:add-extension
|
||||||
:do-directory
|
:do-directory
|
||||||
@ -2029,6 +2031,7 @@
|
|||||||
:expand-treenode
|
:expand-treenode
|
||||||
:rename-treenode
|
:rename-treenode
|
||||||
:delete-treenode
|
:delete-treenode
|
||||||
|
:create-treenode
|
||||||
:resync-rows-db
|
:resync-rows-db
|
||||||
:init))
|
:init))
|
||||||
|
|
||||||
@ -2787,6 +2790,7 @@
|
|||||||
:file-explorer-close
|
:file-explorer-close
|
||||||
:file-explorer-rename
|
:file-explorer-rename
|
||||||
:file-explorer-delete-path
|
:file-explorer-delete-path
|
||||||
|
:file-explorer-create-path
|
||||||
:file-explorer-go-down
|
:file-explorer-go-down
|
||||||
:file-explorer-go-up))
|
:file-explorer-go-up))
|
||||||
|
|
||||||
|
@ -2453,12 +2453,27 @@ printed, on the main window."
|
|||||||
(fields (line-oriented-window:selected-row-fields win))
|
(fields (line-oriented-window:selected-row-fields win))
|
||||||
(path (fstree:tree-path fields)))
|
(path (fstree:tree-path fields)))
|
||||||
(flet ((on-input-complete (new-path)
|
(flet ((on-input-complete (new-path)
|
||||||
(with-enqueued-process ()
|
(when (string-not-empty-p new-path)
|
||||||
(fstree:rename-treenode win path new-path))))
|
(with-enqueued-process ()
|
||||||
|
(fstree:rename-treenode win path new-path)))))
|
||||||
(ask-string-input #'on-input-complete
|
(ask-string-input #'on-input-complete
|
||||||
:prompt
|
:prompt
|
||||||
(format nil (_ "rename ~a to: ") path)))))
|
(format nil (_ "rename ~a to: ") path)))))
|
||||||
|
|
||||||
|
(defun file-explorer-create-path ()
|
||||||
|
"create a file or directory"
|
||||||
|
(when-let* ((win *filesystem-explorer-window*)
|
||||||
|
(fields (line-oriented-window:selected-row-fields win))
|
||||||
|
(path (fstree:tree-path fields)))
|
||||||
|
(flet ((on-input-complete (new-path)
|
||||||
|
(when (string-not-empty-p new-path)
|
||||||
|
(with-enqueued-process ()
|
||||||
|
(let ((dirp (fs:extension-dir-p new-path)))
|
||||||
|
(fstree:create-treenode win new-path dirp))))))
|
||||||
|
(ask-string-input #'on-input-complete
|
||||||
|
:prompt (_ "create: ")
|
||||||
|
:initial-value path))))
|
||||||
|
|
||||||
(defun file-explorer-move (amount)
|
(defun file-explorer-move (amount)
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(line-oriented-window:unselect-all *filesystem-explorer-window*)
|
(line-oriented-window:unselect-all *filesystem-explorer-window*)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user