"Toolbar check buttons" mapped to menu objects, anyone?
Hi! In one of my projects I have a toolbar which has one button that should behave like a check button, i.e. pressing it toggles a state (a global variable *DATA-MODE* which can be 'TMP or 'DB). The button's image is supposed to show the current state. Furthermore there's a menu entry which can also be used to toggle this state and which is also supposed to show the state (with a checkmark). Below are the excerpts from my code that implement this. I think this is quite ugly and I hope there's a more elegant way to do it. Specifically, I was hoping that there's a way to couple the button and the menu object with :REMAPPED. And maybe there's a way to create a kind of "toolbar check button" that changes its image automatically? Extra bonus points for not using a toolbar component which is visually separated from the surrounding toolbar buttons. Any ideas? Thanks, Edi. (capi:define-interface ... (:panes (toolbar capi:toolbar :accessor main-toolbar :items (list (make-instance 'capi:toolbar-button :name 'mode-button ;; PIC is a utility function which returns images ;; created with GP:READ-EXTERNAL-IMAGE :image (pic (ecase *data-mode* (tmp "tmpmode.bmp") (db "dbmode.bmp"))) :callback-type :item-interface :callback 'gui-change-mode) ...) ... (:menus (change-mode-component :component (("DB Mode" :name 'mode-menu-object :selected (eq *data-mode* 'db) :callback-type :item-interface :callback 'gui-change-mode)) :accessor change-mode-component :interaction :multiple-selection) (options-menu "Options" (change-mode-component)) ... (defun find-mode-button (interface) (find 'mode-button (capi:collection-items (main-toolbar interface)) :key #'capi:capi-object-name)) (defun gui-change-mode (item interface) (let ((from-button-p (typep item 'capi:toolbar-button))) (ecase *data-mode* (tmp (setf *data-mode* 'db (capi:toolbar-button-image (find-mode-button interface)) (pic "dbmode.bmp")) (when from-button-p (setf (capi:choice-selection (change-mode-component interface)) (list 0)))) (db (setf *data-mode* 'tmp (capi:toolbar-button-image (find-mode-button interface)) (pic "tmpmode.bmp")) (when from-button-p (setf (capi:choice-selection (change-mode-component interface)) nil))))))