Add 'Extra options' field and checkbox to FIF dialog.
Don't allow arguments appended to Grep command. Prevent warning when using relative paths with open directory button. Refactor FIF options code into get_grep_options(), remove fif_options, fif_match_type. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1435 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
b8d7e96375
commit
cfb073a2bf
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
* src/search.c:
|
* src/search.c:
|
||||||
Add recursive option to Find in Files dialog.
|
Add recursive option to Find in Files dialog.
|
||||||
|
* src/search.c:
|
||||||
|
Add 'Extra options' field and checkbox to FIF dialog.
|
||||||
|
Don't allow arguments appended to Grep command.
|
||||||
|
Prevent warning when using relative paths with open directory button.
|
||||||
|
Refactor FIF options code into get_grep_options(), remove
|
||||||
|
fif_options, fif_match_type.
|
||||||
|
|
||||||
|
|
||||||
2007-03-31 Nick Treleaven <nick.treleaven@btinternet.com>
|
2007-03-31 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||||
|
183
src/search.c
183
src/search.c
@ -61,22 +61,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
FIF_CASE_SENSITIVE = 1 << 0,
|
|
||||||
FIF_WHOLE_WORD = 1 << 1,
|
|
||||||
FIF_INVERT_MATCH = 1 << 2,
|
|
||||||
FIF_RECURSIVE = 1 << 3
|
|
||||||
} fif_options;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
FIF_FGREP,
|
|
||||||
FIF_GREP,
|
|
||||||
FIF_EGREP
|
|
||||||
} fif_match_type;
|
|
||||||
|
|
||||||
|
|
||||||
GeanySearchData search_data;
|
GeanySearchData search_data;
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
@ -120,8 +104,7 @@ static void
|
|||||||
on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data);
|
on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
search_find_in_files(const gchar *search_text, const gchar *dir, fif_match_type regex_opt,
|
search_find_in_files(const gchar *search_text, const gchar *dir, const gchar *opts);
|
||||||
fif_options opts);
|
|
||||||
|
|
||||||
static void on_open_dir_dialog_clicked(GtkButton *button, gpointer user_data);
|
static void on_open_dir_dialog_clicked(GtkButton *button, gpointer user_data);
|
||||||
|
|
||||||
@ -545,6 +528,15 @@ void search_show_replace_dialog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean on_entry_extra_key_press(GtkWidget *widget, GdkEventKey *event,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
// enable extra option checkbutton when extra entry is edited
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(user_data), TRUE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void search_show_find_in_files_dialog()
|
void search_show_find_in_files_dialog()
|
||||||
{
|
{
|
||||||
static GtkWidget *combo = NULL;
|
static GtkWidget *combo = NULL;
|
||||||
@ -560,7 +552,7 @@ void search_show_find_in_files_dialog()
|
|||||||
if (widgets.find_in_files_dialog == NULL)
|
if (widgets.find_in_files_dialog == NULL)
|
||||||
{
|
{
|
||||||
GtkWidget *label, *label1, *checkbox1, *checkbox2, *check_wholeword,
|
GtkWidget *label, *label1, *checkbox1, *checkbox2, *check_wholeword,
|
||||||
*check_recursive;
|
*check_recursive, *check_extra, *entry_extra;
|
||||||
GtkWidget *dbox, *sbox, *cbox, *rbox, *rbtn, *hbox, *vbox, *box;
|
GtkWidget *dbox, *sbox, *cbox, *rbox, *rbtn, *hbox, *vbox, *box;
|
||||||
GtkSizeGroup *size_group;
|
GtkSizeGroup *size_group;
|
||||||
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
||||||
@ -680,6 +672,22 @@ void search_show_find_in_files_dialog()
|
|||||||
gtk_box_pack_start(GTK_BOX(vbox), sbox, TRUE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(vbox), sbox, TRUE, FALSE, 0);
|
||||||
gtk_container_add(GTK_CONTAINER(vbox), hbox);
|
gtk_container_add(GTK_CONTAINER(vbox), hbox);
|
||||||
|
|
||||||
|
check_extra = gtk_check_button_new_with_mnemonic(_("E_xtra options:"));
|
||||||
|
g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "check_extra",
|
||||||
|
gtk_widget_ref(check_extra), (GDestroyNotify)gtk_widget_unref);
|
||||||
|
gtk_button_set_focus_on_click(GTK_BUTTON(check_extra), FALSE);
|
||||||
|
|
||||||
|
entry_extra = gtk_entry_new();
|
||||||
|
g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "entry_extra",
|
||||||
|
gtk_widget_ref(entry_extra), (GDestroyNotify)gtk_widget_unref);
|
||||||
|
g_signal_connect(G_OBJECT(entry_extra), "key-press-event",
|
||||||
|
G_CALLBACK(on_entry_extra_key_press), check_extra);
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new(FALSE, 6);
|
||||||
|
gtk_box_pack_start(GTK_BOX(hbox), check_extra, FALSE, FALSE, 0);
|
||||||
|
gtk_box_pack_start(GTK_BOX(hbox), entry_extra, TRUE, TRUE, 0);
|
||||||
|
gtk_container_add(GTK_CONTAINER(vbox), hbox);
|
||||||
|
|
||||||
g_signal_connect((gpointer) dir_combo, "key-press-event",
|
g_signal_connect((gpointer) dir_combo, "key-press-event",
|
||||||
G_CALLBACK(on_widget_key_pressed_set_focus), combo);
|
G_CALLBACK(on_widget_key_pressed_set_focus), combo);
|
||||||
g_signal_connect((gpointer) widgets.find_in_files_dialog, "response",
|
g_signal_connect((gpointer) widgets.find_in_files_dialog, "response",
|
||||||
@ -733,7 +741,7 @@ static void on_open_dir_dialog_clicked(GtkButton *button, gpointer user_data)
|
|||||||
|
|
||||||
entry_text = gtk_entry_get_text(GTK_ENTRY(entry_dir));
|
entry_text = gtk_entry_get_text(GTK_ENTRY(entry_dir));
|
||||||
dir_locale = utils_get_locale_from_utf8(entry_text);
|
dir_locale = utils_get_locale_from_utf8(entry_text);
|
||||||
if (g_file_test(dir_locale, G_FILE_TEST_IS_DIR))
|
if (g_path_is_absolute(dir_locale) && g_file_test(dir_locale, G_FILE_TEST_IS_DIR))
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir_locale);
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir_locale);
|
||||||
g_free(dir_locale);
|
g_free(dir_locale);
|
||||||
|
|
||||||
@ -1037,6 +1045,55 @@ on_widget_key_pressed_set_focus(GtkWidget *widget, GdkEventKey *event, gpointer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static GString *get_grep_options()
|
||||||
|
{
|
||||||
|
gboolean fgrep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "radio_fgrep")));
|
||||||
|
gboolean grep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "radio_grep")));
|
||||||
|
gboolean invert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "check_invert")));
|
||||||
|
gboolean case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "check_case")));
|
||||||
|
gboolean whole_word = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "check_wholeword")));
|
||||||
|
gboolean recursive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "check_recursive")));
|
||||||
|
gboolean extra = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "check_extra")));
|
||||||
|
GString *gstr = g_string_new("-nHI"); // line numbers, filenames, ignore binaries
|
||||||
|
|
||||||
|
if (invert)
|
||||||
|
g_string_append_c(gstr, 'v');
|
||||||
|
if (! case_sens)
|
||||||
|
g_string_append_c(gstr, 'i');
|
||||||
|
if (whole_word)
|
||||||
|
g_string_append_c(gstr, 'w');
|
||||||
|
if (recursive)
|
||||||
|
g_string_append_c(gstr, 'r');
|
||||||
|
|
||||||
|
if (fgrep)
|
||||||
|
g_string_append_c(gstr, 'F');
|
||||||
|
else if (! grep)
|
||||||
|
g_string_append_c(gstr, 'E');
|
||||||
|
|
||||||
|
if (extra)
|
||||||
|
{
|
||||||
|
gchar *text = g_strdup(gtk_entry_get_text(GTK_ENTRY(
|
||||||
|
lookup_widget(widgets.find_in_files_dialog, "entry_extra"))));
|
||||||
|
|
||||||
|
text = g_strstrip(text);
|
||||||
|
if (*text != 0)
|
||||||
|
{
|
||||||
|
g_string_append_c(gstr, ' ');
|
||||||
|
g_string_append(gstr, text);
|
||||||
|
}
|
||||||
|
g_free(text);
|
||||||
|
}
|
||||||
|
return gstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||||
{
|
{
|
||||||
@ -1054,33 +1111,18 @@ on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user
|
|||||||
else if (search_text && *search_text)
|
else if (search_text && *search_text)
|
||||||
{
|
{
|
||||||
gchar *locale_dir;
|
gchar *locale_dir;
|
||||||
gboolean invert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
GString *opts = get_grep_options();
|
||||||
lookup_widget(widgets.find_in_files_dialog, "check_invert")));
|
|
||||||
gboolean case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
||||||
lookup_widget(widgets.find_in_files_dialog, "check_case")));
|
|
||||||
gboolean whole_word = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
||||||
lookup_widget(widgets.find_in_files_dialog, "check_wholeword")));
|
|
||||||
gboolean recursive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
||||||
lookup_widget(widgets.find_in_files_dialog, "check_recursive")));
|
|
||||||
gint opts = (invert ? FIF_INVERT_MATCH : 0) |
|
|
||||||
(case_sens ? FIF_CASE_SENSITIVE : 0) |
|
|
||||||
(whole_word ? FIF_WHOLE_WORD : 0) |
|
|
||||||
(recursive ? FIF_RECURSIVE: 0);
|
|
||||||
gboolean fgrep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
||||||
lookup_widget(widgets.find_in_files_dialog, "radio_fgrep")));
|
|
||||||
gboolean grep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
||||||
lookup_widget(widgets.find_in_files_dialog, "radio_grep")));
|
|
||||||
gint regex_opt = fgrep ? FIF_FGREP : (grep ? FIF_GREP : FIF_EGREP);
|
|
||||||
|
|
||||||
locale_dir = utils_get_locale_from_utf8(utf8_dir);
|
locale_dir = utils_get_locale_from_utf8(utf8_dir);
|
||||||
|
|
||||||
if (search_find_in_files(search_text, locale_dir, regex_opt, opts))
|
if (search_find_in_files(search_text, locale_dir, opts->str))
|
||||||
{
|
{
|
||||||
ui_combo_box_add_to_history(GTK_COMBO_BOX(user_data), search_text);
|
ui_combo_box_add_to_history(GTK_COMBO_BOX(user_data), search_text);
|
||||||
ui_combo_box_add_to_history(GTK_COMBO_BOX(dir_combo), utf8_dir);
|
ui_combo_box_add_to_history(GTK_COMBO_BOX(dir_combo), utf8_dir);
|
||||||
gtk_widget_hide(widgets.find_in_files_dialog);
|
gtk_widget_hide(widgets.find_in_files_dialog);
|
||||||
}
|
}
|
||||||
g_free(locale_dir);
|
g_free(locale_dir);
|
||||||
|
g_string_free(opts, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ui_set_statusbar(_("No text to find."));
|
ui_set_statusbar(_("No text to find."));
|
||||||
@ -1091,67 +1133,43 @@ on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user
|
|||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
search_find_in_files(const gchar *search_text, const gchar *dir, fif_match_type regex_opt,
|
search_find_in_files(const gchar *search_text, const gchar *dir, const gchar *opts)
|
||||||
fif_options opts)
|
|
||||||
{
|
{
|
||||||
gchar **argv_prefix;
|
gchar **argv_prefix, **argv, **opts_argv;
|
||||||
gchar **grep_cmd_argv;
|
guint opts_argv_len, i;
|
||||||
gchar **argv;
|
|
||||||
gchar grep_opts[] = "-nHI ";
|
|
||||||
GPid child_pid;
|
GPid child_pid;
|
||||||
gint stdout_fd, stdin_fd, grep_cmd_argv_len, i, grep_opts_len = 4;
|
gint stdout_fd, stdin_fd;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
if (! search_text || ! *search_text || ! dir) return TRUE;
|
if (! search_text || ! *search_text || ! dir) return TRUE;
|
||||||
|
|
||||||
// first process the grep command (need to split it in a argv because it can be "grep -I")
|
if (! g_file_test(app->tools_grep_cmd, G_FILE_TEST_IS_EXECUTABLE))
|
||||||
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';"
|
msgwin_status_add(_("Cannot execute grep tool '%s';"
|
||||||
" check the path setting in Preferences."), app->tools_grep_cmd);
|
" check the path setting in Preferences."), app->tools_grep_cmd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_list_store_clear(msgwindow.store_msg);
|
opts_argv = g_strsplit(opts, " ", -1);
|
||||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_MESSAGE);
|
opts_argv_len = g_strv_length(opts_argv);
|
||||||
|
|
||||||
switch (regex_opt)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case FIF_FGREP: grep_opts[grep_opts_len++] = 'F'; break;
|
|
||||||
case FIF_GREP: break;
|
|
||||||
case FIF_EGREP: grep_opts[grep_opts_len++] = 'E'; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! (opts & FIF_CASE_SENSITIVE))
|
|
||||||
grep_opts[grep_opts_len++] = 'i';
|
|
||||||
if (opts & FIF_WHOLE_WORD)
|
|
||||||
grep_opts[grep_opts_len++] = 'w';
|
|
||||||
if (opts & FIF_INVERT_MATCH)
|
|
||||||
grep_opts[grep_opts_len++] = 'v';
|
|
||||||
if (opts & FIF_RECURSIVE)
|
|
||||||
grep_opts[grep_opts_len++] = 'r';
|
|
||||||
grep_opts[grep_opts_len] = '\0';
|
|
||||||
|
|
||||||
// set grep command and options
|
// set grep command and options
|
||||||
argv_prefix = g_new0(gchar*, grep_cmd_argv_len + 4 + 1); // +1 for recursive arg
|
argv_prefix = g_new0(gchar*, 1 + opts_argv_len + 3 + 1); // last +1 for recursive arg
|
||||||
|
|
||||||
for (i = 0; i < grep_cmd_argv_len; i++)
|
argv_prefix[0] = g_strdup(app->tools_grep_cmd);
|
||||||
|
for (i = 0; i < opts_argv_len; i++)
|
||||||
{
|
{
|
||||||
argv_prefix[i] = g_strdup(grep_cmd_argv[i]);
|
argv_prefix[i + 1] = g_strdup(opts_argv[i]);
|
||||||
}
|
}
|
||||||
g_strfreev(grep_cmd_argv);
|
g_strfreev(opts_argv);
|
||||||
|
|
||||||
argv_prefix[i++] = g_strdup(grep_opts);
|
i++; // correct for app->tools_grep_cmd
|
||||||
argv_prefix[i++] = g_strdup("--");
|
argv_prefix[i++] = g_strdup("--");
|
||||||
argv_prefix[i++] = g_strdup(search_text);
|
argv_prefix[i++] = g_strdup(search_text);
|
||||||
|
|
||||||
// finally add the arguments(files to be searched)
|
// finally add the arguments(files to be searched)
|
||||||
if (opts & FIF_RECURSIVE)
|
if (strstr(argv_prefix[1], "r")) // recursive option set
|
||||||
{
|
{
|
||||||
argv_prefix[i++] = g_strdup(".");
|
argv_prefix[i++] = g_strdup(".");
|
||||||
argv_prefix[i++] = NULL;
|
argv_prefix[i++] = NULL;
|
||||||
@ -1164,7 +1182,14 @@ search_find_in_files(const gchar *search_text, const gchar *dir, fif_match_type
|
|||||||
g_strfreev(argv_prefix);
|
g_strfreev(argv_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv == NULL) return FALSE;
|
if (argv == NULL) // no files
|
||||||
|
{
|
||||||
|
g_strfreev(argv);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_list_store_clear(msgwindow.store_msg);
|
||||||
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_MESSAGE);
|
||||||
|
|
||||||
if (! g_spawn_async_with_pipes(dir, (gchar**)argv, NULL,
|
if (! g_spawn_async_with_pipes(dir, (gchar**)argv, NULL,
|
||||||
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_DO_NOT_REAP_CHILD,
|
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_DO_NOT_REAP_CHILD,
|
||||||
@ -1186,8 +1211,8 @@ search_find_in_files(const gchar *search_text, const gchar *dir, fif_match_type
|
|||||||
TRUE, search_read_io, NULL);
|
TRUE, search_read_io, NULL);
|
||||||
g_child_watch_add(child_pid, search_close_pid, NULL);
|
g_child_watch_add(child_pid, search_close_pid, NULL);
|
||||||
|
|
||||||
str = g_strdup_printf(_("%s %s %s %s (in directory: %s)"),
|
str = g_strdup_printf(_("%s %s -- %s (in directory: %s)"),
|
||||||
argv[0], argv[1], argv[2], argv[3], dir);
|
app->tools_grep_cmd, opts, search_text, dir);
|
||||||
utf8_str = utils_get_utf8_from_locale(str);
|
utf8_str = utils_get_utf8_from_locale(str);
|
||||||
msgwin_msg_add(-1, -1, utf8_str);
|
msgwin_msg_add(-1, -1, utf8_str);
|
||||||
utils_free_pointers(str, utf8_str, NULL);
|
utils_free_pointers(str, utf8_str, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user