Index: /main/trunk/gli/src/org/greenstone/gatherer/file/FileCopiedSuccessListener.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/file/FileCopiedSuccessListener.java	(revision 34288)
+++ /main/trunk/gli/src/org/greenstone/gatherer/file/FileCopiedSuccessListener.java	(revision 34288)
@@ -0,0 +1,36 @@
+/**
+ *############################################################################
+ * A component of the Greenstone Librarian Interface, part of the Greenstone
+ * digital library suite from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ *
+ * Copyright (C) 2020 New Zealand Digital Library Project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *############################################################################
+ */
+
+package org.greenstone.gatherer.file;
+
+
+import java.io.File;
+
+
+public interface FileCopiedSuccessListener
+{
+    /** Notification that a file has been successfully copied. */
+    public void fileCopiedSuccessfully(File new_file);
+}
Index: /main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java	(revision 34287)
+++ /main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java	(revision 34288)
@@ -517,5 +517,5 @@
 
     private class ReplaceTask
-	extends Thread
+	extends Thread implements FileCopiedSuccessListener
     {
 	private CollectionTree collection_tree = null;
@@ -563,29 +563,53 @@
 	    
 	    FileNode parent = (FileNode)collection_tree_node.getParent(); // store the original source's parent, need it several times after changing source
-	   
-	    if(!isSameLeafName) {
-		// If the file name of the replacing file is NOT the same as the one being replaced
-		// copy the new file in - but don't bring metadata
-		file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY);
-	    }
-	    
-	    if (Gatherer.isGsdlRemote) {
-		String collection_name = CollectionManager.getLoadedCollectionName();
-		Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node.getFile());
-		Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory);
-	    }
 
 	    if(isSameLeafName) {
 		// If the file name of the replacing file IS the same as the one being replaced
-		// perform a COPY operation, which will copy across metadata too, after confirming whether the user really wants to replace the source with identically named targed
+		// perform a COPY operation, which will copy across metadata too, after confirming whether the user really wants to replace the source with identically named target
+
+		// (a) First, this instance of ReplaceTask and no other starts listening to whether the user
+		// DIDN'T CANCEL out of an identical filename copy operation and if this local file copy
+		// was a success. If so, on successful file copy event fired (only then), the source file
+		// from the workspace tree will also be uploaded to the remote GS3 
+		file_queue.addFileCopiedSuccessListener(this); 
+
+		// (b) Now can finally add the COPY job to the queue
 		file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY);
+		
 	    } else {
-		// If the file name of the replacing file is NOT the same as the one being replaced, final step to finish off:
-		// do a replace of old file with new file
+		// If the file name of the replacing file is NOT the same as the one being replaced
+		// (a) copy the new file in - but don't bring metadata
+		file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY);
+		
+		// (b) final step to finish off: do a replace of old file with new file
 		file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
 	    }
 
+
 	    //DebugStream.setDebugging(false, "FileManager.ReplaceTask");
-
+	}
+    
+	
+	/** In order to detect that the user cancelled out of replacing an identically named target file, 
+	 * we now listen to events fired that the file was successfully copied across. Only then do we
+	 * bother transferring the source file (from the workspace) into the target location in the
+	 * collection on the remote file system. We don't do this if the user cancelled.
+	 */
+	public void fileCopiedSuccessfully(File new_file) {	    
+	    
+	    //DebugStream.setDebugging(true, "FileManager.ReplaceTask.fileCopiedSuccessfully");
+	    
+	    if (Gatherer.isGsdlRemote) {
+		File target_directory = this.collection_tree_node.getFile().getParentFile();
+		File collection_tree_node_file = this.collection_tree_node.getFile();
+		
+		String collection_name = CollectionManager.getLoadedCollectionName();
+		Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node_file);
+		Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory);
+	    }
+
+	    // stop listening to further events fired now that we've handled this event successfully
+	    file_queue.removeFileCopiedSuccessListener(this);
+	    //DebugStream.setDebugging(false, "FileManager.ReplaceTask.fileCopiedSuccessfully");
 	}
     }
Index: /main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java	(revision 34287)
+++ /main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java	(revision 34288)
@@ -69,5 +69,7 @@
     private GProgressBar progress = null;
 
-
+    /** The objects listening for FileCopiedSuccess events. */
+    private ArrayList file_copied_success_listeners = new ArrayList();
+    
     /** Constructor.
      */
@@ -83,5 +85,19 @@
     }
 
-
+    public void fireFileCopiedSuccessfully(File new_file) {
+	// Send the event off to all the matching Listeners
+	for (int i = 0; i < file_copied_success_listeners.size(); i++) {
+	    ((FileCopiedSuccessListener) file_copied_success_listeners.get(i)).fileCopiedSuccessfully(new_file);
+	}
+    }
+    public void addFileCopiedSuccessListener(FileCopiedSuccessListener listener) {
+	file_copied_success_listeners.add(listener);
+    }
+
+    public void removeFileCopiedSuccessListener(FileCopiedSuccessListener listener)
+    {
+	file_copied_success_listeners.remove(listener);
+    }
+    
     /** Add a new job to the queue, specifiying as many arguments as is necessary to complete this type of job (ie delete needs no target information).
      * @param id A long id unique to all jobs created by a single action.
@@ -410,4 +426,5 @@
 	try {
 	    copyFile(source_file, target_file, true);
+	    fireFileCopiedSuccessfully(source_file);
 	}
 	catch (FileAlreadyExistsException exception) {
Index: /main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java	(revision 34287)
+++ /main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java	(revision 34288)
@@ -383,5 +383,5 @@
 	    ElementOption elementToAdd = (ElementOption)chooseElementComboBox.getSelectedItem();
 	    addElementToConfigFile(elementToAdd);
-	    
+	    //editor.setCaretPosition(0);
 	}
     }
