User can now select what kind of file patterns should be used: all - all
files are searched, project - project patterns are used, custom -
manually entered custom patterns are used.

Signed-off-by: Jiří Techet <[email protected]>
---
 src/search.c |  126 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 92 insertions(+), 34 deletions(-)

diff --git a/src/search.c b/src/search.c
index 08c74d4..0754a0e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -73,6 +73,12 @@ enum
 	GEANY_RESPONSE_REPLACE_IN_SEL
 };
 
+enum
+{
+	FILES_MODE_ALL,
+	FILES_MODE_PROJECT,
+	FILES_MODE_CUSTOM
+};
 
 GeanySearchData search_data;
 GeanySearchPrefs search_prefs;
@@ -87,10 +93,10 @@ static struct
 	gboolean fif_recursive;
 	gboolean fif_use_extra_options;
 	gchar *fif_extra_options;
-	gboolean fif_use_files;
+	gint fif_files_mode;
 	gchar *fif_files;
 }
-settings = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL, FALSE, NULL};
+settings = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL, FILES_MODE_ALL, NULL};
 
 static StashGroup *fif_prefs = NULL;
 
@@ -121,9 +127,10 @@ static struct
 	GtkWidget	*files_combo;
 	GtkWidget	*search_combo;
 	GtkWidget	*encoding_combo;
+	GtkWidget	*files_mode_combo;
 	gint		position[2]; /* x, y */
 }
-fif_dlg = {NULL, NULL, NULL, NULL, NULL, {0, 0}};
+fif_dlg = {NULL, NULL, NULL, NULL, NULL, NULL, {0, 0}};
 
 
 static gboolean search_read_io(GIOChannel *source, GIOCondition condition, gpointer data);
@@ -188,14 +195,14 @@ static void init_prefs(void)
 		"fif_invert_results", FALSE, "check_invert");
 	stash_group_add_toggle_button(group, &settings.fif_recursive,
 		"fif_recursive", FALSE, "check_recursive");
+	stash_group_add_combo_box(group, &settings.fif_files_mode,
+		"fif_files_mode", FILES_MODE_ALL, "combo_files_mode");
 	stash_group_add_entry(group, &settings.fif_extra_options,
 		"fif_extra_options", "", "entry_extra");
 	stash_group_add_toggle_button(group, &settings.fif_use_extra_options,
 		"fif_use_extra_options", FALSE, "check_extra");
 	stash_group_add_entry(group, &settings.fif_files,
 		"fif_files", "", "entry_files");
-	stash_group_add_toggle_button(group, &settings.fif_use_files,
-		"fif_use_files", FALSE, "check_files");
 }
 
 
@@ -693,11 +700,55 @@ static void on_widget_toggled_set_sensitive(GtkToggleButton *togglebutton, gpoin
 }
 
 
+static void update_file_patterns(GtkWidget *mode_combo, GtkWidget *fcombo)
+{
+	gint selection;
+	GtkWidget *entry;
+
+	entry = GTK_BIN(fcombo)->child;
+
+	selection = gtk_combo_box_get_active(GTK_COMBO_BOX(mode_combo));
+
+	if (selection == FILES_MODE_ALL)
+	{
+		gtk_entry_set_text(GTK_ENTRY(entry), "");
+		gtk_widget_set_sensitive(fcombo, FALSE);
+	}
+	else if (selection == FILES_MODE_CUSTOM)
+	{
+		gtk_widget_set_sensitive(fcombo, TRUE);
+	}
+	else if (selection == FILES_MODE_PROJECT)
+	{
+		if (app->project && NZV(app->project->file_patterns))
+		{
+			gchar *patterns;
+
+			patterns = g_strjoinv(" ", app->project->file_patterns);
+			gtk_entry_set_text(GTK_ENTRY(entry), patterns);
+			g_free(patterns);
+		}
+		else
+		{
+			gtk_entry_set_text(GTK_ENTRY(entry), "");
+		}
+
+		gtk_widget_set_sensitive(fcombo, FALSE);
+	}
+}
+
+
+static void on_file_mode_changed(GtkWidget *widget, gpointer *user_data)
+{
+	update_file_patterns(widget, GTK_WIDGET(user_data));
+}
+
+
 static void create_fif_dialog(void)
 {
 	GtkWidget *dir_combo, *combo, *fcombo, *e_combo, *entry;
-	GtkWidget *label, *label1, *label2, *checkbox1, *checkbox2, *check_wholeword,
-		*check_recursive, *check_extra, *entry_extra, *check_regexp, *check;
+	GtkWidget *label, *label1, *label2, *label3, *checkbox1, *checkbox2, *check_wholeword,
+		*check_recursive, *check_extra, *entry_extra, *check_regexp, *combo_files_mode;
 	GtkWidget *dbox, *sbox, *lbox, *rbox, *hbox, *vbox, *ebox;
 	GtkSizeGroup *size_group;
 	gchar *encoding_string;
@@ -736,17 +787,22 @@ static void create_fif_dialog(void)
 	size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 	gtk_size_group_add_widget(size_group, label);
 
-	check = gtk_check_button_new_with_mnemonic(_("Fi_les:"));
-	ui_hookup_widget(fif_dlg.dialog, check, "check_files");
-	gtk_button_set_focus_on_click(GTK_BUTTON(check), FALSE);
-	gtk_size_group_add_widget(size_group, check);
-
-	/* tab from search to the files checkbox */
-	g_signal_connect(entry, "key-press-event",
-		G_CALLBACK(on_widget_key_pressed_set_focus), check);
+	label3 = gtk_label_new_with_mnemonic(_("Fi_le patterns:"));
+	gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
+
+	combo_files_mode = gtk_combo_box_new_text();
+	gtk_combo_box_append_text(GTK_COMBO_BOX(combo_files_mode), "all");
+	gtk_combo_box_append_text(GTK_COMBO_BOX(combo_files_mode), "project");
+	gtk_combo_box_append_text(GTK_COMBO_BOX(combo_files_mode), "custom");
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label3), combo_files_mode);
+	ui_widget_set_tooltip_text(combo_files_mode,
+			_("all - search in all files in the directory; "
+			  "project - use file patterns defined in the project settings; "
+			  "custom - specify file patterns manually"));
+	ui_hookup_widget(fif_dlg.dialog, combo_files_mode, "combo_files_mode");
+	fif_dlg.files_mode_combo = combo_files_mode;
 
 	fcombo = gtk_combo_box_entry_new_text();
