From aa3aa23fe18955346a7e4bd07e5336aa8f4de539 Mon Sep 17 00:00:00 2001 From: Luka Hadzi-Djokic Date: Tue, 5 Sep 2023 16:44:35 +0200 Subject: [PATCH] Move theme update logic to `(setf theme) :after`. --- source/browser.lisp | 30 ++++++++++++++++++++++++++++++ source/help.lisp | 27 +-------------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/source/browser.lisp b/source/browser.lisp index b2caaf5b6bb9..e06895297379 100644 --- a/source/browser.lisp +++ b/source/browser.lisp @@ -300,6 +300,36 @@ prevents otherwise.") (declare (ignore ignored)) (make-instance 'theme:theme)) +(defmethod (setf theme) :after (theme (browser browser)) + (declare (ignorable theme)) + (flet ((apply-initfunction (class slot) + (apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition class slot)) + nil))) + (mapc (lambda (window) + (mapc (lambda (panel) + (setf (style panel) + (apply-initfunction 'panel-buffer 'style)) + (reload-buffer panel)) + (panel-buffers window)) + (mapc (lambda (prompt-buffer) + (setf (style prompt-buffer) + (apply-initfunction 'prompt-buffer 'style)) + (show-prompt-buffer prompt-buffer)) + (active-prompt-buffers window)) + (setf (style (status-buffer window)) + (apply-initfunction 'status-buffer 'style)) + (setf (message-buffer-style window) + (apply-initfunction 'window 'message-buffer-style))) + (alex:hash-table-values (windows browser))) + (mapc (lambda (buffer) + (when (internal-url-p (url buffer)) + (setf (style buffer) + (apply-initfunction 'web-buffer 'style)) + (reload-buffer buffer))) + (alex:hash-table-values (buffers browser))) + (print-status) + (echo "Theme changed."))) + (defmethod get-containing-window-for-buffer ((buffer buffer) (browser browser)) "Get the window containing a buffer." (find buffer (alex:hash-table-values (windows browser)) :key #'active-buffer)) diff --git a/source/help.lisp b/source/help.lisp index bebc7223211b..e64fb7f07009 100644 --- a/source/help.lisp +++ b/source/help.lisp @@ -86,32 +86,7 @@ Note that some settings may require restarting Nyxt to take effect.") :style (format nil "background-color: ~a; color: ~a" (theme:accent-color (symbol-value theme-symbol)) (theme:on-accent-color (symbol-value theme-symbol))) - `(nyxt/setting::apply-generic-setting 'nyxt/setting::browser-generic-setting - (lambda (browser) - (setf (theme browser) ,theme-symbol) - (mapc (lambda (window) - (mapc (lambda (panel) - (setf (style panel) - (apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'panel-buffer 'style)) - nil)) - (reload-buffer panel)) - (panel-buffers window)) - (setf (style (status-buffer window)) - (apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'status-buffer 'style)) - nil)) - (setf (message-buffer-style window) - (apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'window 'message-buffer-style)) - nil))) - (alex:hash-table-values (windows browser))) - (mapc (lambda (buffer) - (when (internal-url-p (url buffer)) - (setf (style buffer) - (apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'web-buffer 'style)) - nil)) - (reload-buffer buffer))) - (alex:hash-table-values (buffers browser))) - (print-status) - (echo "Theme changed.")))) + `(nyxt/setting::apply-slot-setting 'theme 'nyxt/setting::browser-slot-setting ,theme-symbol)) (:p "Colors:") (:dl (loop for (name color text-color) in '(("Background" theme:background-color theme:on-background-color)