SF.net SVN: geany: [647] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Fri Jul 28 18:37:44 UTC 2006
Revision: 647
Author: eht16
Date: 2006-07-28 11:37:32 -0700 (Fri, 28 Jul 2006)
ViewCVS: http://svn.sourceforge.net/geany/?rev=647&view=rev
Log Message:
-----------
Added some options to the Find in files dialog, made search directory editable.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/dialogs.c
trunk/src/search.c
trunk/src/search.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-07-28 12:29:10 UTC (rev 646)
+++ trunk/ChangeLog 2006-07-28 18:37:32 UTC (rev 647)
@@ -1,3 +1,10 @@
+2006-07-28 Enrico Tröger <enrico.troeger at uvena.de>
+
+ * src/search.c, src/callbacks.c, src/dialogs.c:
+ Added some options to the Find in files dialog, made search
+ directory editable.
+
+
2006-07-28 Nick Treleaven <nick.treleaven at btinternet.com>
* src/sciwrappers.h: Set PLAT_GTK before including ScintillaWidget.h.
@@ -18,7 +25,7 @@
styles to keep the syntax highlighting consistent.
* src/main.c: Removed startup warning.
* src/geany.h, src/main.c: Added Select All item to sensitive buttons.
- * src/win32.c, src/dialogs.c, src/callbacks.c:
+ * src/win32.c, src/dialogs.c, src/callbacks.c:
Let the colour chooser pick the colour under the cursor(Win32 code).
Added some sanity checks.
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-07-28 12:29:10 UTC (rev 646)
+++ trunk/src/callbacks.c 2006-07-28 18:37:32 UTC (rev 647)
@@ -2065,26 +2065,35 @@
{
const gchar *search_text =
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data))));
- gchar *utf8_dir = utils_get_current_file_dir();
+ const gchar *utf8_dir =
+ gtk_entry_get_text(GTK_ENTRY(lookup_widget(app->find_in_files_dialog, "entry_dir")));
- if (utf8_dir == NULL)
+ if (utf8_dir == NULL || utils_strcmp(utf8_dir, ""))
msgwin_status_add(_("Invalid directory for find in files."));
else if (search_text && *search_text)
{
gchar *locale_dir;
+ gboolean eregexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
+ lookup_widget(app->find_in_files_dialog, "check_eregexp")));
+ gboolean invert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
+ lookup_widget(app->find_in_files_dialog, "check_invert")));
+ gboolean case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
+ lookup_widget(app->find_in_files_dialog, "check_case")));
+ gint opts = (eregexp ? FIF_USE_EREGEXP : 0) |
+ (invert ? FIF_INVERT_MATCH : 0) |
+ (case_sens ? FIF_CASE_SENSITIVE : 0);
locale_dir = g_locale_from_utf8(utf8_dir, -1, NULL, NULL, NULL);
if (locale_dir == NULL) locale_dir = g_strdup(utf8_dir);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), search_text);
- search_find_in_files(search_text, locale_dir);
+ search_find_in_files(search_text, locale_dir, opts);
g_free(locale_dir);
gtk_widget_hide(app->find_in_files_dialog);
}
else
msgwin_status_add(_("No text to find."));
- g_free(utf8_dir);
}
else
gtk_widget_hide(app->find_in_files_dialog);
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2006-07-28 12:29:10 UTC (rev 646)
+++ trunk/src/dialogs.c 2006-07-28 18:37:32 UTC (rev 647)
@@ -1004,24 +1004,21 @@
void dialogs_show_find_in_files(void)
{
- static GtkWidget *dirlabel = NULL, *combo = NULL;
- GtkWidget *entry; //the child GtkEntry of combo
+ static GtkWidget *combo = NULL;
+ static GtkWidget *entry1;
+ GtkWidget *entry2; // the child GtkEntry of combo
gint idx = document_get_cur_idx();
gchar *sel = NULL;
- gchar *cur_dir, *dirtext;
+ gchar *cur_dir;
if (idx == -1 || ! doc_list[idx].is_valid) return;
cur_dir = utils_get_current_file_dir();
- if (cur_dir == NULL)
- {
- utils_set_statusbar(_("Invalid directory for find in files."), FALSE);
- return;
- }
if (app->find_in_files_dialog == NULL)
{
- GtkWidget *label;
+ GtkWidget *label, *label1, *checkbox1, *checkbox2, *checkbox3, *vbox2, *vbox1;
+ GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
app->find_in_files_dialog = gtk_dialog_new_with_buttons(
_("Find in files"), GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1031,31 +1028,65 @@
gtk_dialog_set_default_response(GTK_DIALOG(app->find_in_files_dialog),
GTK_RESPONSE_ACCEPT);
- dirlabel = gtk_label_new("");
- gtk_misc_set_alignment(GTK_MISC(dirlabel), 0, 0);
+ label1 = gtk_label_new("Directory to be searched:");
+ gtk_misc_set_alignment(GTK_MISC(label1), 0, 0);
+ entry1 = gtk_entry_new();
+ gtk_entry_set_max_length(GTK_ENTRY(entry1), 248);
+ gtk_entry_set_width_chars(GTK_ENTRY(entry1), 50);
+ g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "entry_dir",
+ gtk_widget_ref(entry1), (GDestroyNotify)gtk_widget_unref);
+
+ vbox1 = gtk_vbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(vbox1), label1, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox1), entry1, FALSE, FALSE, 0);
+
label = gtk_label_new(_("Enter the search text here:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
combo = gtk_combo_box_entry_new_text();
- entry = gtk_bin_get_child(GTK_BIN(combo));
- gtk_entry_set_max_length(GTK_ENTRY(entry), 248);
- gtk_entry_set_width_chars(GTK_ENTRY(entry), 50);
- gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
+ entry2 = gtk_bin_get_child(GTK_BIN(combo));
+ gtk_entry_set_max_length(GTK_ENTRY(entry2), 248);
+ gtk_entry_set_width_chars(GTK_ENTRY(entry2), 50);
+ gtk_entry_set_activates_default(GTK_ENTRY(entry2), TRUE);
+ checkbox1 = gtk_check_button_new_with_mnemonic(_("_Case sensitive"));
+ g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_case",
+ gtk_widget_ref(checkbox1), (GDestroyNotify)gtk_widget_unref);
+ gtk_button_set_focus_on_click(GTK_BUTTON(checkbox1), FALSE);
+
+ checkbox2 = gtk_check_button_new_with_mnemonic(_("Invert search results"));
+ g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_invert",
+ gtk_widget_ref(checkbox2), (GDestroyNotify)gtk_widget_unref);
+ gtk_button_set_focus_on_click(GTK_BUTTON(checkbox2), FALSE);
+ gtk_tooltips_set_tip(tooltips, checkbox2,
+ _("Invert the sense of matching, to select non-matching lines."), NULL);
+
+ checkbox3 = gtk_check_button_new_with_mnemonic(_("_Use extended regular expressions"));
+ g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_eregexp",
+ gtk_widget_ref(checkbox3), (GDestroyNotify)gtk_widget_unref);
+ gtk_button_set_focus_on_click(GTK_BUTTON(checkbox3), FALSE);
+ gtk_tooltips_set_tip(tooltips, checkbox3,
+ _("See grep's manual page for more information."), NULL);
+
+ vbox2 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(vbox2), checkbox1);
+ gtk_container_add(GTK_CONTAINER(vbox2), checkbox2);
+ gtk_container_add(GTK_CONTAINER(vbox2), checkbox3);
+
g_signal_connect((gpointer) app->find_in_files_dialog, "response",
G_CALLBACK(on_find_in_files_dialog_response), combo);
g_signal_connect((gpointer) app->find_in_files_dialog, "delete_event",
G_CALLBACK(gtk_widget_hide), NULL);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox),
- dirlabel, TRUE, TRUE, 6);
+ vbox1, TRUE, TRUE, 6);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox),
label, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox),
combo, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox),
- gtk_label_new(""), TRUE, TRUE, 0);
+ vbox2, TRUE, TRUE, 6);
gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), 6);
@@ -1068,16 +1099,19 @@
sci_get_selected_text(doc_list[idx].sci, sel);
}
- entry = GTK_BIN(combo)->child;
- if (sel) gtk_entry_set_text(GTK_ENTRY(entry), sel);
+ entry2 = GTK_BIN(combo)->child;
+ if (sel) gtk_entry_set_text(GTK_ENTRY(entry2), sel);
g_free(sel);
- gtk_widget_grab_focus(entry);
- dirtext = g_strdup_printf(_("Current directory: %s"), cur_dir);
- gtk_label_set_text(GTK_LABEL(dirlabel), dirtext);
+ if (cur_dir) gtk_entry_set_text(GTK_ENTRY(entry1), cur_dir);
g_free(cur_dir);
- g_free(dirtext);
+ // put the focus to the directory entry if it is empty
+ if (utils_strcmp(gtk_entry_get_text(GTK_ENTRY(entry1)), ""))
+ gtk_widget_grab_focus(entry1);
+ else
+ gtk_widget_grab_focus(entry2);
+
gtk_widget_show(app->find_in_files_dialog);
}
Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c 2006-07-28 12:29:10 UTC (rev 646)
+++ trunk/src/search.c 2006-07-28 18:37:32 UTC (rev 647)
@@ -45,27 +45,57 @@
static GSList *search_get_file_list(const gchar *path, gint *length);
-gboolean search_find_in_files(const gchar *search_text, const gchar *dir)
+gboolean search_find_in_files(const gchar *search_text, const gchar *dir, fif_options opts)
{
- const gchar *argv_prefix[] = {app->tools_grep_cmd, "-nHI", "--", search_text, NULL};
+ gchar **argv_prefix;
+ gchar **grep_cmd_argv;
gchar **argv;
+ gchar grep_opts[] = "-nHI ";
GPid child_pid;
- gint stdout_fd, stdin_fd;
+ gint stdout_fd, stdin_fd, grep_cmd_argv_len, i, grep_opts_len = 4;
GError *error = NULL;
gboolean ret = FALSE;
if (! search_text || ! *search_text || ! dir) return TRUE;
- if (! g_file_test(app->tools_grep_cmd, G_FILE_TEST_IS_EXECUTABLE))
+
+ // first process the grep command (need to split it in a argv because it can be "grep -I")
+ grep_cmd_argv = g_strsplit(app->tools_grep_cmd, " ", -1);
+ grep_cmd_argv_len = g_strv_length(grep_cmd_argv);
+
+ if (! g_file_test(grep_cmd_argv[0], G_FILE_TEST_IS_EXECUTABLE))
{
msgwin_status_add(_("Cannot execute grep tool '%s';"
- " check the path setting in Preferences."), argv_prefix[0]);
+ " check the path setting in Preferences."), app->tools_grep_cmd);
return FALSE;
}
gtk_list_store_clear(msgwindow.store_msg);
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_MESSAGE);
- argv = search_get_argv(argv_prefix, dir);
+ if (! (opts & FIF_CASE_SENSITIVE))
+ grep_opts[grep_opts_len++] = 'i';
+ if (opts & FIF_USE_EREGEXP)
+ grep_opts[grep_opts_len++] = 'E';
+ if (opts & FIF_INVERT_MATCH)
+ grep_opts[grep_opts_len++] = 'v';
+ grep_opts[grep_opts_len] = '\0';
+
+ // set grep command and options
+ argv_prefix = g_new0(gchar*, grep_cmd_argv_len + 4);
+ for (i = 0; i < grep_cmd_argv_len; i++)
+ {
+ argv_prefix[i] = g_strdup(grep_cmd_argv[i]);
+ }
+ argv_prefix[grep_cmd_argv_len ] = g_strdup(grep_opts);
+ argv_prefix[grep_cmd_argv_len + 1] = g_strdup("--");
+ argv_prefix[grep_cmd_argv_len + 2] = g_strdup(search_text);
+ argv_prefix[grep_cmd_argv_len + 3] = NULL;
+ g_strfreev(grep_cmd_argv);
+
+ // finally add the arguments(files to be searched)
+ argv = search_get_argv((const gchar**)argv_prefix, dir);
+ g_strfreev(argv_prefix);
+ //geany_debug(g_strjoinv(" ", argv));
if (argv == NULL) return FALSE;
if (! g_spawn_async_with_pipes(dir, (gchar**)argv, NULL,
@@ -80,9 +110,9 @@
}
else
{
- g_child_watch_add(child_pid, search_close_pid, NULL);
utils_set_up_io_channel(stdout_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
search_read_io, NULL);
+ g_child_watch_add(child_pid, search_close_pid, NULL);
ret = TRUE;
}
g_strfreev(argv);
Modified: trunk/src/search.h
===================================================================
--- trunk/src/search.h 2006-07-28 12:29:10 UTC (rev 646)
+++ trunk/src/search.h 2006-07-28 18:37:32 UTC (rev 647)
@@ -21,5 +21,13 @@
*/
-gboolean search_find_in_files(const gchar *search_text, const gchar *dir);
+typedef enum
+{
+ FIF_CASE_SENSITIVE = 1 << 0,
+ FIF_USE_EREGEXP = 1 << 1,
+ FIF_INVERT_MATCH = 1 << 2
+} fif_options;
+
+gboolean search_find_in_files(const gchar *search_text, const gchar *dir, fif_options opts);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list