Revision: 5044 http://geany.svn.sourceforge.net/geany/?rev=5044&view=rev Author: ntrel Date: 2010-06-17 17:28:28 +0000 (Thu, 17 Jun 2010)
Log Message: ----------- Remove any duplicate on adding to combo box histories.
Modified Paths: -------------- trunk/ChangeLog trunk/src/ui_utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-06-17 14:58:57 UTC (rev 5043) +++ trunk/ChangeLog 2010-06-17 17:28:28 UTC (rev 5044) @@ -9,6 +9,8 @@ * src/ui_utils.c: Display 'new instance' on title bar (patch by Eugene Arshinov, thanks). + * src/ui_utils.c: + Remove any duplicate on adding to combo box histories.
2010-06-16 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2010-06-17 14:58:57 UTC (rev 5043) +++ trunk/src/ui_utils.c 2010-06-17 17:28:28 UTC (rev 5044) @@ -1384,26 +1384,44 @@ }
-/* Prepends the active text to the drop down list, unless the first element in - * the list is identical, ensuring there are <= history_len elements. */ +static gboolean tree_model_find_text(GtkTreeModel *model, + GtkTreeIter *iter, gint column, const gchar *text) +{ + gchar *combo_text; + gboolean found = FALSE; + + if (gtk_tree_model_get_iter_first(model, iter)) + { + do + { + gtk_tree_model_get(model, iter, 0, &combo_text, -1); + found = utils_str_equal(combo_text, text); + g_free(combo_text); + + if (found) + return TRUE; + } + while (gtk_tree_model_iter_next(model, iter)); + } + return FALSE; +} + + +/* Prepends the active text to the drop down list, removing a duplicate element in + * the list if found. Ensures there are <= history_len elements. */ void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text) { - const gint history_len = 30; + const gint history_len = 10; GtkTreeModel *model; GtkTreeIter iter; - gchar *combo_text; - gboolean equal = FALSE; GtkTreePath *path;
model = gtk_combo_box_get_model(combo); - if (gtk_tree_model_get_iter_first(model, &iter)) + + if (tree_model_find_text(model, &iter, 0, text)) { - gtk_tree_model_get(model, &iter, 0, &combo_text, -1); - equal = utils_str_equal(combo_text, text); - g_free(combo_text); + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); } - if (equal) return; /* don't prepend duplicate */ - gtk_combo_box_prepend_text(combo, text);
/* limit history */ @@ -1422,21 +1440,9 @@ { GtkTreeModel *model; GtkTreeIter iter; - gchar *combo_text; - gboolean found = FALSE;
model = gtk_combo_box_get_model(combo); - if (gtk_tree_model_get_iter_first(model, &iter)) - { - do - { - gtk_tree_model_get(model, &iter, 0, &combo_text, -1); - found = utils_str_equal(combo_text, text); - g_free(combo_text); - } - while (!found && gtk_tree_model_iter_next(model, &iter)); - } - if (found) + if (!tree_model_find_text(model, &iter, 0, text)) return; /* don't prepend duplicate */
gtk_combo_box_prepend_text(combo, text);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.