Update of /project/cells-gtk/cvsroot/root/cells-gtk
In directory common-lisp.net:/tmp/cvs-serv14035/root/cells-gtk
Modified Files:
menus.lisp
Log Message:
New method cgtk-set-active-item-by-path (on combo-box)
Date: Sat Oct 8 16:28:49 2005
Author: pdenno
Index: root/cells-gtk/menus.lisp
diff -u root/cells-gtk/menus.lisp:1.10 root/cells-gtk/menus.lisp:1.11
--- root/cells-gtk/menus.lisp:1.10 Sun May 29 23:09:40 2005
+++ root/cells-gtk/menus.lisp Sat Oct 8 16:28:49 2005
@@ -18,6 +18,8 @@
(in-package :cgtk)
+(export '(cgtk-set-active-item-by-path))
+
(defmacro with-tree-iters (vars &body body)
`(let (,@(loop for var in vars collect `(,var (gtk-adds-tree-iter-new))))
(unwind-protect
@@ -40,7 +42,7 @@
:new-tail '-text
:on-changed
(callback (widget event data)
- (trc nil "combo-box onchanged cb" widget event data (id self))
+ ;(trc nil "combo-box onchanged cb" widget event data (id self))
(if (items self)
;; flat model (:items specified)
(let ((pos (gtk-combo-box-get-active (id self))))
@@ -74,12 +76,19 @@
for index from 0 do
(gtk-tree-store-set-kids (id (tree-model self)) root c-null index
'(:string :string) pfunc (children-fn self)))
- ;; Spec says iter must correspond to a path of depth one. Hence no point in set-active-iter.
- ;; init should just be the index of the depth one item you want displayed.
- (bwhen (item-index (init self))
- (gtk-combo-box-set-active (id self) item-index)
- (let ((item (item-from-path (children-fn self) (roots self) (list item-index))))
- (setf (md-value self) item))))))
+ ;; Spec says iter must correspond to a path of depth one. But then there would be no point
+ ;; in set-active-iter. Well, the spec seems to be wrong (or poorly worded).
+ (bwhen (path (init self))
+ (cgtk-set-active-item-by-path self path)))))
+
+(defmethod cgtk-set-active-item-by-path ((self combo-box) path)
+ "Sets the value of the tree-model type combo-box to the item at the path. Path is a list of integers."
+ (bwhen (tree (tree-model self))
+ (with-tree-iters (it)
+ (when (gtk-tree-model-get-iter-from-string (id tree) it (format nil "~{~A~^:~}" path))
+ (gtk-combo-box-set-active-iter (id self) it)
+ ;(break "in cgtk setting path = ~A" path)
+ (setf (md-value self) (item-from-path (children-fn self) (roots self) path))))))
(def-c-output items ((self combo-box))
(when old-value
@@ -88,11 +97,11 @@
(when new-value
(dolist (item (items self))
(gtk-combo-box-append-text (id self) (funcall (print-fn self) item)))
- (when (init self)
- (let ((index (position (init self) (items self))))
- (when index
- (gtk-combo-box-set-active (id self) index)
- (setf (md-value self) (init self)))))))
+ (bif (index (position (init self) (items self)))
+ (progn (gtk-combo-box-set-active (id self) index)
+ (setf (md-value self) (init self)))
+ (progn (gtk-combo-box-set-active (id self) 0)
+ (setf (md-value self) (car (items self)))))))
;;; ============= Toolbar/Toolbutton ============================
(def-object tooltips ()
@@ -295,3 +304,4 @@
(def-widget tearoff-menu-item (menu-item)
() () ())
+(export '(gtk-combo-box-set-active))
\ No newline at end of file