summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-01-27 16:40:01 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-28 13:17:44 -0800
commit77ece3fccb1a08ef8eea10a9f548bc6a4a3c889e (patch)
tree71dd23e661b88cf690779193a8579a3c6aaa944b /info.c
parent32e497b5744ef690e91b4a9f22a63109dde4c7df (diff)
downloadsubsurface-77ece3fccb1a08ef8eea10a9f548bc6a4a3c889e.tar.gz
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>
Diffstat (limited to 'info.c')
-rw-r--r--info.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/info.c b/info.c
index 4104b5af5..8caf726d9 100644
--- a/info.c
+++ b/info.c
@@ -61,12 +61,11 @@ static const char *skip_space(const char *str)
* The "master" string is the string of the current dive - we only consider it
* changed if the old string is either empty, or matches that master string.
*/
-static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, const char *master)
+static char *get_combo_box_entry_text(GtkComboBox *combo_box, char **textp, const char *master)
{
char *old = *textp;
const char *old_text;
const gchar *new;
- GtkEntry *entry;
old_text = skip_space(old);
master = skip_space(master);
@@ -81,8 +80,7 @@ static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp,
if (strcmp(master, old_text))
return NULL;
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
- new = gtk_entry_get_text(entry);
+ new = get_active_text(combo_box);
while (isspace(*new))
new++;
/* If the master string didn't change, don't change other dives either! */
@@ -202,7 +200,7 @@ static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
edit_multi_dive_info(NULL);
}
-static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
+static void add_menu_item(GtkMenuShell *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
{
GtkWidget *item;
if (icon) {
@@ -215,10 +213,10 @@ static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, vo
}
g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
gtk_widget_show(item); /* Yes, really */
- gtk_menu_prepend(menu, item);
+ gtk_menu_shell_prepend(menu, item);
}
-static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
+static void populate_popup_cb(GtkTextView *entry, GtkMenuShell *menu, gpointer user_data)
{
if (amount_selected)
add_menu_item(menu, _("Edit"), GTK_STOCK_EDIT, info_menu_edit_cb);
@@ -251,32 +249,20 @@ static GtkEntry *single_text_entry(GtkWidget *box, const char *label, const char
return entry;
}
-static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
+static GtkComboBox *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
{
- GtkEntry *entry;
GtkWidget *combo_box;
GtkWidget *frame = gtk_frame_new(label);
- GtkEntryCompletion *completion;
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
- combo_box = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(completions), 0);
+ combo_box = combo_box_with_model_and_entry(completions);
gtk_container_add(GTK_CONTAINER(frame), combo_box);
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
if (text && *text)
- gtk_entry_set_text(entry, text);
-
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(completions));
- 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(entry, completion);
- g_object_unref(completion);
+ set_active_text(GTK_COMBO_BOX(combo_box), text);
- return GTK_COMBO_BOX_ENTRY(combo_box);
+ return GTK_COMBO_BOX(combo_box);
}
enum writable {
@@ -518,7 +504,7 @@ static gboolean gps_changed(struct dive *dive, struct dive *master, const char *
}
struct dive_info {
- GtkComboBoxEntry *location, *divemaster, *buddy, *rating, *suit, *viz;
+ GtkComboBox *location, *divemaster, *buddy, *rating, *suit, *viz;
GtkEntry *airtemp, *gps;
GtkTextView *notes;
};