Date: Fri, 04 Mar 2005 10:25:39 +0100 (CET) Message-Id: <20050304.102539.78723449.andrieu at ijm.jussieu.fr> To: rich at annexia.org Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: How to use file_chooser_dialog From: Olivier Andrieu In-Reply-To: <20050304000458.GA28358 at furbychan.cocan.org> References: <20050304000458.GA28358 at furbychan.cocan.org> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Richard Jones [Fri, 4 Mar 2005]: > I can't work this one out. > > So far I have this, but the Cancel button acts as an accept button. > > let callback () = > let dialog = GWindow.file_chooser_dialog ~action:`OPEN () in > dialog#add_select_button_stock `CANCEL `CANCEL; > dialog#add_select_button_stock `OPEN `ACCEPT; > if dialog#run () = `ACCEPT then ( > let filename = dialog#filename in > Option.may > (fun filename -> prerr_endline ("filename = " ^ filename)) filename; > ); > dialog#destroy () > in > open_item#connect#activate ~callback; You must use the #add_select_button_stock method only once; use #add_button_stock (from the dialog class) for your Cancel button. [The reason is that GTK+ needs integer ids assigned to buttons. LablGTK automatically assigns ids starting from 0 but the file chooser needs a special value (-3) for the Accept button. Hence the #add_select_button method. If you use it multiple times, the same id is assigned to several buttons and it stops working.] -- Olivier