summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2025-09-21 19:09:14 +0000
committerGitHub <[email protected]>2025-09-21 19:09:14 +0000
commitf3998312f42dbd8b76eba71b976015b0813769f7 (patch)
tree41b4fd62889a774b2d1e4d19e2a86c3acb14ab07 /src
parentf093cfa7e4cbb27280576d39d63e5000df9f0d7c (diff)
downloadcaja-f3998312f42dbd8b76eba71b976015b0813769f7.tar.bz2
caja-f3998312f42dbd8b76eba71b976015b0813769f7.tar.xz
File search improvements (#1851)
* search: Respect hidden files setting when searching When starting a search, check the current window's hidden files mode and apply the same setting to search results. This ensures search results match the visibility of files in the current directory view. * search: Add support for globs Add globbing when searching for files. Caja will autodetect if the query contains a glob and change its search to use that instead of substrings. Example: - "*.txt" finds all text files - "photo-?.jpg" finds numbered photo files - "data[0-9]*.csv" finds numbered data files * search: Add location tooltips for search results Display file location in tooltips when hovering over search results in both icon and list views. This can help users tell where files are located since search happens across subdirectories.
Diffstat (limited to 'src')
-rw-r--r--src/caja-navigation-window-pane.c26
-rw-r--r--src/file-manager/fm-icon-view.c59
-rw-r--r--src/file-manager/fm-list-view.c69
3 files changed, 154 insertions, 0 deletions
diff --git a/src/caja-navigation-window-pane.c b/src/caja-navigation-window-pane.c
index 19669411..5e870d45 100644
--- a/src/caja-navigation-window-pane.c
+++ b/src/caja-navigation-window-pane.c
@@ -26,6 +26,7 @@
#include <libcaja-private/caja-global-preferences.h>
#include <libcaja-private/caja-window-slot-info.h>
+#include <libcaja-private/caja-window-info.h>
#include <libcaja-private/caja-view-factory.h>
#include <libcaja-private/caja-entry.h>
@@ -139,6 +140,31 @@ search_bar_activate_callback (CajaSearchBar *bar,
caja_query_set_location (query, current_uri);
g_free (current_uri);
}
+
+ /* Set hidden files visibility based on current window setting */
+ {
+ CajaWindow *window;
+ CajaWindowShowHiddenFilesMode mode;
+ gboolean show_hidden_files = FALSE;
+
+ window = slot->pane->window;
+ mode = caja_window_info_get_hidden_files_mode (CAJA_WINDOW_INFO (window));
+
+ if (mode == CAJA_WINDOW_SHOW_HIDDEN_FILES_ENABLE)
+ {
+ show_hidden_files = TRUE;
+ }
+ else if (mode == CAJA_WINDOW_SHOW_HIDDEN_FILES_DEFAULT)
+ {
+ show_hidden_files = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_SHOW_HIDDEN_FILES);
+ }
+
+ CajaSearchEngine *engine = caja_search_directory_get_engine (search_directory);
+ if (engine) {
+ caja_search_engine_set_show_hidden_files (engine, show_hidden_files);
+ }
+ }
+
caja_search_directory_set_query (search_directory, query);
g_object_unref (query);
}
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index 25708184..c17bedf6 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -38,6 +38,7 @@
#include <sys/wait.h>
#include <eel/eel-background.h>
+#include <eel/eel-canvas.h>
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
@@ -48,11 +49,14 @@
#include <libcaja-private/caja-clipboard-monitor.h>
#include <libcaja-private/caja-directory-background.h>
#include <libcaja-private/caja-directory.h>
+#include <libcaja-private/caja-search-directory.h>
#include <libcaja-private/caja-dnd.h>
#include <libcaja-private/caja-file-utilities.h>
#include <libcaja-private/caja-ui-utilities.h>
#include <libcaja-private/caja-global-preferences.h>
+#include <libcaja-private/caja-icon-canvas-item.h>
#include <libcaja-private/caja-icon-container.h>
+#include <libcaja-private/caja-icon-private.h>
#include <libcaja-private/caja-icon-dnd.h>
#include <libcaja-private/caja-link.h>
#include <libcaja-private/caja-metadata.h>
@@ -3114,6 +3118,58 @@ focus_in_event_callback (GtkWidget *widget, GdkEventFocus *event, gpointer user_
return FALSE;
}
+static gboolean
+icon_container_query_tooltip_callback (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ FMIconView *icon_view)
+{
+ CajaIconContainer *icon_container;
+ EelCanvasItem *item;
+ CajaFile *file;
+ char *location_text;
+
+ /* Only show tooltips in search directories */
+ if (!CAJA_IS_SEARCH_DIRECTORY (fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view))))
+ {
+ return FALSE;
+ }
+
+ icon_container = CAJA_ICON_CONTAINER (widget);
+
+ /* Get the canvas item at the cursor position */
+ item = eel_canvas_get_item_at (EEL_CANVAS (icon_container), x, y);
+ if (item == NULL || !CAJA_IS_ICON_CANVAS_ITEM (item))
+ {
+ return FALSE;
+ }
+
+ /* Get the file from the canvas item's user_data */
+ CajaIcon *icon = CAJA_ICON_CANVAS_ITEM (item)->user_data;
+ file = CAJA_FILE (icon->data);
+ if (file == NULL)
+ {
+ return FALSE;
+ }
+
+ /* Get the location attribute */
+ location_text = caja_file_get_string_attribute_with_default (file, "location");
+ if (location_text == NULL || location_text[0] == '\0')
+ {
+ g_free (location_text);
+ return FALSE;
+ }
+
+ /* Set tooltip text with file location */
+ gtk_tooltip_set_text (tooltip, location_text);
+
+ g_free (location_text);
+
+ return TRUE;
+}
+
static CajaIconContainer *
create_icon_container (FMIconView *icon_view)
{
@@ -3122,9 +3178,12 @@ create_icon_container (FMIconView *icon_view)
icon_container = fm_icon_container_new (icon_view);
gtk_widget_set_can_focus (GTK_WIDGET (icon_container), TRUE);
+ gtk_widget_set_has_tooltip (GTK_WIDGET (icon_container), TRUE);
g_signal_connect_object (icon_container, "focus_in_event",
G_CALLBACK (focus_in_event_callback), icon_view, 0);
+ g_signal_connect_object (icon_container, "query-tooltip",
+ G_CALLBACK (icon_container_query_tooltip_callback), icon_view, 0);
g_signal_connect_object (icon_container, "activate",
G_CALLBACK (icon_container_activate_callback), icon_view, 0);
g_signal_connect_object (icon_container, "activate_alternate",
diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c
index b5a61459..57b5862c 100644
--- a/src/file-manager/fm-list-view.c
+++ b/src/file-manager/fm-list-view.c
@@ -48,6 +48,7 @@
#include <libcaja-private/caja-column-utilities.h>
#include <libcaja-private/caja-debug-log.h>
#include <libcaja-private/caja-directory-background.h>
+#include <libcaja-private/caja-search-directory.h>
#include <libcaja-private/caja-dnd.h>
#include <libcaja-private/caja-file-dnd.h>
#include <libcaja-private/caja-file-utilities.h>
@@ -1640,6 +1641,70 @@ focus_in_event_callback (GtkWidget *widget, GdkEventFocus *event, gpointer user_
return FALSE;
}
+static gboolean
+tree_view_query_tooltip_callback (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ FMListView *list_view)
+{
+ GtkTreeView *tree_view;
+ GtkTreePath *path;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ CajaFile *file;
+ char *location_text;
+
+ /* Only show tooltips in search directories */
+ if (!CAJA_IS_SEARCH_DIRECTORY (fm_directory_view_get_model (FM_DIRECTORY_VIEW (list_view))))
+ {
+ return FALSE;
+ }
+
+ tree_view = GTK_TREE_VIEW (widget);
+
+ /* Get the tree path at the cursor position */
+ if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL))
+ {
+ return FALSE;
+ }
+
+ model = gtk_tree_view_get_model (tree_view);
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ {
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ /* Get the file from the model */
+ gtk_tree_model_get (model, &iter, FM_LIST_MODEL_FILE_COLUMN, &file, -1);
+ if (file == NULL)
+ {
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ /* Get the location attribute */
+ location_text = caja_file_get_string_attribute_with_default (file, "location");
+ if (location_text == NULL || location_text[0] == '\0')
+ {
+ g_free (location_text);
+ caja_file_unref (file);
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ /* Set tooltip text with file location */
+ gtk_tooltip_set_text (tooltip, location_text);
+
+ g_free (location_text);
+ caja_file_unref (file);
+ gtk_tree_path_free (path);
+
+ return TRUE;
+}
+
static gint
get_icon_scale_callback (FMListModel *model,
FMListView *view)
@@ -1664,6 +1729,8 @@ create_and_set_up_tree_view (FMListView *view)
NULL);
gtk_tree_view_set_enable_search (view->details->tree_view, TRUE);
+ gtk_widget_set_has_tooltip (GTK_WIDGET (view->details->tree_view), TRUE);
+
/* Don't handle backspace key. It's used to open the parent folder. */
binding_set = gtk_binding_set_by_class (GTK_WIDGET_GET_CLASS (view->details->tree_view));
gtk_binding_entry_remove (binding_set, GDK_KEY_BackSpace, 0);
@@ -1723,6 +1790,8 @@ create_and_set_up_tree_view (FMListView *view)
g_signal_connect_object (view->details->tree_view, "focus_in_event",
G_CALLBACK(focus_in_event_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "query-tooltip",
+ G_CALLBACK (tree_view_query_tooltip_callback), view, 0);
view->details->model = g_object_new (FM_TYPE_LIST_MODEL, NULL);
gtk_tree_view_set_model (view->details->tree_view, GTK_TREE_MODEL (view->details->model));