Skip to content

Commit

Permalink
Fix Find in Files invalid directory error (geany#3818)
Browse files Browse the repository at this point in the history
When the Find in Files path doesn't exist, the status bar says "Cannot execute grep tool...: Failed to change the working directory. Check the path setting in Preferences". Which is confusing and hides the real problem in the middle of irrelevant text. Instead, show a dialog with the correct error only. Fixes geany#1347.

* Fix FiF capitalization
* Set FIF search/directory entry background to indicate error
  • Loading branch information
ntrel committed Apr 15, 2024
1 parent fc91262 commit 32bbe10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/geany.glade
Original file line number Diff line number Diff line change
Expand Up @@ -8808,7 +8808,7 @@
<object class="GtkEntry" id="entry_project_dialog_file_patterns">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Space separated list of file patterns used for the find in files dialog (e.g. *.c *.h)</property>
<property name="tooltip-text" translatable="yes">Space separated list of file patterns used for the Find in Files dialog (e.g. *.c *.h)</property>
<property name="invisible-char">•</property>
<property name="primary-icon-activatable">False</property>
</object>
Expand Down
20 changes: 15 additions & 5 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,8 @@ void search_show_find_in_files_dialog_full(const gchar *text, const gchar *dir)
g_free(cur_dir);
}

ui_set_search_entry_background(fif_dlg.search_combo, TRUE);
ui_set_search_entry_background(fif_dlg.dir_combo, TRUE);
update_fif_file_mode_combo();
update_file_patterns(fif_dlg.files_mode_combo, fif_dlg.files_combo);

Expand Down Expand Up @@ -1632,12 +1634,21 @@ on_find_in_files_dialog_response(GtkDialog *dialog, gint response,
GtkWidget *dir_combo = fif_dlg.dir_combo;
const gchar *utf8_dir =
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(dir_combo))));
gchar *locale_dir = utils_get_locale_from_utf8(utf8_dir);
GeanyEncodingIndex enc_idx =
ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(fif_dlg.encoding_combo));

if (G_UNLIKELY(EMPTY(utf8_dir)))
ui_set_statusbar(FALSE, _("Invalid directory for find in files."));
else if (!EMPTY(search_text))
if (!g_file_test(locale_dir, G_FILE_TEST_IS_DIR))
{
ui_set_statusbar(FALSE, _("Invalid directory for Find in Files."));
ui_set_search_entry_background(dir_combo, FALSE);
}
else if (EMPTY(search_text))
{
ui_set_statusbar(FALSE, _("No text to find."));
ui_set_search_entry_background(search_combo, FALSE);
}
else
{
GString *opts = get_grep_options();
const gchar *enc = (enc_idx == GEANY_ENCODING_UTF_8) ? NULL :
Expand All @@ -1652,8 +1663,7 @@ on_find_in_files_dialog_response(GtkDialog *dialog, gint response,
}
g_string_free(opts, TRUE);
}
else
ui_set_statusbar(FALSE, _("No text to find."));
g_free(locale_dir);
}
else
gtk_widget_hide(fif_dlg.dialog);
Expand Down
5 changes: 5 additions & 0 deletions src/ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,13 @@ void ui_document_show_hide(GeanyDocument *doc)
}


/* success = FALSE indicates an error for widget */
void ui_set_search_entry_background(GtkWidget *widget, gboolean success)
{
// set the entry, not just the button
if (GTK_IS_COMBO_BOX(widget))
widget = gtk_bin_get_child(GTK_BIN(widget));

gtk_widget_set_name(widget, success ? NULL : "geany-search-entry-no-match");
}

Expand Down

0 comments on commit 32bbe10

Please sign in to comment.