Author: nextgens
Date: 2007-11-20 20:03:48 +0000 (Tue, 20 Nov 2007)
New Revision: 15885

Modified:
   trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
Log:
BookmarkToadlet:
        * Add a description to each bookmark
        * some bugfixes

Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java   
2007-11-20 19:25:07 UTC (rev 15884)
+++ trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java   
2007-11-20 20:03:48 UTC (rev 15885)
@@ -194,7 +194,8 @@

                 } else if ("paste".equals(action) && cutedPath != null) {

-                    bookmarkManager.moveBookmark(cutedPath, bookmarkPath, 
true);
+                    bookmarkManager.moveBookmark(cutedPath, bookmarkPath);
+                    bookmarkManager.storeBookmarks();
                     cutedPath = null;

                 } else if ("edit".equals(action) || "addItem".equals(action) 
|| "addCat".equals(action)) {
@@ -223,6 +224,10 @@
                         form.addChild("label", "for", "key", 
(L10n.getString("BookmarkEditorToadlet.keyLabel") + ' '));
                         form.addChild("input", new String[]{"type", "id", 
"name", "size", "value"}, new String[]{"text", "key", "key", "50", key});
                         form.addChild("br");
+                        form.addChild("label", "for", "descB", 
(L10n.getString("BookmarkEditorToadlet.descLabel") + ' '));
+                        form.addChild("br");
+                        form.addChild("textarea", new String[]{"id", "name", 
"row", "cols", "value"}, new String[]{"descB", "descB", "3", "70", (item == 
null ? "" : item.getDescription())});
+                        form.addChild("br");
                         form.addChild("label", "for", "hasAnActivelink", 
(L10n.getString("BookmarkEditorToadlet.hasAnActivelinkLabel") + ' '));
                         if (item != null && item.hasAnActivelink()) {
                             form.addChild("input", new String[]{"type", "id", 
"name", "checked"}, new String[]{"checkbox", "hasAnActivelink", 
"hasAnActivelink", String.valueOf(item.hasAnActivelink())});
@@ -294,7 +299,8 @@
             String action = req.getPartAsString("action", MAX_ACTION_LENGTH);

             if (req.isPartSet("confirmdelete")) {
-                bookmarkManager.removeBookmark(bookmarkPath, true);
+                bookmarkManager.removeBookmark(bookmarkPath);
+                bookmarkManager.storeBookmarks();
                 HTMLNode successBox = 
content.addChild(pageMaker.getInfobox("infobox-success", 
L10n.getString("BookmarkEditorToadlet.deleteSucceededTitle")));
                 pageMaker.getContentNode(successBox).addChild("p", 
L10n.getString("BookmarkEditorToadlet.deleteSucceeded"));

@@ -312,9 +318,9 @@
                     bookmarkManager.renameBookmark(bookmarkPath, name);
                     boolean hasAnActivelink = req.isPartSet("hasAnActivelink");
                     if (bookmark instanceof BookmarkItem) {
-                        ((BookmarkItem) bookmark).setKey(new 
FreenetURI(req.getPartAsString("key", MAX_KEY_LENGTH)), hasAnActivelink);
+                        ((BookmarkItem) bookmark).update(new 
FreenetURI(req.getPartAsString("key", MAX_KEY_LENGTH)), hasAnActivelink, 
req.getPartAsString("descB", MAX_KEY_LENGTH));
                     }
-
+                    bookmarkManager.storeBookmarks();
                     HTMLNode successBox = 
content.addChild(pageMaker.getInfobox("infobox-success", 
L10n.getString("BookmarkEditorToadlet.changesSavedTitle")));
                     pageMaker.getContentNode(successBox).addChild("p", 
L10n.getString("BookmarkEditorToadlet.changesSaved"));

@@ -329,8 +335,8 @@
                         newBookmark = new BookmarkCategory(name);
                     }

-                    bookmarkManager.addBookmark(bookmarkPath, newBookmark, 
true);
-
+                    bookmarkManager.addBookmark(bookmarkPath, newBookmark);
+                    bookmarkManager.storeBookmarks();
                     HTMLNode successBox = 
content.addChild(pageMaker.getInfobox("infobox-success", 
L10n.getString("BookmarkEditorToadlet.addedNewBookmarkTitle")));
                     pageMaker.getContentNode(successBox).addChild("p", 
L10n.getString("BookmarkEditorToadlet.addedNewBookmark"));
                 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-11-20 19:25:07 UTC (rev 15884)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-11-20 20:03:48 UTC (rev 15885)
@@ -132,8 +132,9 @@
         return key;
     }

-    public synchronized void setKey(FreenetURI uri, boolean hasAnActivelink) {
-        key = uri;
+    public synchronized void update(FreenetURI uri, boolean hasAnActivelink, 
String description) {
+        this.key = uri;
+        this.desc = description;
         this.hasAnActivelink = hasAnActivelink;
     }

@@ -146,7 +147,7 @@
     }

     public String toString() {
-        return this.name + "###" + this.desc + "###" + this.hasAnActivelink + 
"###" + this.key.toString();
+        return this.name + "###" + (this.desc != null ? this.desc : "") + 
"###" + this.hasAnActivelink + "###" + this.key.toString();
     }

     public synchronized void setEdition(long ed, NodeClientCore node) {
@@ -194,4 +195,8 @@
     public boolean hasAnActivelink() {
         return hasAnActivelink;
     }
+    
+    public String getDescription() {
+        return desc;
+    }
 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-11-20 19:25:07 UTC (rev 15884)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-11-20 20:03:48 UTC (rev 15885)
@@ -99,7 +99,7 @@
                     String title = matcher.group(2);
                     boolean hasAnActiveLink = matcher.group(3).indexOf('|') > 
-1;
                     addBookmark(matcher.group(1), new BookmarkItem(key,
-                            title, hasAnActiveLink, node.alerts), false);
+                            title, hasAnActiveLink, node.alerts));
                 }
             } catch (MalformedURLException e) {
             }
