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

FIX>Pop-up-menu bug removin



        Reply to:   FIX>Pop-up-menu bug removing la
> Evaluate the following code, select "2" from the pop-up, then click
> "Remove". I get this error:

Same for me. Think the problem is related to the value of the slot
"default-item" of the menu.
Made the following patch that fixes this  (standard disclaimer):


(in-package "CCL")

(defmethod view-draw-contents :before ((menu pop-up-menu) &aux (items
(menu-items menu)))
"fixes erroneous behaviour when the last menu-item is removed"
  (with-slots (default-item) menu
    (when (> default-item (length items))
      (setf default-item 1))))


(require "POP-UP-MENU")

(make-instance 'window
  :view-size #@(200 50)
  :view-subviews
  (list (make-instance 'pop-up-menu
          :dialog-item-text "Remove"
          :view-nick-name 'pop-up
          :menu-items (list (make-instance 'menu-item :menu-item-title "1")
                            (make-instance 'menu-item :menu-item-title "2")))
        (make-instance 'button-dialog-item
          :dialog-item-text "Delete"
          :dialog-item-action
          #'(lambda (button)
              (let ((pop-up (view-named 'pop-up (view-container button))))
                (remove-menu-items pop-up (selected-item pop-up))
                ;; BUG?: remove-menu-items doesn't update pop-up-menu items:
                (invalidate-view pop-up t))))))