Commit fbc60adf authored by Martin Krohn's avatar Martin Krohn Committed by Andre Miranda
Browse files

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
parent 562385f0
Loading
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -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,7 +1207,6 @@ 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);
                          g_free (command);
                        }
@@ -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");