[freenet-cvs] r12982 - in trunk/freenet/src/freenet/clients/http: . bookmark

fred at freenetproject.org fred at freenetproject.org
Thu Apr 26 14:10:20 UTC 2007


Author: fred
Date: 2007-04-26 14:10:20 +0000 (Thu, 26 Apr 2007)
New Revision: 12982

Modified:
   trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
Log:
Fix cut/paste bug in the bookmarks editor

Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java	2007-04-26 12:58:09 UTC (rev 12981)
+++ trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java	2007-04-26 14:10:20 UTC (rev 12982)
@@ -34,7 +34,7 @@
 		super(client);
 		this.core = core;
 		this.bookmarkManager = core.bookmarkManager;
-		this.cutedPath = "";
+		this.cutedPath = null;
 	}
 	
 	private void addCategoryToList(BookmarkCategory cat, String path, HTMLNode list)
@@ -51,7 +51,7 @@
 			
 			actions.addChild("a", "href", "?action=del&bookmark=" + itemPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/delete.png", "delete", "Delete"});
 			
-			if("".equals(cutedPath))
+			if(cutedPath == null)
 				actions.addChild("a", "href", "?action=cut&bookmark=" + itemPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/cut.png", "cut", "Cut"});
 			
 			if(i != 0)
@@ -81,7 +81,7 @@
 			
 			actions.addChild("a", "href", "?action=addCat&bookmark=" + catPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/folder-new.png", "add category", "Add category"});
 			
-			if("".equals(cutedPath))
+			if(cutedPath == null)
 				actions.addChild("a", "href", "?action=cut&bookmark=" + catPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/cut.png", "cut", "Cut"});
 			
 			if(i != 0)
@@ -90,7 +90,7 @@
 			if(i != cats.size() -1)
 				actions.addChild("a", "href", "?action=down&bookmark=" + catPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/go-down.png", "down", "Go down"});
 
-			if(! "".equals(cutedPath) && ! catPath.equals(cutedPath))
+			if(cutedPath != null && ! catPath.startsWith(cutedPath) && ! catPath.equals(bookmarkManager.parentPath(cutedPath)))
 				actions.addChild("a", "href", "?action=paste&bookmark=" + catPath).addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/paste.png", "paste", "Paste"});
 			
 			subCat.addChild(actions);
@@ -108,7 +108,7 @@
 		actions.addChild("a", "href", "?action=addItem&bookmark=/").addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/bookmark-new.png", "add bookmark", "Add bookmark"});
 		actions.addChild("a", "href", "?action=addCat&bookmark=/").addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/folder-new.png", "add category", "Add category"});
 		
-		if(! "".equals(cutedPath))
+		if(cutedPath != null && ! "/".equals(bookmarkManager.parentPath(cutedPath)))
 			actions.addChild("a", "href", "?action=paste&bookmark=/").addChild("img", new String[] {"src", "alt", "title"}, new String[] {"/static/icon/paste.png", "paste", "Paste"});
 		
 		root.addChild(actions);
@@ -158,11 +158,10 @@
 
 				cutedPath = bookmarkPath;
 
-			} else if ("paste".equals(action) && ! "".equals(cutedPath)) {
-				bookmarkManager.addBookmark(bookmarkPath, bookmarkManager.getBookmarkByPath(cutedPath), false);
-				bookmarkManager.removeBookmark(cutedPath, true);
+			} else if ("paste".equals(action) && cutedPath != null) {
 				
-				cutedPath = "";
+				bookmarkManager.moveBookmark(cutedPath, bookmarkPath, true);
+				cutedPath = null;
 				
 			} else if (action.equals("edit") || action.equals("addItem") || action.equals("addCat")) {
 				
@@ -204,7 +203,7 @@
 			
 		}
 
-		if(! "".equals(cutedPath)) {
+		if(cutedPath != null) {
 			HTMLNode infoBox = content.addChild(ctx.getPageMaker().getInfobox("infobox-normal", "Cut/Paste"));
 			infoBox.addChild("#","Click on a paste icon or cancel.");
 			HTMLNode cancelForm = ctx.addFormChild(infoBox.addChild("p"), "", "cancelCutForm");
@@ -247,7 +246,7 @@
 				successBox.addChild("p", "The bookmark has been deleted successfully");
 				
 			} else if (req.isPartSet("cancelCut")) {
-				cutedPath = "";
+				cutedPath = null;
 			
 			} else if (action.equals("edit") || action.equals("addItem") || action.equals("addCat")) {
 				

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-04-26 12:58:09 UTC (rev 12981)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-04-26 14:10:20 UTC (rev 12982)
@@ -245,8 +245,9 @@
       throw new NullPointerException ();
     else {
       parent.addBookmark (b);
-      bookmarks.put (parentPath + b.getName () +
-		     ((b instanceof BookmarkCategory) ? "/" : ""), b);
+      putPaths(parentPath + b.getName () + ((b instanceof BookmarkCategory) ? "/" : ""), b);
+      
+  
     }
     if (store)
         node.storeConfig ();
@@ -266,7 +267,19 @@
     }
 
   }
-
+  
+  public void moveBookmark(String bookmarkPath, String newParentPath, boolean store) {
+	Bookmark b = getBookmarkByPath(bookmarkPath);
+  	addBookmark(newParentPath, b, false);
+	
+	getCategoryByPath(parentPath(bookmarkPath)).removeBookmark(b);
+	removePaths(bookmarkPath);
+	
+	if (store)
+		node.storeConfig ();
+	
+  }
+  
   public void removeBookmark (String path, boolean store) {
     Bookmark bookmark = getBookmarkByPath (path);
     if (bookmark == null)
@@ -332,7 +345,30 @@
       return cat;
     }
   }
+  
+    private void putPaths(String path, Bookmark b) {
 
+    bookmarks.put(path , b);
+    System.out.println("PUT " + path);
+    if(b instanceof BookmarkCategory) {  
+	  for(int i=0; i < ((BookmarkCategory) b).size(); i++) {
+                Bookmark child = ((BookmarkCategory) b).get(i);
+                putPaths(path + child.getName () + (child instanceof BookmarkItem ? "" : "/"), child);
+	  }
+      }
+
+  }
+  
+    private void removePaths(String path) {
+	if(getBookmarkByPath(path) instanceof BookmarkCategory){
+		BookmarkCategory cat = getCategoryByPath(path);
+  		for (int i=0; i < cat.size(); i++) {
+			removePaths(path +cat.get(i).getName() + (cat.get(i) instanceof BookmarkCategory ? "/" : ""));
+		}
+	}
+	bookmarks.remove(path);
+  }
+
   public void clear () {
 
     removeBookmark ("/", false);




More information about the cvs mailing list