From 9975737eff469579eebf67ced47e39a70f66499a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 16 Nov 2008 17:53:55 +0000 Subject: [PATCH] Add and use ui_combo_box_prepend_text_once() to add project's base_path to the Find in Files dialog even if another project was opened. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3237 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ src/search.c | 6 ++---- src/ui_utils.c | 27 +++++++++++++++++++++++++++ src/ui_utils.h | 2 ++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4fff86a7..ec86dff6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ when a Find in Files search fails. Add the project's base_path to the directory list in the Find in Files dialog if a project is open. + * src/search.c, src/ui_utils.c, src/ui_utils.h: + Add and use ui_combo_box_prepend_text_once() to add project's + base_path to the Find in Files dialog even if another project was + opened. 2008-11-15 Enrico Tröger diff --git a/src/search.c b/src/search.c index 76cb7997..d9227271 100644 --- a/src/search.c +++ b/src/search.c @@ -744,7 +744,6 @@ void search_show_find_in_files_dialog(const gchar *dir) gchar *sel = NULL; gchar *cur_dir = NULL; GeanyEncodingIndex enc_idx = GEANY_ENCODING_UTF_8; - static gboolean project_basepath_added = FALSE; if (widgets.find_in_files_dialog == NULL) { @@ -762,11 +761,10 @@ void search_show_find_in_files_dialog(const gchar *dir) /* add project's base path directory to the dir list, we do this here once * (in create_fif_dialog() it would fail if a project is opened after dialog creation) */ - if (app->project != NULL && NZV(app->project->base_path) && ! project_basepath_added) + if (app->project != NULL && NZV(app->project->base_path)) { - gtk_combo_box_prepend_text(GTK_COMBO_BOX(find_in_files.dir_combo), + ui_combo_box_prepend_text_once(GTK_COMBO_BOX(find_in_files.dir_combo), app->project->base_path); - project_basepath_added = TRUE; } entry = GTK_BIN(find_in_files.dir_combo)->child; diff --git a/src/ui_utils.c b/src/ui_utils.c index f49ae83f..684661ec 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -1259,6 +1259,33 @@ void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text) } +/* Same as gtk_combo_box_prepend_text(), except that text is only prepended if it not already + * exists in the combo's model. */ +void ui_combo_box_prepend_text_once(GtkComboBox *combo, const gchar *text) +{ + 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) + return; /* don't prepend duplicate */ + + gtk_combo_box_prepend_text(combo, text); +} + + /* Changes the color of the notebook tab text and open files items according to * document status. */ void ui_update_tab_status(GeanyDocument *doc) diff --git a/src/ui_utils.h b/src/ui_utils.h index 7f0972c0..edcf77a6 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -154,6 +154,8 @@ void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy); void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text); +void ui_combo_box_prepend_text_once(GtkComboBox *combo, const gchar *text); + GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry); void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,