app-chooser-combobox: make refresh properly work with custom items

The refresh implementation leaves the custom items in place, and just
refreshes the recommended applications.
This commit is contained in:
Cosimo Cecchi 2010-11-24 19:08:17 +01:00
parent 2a95707b4c
commit 183d75b812
3 changed files with 46 additions and 6 deletions

View File

@ -101,15 +101,35 @@ row_separator_func (GtkTreeModel *model,
return separator;
}
static void
get_first_iter (GtkListStore *store,
GtkTreeIter *iter)
{
GtkTreeIter iter2;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), iter))
{
/* the model is empty, append */
gtk_list_store_append (store, iter);
}
else
{
gtk_list_store_insert_before (store, &iter2, iter);
*iter = iter2;
}
}
static void
gtk_app_chooser_combo_box_populate (GtkAppChooserComboBox *self)
{
GList *recommended_apps = NULL, *l;
GAppInfo *app;
GtkTreeIter iter;
GtkTreeIter iter, iter2;
GIcon *icon;
gboolean first;
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
first = TRUE;
for (l = recommended_apps; l != NULL; l = l->next)
{
@ -122,7 +142,17 @@ gtk_app_chooser_combo_box_populate (GtkAppChooserComboBox *self)
else
g_object_ref (icon);
gtk_list_store_append (self->priv->store, &iter);
if (first)
{
get_first_iter (self->priv->store, &iter);
first = FALSE;
}
else
{
gtk_list_store_insert_after (self->priv->store, &iter2, &iter);
iter = iter2;
}
gtk_list_store_set (self->priv->store, &iter,
COLUMN_APP_INFO, app,
COLUMN_NAME, g_app_info_get_display_name (app),
@ -177,7 +207,7 @@ gtk_app_chooser_combo_box_remove_non_custom (GtkAppChooserComboBox *self)
GtkTreeIter iter;
gboolean custom, res;
model = GTK_TREE_MODEL (self->priv->store);
model = GTK_TREE_MODEL (self->priv->store);
if (!gtk_tree_model_get_iter_first (model, &iter))
return;
@ -187,9 +217,9 @@ gtk_app_chooser_combo_box_remove_non_custom (GtkAppChooserComboBox *self)
COLUMN_CUSTOM, &custom,
-1);
if (custom)
res = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
else
res = gtk_tree_model_iter_next (model, &iter);
else
res = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
} while (res);
}
@ -201,7 +231,8 @@ gtk_app_chooser_combo_box_changed (GtkComboBox *object)
gboolean custom, separator;
CustomAppComboData *custom_data = NULL;
gtk_combo_box_get_active_iter (object, &iter);
if (!gtk_combo_box_get_active_iter (object, &iter))
return;
gtk_tree_model_get (GTK_TREE_MODEL (self->priv->store), &iter,
COLUMN_CUSTOM, &custom,

View File

@ -67,6 +67,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testoffscreenwindow \
testorientable \
testappchooser \
testappchoosercombo \
testprint \
testrecentchooser \
testrecentchoosermenu \
@ -155,6 +156,7 @@ testnouiprint_DEPENDENCIES = $(TEST_DEPS)
testoffscreen_DEPENDENCIES = $(TEST_DEPS)
testoffscreenwindow_DEPENDENCIES = $(TEST_DEPS)
testappchooser_DEPENDENCIES = $(TEST_DEPS)
testappchoosercombo_DEPENDENCIES = $(TEST_DEPS)
testorientable_DEPENDENCIES = $(TEST_DEPS)
testprint_DEPENDENCIES = $(TEST_DEPS)
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
@ -228,6 +230,7 @@ testnouiprint_LDADD = $(LDADDS)
testoffscreen_LDADD = $(LDADDS)
testoffscreenwindow_LDADD = $(LDADDS)
testappchooser_LDADD = $(LDADDS)
testappchoosercombo_LDADD = $(LDADDS)
testorientable_LDADD = $(LDADDS)
testprint_LDADD = $(LDADDS)
testrecentchooser_LDADD = $(LDADDS)
@ -381,6 +384,9 @@ testoffscreenwindow_SOURCES = \
testappchooser_SOURCES = \
testappchooser.c
testappchoosercombo_SOURCES = \
testappchoosercombo.c
testwindows_SOURCES = \
testwindows.c

View File

@ -93,6 +93,9 @@ main (int argc,
special_item_activated_cb,
NULL);
/* test refresh on a combo */
gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
gtk_widget_show_all (toplevel);
g_signal_connect (toplevel, "delete-event",