[nautilus/wip/minButWidth: 1/2] nautilus-window-slot: Indicate no results when searching
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/minButWidth: 1/2] nautilus-window-slot: Indicate no results when searching
- Date: Tue, 23 Sep 2014 15:15:35 +0000 (UTC)
commit 8e90cbcc9f9ac27ce801f83113f474f78eda4b91
Author: Carlos Soriano <carlos soriano89 gmail com>
Date: Fri Aug 22 13:13:14 2014 +0200
nautilus-window-slot: Indicate no results when searching
Currently when no results are found for a search, the view becomes empty
with no feedback to the user.
Instead of that add a "No results" label when that happens.
https://bugzilla.gnome.org/show_bug.cgi?id=735216
libnautilus-private/nautilus-search-directory.c | 36 +++++++++++++++++++---
src/nautilus-window-slot.c | 30 +++++++++++++++++++
2 files changed, 61 insertions(+), 5 deletions(-)
---
diff --git a/libnautilus-private/nautilus-search-directory.c b/libnautilus-private/nautilus-search-directory.c
index 3f9144c..5f1a8a2 100644
--- a/libnautilus-private/nautilus-search-directory.c
+++ b/libnautilus-private/nautilus-search-directory.c
@@ -82,6 +82,13 @@ enum {
NUM_PROPERTIES
};
+enum {
+ DONE_SEARCHING,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
G_DEFINE_TYPE (NautilusSearchDirectory, nautilus_search_directory,
NAUTILUS_TYPE_DIRECTORY);
@@ -505,15 +512,25 @@ search_callback_add_pending_file_callbacks (SearchCallback *callback)
}
static void
-search_directory_ensure_loaded (NautilusSearchDirectory *search)
+search_directory_emit_done_searching (NautilusSearchDirectory *search)
+{
+ g_signal_emit (search, signals[DONE_SEARCHING], 0);
+}
+
+static void
+search_directory_ensure_loaded (NautilusSearchDirectory *search,
+ gboolean search_loaded)
{
if (search->details->search_loaded) {
return;
}
- search->details->search_loaded = TRUE;
- nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));
+ if (search_loaded) {
+ search->details->search_loaded = TRUE;
+ search_directory_emit_done_searching(search);
+ }
+ nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));
/* Add all file callbacks */
g_list_foreach (search->details->pending_callback_list,
(GFunc)search_callback_add_pending_file_callbacks, NULL);
@@ -572,7 +589,7 @@ search_engine_hits_added (NautilusSearchEngine *engine, GList *hits,
nautilus_file_emit_changed (file);
nautilus_file_unref (file);
- search_directory_ensure_loaded (search);
+ search_directory_ensure_loaded (search, FALSE);
}
static void
@@ -590,7 +607,7 @@ search_engine_error (NautilusSearchEngine *engine, const char *error_message, Na
static void
search_engine_finished (NautilusSearchEngine *engine, NautilusSearchDirectory *search)
{
- search_directory_ensure_loaded (search);
+ search_directory_ensure_loaded (search, TRUE);
}
static void
@@ -815,6 +832,15 @@ nautilus_search_directory_class_init (NautilusSearchDirectoryClass *class)
NAUTILUS_TYPE_QUERY,
G_PARAM_READWRITE);
+ signals[DONE_SEARCHING] =
+ g_signal_new ("done-searching",
+ G_TYPE_FROM_CLASS (oclass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 0);
+
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
g_type_class_add_private (class, sizeof (NautilusSearchDirectoryDetails));
}
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index ea2ff71..c216ba3 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -70,6 +70,9 @@ struct NautilusWindowSlotDetails {
GtkWidget *floating_bar;
GtkWidget *view_overlay;
+ /* no results label */
+ GtkLabel *no_results_label;
+
/* slot contains
* 1) an vbox containing extra_location_widgets
* 2) the view
@@ -214,6 +217,7 @@ sync_search_directory (NautilusWindowSlot *slot)
text = nautilus_query_get_text (query);
if (!strlen (text)) {
+ gtk_widget_hide (GTK_WIDGET (slot->details->no_results_label));
/* Prevent the location change from hiding the query editor in this case */
slot->details->load_with_search = TRUE;
location = nautilus_query_editor_get_location (slot->details->query_editor);
@@ -231,6 +235,19 @@ sync_search_directory (NautilusWindowSlot *slot)
}
static void
+done_searching_callback (NautilusDirectory *directory,
+ NautilusWindowSlot *slot)
+{
+ GList *files = nautilus_directory_get_file_list (directory);
+
+ if (!g_list_length (files)) {
+ gtk_widget_show (GTK_WIDGET (slot->details->no_results_label));
+ } else {
+ gtk_widget_hide (GTK_WIDGET (slot->details->no_results_label));
+ }
+}
+
+static void
create_new_search (NautilusWindowSlot *slot)
{
char *uri;
@@ -244,6 +261,9 @@ create_new_search (NautilusWindowSlot *slot)
directory = nautilus_directory_get (location);
g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
+ g_signal_connect_object (NAUTILUS_SEARCH_DIRECTORY (directory), "done-searching",
+ G_CALLBACK (done_searching_callback), slot, 0);
+
query = nautilus_query_editor_get_query (slot->details->query_editor);
nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
@@ -397,6 +417,7 @@ nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
if (visible) {
show_query_editor (slot);
} else {
+ gtk_widget_hide (GTK_WIDGET (slot->details->no_results_label));
/* If search was active on this slot and became inactive, change
* the slot location to the real directory.
*/
@@ -606,6 +627,15 @@ nautilus_window_slot_constructed (GObject *object)
gtk_box_pack_start (GTK_BOX (slot), slot->details->view_overlay, TRUE, TRUE, 0);
gtk_widget_show (slot->details->view_overlay);
+ slot->details->no_results_label = gtk_label_new(NULL);
+ const char *markup = g_markup_printf_escaped("<span size=\"large\" font_weight=\"bold\">\%s</span>",
_("No results"));
+ GtkStyleContext *style = gtk_widget_get_style_context (GTK_WIDGET (slot->details->no_results_label));
+ gtk_style_context_add_class (style, "dim-label");
+ gtk_label_set_markup(slot->details->no_results_label, markup);
+
+ gtk_overlay_add_overlay (GTK_OVERLAY (slot->details->view_overlay),
+ GTK_WIDGET (slot->details->no_results_label));
+
slot->details->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE);
gtk_widget_set_halign (slot->details->floating_bar, GTK_ALIGN_END);
gtk_widget_set_valign (slot->details->floating_bar, GTK_ALIGN_END);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]