diff options
author | Martin Krohn <martin.krohn@web.de> | 2020-05-19 12:53:27 +0200 |
---|---|---|
committer | Andre Miranda <andreldm@xfce.org> | 2020-05-23 19:14:43 -0300 |
commit | fbc60adf654e657537daf7e1a942cd15e7acfe01 (patch) | |
tree | 6dce6bd40d900c4a0b7a899ac2045d7990655f68 /src | |
parent | 562385f086cb21c3497f2e79e1afbb8abbf9b731 (diff) | |
download | xfce4-appfinder-fbc60adf654e657537daf7e1a942cd15e7acfe01.tar.gz |
Record last commands only once (Bug #15767)
First check the history (model->items_hash) if the command is already in.
Only if the command is not in yet, add it to the history
Diffstat (limited to 'src')
-rw-r--r-- | src/appfinder-model.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/appfinder-model.c b/src/appfinder-model.c index 35c34cd..08e357b 100644 --- a/src/appfinder-model.c +++ b/src/appfinder-model.c @@ -1112,7 +1112,7 @@ xfce_appfinder_model_file_get_mtime (GFile *file) -static void +static gboolean xfce_appfinder_model_history_insert (XfceAppfinderModel *model, const gchar *command) { @@ -1122,12 +1122,18 @@ xfce_appfinder_model_history_insert (XfceAppfinderModel *model, GSList *lp; guint idx; - appfinder_return_if_fail (XFCE_IS_APPFINDER_MODEL (model)); - appfinder_return_if_fail (IS_STRING (command)); + appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE); + appfinder_return_val_if_fail (IS_STRING (command), FALSE); /* add new command */ item = g_slice_new0 (ModelItem); item->command = g_strdup (command); + if (g_slist_find_custom (model->items, item, xfce_appfinder_model_item_compare) != NULL) + { + APPFINDER_DEBUG ("Skip adding %s to the model as it's already contained.", command); + g_slice_free (ModelItem, item); + return FALSE; + } item->icon = GDK_PIXBUF (g_object_ref (G_OBJECT (model->command_icon))); item->icon_large = GDK_PIXBUF (g_object_ref (G_OBJECT (model->command_icon_large))); model->items = g_slist_insert_sorted (model->items, item, xfce_appfinder_model_item_compare); @@ -1147,6 +1153,7 @@ xfce_appfinder_model_history_insert (XfceAppfinderModel *model, gtk_tree_path_free (path); g_hash_table_insert (model->items_hash, item->command, item); + return TRUE; } @@ -1200,8 +1207,7 @@ xfce_appfinder_model_history_changed (GFileMonitor *monitor, { /* look for new commands */ command = g_strndup (contents, end - contents); - if (g_hash_table_lookup (model->items_hash, command) == NULL) - xfce_appfinder_model_history_insert (model, command); + xfce_appfinder_model_history_insert (model, command); g_free (command); } contents = end + 1; @@ -2542,8 +2548,9 @@ xfce_appfinder_model_save_command (XfceAppfinderModel *model, if (!IS_STRING (command)) return TRUE; - /* add command to the model */ - xfce_appfinder_model_history_insert (model, command); + /* add command to the model history if unique, else just return */ + if (!xfce_appfinder_model_history_insert (model, command)) + return TRUE; /* add to the hashtable */ APPFINDER_DEBUG ("saving history"); |