@@ -164,7 +164,7 @@
         return null;
     }

-    public void addBookmark(BookmarkCategory parent, Bookmark bookmark, 
boolean store) {
+    public void addBookmark(BookmarkCategory parent, Bookmark bookmark) {
         if (bookmark instanceof BookmarkItem && ((BookmarkItem) 
bookmark).getKeyType().equals("USK")) {
             try {
                 USK u = ((BookmarkItem) bookmark).getUSK();
@@ -172,17 +172,14 @@
             } catch (MalformedURLException mue) {
             }
         }
-        if (store) {
-            storeBookmarks();
-        }
     }

-    public void addBookmark(String parentPath, Bookmark bookmark, boolean 
store) {
+    public void addBookmark(String parentPath, Bookmark bookmark) {
         BookmarkCategory parent = getCategoryByPath(parentPath);
         parent.addBookmark(bookmark);
         putPaths(parentPath + bookmark.getName() + ((bookmark instanceof 
BookmarkCategory) ? "/" : ""),
                 bookmark);
-        addBookmark(parent, bookmark, store);
+        addBookmark(parent, bookmark);
     }

     public void renameBookmark(String path, String newName) {
@@ -208,19 +205,15 @@
         storeBookmarks();
     }

-    public void moveBookmark(String bookmarkPath, String newParentPath, 
boolean store) {
+    public void moveBookmark(String bookmarkPath, String newParentPath) {
         Bookmark b = getBookmarkByPath(bookmarkPath);
-        addBookmark(newParentPath, b, false);
+        addBookmark(newParentPath, b);

         getCategoryByPath(parentPath(bookmarkPath)).removeBookmark(b);
         removePaths(bookmarkPath);
-
-        if (store) {
-            storeBookmarks();
-        }
     }

-    public void removeBookmark(String path, boolean store) {
+    public void removeBookmark(String path) {
         Bookmark bookmark = getBookmarkByPath(path);
         if (bookmark == null) {
             return;
@@ -230,7 +223,7 @@
             BookmarkCategory cat = (BookmarkCategory) bookmark;
             for (int i = 0; i < cat.size(); i++) {
                 removeBookmark(path + cat.get(i).getName() + ((cat.get(i) 
instanceof BookmarkCategory) ? "/"
-                        : ""), false);
+                        : ""));
             }
         } else {
             if (((BookmarkItem) bookmark).getKeyType().equals("USK")) {
@@ -246,10 +239,6 @@
         synchronized (bookmarks) {
             bookmarks.remove(path);
         }
-
-        if (store) {
-            storeBookmarks();
-        }
     }

     public void moveBookmarkUp(String path, boolean store) {
@@ -284,7 +273,7 @@

             BookmarkCategory cat = new BookmarkCategory(name);
             makeParents(parentPath(path));
-            addBookmark(parentPath(path), cat, false);
+            addBookmark(parentPath(path), cat);

             return cat;
         }
@@ -314,7 +303,7 @@
     }

     public void clear() {
-        removeBookmark("/", false);
+        removeBookmark("/");
         synchronized (bookmarks) {
             bookmarks.clear();
             bookmarks.put("/", MAIN_CATEGORY);
@@ -331,7 +320,7 @@
         return uris;
     }

-    private void storeBookmarks() {
+    public void storeBookmarks() {
         Logger.normal(this, "Attempting to save bookmarks to " + 
bookmarksFile.toString());
         SimpleFieldSet sfs;
         synchronized (bookmarks) {
@@ -378,7 +367,7 @@
                 SimpleFieldSet subset = sfs.subset(categories[i]);
                 BookmarkCategory currentCategory = new 
BookmarkCategory(categories[i]);
                 category.addBookmark(currentCategory);
-                addBookmark(currentCategory, currentCategory, false);
+                addBookmark(currentCategory, currentCategory);
                 readBookmarks(currentCategory, subset);
             }

@@ -389,7 +378,7 @@
                 try {
                     BookmarkItem item = new BookmarkItem(line, node.alerts);
                     category.addBookmark(item);
-                    addBookmark(category, item, false);
+                    addBookmark(category, item);
                 } catch (MalformedURLException e) {
                     Logger.error(this, "Error while adding one of the 
bookmarks :" + e.getMessage(), e);
                 }

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-11-20 
19:25:07 UTC (rev 15884)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-11-20 
20:03:48 UTC (rev 15885)
@@ -18,6 +18,7 @@
 BookmarkEditorToadlet.deleteCategoryConfirm=Are you sure you want to delete 
${bookmark} and all of its children?
 BookmarkEditorToadlet.deleteSucceeded=The bookmark has been deleted 
successfully.
 BookmarkEditorToadlet.deleteSucceededTitle=Delete Succeeded
+BookmarkEditorToadlet.descLabel=Description of the bookmark:
 BookmarkEditorToadlet.edit=Edit
 BookmarkEditorToadlet.editBookmarkTitle=Edit Bookmark
 BookmarkEditorToadlet.editCategoryTitle=Edit Category


Reply via email to