From 70a6d51a2808f7ea5af18ade0e4c3b8f92b4954f Mon Sep 17 00:00:00 2001 From: cage Date: Thu, 6 Jan 2022 13:00:16 +0100 Subject: [PATCH] - added downloading and opening a file from filesystem explorer window. --- etc/init.lisp | 2 ++ etc/shared.conf | 2 +- src/filesystem-tree-window.lisp | 43 ++++++++++++++++++++++++++------- src/package.lisp | 4 ++- src/ui-goodies.lisp | 8 +++++- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/etc/init.lisp b/etc/init.lisp index df39c27..bbfca9f 100644 --- a/etc/init.lisp +++ b/etc/init.lisp @@ -628,6 +628,8 @@ (define-key "q" #'file-explorer-close-window *filesystem-explorer-keymap*) +(define-key "C-J" #'file-explorer-open-node *filesystem-explorer-keymap*) + ;;;; hooks ;; this module will install an hook to rewrite urls; By default it diff --git a/etc/shared.conf b/etc/shared.conf index 6c0d997..b1e6634 100644 --- a/etc/shared.conf +++ b/etc/shared.conf @@ -197,7 +197,7 @@ gemini.exclusive.mode.toc.width = 1/5 # using "buffer NUMBER" after "no wait" allow to customize the cache # (in Mib) to be cached before opening the partial downloaded data - +# ▼▼▼▼▼▼▼▼▼ buffer 20 Mib # open "mp4$" with "xterm -e mpv" no wait buffer 20 # finally if you want to open some kind of file with tinmop try the diff --git a/src/filesystem-tree-window.lisp b/src/filesystem-tree-window.lisp index 221d30a..93a3726 100644 --- a/src/filesystem-tree-window.lisp +++ b/src/filesystem-tree-window.lisp @@ -71,15 +71,19 @@ :accessor filesystem-download-function :type function :documentation "A function to download a remote file, parameters - are - node (remote file) - destination-file (local file, note that - this should be an optional parameter with default - : (fs:temporary-file).") + are: + + - node (remote file) + - destination-file (local file, note that + this should be an optional parameter with default: + (make-temporary-file-from-node node). + + Must returns the path of the downloaded file.") (filesystem-upload-function :initform #'upload-local-filesystem-node :accessor filesystem-upload-function :type function :documentation "A function to upload a local file, parameters: - - source-path (local path) - matching-node (remote directory).") (filesystem-query-path-function @@ -87,10 +91,10 @@ :accessor filesystem-query-path-function :type function :documentation "function with two parameter the path and a feature -to query Valid feature values are :size. Returns nil if Returns nil -if the path does not point to an actual file.")) + to query Valid feature values are :size. Returns nil if Returns + nil if the path does not point to an actual file.")) (:documentation "A window that shows and allow interacting with a - hierarchical filesystem")) + hierarchical filesystem")) (defmethod refresh-config :after ((object filesystem-tree-window)) (with-croatoan-window (croatoan-window object) @@ -179,8 +183,18 @@ if the path does not point to an actual file.")) (define-constant +octect-type+ '(unsigned-byte 8) :test #'equalp) +(defun make-temporary-file-from-path (path) + (let ((extension (fs:get-extension path))) + (fs:temporary-file :extension extension))) + +(defun make-temporary-file-from-node (node) + (let ((path (tree-path (data node)))) + (make-temporary-file-from-path path))) + (defun download-local-filesystem-node (matching-node - &optional (destination-file (fs:temporary-file))) + &optional + (destination-file + (make-temporary-file-from-node matching-node))) (with-open-file (input-stream (tree-path (data matching-node)) :direction :input :element-type +octect-type+) @@ -365,7 +379,8 @@ if the path does not point to an actual file.")) (resync-rows-db window :redraw t :selected-path path))) (defun download-treenode (window remote-path - &optional (destination-file (fs:temporary-file))) + &optional + (destination-file (make-temporary-file-from-path remote-path))) (when-let* ((root-node (filesystem-root window)) (matching-node (find-node root-node remote-path))) (funcall (filesystem-download-function window) matching-node destination-file))) @@ -472,6 +487,16 @@ if the path does not point to an actual file.")) (not (tree-marked-p (data matching-node)))) (setf (tree-marked-p (data matching-node)) t)))) +(defun open-node (window path) + (when-let* ((root-node (filesystem-root window)) + (matching-node (find-node root-node path)) + (node-data (data matching-node)) + (node-path (tree-path node-data))) + (if (tree-dir-p node-data) + (expand-treenode window node-path) + (let ((downloaded-path (download-treenode window node-path))) + (os-utils:open-resource-with-external-program downloaded-path nil))))) + (defun init (root) "Initialize the window" (let* ((low-level-window (make-croatoan-window :border t)) diff --git a/src/package.lisp b/src/package.lisp index 2fd63ad..8304192 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -2041,6 +2041,7 @@ :recursive-delete-node :filesystem-query-treenode :mark-node + :open-node :resync-rows-db :init)) @@ -2811,7 +2812,8 @@ :file-explorer-delete-marked :file-explorer-scroll-begin :file-explorer-scroll-end - :file-explorer-close-window)) + :file-explorer-close-window + :file-explorer-open-node)) (defpackage :scheduled-events (:use diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index a181e48..d3ba266 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -2552,7 +2552,7 @@ printed, on the main window." (file-explorer-go-down)))) (defun file-explorer-delete-tree () - (when-let* ((win *filesystem-explorer-window*) + (when-let* ((win *filesystem-explorer-window*) (fields (line-oriented-window:selected-row-fields win)) (path (fstree:tree-path fields))) (flet ((on-input-complete (maybe-accepted) @@ -2602,3 +2602,9 @@ printed, on the main window." (defun file-explorer-close-window () (close-window-and-return-to-message *filesystem-explorer-window*)) + +(defun file-explorer-open-node () + (when-let* ((win *filesystem-explorer-window*) + (fields (line-oriented-window:selected-row-fields win)) + (path (fstree:tree-path fields))) + (fstree:open-node win path)))