Skip to content

Commit

Permalink
extract popup-message interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Dec 10, 2023
1 parent 636eba3 commit be98202
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
6 changes: 0 additions & 6 deletions frontends/jsonrpc/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 11 additions & 6 deletions src/ext/popup-message.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))))
Expand All @@ -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)))

Expand Down
6 changes: 0 additions & 6 deletions src/interface.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
8 changes: 6 additions & 2 deletions src/internal-packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 22 additions & 7 deletions src/popup.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be98202

Please sign in to comment.