Index: gli/trunk/src/org/greenstone/gatherer/collection/CollectionTree.java
===================================================================
--- gli/trunk/src/org/greenstone/gatherer/collection/CollectionTree.java	(revision 15106)
+++ gli/trunk/src/org/greenstone/gatherer/collection/CollectionTree.java	(revision 15107)
@@ -99,9 +99,11 @@
 	    JLabel tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
 
-	    // Mark explodable files with a different icon
-	    if (value instanceof CollectionTreeNode && ((CollectionTreeNode) value).isExplodable()) {
-		tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON);
-	    }
-
+	    // Mark explodable files and SrcReplaceable files with a different icon (Green file icon)
+	    if(value instanceof CollectionTreeNode) {
+		if(((CollectionTreeNode) value).isExplodable() || ((CollectionTreeNode) value).isSrcReplaceable()) {
+		    tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON);
+		}
+	    }
+	        
 	    return tree_cell;
 	}
@@ -125,8 +127,10 @@
 	private JMenuItem expand_folder = null;
 	private JMenuItem explode_metadata_database = null;
+	private JMenuItem replace_srcdoc_with_html = null;
 	private JMenuItem delete = null;
 	private JMenuItem metaaudit = null;
 	private JMenuItem new_folder = null;
 	private JMenuItem new_dummy_doc = null;
+	private JMenuItem refresh = null; // for refreshing folder view
 	private JMenuItem open_externally = null;
 	private JMenuItem rename = null;
@@ -202,4 +206,36 @@
 	}
 
+	/** Checks whether the files selected are of the same filetype (have the same extension).
+	 * @param selectedFilePaths - the full file paths to the treenodes selected in the 
+	 * collection fileview. 
+	 * @return true if the file extensions of all the selected files are the same. False is 
+	 * returned if the file extension of any selected file is different (this means that if 
+	 * a folder was selected, false would be returned). False is also returned if nothing was
+	 * selected.
+	 * For use with replace_srcdoc_with_html.pl
+	*/
+	private boolean selectedFilesOfSameType(TreePath[] selectedFilePaths) {
+	    if(selectedFilePaths == null || selectedFilePaths.length <= 0)
+		return false;
+
+	    boolean sameExtension = true;
+
+	    // get just the filename from the path and extract its extension
+	    String firstFile = selectedFilePaths[0].getLastPathComponent().toString();
+	    int period = firstFile.lastIndexOf('.');
+	    if(period == -1) { // someone could have selected a folder
+		return false;
+	    }
+	    String extension = firstFile.substring(period); // includes period
+
+	    // compare with the other selected files' extensions:
+	    for(int i = 1; i < selectedFilePaths.length && sameExtension; i++) {
+		String otherFile = selectedFilePaths[i].getLastPathComponent().toString();
+		String otherFileExt = otherFile.substring(otherFile.lastIndexOf('.'));
+		if(!extension.equals(otherFileExt)) 
+		    sameExtension = false;
+	    }
+	    return sameExtension;
+	}
 
 	private void buildContextMenu(TreePath[] selection_paths)
@@ -215,4 +251,8 @@
 		add(new_dummy_doc);
 
+		refresh = new JMenuItem(Dictionary.get("CollectionPopupMenu.Refresh"));
+		refresh.addActionListener(this);
+		add(refresh);
+
 		node = (CollectionTreeNode) collection_tree.getModel().getRoot();
 		return;
@@ -228,5 +268,19 @@
 	    add(delete);
 
-	    // Only meta-audit and delete are available if multiple items are selected...
+	    // The src doc replaceable (with html file) option is only available when all files selected are of the
+	    // same type (same extension). For srcreplaceable files only. Works with replace_srcdoc_with_html.pl
+	    CollectionTreeNode firstSelectedNode = (CollectionTreeNode)selection_paths[0].getLastPathComponent();
+	    if(firstSelectedNode.isSrcReplaceable()) { // test the first selected node
+		replace_srcdoc_with_html = new JMenuItem(Dictionary.get("Menu.Replace_SrcDoc_With_HTML"), KeyEvent.VK_H);
+		replace_srcdoc_with_html.addActionListener(this);		
+		add(replace_srcdoc_with_html);
+		
+		// Now the menu is there, grey it out if not all the files are of the same type
+		if(!selectedFilesOfSameType(selection_paths)) {
+		    replace_srcdoc_with_html.setEnabled(false);
+		} 
+	    }
+	   
+	    // Only meta-audit and delete (and possibly replace_srcdoc) are available if multiple items are selected...
 	    if (selection_paths.length > 1) {
 		return;
@@ -249,5 +303,5 @@
 		    add(explode_metadata_database);
 		}
-
+	
 		// Replace file
 		// !! TO DO: Remote building
@@ -294,6 +348,6 @@
 	/** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */
 	public void actionPerformed(ActionEvent event)
-	{
-  	    Object source = event.getSource();
+	{	
+	    Object source = event.getSource();
 
 	    // Collapse folder
@@ -310,4 +364,14 @@
 	    else if (source == explode_metadata_database) {
  		Gatherer.f_man.explodeMetadataDatabase(node.getFile());
+	    }
+	    
+	    // Replace source document with generated html (works with replace_srcdoc_with_html.pl)
+	    else if (source == replace_srcdoc_with_html) {
+		java.io.File[] source_files = new java.io.File[selection_paths.length];
+		for (int i = 0; i < selection_paths.length; i++) {
+		    CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent(); 
+		    source_files[i] = node.getFile();
+		}
+		Gatherer.f_man.replaceSrcDocWithHtml(source_files); // passing the selected files
 	    }
 
@@ -338,4 +402,9 @@
 	    }
 
+	    // Refresh action to reload folder view
+	    else if (source == refresh) { // Refresh collection tree
+		Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
+	    }
+
 	    // Open in external program
 	    else if (source == open_externally) {
