From be98202b2001fad07e3b108ce190a017d7a3ba3b Mon Sep 17 00:00:00 2001 From: cxxxr Date: Mon, 11 Dec 2023 04:27:42 +0900 Subject: [PATCH] extract popup-message interface --- frontends/jsonrpc/main.lisp | 6 ------ src/ext/popup-message.lisp | 17 +++++++++++------ src/interface.lisp | 6 ------ src/internal-packages.lisp | 8 ++++++-- src/popup.lisp | 29 ++++++++++++++++++++++------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/frontends/jsonrpc/main.lisp b/frontends/jsonrpc/main.lisp index 8390fb55e..549195b84 100644 --- a/frontends/jsonrpc/main.lisp +++ b/frontends/jsonrpc/main.lisp @@ -229,12 +229,6 @@ #+(or)(defmethod lem-if:popup-menu-first ((jsonrpc jsonrpc) popup-menu)) #+(or)(defmethod lem-if:popup-menu-last ((jsonrpc jsonrpc) popup-menu)) #+(or)(defmethod lem-if:popup-menu-select ((jsonrpc jsonrpc) popup-menu)) -#+(or)(defmethod lem-if:display-popup-message - ((jsonrpc jsonrpc) buffer-or-string &key timeout - destination-window - source-window - style)) -#+(or)(defmethod lem-if:delete-popup-message ((jsonrpc jsonrpc) popup-message)) #+(or)(defmethod lem-if:display-context-menu ((jsonrpc jsonrpc) context-menu style)) (defmethod lem-if:clipboard-paste ((jsonrpc jsonrpc)) diff --git a/src/ext/popup-message.lisp b/src/ext/popup-message.lisp index 1cb5e817b..38e29043c 100644 --- a/src/ext/popup-message.lisp +++ b/src/ext/popup-message.lisp @@ -4,6 +4,10 @@ (:lock t)) (in-package :lem/popup-message) +(defclass popup-messenger () ()) + +(setf lem-core/popup-message-interface:*popup-messenger* (make-instance 'popup-messenger)) + (defun make-popup-buffer (text) (let ((buffer (make-buffer "*Popup Message*" :temporary t :enable-undo-p nil))) (setf (variable-value 'line-wrap :buffer buffer) nil) @@ -12,11 +16,12 @@ (buffer-start (buffer-point buffer)) buffer)) -(defmethod lem-if:display-popup-message (implementation buffer-or-string - &key timeout - destination-window - source-window - style) +(defmethod lem-core/popup-message-interface:display-popup-message + ((popup-messenger popup-messenger) buffer-or-string + &key timeout + destination-window + source-window + style) (let ((buffer (etypecase buffer-or-string (string (make-popup-buffer buffer-or-string)) (buffer buffer-or-string)))) @@ -39,7 +44,7 @@ (round (* timeout 1000)))) window)))) -(defmethod lem-if:delete-popup-message (implementation popup-message) +(defmethod lem-core/popup-message-interface:delete-popup-message ((popup-messenger popup-messenger) popup-message) (when (and popup-message (not (deleted-window-p popup-message))) (delete-window popup-message))) diff --git a/src/interface.lisp b/src/interface.lisp index 7bed65e10..5657e7f51 100644 --- a/src/interface.lisp +++ b/src/interface.lisp @@ -79,12 +79,6 @@ (defgeneric lem-if:popup-menu-first (implementation popup-menu)) (defgeneric lem-if:popup-menu-last (implementation popup-menu)) (defgeneric lem-if:popup-menu-select (implementation popup-menu)) -(defgeneric lem-if:display-popup-message - (implementation buffer-or-string &key timeout - destination-window - source-window - style)) -(defgeneric lem-if:delete-popup-message (implementation popup-message)) (defgeneric lem-if:display-context-menu (implementation context-menu style) (:method (implementation context-menu style))) diff --git a/src/internal-packages.lisp b/src/internal-packages.lisp index ca4c695dc..f33f0901a 100644 --- a/src/internal-packages.lisp +++ b/src/internal-packages.lisp @@ -554,6 +554,12 @@ #+sbcl (sb-ext:lock-package :lem-core) +(defpackage :lem-core/popup-message-interface + (:use :cl) + (:export :*popup-messenger* + :display-popup-message + :delete-popup-message)) + (defpackage :lem-restart (:use) (:export :message @@ -597,8 +603,6 @@ :popup-menu-first :popup-menu-last :popup-menu-select - :display-popup-message - :delete-popup-message :display-context-menu :clipboard-paste :clipboard-copy diff --git a/src/popup.lisp b/src/popup.lisp index 71b9c7999..25cda66e0 100644 --- a/src/popup.lisp +++ b/src/popup.lisp @@ -2,20 +2,35 @@ (defparameter *default-popup-message-timeout* 5) +(defvar lem-core/popup-message-interface:*popup-messenger*) + +(defgeneric lem-core/popup-message-interface:display-popup-message + (popup-messenger + buffer-or-string + &key timeout + destination-window + source-window + style)) + +(defgeneric lem-core/popup-message-interface:delete-popup-message (popup-messenger popup-message)) + (defun display-popup-message (buffer-or-string &key (timeout *default-popup-message-timeout*) destination-window source-window style) - (lem-if:display-popup-message (implementation) - buffer-or-string - :timeout timeout - :destination-window destination-window - :source-window source-window - :style style)) + (lem-core/popup-message-interface:display-popup-message + lem-core/popup-message-interface:*popup-messenger* + buffer-or-string + :timeout timeout + :destination-window destination-window + :source-window source-window + :style style)) (defun delete-popup-message (popup-message) - (lem-if:delete-popup-message (implementation) popup-message)) + (lem-core/popup-message-interface:delete-popup-message + lem-core/popup-message-interface:*popup-messenger* + popup-message)) (defun display-popup-menu (items &rest args