diff -r 6b90117d0e99 -r f16f6e0e5b69 src/pithos/content/operations.js
--- a/src/pithos/content/operations.js
+++ b/src/pithos/content/operations.js
@@ -1,26 +1,58 @@
+// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
+// (http://www.grnet.gr)
+//
+// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//   - Redistributions of source code must retain the above copyright
+//     notice, this list of conditions and the following disclaimer.
+//   - Redistributions in binary form must reproduce the above
+//     copyright notice, this list of conditions and the following
+//     disclaimer in the documentation and/or other materials provided
+//     with the distribution.
+//   - Neither the name of GRNET S.A. nor the names of its contributors
+//     may be used to endorse or promote products derived from this
+//     software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 //////////////////////////////////// CREATE FOLDER //////////////////////////////////////////////////////////////
 
 function create_folder_event() {
 	var new_directory = window.prompt("Enter the directory name:", "");
 	var source_directory = pithos_object.getSourceCurrentDirectory();
 	if (new_directory == null) {
-		alert('Directory creation canceled');
+		promptAlert('Directory creation canceled');
 		return;
 	} else {
 		if( create_folder(source_directory, new_directory) ) {
-			alert(source_directory + new_directory + ' - created');
+			promptAlert(source_directory + new_directory + ' - created');
 			pithos_object.refreshLists();
 		} else {
-			alert(source_directory + new_directory + ' - Directory creation failed');
+			promptAlert(source_directory + new_directory + ' - Directory creation failed');
 		}
 	}
 }
 
 function create_folder(uri, new_directory) {
-	if ( isRemoteDirectory(uri) ) {
+	if ( vfs.isRemoteResource(uri) ) {
 		var req = connection_obj.rest_request_post(uri, '?new=' + encodeURIComponent(new_directory), '');
 		return (connection_obj.success(req.status));
-	} else if ( isLocalDirectory(uri) ) {
+	} else if ( vfs.isLocalResource(uri) ) {
 		try {
 			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@@ -47,31 +79,27 @@
     var copied = 0;
 	
 	if (sources.length == 0) {
-		alert('No Files/Folders are selected');
+		promptAlert('No Files/Folders are selected');
 		return;
 	}
 	
 	if ( sources.length > 1 ) {
-		alert('Copy ' + sources.length + ' items to ' + destination);
+		promptAlert('Copy ' + sources.length + ' items to ' + destination);
 	} else if (sources.length == 1) {
-        alert('Copy ' + sources[0] + ' to ' + destination);
+        promptAlert('Copy ' + sources[0] + ' to ' + destination);
     }
 	
 	for ( i = 0; i < sources.length; i++ ) {
         if ( vfs.isDirectory(sources[i]) ) {
-            alert('Copy of directories is not supported!');
-            continue;
-        }
-
-		if ( !copy(sources[i], destination) ) {
-			alert('Could not copy - ' + sources[i] + '. Copy canceled!');
-			return;
-		} else {
-            copied++;
+            promptAlert('Copy of directories is not supported! Operation Canceled.');
+            return;
         }
 	}
+	
+	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+	window.openDialog("dialogs/operation_dialog.xul", "Copy Files", "chrome,resizable,centerscreen,window", "copy", sources, destination);
+	
     pithos_object.refreshLists();
-	alert('Copied ' + copied + ' file(s) (total: ' + sources.length + ')');
 }
 
 function copy(source, destination) {
@@ -87,7 +115,7 @@
         
 		return connection_obj.success(req.status);
 	} else if ( vfs.isLocalResource(source) && vfs.isRemoteResource(destination) ) {
-        var req = connection_obj.rest_request_put_upload(source, destination + encodeURIComponent(source_metadata.name), data, mimes.getByExtension(source_metadata.name));
+        var req = connection_obj.rest_request_put_upload(source, destination + source_metadata.name, data, mimes.getByExtension(source_metadata.name));
 
         return connection_obj.success(req.status);
 	} else if ( vfs.isRemoteResource(source) && vfs.isLocalResource(destination) ) {
@@ -127,29 +155,24 @@
 function move_event() {
 	var sources = pithos_object.getSelectedResources();
 	var destination = pithos_object.getDestinationCurrentDirectory();
-    var moved = 0;
 	
 	if (sources.length == 0) {
-		alert('No Files/Folders are selected');
+		promptAlert('No Files/Folders are selected');
 		return;
 	}
 	
 	for ( i = 0; i < sources.length; i++ ) {
         if ( vfs.isDirectory(sources[i]) ) {
-            alert('Moving directories is not supported!');
+            promptAlert('Moving directories is not supported!');
             continue;
         }
 
-		if ( !move(sources[i], destination) ) {
-			alert('Move failed (' + sources[i] + ')');
-			return;
-		} else {
-            moved++;
-        }
 	}
+	
+	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+	window.openDialog("dialogs/operation_dialog.xul", "Move Files", "chrome,resizable,centerscreen,window", "move", sources, destination);	
 
     pithos_object.refreshLists();
-	alert('Moved ' + moved + ' file(s) (total: ' + sources.length + ')');
 }
 
 function move(source, destination) {
@@ -184,17 +207,23 @@
 
 ////////////////////////////////////////////////////// DELETE /////////////////////////////////////////////////////////////////////
 
+function delete_all_async(uris) {
+	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+	window.openDialog("dialogs/operation_dialog.xul", "Delete Files", "chrome,resizable,centerscreen,window", "delete_all", uris);
+	pithos_object.refreshLists();    
+}
+
 function delete_context_menu(uri) {
 	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 	var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
 	var result = prompt.confirm(window, "Confirm action", "Delete " + uri + "?");
 	if ( result ) {
 		if ( !delete_resource(uri) ) {
-			alert('Cannot delete ' + uri);
+			promptAlert('Cannot delete ' + uri);
 			return;
 		}
 	} else {
-		alert('Action canceled');
+		promptAlert('Action canceled');
 		return;
 	}
 	pithos_object.refreshLists();
@@ -204,7 +233,7 @@
 	var resources = pithos_object.getSelectedResources();
 	
 	if (resources.length == 0) {
-		alert('No File/Directory is selected');		
+		promptAlert('No File/Directory is selected');
 		return;
 	}
 	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
@@ -217,24 +246,35 @@
 			if (!b) {
 				b = prompt.confirm(window, "Failed!", "Deletion of " + resources[i] + " failed. Continue?");
 				if (!b) {
-					alert('Action canceled');
+					promptAlert('Action canceled');
 					return;
 				}
 			}
 		}
 	} else {
-		alert('Action canceled');
+		promptAlert('Action canceled');
 		return;
 	}
-	alert('Removed ' + resources.length + ' items.');
+	promptAlert('Removed ' + resources.length + ' items.');
+	pithos_object.refreshLists();
+}
+
+function delete_context_menu_trash(uri) {
+    if(promptBox('Realy delete ' + uri)) {
+        if ( delete_resource(uri) ) {
+            promptAlert(uri + ' purged');
+        }
+    } else {
+        promptAlert('Purge canceled');
+    }
 	pithos_object.refreshLists();
 }
 
 function delete_resource(uri) {
-	if ( isRemoteDirectory(uri) ) {
+	if ( vfs.isRemoteResource(uri) ) {
 		var req = connection_obj.rest_request_delete(uri, '?trash=', '');
 		return connection_obj.success(req.status);
-	} else if ( isLocalDirectory(uri) ) {
+	} else if ( vfs.isLocalResource(uri) ) {
 		try {
 			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@@ -260,21 +300,21 @@
 	var result = prompt.confirm(window, "Confirm action", "Delete " + uri + "?");
 	if ( result ) {
 		if ( !movetotrash_resource(uri) ) {
-			alert('Cannot delete ' + uri);
+			promptAlert('Cannot delete ' + uri);
 			return;
 		}
 	} else {
-		alert('Action canceled');
+		promptAlert('Action canceled');
 		return;
 	}
 	pithos_object.refreshLists();
 }
 
 function movetotrash_resource(uri) {
-	if ( isRemoteDirectory(uri) ) {
+	if ( vfs.isRemoteResource(uri) ) {
 		var req = connection_obj.rest_request_post(uri, '?trash=', '');
 		return connection_obj.success(req.status);
-	} else if ( isLocalDirectory(uri) ) {
+	} else if ( vfs.isLocalResource(uri) ) {
 		try {
 			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@@ -308,7 +348,7 @@
 	// Create a parameter list
 	var params = { inp: source, out: null };
 	
-	window.openDialog("share/addshare.xul", "Share item", "chrome,dialog,modal,resizable",params);
+	window.openDialog("share/addshare.xul", "Share item", "chrome,dialog,resizable,centerscreen",params);
     connection_obj.get_shared_data();
 	pithos_object.refreshLists();
 }
@@ -348,10 +388,10 @@
             connection_obj.get_shared_data();
             pithos_object.refreshLists();
         } else {
-            alert('Unshare failed');
+            promptAlert('Unshare failed');
         }
 	} else {
-		alert('Unshare process canceled');
+		promptAlert('Unshare process canceled');
 	}
 }
 
@@ -397,17 +437,17 @@
 	var new_name = window.prompt("Enter the new name:", "");
 	if ( new_name != null ) {
 		if ( !rename_resource(uri, new_name) ) {
-			alert('Cannot rename ' + uri + ' to ' + new_name);
+			promptAlert('Cannot rename ' + uri + ' to ' + new_name);
 			return;
 		}
 	} else {
-		alert('Action canceled');
+		promptAlert('Action canceled');
 	}
 	pithos_object.refreshLists();
 }
 
 function rename_resource(uri, new_name) {
-	if ( isRemoteDirectory(uri) ) {
+	if ( vfs.isRemoteResource(uri) ) {
 		var update = new Object();
 		if ( vfs.isFile(uri) ) {
 			update.name = new_name;
@@ -416,7 +456,7 @@
 		}
 		var req = connection_obj.rest_request_post(uri, '?update=', jsonToString(update));
 		return (connection_obj.success(req.status));
-	} else if ( isLocalDirectory(uri) ) {
+	} else if ( vfs.isLocalResource(uri) ) {
 		try {
 			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@@ -459,13 +499,13 @@
 
 function enable_version_event(uri) {
     if ( vfs.isLocalResource(uri) ) {
-        alert('Cannot enable versioning in local files');
+        promptAlert('Cannot enable versioning in local files');
         return;
     }
     if ( enable_version_resource(uri) ) {
-        alert('File versioning is enabled');
+        promptAlert('File versioning is enabled');
     } else {
-        alert('Could not enable file versioning for ' + uri);
+        promptAlert('Could not enable file versioning for ' + uri);
     }
 }
 
@@ -482,17 +522,66 @@
 }
 
 function download_version_event(uri, current_version) {
-    var version = window.prompt("Download version:", current_version);
-    if (version != null) {
-        if ( (new Number(version) >= 1) && (new Number(version) <= current_version) ) {
-            var local_url = connection_obj.create_request_get(uri) + '&version=' + version;
+    //var version = window.prompt("Download version:", current_version);
+    var versions = new Array();
+    var outChoice = new Object();
+
+    for ( i = 0; i < current_version; i++ ) {
+        versions.push(i + 1);
+    }
+
+    if (promptSelect('Open Resource', 'Download version:', versions, outChoice)) {
+        var version_number = new Number(versions[outChoice.value]);
+        if ( (version_number >= 1) && (version_number <= current_version) ) {
+            var local_url = connection_obj.create_request_get(uri) + '&version=' + version_number;
             window.open(local_url);
         } else {
-            alert('Invalid version number (' + version + '). Available versions: 1 ... ' + current_version);
+            promptAlert('Invalid version number (' + version_number + '). Available versions: 1 ... ' + current_version);
         }            
     } else {
-        alert('Action canceled');
+        promptAlert('Action canceled');
     }
 }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////// UNDELETE ///////////////////////////////////////////////////////////////////////////////
+
+function restore_context_menu_trash(uri) {
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+    var theuri = uri;
+    var theobj = vfs.getResourceMetadata(theuri);
+
+    // Set the metadata delete property to false (i.e. not deleted)
+    theobj.deleted = false;
+
+    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
+    var theitem_with_path = '';
+    
+    if (theobj.hasOwnProperty('directoryName')) {
+        theitem_with_path = theobj.parentFolder + '/' + theobj.directoryName;
+        theitem_with_path = theitem_with_path.replace(connection_obj.user_homepage().fileroot, "");
+    } else {
+        theitem_with_path = theobj.path + theobj.name;
+    }
+
+    if (prompts.confirm(window, "Confirm action", "Are you sure you want to restore " + theitem_with_path + ' ?')) {
+        // trim the trailing slash ...
+        theuri = theuri.replace(/\/$/,'');
+        if (restore_resource(theuri)) {
+            promptAlert(theuri + ' succesfully restored');
+	    pithos_object.refreshLists();
+        } else {
+            promptAlert('Restoration of ' + theuri + ' failed');
+        }
+    }
+}
+
+function restore_resource(uri) {
+    var retcode = connection_obj.rest_request_post(uri,'?restore=', '');
+    return connection_obj.success(retcode.status);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
