command-tables (still)
Greg Bennett
gwbennett at sentex.ca
Mon Mar 18 15:46:10 UTC 2019
From Greg Bennett running sbcl 1.4.11 (64bit) under linux mint 18.1
(64bit)
and using mcclim-2019-0202-git, as far as I can tell.
I'm trying to learn how to add and remove menus from an existing menubar
which I presume is done through its associated command-table. In the
interests of
completeness I include the contents of the example file. If this is a
silly thing to do,
let me know.
From that git, I'm using the file Examples/menutest.lisp as a basis for
experiments with menus,
menubars, adding and removing menus.
;; START File contents of Examples/menutest.lisp
;;; (c) copyright 2000 by
;;; Robert Strandh (robert.strandh at gmail.com)
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
(defpackage #:menutest
(:use :clim :clim-extensions :clim-lisp)
(:export #:menutest))
(in-package #:menutest)
(define-application-frame menutest ()
()
(:menu-bar menubar-command-table)
(:panes
(screen :application
:display-time nil
:text-style (make-text-style :sans-serif :roman :normal)))
(:layouts
(defaults (vertically () screen))))
(define-menutest-command com-file ()
(format *standard-output* "You pressed the File button.~%")
(finish-output *standard-output*))
(define-menutest-command com-hello ()
(format *standard-output* "You pressed the Hello button.~%")
(finish-output *standard-output*))
(define-menutest-command com-hi ()
(format *standard-output* "You pressed the Hi button.~%")
(finish-output *standard-output*))
(make-command-table 'buffer-command-table
:errorp nil
:menu '(("Hello there" :command com-hello)
("Hi there" :command com-hi)))
(make-command-table 'menubar-command-table
:errorp nil
:menu '(("Buffer" :menu buffer-command-table)
("File" :command com-file)))
;; END file contents
Inside the package menutest, I added this form:
(defun run-menutest (thread-name)
(flet ((run ()
(let ((frame (make-application-frame 'menutest)))
(run-frame-top-level frame))))
(sb-thread::make-thread #'run :name thread-name)))
so that I can create the frame and keep the listener.
With Daniel's help I can see what is on the command-table:
(let (foo)
(map-over-command-table-commands
(lambda (elt) (push elt foo))
(frame-command-table (find-application-frame 'menutest))) ;;
from CLIM 2 P201 [f-c-t], P178 [f-a-f] 'menutest
;;; from define application-frame itself
(nreverse foo))
;; ->
(COM-FILE COM-HELLO COM-HI CLIM-INTERNALS::COM-NULL-COMMAND
CLIM-INTERNALS::COM-HELP CLIM-INTERNALS::COM-DESCRIBE
CLIM-INTERNALS::COM-DESCRIBE-PRESENTATION
CLIM-TAB-LAYOUT:COM-SWITCH-TO-TAB-PAGE
CLIM-TAB-LAYOUT:COM-REMOVE-TAB-PAGE)
And I seem to be able to add a command:
(define-menutest-command com-RWO ()
(format *standard-output* "Fearless Leader~%")
(finish-output *standard-output*))
;; followed by [CLIM2.2 P219]
(add-menu-item-to-command-table
(frame-command-table (find-application-frame 'menutest))
"RWO"
:command
(cons 'COM-RWO (list ())))
;; -> NIL
;; Does NIL indicate something is wrong, I wonder ?
;; Rerun (let ..)
(COM-FILE COM-HELLO COM-HI COM-RWO CLIM-INTERNALS::COM-NULL-COMMAND
CLIM-INTERNALS::COM-HELP CLIM-INTERNALS::COM-DESCRIBE
CLIM-INTERNALS::COM-DESCRIBE-PRESENTATION
CLIM-TAB-LAYOUT:COM-SWITCH-TO-TAB-PAGE
CLIM-TAB-LAYOUT:COM-REMOVE-TAB-PAGE)
;;; and there it seems to be.
I had hoped that the application-frame would now show RWO.
Do I have to explicitly redisplay the items of the frame's menubar,
perhaps ?
My attempts to use (display-command-table-menu ..) each yield a
no applicable method error.
I would appreciate pointers to what I am still missing in exploring
command-tables.
Cheers /Greg Bennett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/mcclim-devel/attachments/20190318/f574c0ad/attachment.html>
More information about the mcclim-devel
mailing list