Date: Fri, 20 Aug 2004 14:53:24 +0200 (CEST) Message-Id: <20040820.145324.41627916.andrieu at ijm.jussieu.fr> To: mike at halcrow.us Cc: lablgtk at kaba.or.jp Subject: Re: Combo entry_completion? From: Olivier Andrieu In-Reply-To: <20040819152938.GA6894 at halcrow.us> References: <20040819152938.GA6894 at halcrow.us> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Michael Halcrow [Thu, 19 Aug 2004]: > I am just learning Objective Caml, so if you feel inclined to > critique my ocaml coding style, please do so. > > I am working on a project where I view records in a database. I would > like the user to be able to search the contents of the data set based > on a person's name and display the record. Here is what I have so far: > > http://cvs.sourceforge.net/viewcvs.py/ldsdps/src_ocaml/ldsdps_stage.ml?rev=1.15&view=auto > > Basically, I want this behavior: > > As the user types into the entry widget of the combo widget, the first > element in the combo list for which the text typed so far matches is > auto-completed and highlighted, so that the next character typed > replaces the auto-completed remainder and re-does the auto completion. > Let's do an example: > > Combo list contents: [ "abc"; "123"; "abcdef"; "abcxyz"; "abcxyzw" ] > Entry widget contents: "" > > User enters the entry widget and types "a". "abc" gets automatically > put into the widget. The cursor is after the "a" and before the "b", > and "bc" is highlighted. User types "b". Contents are still "abc", > with the cursor after the "b" and before the "c", with "c" > highlighted. User types "c". Contents are "abc", with the cursor > after the "c" and nothing highlighted. User types "x". Now the > contents are "abcxyz", with the cursor after the "x" and before the > "y", with "yz" highlighted. User hits "enter", and the search is made > for the record with "abcxyz" as the key, etc., etc. > > Alternatively, I would like the combo box to be dropped down for the > entire process, and the contents of the entry widget matched against > the list, with the closest matching element highlighted. As it > stands, I am hooking the activate signal, which is sent when the user > hits ``enter'', but that also drops down the combo box, which I don't > really want at that point... > > I tried referencing entry_completion in my code, but I got that > run-time error that one gets when linking against the wrong version > of gtk (although I checked carefully, and I think I am linking > against gtk 2.4). In any case, I'm not sure how to use > entry_completion to get this functionality. If you get a runtime error (Failure "unsupported in GTK+ < ...") this means that lablGTK was not compiled against 2.4 but against a previous version. If lablGTK was compiled with 2.4 but your program is linked with a previous version, you will get a linker error. To use completion with a combo box entry, it goes somehow like this: ,---- | let make_combo_box_entry_with_completion packing strings = | let (combo, (model, column)) = GEdit.combo_box_entry_text ~strings ~packing () in | let entry = combo#entry in | let completion = GEdit.entry_completion ~model ~entry () in | completion#set_text_column column ; | (combo, entry, completion) `---- -- Olivier