[Bese-devel] Status-bar-mixin

Vladimir Sekissov svg at surnet.ru
Wed Jun 8 22:43:47 UTC 2005


Good day,

I'm starting to use UCW.
Here is small mixin component I've found helpful.
May be you find it useful too.

* Usage sample

(defcomponent my-window (simple-window-component status-bar-mixin)
  ...)

(defmethod render-on ((res response) (win my-window))
  (show-status-bar res win)
   ...)

... somewhere in code ...

  (show-message "My info message" :severity :info)
  (show-message "My error message" :severity :error)
...

* Code

(in-package :it.bese.ucw)

(defcomponent status-bar ()
  ((messages :accessor messages :initarg messages :initform '()))
  (:documentation "Stateless status bar to display messages."))

(defmethod render-on ((res response) (sb status-bar))
  (with-slots (messages) sb
  (<:div :id "status-bar"
   (iter (for (severity . msg) in messages)
              (<:p :class (strcat "status-bar-"
                                    (string-downcase (symbol-name severity)))
                     (<:as-html msg))))
  (setf messages '())))

(defgeneric add-message (status-bar msg &key &allow-other-keys)
  (:method ((sb status-bar) msg &key (severity :info))
    (setf (messages sb) (acons severity msg (messages sb))))
  (:documentation "Stateless status bar to display messages with severity."))

(defcomponent status-bar-mixin ()
  ((status-bar :accessor status-bar
              :initarg status-bar
              :component (status-bar))))

(defmethod show-status-bar ((res response) (win status-bar-mixin))
  (render-on res (status-bar win)))

(defgeneric show-message (msg &key &allow-other-keys)
  (:method ((msg string) &key (severity :info) (context *context*))
    (let* ((win (context.window-component context))
           (win-class (class-of win)))
      (when (not (subtypep win-class (find-class 'status-bar-mixin)))
        (error "Type ~S of ~S is not a subclass of STATUS-BAR-MIXIN"
               win-class win))
      (add-message (status-bar win) msg :severity severity))))

Best Regards,
Vladimir Sekissov



More information about the bese-devel mailing list