[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pop-up-menu bug removing last menu item

At  2:48 PM 6/6/94 -0400, cornell@freya.cs.umass.edu wrote:
>Evaluate the following code, select "2" from the pop-up, then click
>"Remove". I get this error:

The pop-up-menu code encodes the default item, the one displayed
when the mouse button is not down, as an index into the list of
items. It neglected to update this index when some menu items were
removed. Here's a patch:


; remove-pop-up-item-patch.lisp
; Update the default-item of a pop-up menu after items are removed.

(in-package :ccl)

(defmethod remove-menu-items :around ((menu pop-up-menu) &rest items)
  (declare (ignore items))
  (let* ((default-item-number (pop-up-menu-default-item menu))
         (default-item (unless (eql default-item-number 0)
                         (nth (1- default-item-number) (menu-items menu)))))
      (when default-item
        (let ((index (position default-item (menu-items menu))))
          (setf (pop-up-menu-default-item menu)
                (if index (1+ index) 1)))))))