From 4de0de1e2cc62c955a1d310376de40119663980c Mon Sep 17 00:00:00 2001 From: cage Date: Wed, 29 May 2024 17:10:56 +0200 Subject: [PATCH] - added code to perform a search of gemspace, when the software is unable to understand the input typed in the address bar. --- src/gui/client/main-window.lisp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 4ab8942..42b2b8a 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -968,7 +968,11 @@ local file paths." ((fs:directory-exists-p path) (gui:choose-directory :initial-dir path :parent main-window :mustexist t)) (t - (gui-goodies:notify-request-error (format nil (_ "No such file or directory: ~a") path))))) + (when (gui:ask-yesno (format nil (_ "No such file or directory: ~s, search genspace instead?") + path) + :title (_ "Error") + :parent main-window) + (open-search-iri path main-window))))) (defun render-gemtext-string (main-window parsed-lines &key (links-path-prefix "")) (ev:with-enqueued-process-and-unblock () @@ -1032,6 +1036,14 @@ local file paths." (otherwise (render-line rendered-line)))))))))))) +(defun open-search-iri (criteria main-window) + (let ((parsed-iri-search-capsule (iri:iri-parse constants:+gemini-search-engine+))) + (setf (uri:query parsed-iri-search-capsule) + (text-utils:maybe-percent-encode criteria)) + (let ((search-iri (with-output-to-string (stream) + (iri:render-iri parsed-iri-search-capsule stream)))) + (open-iri search-iri main-window nil)))) + (defun open-iri (iri main-window use-cache &key (status +stream-status-streaming+)) (handler-case (let* ((actual-iri (remove-standard-port iri)) @@ -1068,7 +1080,10 @@ local file paths." (client-os-utils:open-resource-with-external-program main-window actual-iri)))) (esrap:esrap-parse-error (e) (declare (ignore e)) - (gui-goodies:notify-request-error (format nil (_ "Invalid address: ~s") iri))) + (when (gui:ask-yesno (_ "Invalid address, perform a search using your input?") + :title (_ "Invalid address") + :parent main-window) + (open-search-iri iri main-window))) (error (e) (gui-goodies:notify-request-error e))))