From fd19aa8704f1ebbfe06116f86532a3f83a4c8c68 Mon Sep 17 00:00:00 2001 From: cage Date: Thu, 2 Mar 2023 18:17:19 +0100 Subject: [PATCH] - [GUI] allowed expanding of local paths in the address bar; - refactored callback related to opening address. --- src/complete.lisp | 9 +++-- src/gui/client/main-window.lisp | 67 ++++++++++++++++++++------------- src/package.lisp | 1 + 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/complete.lisp b/src/complete.lisp index 9d00fff..9f44a1a 100644 --- a/src/complete.lisp +++ b/src/complete.lisp @@ -222,11 +222,14 @@ list af all possible candidtae for completion." (setf indices (loop for i in ordering collect (elt indices i))) (values strings indices))) +(defun expand-iri-as-local-path-p (hint) + (or (text-utils:string-starts-with-p fs:*directory-sep* hint) + (text-utils:string-starts-with-p "." hint) + (text-utils:string-starts-with-p "~" hint))) + (defun make-complete-gemini-iri-fn (prompt) (lambda (hint) - (if (or (text-utils:string-starts-with-p fs:*directory-sep* hint) - (text-utils:string-starts-with-p "." hint) - (text-utils:string-starts-with-p "~" hint)) + (if (expand-iri-as-local-path-p hint) (directory-complete hint) (when-let ((bag (remove-duplicates (funcall #'db:history-prompt->values prompt) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 1d4fcee..844fc68 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -164,7 +164,8 @@ (defun autocomplete-iri-clsr (toolbar) (declare (ignore toolbar)) (lambda (hint) - (if (> (length hint) 2) + (if (or (complete:expand-iri-as-local-path-p hint) + (> (length hint) 2)) (with-notify-errors (let ((match-results (cev:enqueue-request-and-wait-results :complete-net-address 1 @@ -193,9 +194,8 @@ (gen-ir-access pre-alt-text) (defun link-click-mouse-1-callback (link-value main-window &key (use-cache t)) - (declare (ignore link-value)) (lambda () - (funcall (start-stream-iri-clsr main-window :use-cache use-cache)))) + (open-iri link-value main-window use-cache))) (defun collect-ir-lines (main-window lines) (with-accessors ((ir-lines ir-lines) @@ -372,30 +372,45 @@ (getf response :cached) (getf response :iri))) -(defun start-stream-iri-clsr (main-window use-cache &optional (status :streaming)) +(defun open-iri (iri main-window use-cache) + (handler-case + (let ((parsed-iri (iri:iri-parse iri))) + (if (string= (uri:scheme parsed-iri) + gemini-constants:+gemini-scheme+) + (start-stream-iri iri main-window use-cache) + (progn))) + (error (e) + #+debug-mode (misc:dbg "error quen getting iri from autocomplete ~a" e) + (notify-request-error e)))) + +(defun start-stream-iri (iri main-window use-cache &optional (status :streaming)) + (let ((connecting-response (cev:enqueue-request-and-wait-results :gemini-request + 1 + ev:+maximum-event-priority+ + iri + use-cache))) + (multiple-value-bind (status-code + status-description + meta + cached + original-iri) + (displace-gemini-response connecting-response) + (cond + ((gemini-client:header-success-p status-code) + (start-streaming-thread iri + :use-cache nil + :process-function (lambda (lines) + (collect-ir-lines main-window lines) + (misc:dbg "lines ~a" lines)) + :status status)))))) + + +(defun open-iri-clsr (main-window use-cache) (lambda () (with-accessors ((tool-bar tool-bar)) main-window (with-accessors ((iri-entry iri-entry)) tool-bar - (let* ((iri (trim-blanks (gui:text iri-entry))) - (connecting-response (cev:enqueue-request-and-wait-results :gemini-request - 1 - ev:+maximum-event-priority+ - iri - use-cache))) - (multiple-value-bind (status-code - status-description - meta - cached - original-iri) - (displace-gemini-response connecting-response) - (cond - ((gemini-client:header-success-p status-code) - (start-streaming-thread iri - :use-cache nil - :process-function (lambda (lines) - (collect-ir-lines main-window lines) - (misc:dbg "lines ~a" lines)) - :status status))))))))) + (let* ((iri (trim-blanks (gui:text iri-entry)))) + (open-iri iri main-window use-cache)))))) (defun setup-main-window-events (main-window) (with-accessors ((tool-bar tool-bar)) main-window @@ -409,9 +424,9 @@ #$$ (lambda (e) (declare (ignore e)) - (funcall (start-stream-iri-clsr main-window t))) + (funcall (open-iri-clsr main-window t))) :append nil)) - (setf (gui:command go-button) (start-stream-iri-clsr main-window t))))) + (setf (gui:command go-button) (open-iri-clsr main-window t))))) (defmethod initialize-instance :after ((object tool-bar) &key &allow-other-keys) (with-accessors ((iri-entry iri-entry) diff --git a/src/package.lisp b/src/package.lisp index b16e5c0..0a9e161 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1563,6 +1563,7 @@ :followed-user-complete :tags-complete :conversation-folder + :expand-iri-as-local-path-p :make-complete-gemini-iri-fn :complete-chat-message :complete-always-empty