summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Westman <james@flyingpimonster.net>2021-01-01 18:17:33 -0600
committerAntónio Fernandes <antoniof@gnome.org>2021-02-12 23:56:07 +0000
commita65fe36d6dd52cf2cf174a3ac750e016a4b862d4 (patch)
treeb016c3e10f2fd572fa5a21093bfbdd8eeaf73415
parentdbd5be23a6645188f942ee99a22f91966ae83260 (diff)
downloadnautilus-a65fe36d6dd52cf2cf174a3ac750e016a4b862d4.tar.gz
location-entry: Highlight basenames of completions
Or, rather, dim the dirnames so the basenames stand out.
-rw-r--r--src/nautilus-location-entry.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c
index f09611f19..e9ad0dadc 100644
--- a/src/nautilus-location-entry.c
+++ b/src/nautilus-location-entry.c
@@ -77,6 +77,7 @@ typedef struct _NautilusLocationEntryPrivate
GtkEntryCompletion *completion;
GtkListStore *completions_store;
+ GtkCellRenderer *completion_cell;
} NautilusLocationEntryPrivate;
enum
@@ -354,6 +355,35 @@ drag_data_get_callback (GtkWidget *widget,
}
+static void
+set_prefix_dimming (GtkCellRenderer *completion_cell,
+ char *user_location)
+{
+ g_autofree char *location_basename = NULL;
+ PangoAttrList *attrs;
+ PangoAttribute *attr;
+
+ /* Dim the prefixes of the completion rows, leaving the basenames
+ * highlighted. This makes it easier to find what you're looking for.
+ *
+ * Perhaps a better solution would be to *only* show the basenames, but
+ * it would take a reimplementation of GtkEntryCompletion to align the
+ * popover. */
+
+ location_basename = g_path_get_basename (user_location);
+
+ attrs = pango_attr_list_new ();
+
+ /* 55% opacity. This is the same as the dim-label style class in Adwaita. */
+ attr = pango_attr_foreground_alpha_new (36045);
+ attr->end_index = strlen (user_location) - strlen (location_basename);
+ pango_attr_list_insert (attrs, attr);
+
+ g_object_set (completion_cell, "attributes", attrs, NULL);
+ pango_attr_list_unref (attrs);
+}
+
+
/* Update the path completions list based on the current text of the entry. */
static gboolean
update_completions_store (gpointer callback_data)
@@ -386,6 +416,7 @@ update_completions_store (gpointer callback_data)
}
g_strstrip (user_location);
+ set_prefix_dimming (priv->completion_cell, user_location);
priv->idle_id = 0;
@@ -964,6 +995,12 @@ nautilus_location_entry_init (NautilusLocationEntry *entry)
"popup-single-match", TRUE,
NULL);
+ priv->completion_cell = gtk_cell_renderer_text_new ();
+ g_object_set (priv->completion_cell, "xpad", 6, NULL);
+
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->completion), priv->completion_cell, FALSE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->completion), priv->completion_cell, "text", 0);
+
gtk_entry_set_completion (GTK_ENTRY (entry), priv->completion);
}