From 6f229cdcdeed53d48128fded12d61461a4e00702 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jan 2018 00:22:25 +0100 Subject: [PATCH] Replace DoRefresh() with UseModel() helper function The new function both sets the new model and calls gtk_entry_completion_complete() instead of always doing first the one and then the other: if both calls needs to always be done together, it makes sense to have a function doing both of them. --- src/gtk/textentry.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 8757540204..137fbde9fc 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -240,10 +240,8 @@ public: AppendToStore(store, *i); } - gtk_entry_completion_set_model (GetEntryCompletion(), GTK_TREE_MODEL(store)); + UseModel(store); g_object_unref (store); - - DoRefresh(); } // Takes ownership of the pointer if it is non-NULL. @@ -375,9 +373,12 @@ private: } } - void DoRefresh() + // Really change the completion model (which may be NULL). + void UseModel(GtkListStore* store) { - gtk_entry_completion_complete (GetEntryCompletion()); + GtkEntryCompletion* const c = gtk_entry_get_completion (GetGtkEntry()); + gtk_entry_completion_set_model (c, GTK_TREE_MODEL(store)); + gtk_entry_completion_complete (c); } // Recreate the model to contain all completions for the current prefix. @@ -402,17 +403,15 @@ private: AppendToStore(store, s); } - gtk_entry_completion_set_model (GetEntryCompletion(), GTK_TREE_MODEL(store)); + UseModel(store); g_object_unref (store); m_newCompletionsNeeded = false; } else { - gtk_entry_completion_set_model (GetEntryCompletion(), NULL); + UseModel(NULL); } - - DoRefresh(); }