Code

patch for bug 1515934
authorbuliabyak <buliabyak@users.sourceforge.net>
Sun, 2 Jul 2006 23:26:45 +0000 (23:26 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sun, 2 Jul 2006 23:26:45 +0000 (23:26 +0000)
src/prefs-utils.cpp

index 54c83c1e9580805d1c37ab2d0f20d9bea031273f..a0851a3543693ffbe22d83c8aa653384192b29c7 100644 (file)
@@ -123,26 +123,32 @@ prefs_set_recent_file(gchar const *uri, gchar const *name)
     if (uri != NULL) {
         Inkscape::XML::Node *recent = inkscape_get_repr(INKSCAPE, "documents.recent");
         if (recent) {
-            Inkscape::XML::Node *child = sp_repr_lookup_child(recent, "uri", uri);
-            if (child) {
-                recent->changeOrder(child, NULL);
-            } else {
-                if (recent->childCount() >= max_documents) {
-                    child = recent->firstChild();
-                    // count to the last
-                    for (unsigned i = 0; i + 2 < max_documents; ++i) {
-                        child = child->next();
-                    }
-                    // remove all after the last
-                    while (child->next()) {
-                        sp_repr_unparent(child->next());
-                    }
+            // remove excess recent files
+            if (recent->childCount() >= max_documents) {
+                Inkscape::XML::Node *child = recent->firstChild();
+                // count to the last
+                for (unsigned i = 0; child && i + 1 < max_documents; ++i) {
+                    child = child->next();
                 }
-                child = sp_repr_new("document");
-                child->setAttribute("uri", uri);
-                recent->addChild(child, NULL);
+                // remove all after the last
+                while (child) {
+                    Inkscape::XML::Node *next = child->next();
+                    sp_repr_unparent(child);
+                    child = next;
+                }
+            }
+
+            if (max_documents > 0) {
+                Inkscape::XML::Node *child = sp_repr_lookup_child(recent, "uri", uri);
+                if (child) {
+                    recent->changeOrder(child, NULL);
+                } else {
+                    child = sp_repr_new("document");
+                    child->setAttribute("uri", uri);
+                    recent->addChild(child, NULL);
+                }
+                child->setAttribute("name", name);
             }
-            child->setAttribute("name", name);
         }
     }
 }