[Xfce4-commits] <xfce-utils:completion> Add a maximum length for the history list.

Jérôme Guelfucci noreply at xfce.org
Thu Nov 4 13:28:01 CET 2010


Updating branch refs/heads/completion
         to b19bc6f0113e1b76ca21b953b9bed9469493e085 (commit)
       from 8448cf33026d38d7a7697fd6494ca22c6c2a5641 (commit)

commit b19bc6f0113e1b76ca21b953b9bed9469493e085
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Thu Nov 4 13:25:31 2010 +0100

    Add a maximum length for the history list.
    
    It is currently set to 20 items.

 xfrun/xfrun-history.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/xfrun/xfrun-history.c b/xfrun/xfrun-history.c
index 1a572a6..f438b10 100644
--- a/xfrun/xfrun-history.c
+++ b/xfrun/xfrun-history.c
@@ -24,6 +24,8 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
 
+#define MAX_LENGTH 20
+
 struct _XfrunHistoryPrivate
 {
   GList       *history;
@@ -147,7 +149,7 @@ static GList
   list = NULL;
 
   /* Add the lines to the history list */
-  for (i = 0; history_contents[i] != NULL; i++)
+  for (i = 0; history_contents[i] != NULL && i < MAX_LENGTH; i++)
     {
       XfrunHistoryItem *item;
 
@@ -488,6 +490,7 @@ void xfrun_history_add (XfrunHistory *history,
 {
   XfrunHistoryItem *item;
   GList            *add;
+  guint             length;
 
   g_return_if_fail (XFRUN_IS_HISTORY (history));
   g_return_if_fail (command != NULL);
@@ -507,6 +510,23 @@ void xfrun_history_add (XfrunHistory *history,
                           add);
 
   g_list_free (add);
+
+  if ((length = g_list_length (history->priv->history)) > MAX_LENGTH)
+    {
+      XfrunHistoryItem *last_item;
+      GList            *remove_list = NULL;
+
+      last_item = g_list_nth_data (history->priv->history, length);
+      remove_list = g_list_append (remove_list, last_item);
+
+      history->priv->history =
+        g_list_remove (history->priv->history, last_item);
+      g_completion_remove_items (history->priv->full_completion,
+                                 remove_list);
+
+      g_list_free (remove_list);
+      g_slice_free (XfrunHistoryItem, last_item);
+    }
 }
 
 



More information about the Xfce4-commits mailing list