From 6b12729128605c1ff6232fe35d7806ba23b894c7 Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 13 May 2023 11:54:52 +0200 Subject: [PATCH] - [GUI] completed inilining of image one by one. --- src/gui/client/main-window.lisp | 36 +++++++++++++++----- src/gui/client/stream-window.lisp | 4 +-- src/gui/server/public-api-gemini-stream.lisp | 2 +- src/misc-utils.lisp | 15 +++++--- src/package.lisp | 1 + 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 23bb85e..fb0ea6f 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -365,8 +365,8 @@ (slurp-iri redirect-iri main-window)))) ((gemini-client:header-success-p status-code) (ev:with-enqueued-process-and-unblock () - (comm:make-request :gemini-save-url-db-history 1 iri) - (slurp-non-text-data main-window iri :try-to-open nil))))))) + (comm:make-request :gemini-save-url-db-history 1 iri)) + (slurp-non-text-data main-window iri :try-to-open nil)))))) (defun contextual-menu-link-clrs (link-name link-value main-window line-count) (labels ((add-to-tour-callback () @@ -393,25 +393,43 @@ link-value) :bold t) (client-bookmark-window:init-window main-window link-value)))) - (inline-possible-p () + (inline-image-p (link-value) (or (re:scan "(?i)jpg$" link-value) (re:scan "(?i)jpeg$" link-value) (re:scan "(?i)png$" link-value) (re:scan "(?i)gif$" link-value) (re:scan "(?i)bmp$" link-value) (re:scan "(?i)tga$" link-value))) + (inline-possible-p (link-value) + (inline-image-p link-value)) + (inline-type (link-value) + (when (inline-image-p link-value) + :inline-image)) (open-inline-callback () - (if (inline-possible-p) + (if (inline-possible-p link-value) (let* ((file-path (slurp-iri main-window link-value)) (image (gui:make-image file-path)) (coordinates `(+ (:line ,line-count :char 0) 1 :lines))) - (gui:insert-image (gemtext-widget main-window) image coordinates)) + (gui:insert-image (gemtext-widget main-window) image coordinates) + (with-accessors ((ir-lines ir-lines) + (ir-rendered-lines ir-rendered-lines)) main-window + (let* ((parent-line (elt ir-lines (- line-count 1))) + (new-line (copy-list parent-line))) + (setf (getf new-line :type) (inline-type link-value)) + (setf ir-lines + (fresh-vector-insert@ ir-lines + new-line + line-count)) + (setf ir-rendered-lines + (fresh-vector-insert@ ir-lines + "" + line-count))))) (funcall (link-click-mouse-1-callback-clsr link-value main-window))))) (lambda () (let* ((popup-menu (gui:make-menu nil (_"link menu"))) (x (gui:screen-mouse-x)) (y (gui:screen-mouse-y))) - (when (inline-possible-p) + (when (inline-possible-p link-value) (gui:make-menubutton popup-menu (_ "Inline") #'open-inline-callback)) (gui:make-menubutton popup-menu (_ "Add link to bookmarks") #'bookmark-link-callback) (gui:make-menubutton popup-menu (_ "Add link to tour") #'add-to-tour-callback) @@ -519,9 +537,9 @@ (lambda () (print-info-message ""))) (gui:append-line gemtext-widget ""))))) (render-line (key text line-number &key (wrap :word)) - (let ((font (key->font key)) - (justification (key->justification key)) - (start-index `(:line ,line-number :char 0))) + (let ((font (key->font key)) + (justification (key->justification key)) + (start-index `(:line ,line-number :char 0))) (gui:append-text gemtext-widget text) (gui:append-line gemtext-widget "") (multiple-value-bind (background foreground) diff --git a/src/gui/client/stream-window.lisp b/src/gui/client/stream-window.lisp index d84becc..05637ef 100644 --- a/src/gui/client/stream-window.lisp +++ b/src/gui/client/stream-window.lisp @@ -18,7 +18,7 @@ :text iri :column-values (list stream-status - (to-s (getf row :octet-count))) + (to-s (getf row :octect-count))) :index gui:+treeview-last-index+))) (gui:treeview-insert-item tree :item tree-row))) (gui:treeview-refit-columns-width (gui-goodies:tree stream-frame)) @@ -37,7 +37,7 @@ :master object :pack '(:side :top :expand t :fill :both) :columns (list (_ "Status") - (_ "Number of octets downloaded"))))) + (_ "Number of octects downloaded"))))) (setf tree treeview) (gui:treeview-heading tree gui:+treeview-first-column-id+ :text (_ "Address")) diff --git a/src/gui/server/public-api-gemini-stream.lisp b/src/gui/server/public-api-gemini-stream.lisp index 7eb55f2..bda3b30 100644 --- a/src/gui/server/public-api-gemini-stream.lisp +++ b/src/gui/server/public-api-gemini-stream.lisp @@ -312,7 +312,7 @@ (cons "download-iri" download-iri) (cons "start-time" actual-start-time) (cons "support-file" support-file) - (cons "octet-count" octect-count) + (cons "octect-count" octect-count) (cons "port" port) (cons "status-code" status-code) (cons "status-code-description" status-code-description) diff --git a/src/misc-utils.lisp b/src/misc-utils.lisp index b60cdfe..38a9478 100644 --- a/src/misc-utils.lisp +++ b/src/misc-utils.lisp @@ -616,12 +616,12 @@ to the array" (declare (optimize (speed 3) (safety 1) (debug 0))) (*cat vector v)) -(defun fresh-list-insert@ (a v pos) +(defun fresh-list-insert@ (list value pos) (declare (optimize (speed 3) (safety 1) (debug 0))) - (declare (list a)) - (lcat (subseq a 0 pos) - (list v) - (subseq a pos))) + (declare (list list)) + (lcat (subseq list 0 pos) + (list value) + (subseq list pos))) (defun fresh-list-subst@ (a v pos) (declare (optimize (speed 3) (safety 1) (debug 0))) @@ -630,6 +630,11 @@ to the array" (list v) (subseq a (1+ pos)))) +(defun fresh-vector-insert@ (a v pos) + (vcat (subseq a 0 pos) + (vector v) + (subseq a (1+ pos)))) + (eval-when (:compile-toplevel :load-toplevel :execute) (defun make-array-frame (size &optional (el nil) (type t) (simplep nil)) "All elements points to the same address/reference!" diff --git a/src/package.lisp b/src/package.lisp index 7102898..ae90db0 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -171,6 +171,7 @@ :vcat :fresh-list-insert@ :fresh-list-subst@ + :fresh-vector-insert@ :make-array-frame :make-fresh-array :sequence->list