diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-22 19:39:03 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-22 19:39:03 +0300 |
commit | 0b4814a95d822ff99258f465cb123cd3f821eec2 (patch) | |
tree | 21cc184b2024808a8108272192e9491eeca9b11a /equipment.c | |
parent | f9cb526c969488e6a12d7fe2baf4a71417521460 (diff) | |
download | subsurface-0b4814a95d822ff99258f465cb123cd3f821eec2.tar.gz |
Add a completion for the cylinder type entry combo box
This allows us to start typing the cylinder description and we'll get a
matching list that we can select. This is similar to selecting one from
the model, and works in addition to the explicit selection.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'equipment.c')
-rw-r--r-- | equipment.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/equipment.c b/equipment.c index a360daeb4..d7ccbc3ab 100644 --- a/equipment.c +++ b/equipment.c @@ -466,9 +466,21 @@ static void nitrox_cb(GtkToggleButton *button, gpointer data) gtk_widget_set_sensitive(cylinder->o2, state); } +static gboolean completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct cylinder_widget *cylinder) +{ + const char *desc; + unsigned int ml, mbar; + + gtk_tree_model_get(model, iter, CYL_DESC, &desc, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1); + add_cylinder(cylinder, desc, ml, mbar); + return TRUE; +} + static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model) { GtkWidget *frame, *hbox; + GtkEntry *entry; + GtkEntryCompletion *completion; GtkWidget *widget; /* @@ -486,6 +498,13 @@ static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, G cylinder->description = GTK_COMBO_BOX(widget); g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder); + entry = GTK_ENTRY(GTK_BIN(widget)->child); + completion = gtk_entry_completion_new(); + gtk_entry_completion_set_text_column(completion, 0); + gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model)); + g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder); + gtk_entry_set_completion(entry, completion); + hbox = gtk_hbox_new(FALSE, 3); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0); |