filechooserentry: unselect text when unfocused

There's no gain in keeping text selected while entry is
unfocused other than confusing users which (misguided by
the strong selection color) think the entry is focused
and so when start typing to edit the text an unexpected
search dialog appears.

Fixes #326
Fixes #665
This commit is contained in:
Nelson Benítez León
2022-08-16 16:13:21 -04:00
parent 187093f2a1
commit 884d08b9ed
2 changed files with 14 additions and 4 deletions

View File

@@ -115,6 +115,7 @@ static void set_completion_folder (GtkFileChooserEntry *chooser_entry,
static void finished_loading_cb (GtkFileSystemModel *model,
GError *error,
GtkFileChooserEntry *chooser_entry);
static void _gtk_file_chooser_entry_unselect_text (GtkFileChooserEntry *chooser_entry);
G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
@@ -483,7 +484,6 @@ static void
gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
{
GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
_gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
}
static void
@@ -543,6 +543,7 @@ gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
set_complete_on_load (chooser_entry, FALSE);
_gtk_file_chooser_entry_unselect_text (chooser_entry);
return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
}
@@ -1050,6 +1051,18 @@ _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
}
/*
* _gtk_file_chooser_entry_unselect_text:
* @chooser_entry: a #GtkFileChooserEntry
*
* Unselects any existing text selection.
*/
static void
_gtk_file_chooser_entry_unselect_text (GtkFileChooserEntry *chooser_entry)
{
gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, 0);
}
void
_gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
gboolean local_only)

View File

@@ -5466,9 +5466,6 @@ update_chooser_entry (GtkFileChooserWidget *impl)
g_signal_handlers_block_by_func (priv->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
gtk_entry_set_text (GTK_ENTRY (priv->location_entry), priv->browse_files_last_selected_name);
g_signal_handlers_unblock_by_func (priv->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
if (priv->action == GTK_FILE_CHOOSER_ACTION_SAVE)
_gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (priv->location_entry));
}
return;