[gtk+/gtk-2-24] filechooserentry: Use inline completion
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] filechooserentry: Use inline completion
- Date: Thu, 10 Mar 2016 21:30:03 +0000 (UTC)
commit 46adc18c1dac323696a9a5faf8f0e0a7b23ad411
Author: Benjamin Otte <otte redhat com>
Date: Sun Nov 6 03:00:47 2011 +0100
filechooserentry: Use inline completion
... from GtkEntryCompletion instead of implementing a poor copy
ourselves. This also makes the file chooser entry behave a lot closer to
normal entries.
Conflicts:
gtk/gtkfilechooserentry.c
gtk/gtkfilechooserentry.c | 128 +++++++++++----------------------------------
1 files changed, 30 insertions(+), 98 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index d658fa2..7afd8c3 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -51,7 +51,6 @@ struct _GtkFileChooserEntryClass
/* Action to take when the current folder finishes loading (for explicit or automatic completion) */
typedef enum {
LOAD_COMPLETE_NOTHING,
- LOAD_COMPLETE_AUTOCOMPLETE,
LOAD_COMPLETE_EXPLICIT_COMPLETION
} LoadCompleteAction;
@@ -85,7 +84,6 @@ struct _GtkFileChooserEntry
guint completion_feedback_timeout_id;
guint current_folder_loaded : 1;
- guint has_completion : 1;
guint in_change : 1;
guint eat_tabs : 1;
guint local_only : 1;
@@ -156,8 +154,6 @@ static RefreshStatus refresh_current_folder_and_file_part (GtkFileChooserEntry *
static void finished_loading_cb (GtkFileSystemModel *model,
GError *error,
GtkFileChooserEntry *chooser_entry);
-static void autocomplete (GtkFileChooserEntry *chooser_entry);
-static void start_autocompletion (GtkFileChooserEntry *chooser_entry);
static void remove_completion_feedback (GtkFileChooserEntry *chooser_entry);
static void pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
const gchar *feedback);
@@ -266,17 +262,6 @@ discard_loading_and_current_folder_file (GtkFileChooserEntry *chooser_entry)
}
static void
-discard_completion_store (GtkFileChooserEntry *chooser_entry)
-{
- if (!chooser_entry->completion_store)
- return;
-
- gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
- g_object_unref (chooser_entry->completion_store);
- chooser_entry->completion_store = NULL;
-}
-
-static void
gtk_file_chooser_entry_dispose (GObject *object)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
@@ -396,7 +381,6 @@ completion_match_func (GtkEntryCompletion *comp,
static void
clear_completions (GtkFileChooserEntry *chooser_entry)
{
- chooser_entry->has_completion = FALSE;
chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
remove_completion_feedback (chooser_entry);
@@ -674,9 +658,7 @@ typedef enum {
* and mandatorily appends it
*/
static CommonPrefixResult
-append_common_prefix (GtkFileChooserEntry *chooser_entry,
- gboolean highlight,
- gboolean show_errors)
+append_common_prefix (GtkFileChooserEntry *chooser_entry)
{
gchar *common_prefix;
GFile *unique_file;
@@ -740,16 +722,7 @@ append_common_prefix (GtkFileChooserEntry *chooser_entry,
&pos);
chooser_entry->in_change = FALSE;
- if (highlight)
- {
- /* equivalent to cursor_pos + common_prefix_len); */
- gtk_editable_select_region (GTK_EDITABLE (chooser_entry),
- cursor_pos,
- pos);
- chooser_entry->has_completion = TRUE;
- }
- else
- gtk_editable_set_position (GTK_EDITABLE (chooser_entry), pos);
+ gtk_editable_set_position (GTK_EDITABLE (chooser_entry), pos);
}
else if (!have_result)
{
@@ -780,11 +753,6 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
gint *position)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
- gint old_text_len;
- gint insert_pos;
-
- old_text_len = gtk_entry_get_text_length (GTK_ENTRY (chooser_entry));
- insert_pos = *position;
parent_editable_iface->do_insert_text (editable, new_text, new_text_length, position);
@@ -792,11 +760,7 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
return;
remove_completion_feedback (chooser_entry);
-
- if ((chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN
- || chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
- && insert_pos == old_text_len)
- start_autocompletion (chooser_entry);
+ refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
}
static void
@@ -1065,7 +1029,7 @@ explicitly_complete (GtkFileChooserEntry *chooser_entry)
* - If there are no matches at all, beep and bring up a tooltip (done)
* - If the suggestion window is already up, scroll it
*/
- result = append_common_prefix (chooser_entry, FALSE, TRUE);
+ result = append_common_prefix (chooser_entry);
switch (result)
{
@@ -1208,13 +1172,11 @@ gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
{
GtkFileChooserEntry *chooser_entry;
GtkEditable *editable;
- GtkEntry *entry;
GdkModifierType state;
gboolean control_pressed;
chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
editable = GTK_EDITABLE (widget);
- entry = GTK_ENTRY (widget);
if (!chooser_entry->eat_tabs)
return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
@@ -1231,8 +1193,12 @@ gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
* makes it 'safe' for people to hit. */
if (event->keyval == GDK_Tab && !control_pressed)
{
- if (chooser_entry->has_completion)
- gtk_editable_set_position (editable, gtk_entry_get_text_length (entry));
+ gint start, end;
+
+ gtk_editable_get_selection_bounds (editable, &start, &end);
+
+ if (start != end)
+ gtk_editable_set_position (editable, MAX (start, end));
else
start_explicit_completion (chooser_entry);
@@ -1257,12 +1223,6 @@ gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
static void
commit_completion_and_refresh (GtkFileChooserEntry *chooser_entry)
{
- if (chooser_entry->has_completion)
- {
- gtk_editable_set_position (GTK_EDITABLE (chooser_entry),
- gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)));
- }
-
/* Here we ignore the result of refresh_current_folder_and_file_part(); there is nothing we can do with it
*/
refresh_current_folder_and_file_part (chooser_entry, REFRESH_WHOLE_TEXT);
}
@@ -1276,6 +1236,18 @@ gtk_file_chooser_entry_activate (GtkEntry *entry)
GTK_ENTRY_CLASS (_gtk_file_chooser_entry_parent_class)->activate (entry);
}
+static void
+discard_completion_store (GtkFileChooserEntry *chooser_entry)
+{
+ if (!chooser_entry->completion_store)
+ return;
+
+ gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
+ gtk_entry_completion_set_inline_completion (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), FALSE);
+ g_object_unref (chooser_entry->completion_store);
+ chooser_entry->completion_store = NULL;
+}
+
static gboolean
completion_store_set (GtkFileSystemModel *model,
GFile *file,
@@ -1341,7 +1313,7 @@ populate_completion_store (GtkFileChooserEntry *chooser_entry)
}
/* When we finish loading the current folder, this function should get called to
- * perform the deferred autocompletion or explicit completion.
+ * perform the deferred explicit completion.
*/
static void
perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
@@ -1351,10 +1323,6 @@ perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
case LOAD_COMPLETE_NOTHING:
break;
- case LOAD_COMPLETE_AUTOCOMPLETE:
- autocomplete (chooser_entry);
- break;
-
case LOAD_COMPLETE_EXPLICIT_COMPLETION:
explicitly_complete (chooser_entry);
break;
@@ -1372,6 +1340,8 @@ finished_loading_cb (GtkFileSystemModel *model,
GError *error,
GtkFileChooserEntry *chooser_entry)
{
+ GtkEntryCompletion *completion;
+
chooser_entry->current_folder_loaded = TRUE;
if (error)
@@ -1397,6 +1367,11 @@ finished_loading_cb (GtkFileSystemModel *model,
perform_load_complete_action (chooser_entry);
gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
+
+ completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
+ gtk_entry_completion_set_inline_completion (completion, TRUE);
+ gtk_entry_completion_complete (completion);
+ gtk_entry_completion_insert_prefix (completion);
}
static RefreshStatus
@@ -1521,49 +1496,6 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
return result;
}
-static void
-autocomplete (GtkFileChooserEntry *chooser_entry)
-{
- if (!(chooser_entry->current_folder_loaded
- && gtk_editable_get_position (GTK_EDITABLE (chooser_entry)) == gtk_entry_get_text_length (GTK_ENTRY
(chooser_entry))))
- return;
-
- append_common_prefix (chooser_entry, TRUE, FALSE);
-}
-
-static void
-start_autocompletion (GtkFileChooserEntry *chooser_entry)
-{
- RefreshStatus status;
-
- status = refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
-
- switch (status)
- {
- case REFRESH_OK:
- g_assert (chooser_entry->current_folder_file != NULL);
-
- if (chooser_entry->current_folder_loaded)
- autocomplete (chooser_entry);
- else
- chooser_entry->load_complete_action = LOAD_COMPLETE_AUTOCOMPLETE;
-
- break;
-
- case REFRESH_INVALID_INPUT:
- case REFRESH_INCOMPLETE_HOSTNAME:
- case REFRESH_NONEXISTENT:
- case REFRESH_NOT_LOCAL:
- /* We don't beep or anything, since this is autocompletion - the user
- * didn't request any action explicitly.
- */
- break;
-
- default:
- g_assert_not_reached ();
- }
-}
-
#ifdef G_OS_WIN32
static gint
insert_text_callback (GtkFileChooserEntry *chooser_entry,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]