diff --git a/etc/init.lisp b/etc/init.lisp index f751311..7043cf9 100644 --- a/etc/init.lisp +++ b/etc/init.lisp @@ -766,6 +766,12 @@ (define-key "b" #'gemini-history-back *gopher-keymap*) +(define-key "C-b a" #'bookmark-gopher-page *gopher-keymap*) + +(define-key "C-b s" #'display-bookmark *gopher-keymap*) + +(define-key "C-b d" #'delete-gemini-bookmark *gopher-keymap*) + ;;;; hooks ;; this module will install an hook to rewrite urls; By default it diff --git a/src/gopher-window.lisp b/src/gopher-window.lisp index ba6f264..67f8834 100644 --- a/src/gopher-window.lisp +++ b/src/gopher-window.lisp @@ -27,6 +27,16 @@ :accessor page-type :documentation "The type of the page , 0,1,2,i etc."))) +(defun gopher-window-p (w) + (typep w 'gopher-window)) + +(defun current-gopher-url () + (when (gopher-window-p specials:*gopher-window*) + (a:when-let* ((metadata (message-window:metadata specials:*message-window*)) + (history (gemini-viewer:gemini-metadata-history metadata)) + (link (a:last-elt history))) + link))) + (defmethod refresh-config :after ((object gopher-window)) (refresh-config-colors object swconf:+key-gopher-window+) (let* ((height (win-height *message-window*)) diff --git a/src/open-message-link-window.lisp b/src/open-message-link-window.lisp index 4463b46..6214621 100644 --- a/src/open-message-link-window.lisp +++ b/src/open-message-link-window.lisp @@ -75,25 +75,29 @@ (defun open-message-link (url enqueue) (tui-utils:with-notify-errors - (let* ((parsed (iri:iri-parse url)) - (scheme (uri:scheme parsed)) - (decoded-path (percent-decode url))) - (when (and (not enqueue) - (swconf:close-link-window-after-select-p)) - (ui:close-open-message-link-window)) - (cond - ((string= gemini-constants:+gemini-scheme+ scheme) - (db:insert-in-history (ui:open-url-prompt) url) - (db:gemlog-mark-as-seen url) - (gemini-viewer:ensure-just-one-stream-rendering) - (gemini-viewer:load-gemini-url url - :give-focus-to-message-window t - :enqueue enqueue - :use-cached-file-if-exists t)) - ((fs:dirp decoded-path) - (ui:open-file-explorer decoded-path)) - (t - (os-utils:open-resource-with-external-program decoded-path nil)))))) + (if (text-utils:string-starts-with-p gopher-parser:+gopher-scheme+ url) + (multiple-value-bind (host port type selector) + (gopher-parser:parse-iri url) + (gopher-window::make-request host port type selector)) + (let* ((parsed (iri:iri-parse url)) + (scheme (uri:scheme parsed)) + (decoded-path (percent-decode url))) + (when (and (not enqueue) + (swconf:close-link-window-after-select-p)) + (ui:close-open-message-link-window)) + (cond + ((string= gemini-constants:+gemini-scheme+ scheme) + (db:insert-in-history (ui:open-url-prompt) url) + (db:gemlog-mark-as-seen url) + (gemini-viewer:ensure-just-one-stream-rendering) + (gemini-viewer:load-gemini-url url + :give-focus-to-message-window t + :enqueue enqueue + :use-cached-file-if-exists t)) + ((fs:dirp decoded-path) + (ui:open-file-explorer decoded-path)) + (t + (os-utils:open-resource-with-external-program decoded-path nil))))))) (defclass open-links-window () ((links diff --git a/src/package.lisp b/src/package.lisp index 14b0fc6..5f1688c 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -2292,6 +2292,8 @@ (:a :alexandria)) (:export :gopher-window + :gopher-window-p + :current-gopher-url :go-to-next-link :go-to-previous-link :open-menu-link @@ -2908,6 +2910,7 @@ :ask-input-on-tofu-error :import-gemini-certificate :bookmark-gemini-page + :bookmark-gopher-page :display-bookmark :delete-gemini-bookmark :display-latest-visited-urls diff --git a/src/program-events.lisp b/src/program-events.lisp index e0a9408..2057680 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -1124,6 +1124,7 @@ (refresh-gemini-message-window links page-data ir-text nil) (ui:open-gemini-toc) (ui:open-gemini-message-link-window :give-focus nil :enqueue t) + (ui:focus-to-message-window) (windows:draw window))))) (defclass gemini-request-event (program-event) diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 47ea3c2..e750a0d 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -2577,6 +2577,34 @@ gemini page the program is rendering." :prompt (format nil (_ "Insert certificate file: ")) :complete-fn #'complete:directory-complete)))) +(defun bookmark-gopher-page () + (cond + ((not (gopher-window:gopher-window-p specials:*gopher-window*)) + (error-message (_ "The window is not displaying a gopher document"))) + ((not (gopher-window:current-gopher-url)) + (error-message (_ "This page can not be added to bookmarks"))) + (t + (let* ((link (gopher-window:current-gopher-url)) + (description (_ "No description"))) + (labels ((on-description-completed (new-description) + (if (text-utils:string-empty-p new-description) + (error-message (_ "Empty description")) + (progn + (setf description new-description) + (ui:ask-string-input #'on-section-completed + :prompt (format nil (_ "Insert bookmark section: ")) + :complete-fn #'complete:bookmark-section-complete)))) + (on-section-completed (section) + (db-utils:with-ready-database (:connect nil) + (db:bookmark-add db:+bookmark-gemini-type-entry+ + link + :section section + :description description)) + (notify (format nil (_ "Added ~s in bookmark") link)))) + (ui:ask-string-input #'on-description-completed + :prompt (format nil (_ "Insert bookmark description: ")) + :initial-value description)))))) + (defun bookmark-gemini-page () (cond ((not (message-window:gemini-window-p))