-	gtk_widget_set_sensitive(fcombo, FALSE);
 	entry = gtk_bin_get_child(GTK_BIN(fcombo));
 	ui_entry_add_clear_icon(GTK_ENTRY(entry));
 	gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
@@ -754,12 +810,13 @@ static void create_fif_dialog(void)
 	ui_hookup_widget(fif_dlg.dialog, entry, "entry_files");
 	fif_dlg.files_combo = fcombo;
 
-	/* enable entry when check is checked */
-	g_signal_connect(check, "toggled",
-		G_CALLBACK(on_widget_toggled_set_sensitive), fcombo);
+	/* update the entry when selection is changed */
+	g_signal_connect(combo_files_mode, "changed",
+		G_CALLBACK(on_file_mode_changed), fcombo);
 
 	hbox = gtk_hbox_new(FALSE, 6);
-	gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), label3, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), combo_files_mode, FALSE, FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(hbox), fcombo, TRUE, TRUE, 0);
 
 	label1 = gtk_label_new_with_mnemonic(_("_Directory:"));
@@ -801,6 +858,7 @@ static void create_fif_dialog(void)
 
 	gtk_size_group_add_widget(size_group, label1);
 	gtk_size_group_add_widget(size_group, label2);
+	gtk_size_group_add_widget(size_group, label3);
 	g_object_unref(G_OBJECT(size_group));	/* auto destroy the size group */
 
 	gtk_box_pack_start(GTK_BOX(vbox), sbox, TRUE, FALSE, 0);
@@ -934,6 +992,8 @@ void search_show_find_in_files_dialog(const gchar *dir)
 		g_free(cur_dir);
 	}
 
+	update_file_patterns(fif_dlg.files_mode_combo, fif_dlg.files_combo);
+
 	/* set the encoding of the current file */
 	if (doc != NULL)
 		enc_idx = encodings_get_idx_from_charset(doc->encoding);
@@ -1296,6 +1356,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
 static GString *get_grep_options(void)
 {
 	GString *gstr = g_string_new("-nHI");	/* line numbers, filenames, ignore binaries */
+	GString *tmp;
 
 	if (settings.fif_invert_results)
 		g_string_append_c(gstr, 'v');
@@ -1321,20 +1382,17 @@ static GString *get_grep_options(void)
 			g_string_append(gstr, settings.fif_extra_options);
 		}
 	}
-	if (settings.fif_use_files)
-	{
-		GString *tmp;
-
-		/* put --include= before each pattern */
-		g_strstrip(settings.fif_files);
-		tmp = g_string_new(settings.fif_files);
-		do {} while (utils_string_replace_all(tmp, "  ", " "));
-		if (tmp->len != 0)
-			g_string_prepend_c(tmp, ' ');
-		utils_string_replace_all(tmp, " ", " --include=");
-		g_string_append(gstr, tmp->str);
-		g_string_free(tmp, TRUE);
-	}
+
+	/* put --include= before each pattern */
+	g_strstrip(settings.fif_files);
+	tmp = g_string_new(settings.fif_files);
+	do {} while (utils_string_replace_all(tmp, "  ", " "));
+	if (tmp->len != 0)
+		g_string_prepend_c(tmp, ' ');
+	utils_string_replace_all(tmp, " ", " --include=");
+	g_string_append(gstr, tmp->str);
+	g_string_free(tmp, TRUE);
+
 	return gstr;
 }
 
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to