mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Clean up gtk combo box handling
This cleans up our handling of combo boxes and all the duplicated completion logic, and simplifies the code. In particular, we get rid of the deprecated GtkComboBoxEntry. While it made some things easier, it made other things harder. Just using GtkComboBox and setting that up correctly ends up being simpler, and also makes the logic work with gtk-3. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
32e497b574
commit
77ece3fccb
6 changed files with 84 additions and 99 deletions
36
gtk-gui.c
36
gtk-gui.c
|
@ -415,6 +415,42 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char
|
|||
return col;
|
||||
}
|
||||
|
||||
/* Helper functions for gtk combo boxes */
|
||||
GtkEntry *get_entry(GtkComboBox *combo_box)
|
||||
{
|
||||
return GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
|
||||
}
|
||||
|
||||
const char *get_active_text(GtkComboBox *combo_box)
|
||||
{
|
||||
return gtk_entry_get_text(get_entry(combo_box));
|
||||
}
|
||||
|
||||
void set_active_text(GtkComboBox *combo_box, const char *text)
|
||||
{
|
||||
gtk_entry_set_text(get_entry(combo_box), text);
|
||||
}
|
||||
|
||||
GtkWidget *combo_box_with_model_and_entry(GtkListStore *model)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
GtkEntryCompletion *completion;
|
||||
|
||||
widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
|
||||
gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget), 0);
|
||||
|
||||
completion = gtk_entry_completion_new();
|
||||
gtk_entry_completion_set_text_column(completion, 0);
|
||||
gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
|
||||
gtk_entry_completion_set_inline_completion(completion, TRUE);
|
||||
gtk_entry_completion_set_inline_selection(completion, TRUE);
|
||||
gtk_entry_completion_set_popup_single_match(completion, FALSE);
|
||||
gtk_entry_set_completion(get_entry(GTK_COMBO_BOX(widget)), completion);
|
||||
g_object_unref(completion);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
static void create_radio(GtkWidget *vbox, const char *w_name, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue