Index: /trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java	(revision 7484)
+++ /trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java	(revision 7485)
@@ -521,5 +521,6 @@
     }
 
-    /** When a user right-clicks within the trees on the collection pane view they are presented with a small popup menu of context based options. This class provides such functionality.
+
+    /** When a user right-clicks within the workspace and collection trees they are presented with a small popup menu of context based options. This class provides such functionality.
      */
     private class GPopupMenu
@@ -527,133 +528,170 @@
 	implements ActionListener {
 
-	/** The tree over which the right click action occured. */
+	/** The tree over which the right click action occurred. */
 	private DragTree tree = null;
-	/** The file record over which the right click action occured, if any. */
+	/** The tree nodes selected when the right click action occurred. */
+	private TreePath[] selection_paths = null;
+	/** The file record over which the right click action occurred, if any. */
 	private FileNode node = null;
-	private JMenuItem collapse_expand_folder_menuitem;
-	/** A menu item enabled if a delete action is appropriate in the menus current context. */
+
+	private JMenuItem create_shortcut = null;
+	private JMenuItem delete_shortcut = null;
+	private JMenuItem collapse_folder = null;
+	private JMenuItem expand_folder = null;
 	private JMenuItem delete = null;
-	/** A menu item enabled if a special directory mapping is appropriate in the menus current context. */
-	private JMenuItem map = null;
-	/** A menu item enabled if a new folder action is appropriate in the menus current context. */
+	private JMenuItem metaaudit = null;
 	private JMenuItem new_folder = null;
-	/** A menu item enabled if a show meta-audit dialog action is appropriate in the menus current context. */
-	private JMenuItem show_metaaudit = null;
-	/** A menu item allowing a user to unmap a special directory, if and only if a special directory is selected. */
-	private JMenuItem unmap = null;
-	private TreePath path = null;
-	/** Constructor. */
-	public GPopupMenu(DragTree tree, MouseEvent event) {
+
+
+	public GPopupMenu(DragTree tree, MouseEvent event)
+	{
 	    super();
 	    this.tree = tree;
-	    this.path = tree.getClosestPathForLocation(event.getX(), event.getY());
-	    if(path != null) {
-		node = (FileNode)path.getLastPathComponent();
-		// Any folder node gets a menu item allowing you to collapse or expand it depending on its current status
-		if(!node.isLeaf()) {
-		    // Collapse
-		    if(tree.isExpanded(path)) {
-			collapse_expand_folder_menuitem = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C);
-		    }
-		    // Expand
-		    else {
-			collapse_expand_folder_menuitem = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O);
-		    }
-		    collapse_expand_folder_menuitem.addActionListener(this);
-		    add(collapse_expand_folder_menuitem);
-		}
-		// Set Options based on selection and tree
-		if(tree.getSelectionCount() != 0 && tree == collection_tree) {
-		    String[] args = new String[1];
-		    args[0] = collection_tree.getSelectionDetails();
-		    show_metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", args), KeyEvent.VK_A);
-		    show_metaaudit.addActionListener(this);
-		    add(show_metaaudit);
-		}
-		if(tree == collection_tree && node != null && node.getFile() != null && node.getFile().isDirectory() && !node.isReadOnly()) {
-		    new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N);
-		    new_folder.addActionListener(this);
-		    add(new_folder);
-		    add(new JSeparator());
-		}
-		if(tree == collection_tree && tree.getSelectionCount() != 0 && node != null && !node.isReadOnly()) {
-		    delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D);
-		    delete.addActionListener(this);
-		    add(delete);
-		}
-		if(tree == workspace_tree && node != null && !node.isLeaf()) {
-		    String node_name = node.toString();
-		    FileNode root = (FileNode) tree.getModel().getRoot();
-		    if(!node_name.equals(Dictionary.get("Tree.World")) && !node_name.equals(Dictionary.get("Tree.Root")) && !node_name.equals(Dictionary.get("Tree.Public")) && !node_name.equals(Dictionary.get("Tree.Private"))) {
-			// You can unmap 1st level nodes.
-			if(root.getIndex(node) != -1) {
-			    unmap = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R);
-			    unmap.addActionListener(this);
-			    add(unmap);
-			}
-			// Or map any other level directories.
-			else {
-			    map = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S);
-			    map.addActionListener(this);
-			    add(map);
-			}
-		    }
-		}
-		show(tree, event.getX(), event.getY());
-	    }
-	}
+
+	    // Get the paths currently selected in the tree
+	    selection_paths = tree.getSelectionPaths();
+
+	    // Create an appropriate context menu, based on what is selected
+	    buildContextMenu(selection_paths);
+
+	    // Show the popup menu on screen
+	    show(tree, event.getX(), event.getY());
+	}
+
+
+	private void buildContextMenu(TreePath[] selection_paths)
+	{
+	    // If nothing is selected, only the new folder option is available
+	    if (selection_paths == null) {
+		new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N);
+		new_folder.addActionListener(this);
+		add(new_folder);
+
+		node = (FileNode) tree.getModel().getRoot();
+		return;
+	    }
+
+	    Gatherer.println("Number of files/folders selected: " + selection_paths.length);
+
+	    // Collection tree: display meta-audit option and delete options
+	    if (tree == collection_tree) {
+		String[] args = new String[1];
+		args[0] = collection_tree.getSelectionDetails();
+		metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", args), KeyEvent.VK_A);
+		metaaudit.addActionListener(this);
+		add(metaaudit);
+
+		delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D);
+		delete.addActionListener(this);
+		add(delete);
+	    }
+
+	    // Only meta-audit and delete are available if multiple items are selected...
+	    if (selection_paths.length > 1) {
+		return;
+	    }
+
+	    TreePath path = selection_paths[0];
+	    node = (FileNode) path.getLastPathComponent();
+
+	    // There are currently no options for plain files
+	    if (node.isLeaf()) {
+		return;
+	    }
+
+	    // ---- Options for folder nodes ----
+	    // Collapse or expand, depending on current status
+	    if (tree.isExpanded(path)) {
+		collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C);
+		collapse_folder.addActionListener(this);
+		add(collapse_folder);
+	    }
+	    else {
+		expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O);
+		expand_folder.addActionListener(this);
+		add(expand_folder);
+	    }
+
+	    // New folder option, for collection tree only
+	    if (tree == collection_tree && !node.isReadOnly()) {
+		new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N);
+		new_folder.addActionListener(this);
+		add(new_folder);
+	    }
+
+	    // Create/remove shortcut option, for workspace tree only
+	    if (tree == workspace_tree) {
+		// The "built-in" folders can't be modified
+		String node_name = node.toString();
+		if (node_name.equals(Dictionary.get("Tree.World")) || node_name.equals(Dictionary.get("Tree.Root")) || node_name.equals(Dictionary.get("Tree.Public")) || node_name.equals(Dictionary.get("Tree.Private"))) {
+		    return;
+		}
+
+		// You can unmap 1st level nodes
+		FileNode root = (FileNode) tree.getModel().getRoot();
+		if (root.getIndex(node) != -1) {
+		    delete_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R);
+		    delete_shortcut.addActionListener(this);
+		    add(delete_shortcut);
+		}
+		// Or map any other level directories
+		else {
+		    create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S);
+		    create_shortcut.addActionListener(this);
+		    add(create_shortcut);
+		}
+	    }
+	}
+
 
 	/** Called whenever one of the menu items is actioned apon, this method then causes the appropriate effect. */
-	public void actionPerformed(ActionEvent event) {
-	    Object source = event.getSource();
-	    if(source == delete) {
-		// Retrieve the selection. Of course this gets a bit tricky as the user may have right clicked over a node not in the current selection, in which case we remove only that node.
-		TreePath[] selection_paths = tree.getSelectionPaths();
-		if(selection_paths != null) {
-		    FileNode[] source_nodes = new FileNode[selection_paths.length];
-		    boolean found = false;
-		    for(int i = 0; i < selection_paths.length; i++) {
-			source_nodes[i] = (FileNode) selection_paths[i].getLastPathComponent();
-			if(node != null) {
-			    found = found || source_nodes[i].equals(node);
-			}
-		    }
-		    if(node != null && !found) {
-			source_nodes = null;
-			source_nodes = new FileNode[1];
-			source_nodes[0] = node;
-		    }
-		    // Fire a delete action
-		    Gatherer.f_man.action(tree, source_nodes, bin_button, null);
-		    source_nodes = null;
-		}
-		selection_paths = null;
-	    }
-	    else if(source == map && node != null) {
-		MappingPrompt mp = new MappingPrompt(node.getFile());
-		mp.destroy();
-		mp = null;
-	    }
-	    else if(source == new_folder && node != null) {
-		Gatherer.f_man.newFolder(tree, node);
-	    }
-	    else if(source == show_metaaudit) {
-		Gatherer.g_man.showMetaAuditBox();
-	    }
-	    else if(source == unmap && node != null) {
-		Gatherer.c_man.removeDirectoryMapping(node);
-	    }
-	    else if(source == collapse_expand_folder_menuitem && path != null && node != null && !node.isLeaf()) {
-		// Collapse
-		if(tree.isExpanded(path)) {
-		    tree.collapsePath(path);
-		}
-		// Expand
-		else {
-		    tree.expandPath(path);
-		}
-	    }
-	}
-    }
+	public void actionPerformed(ActionEvent event)
+	{
+  	    Object source = event.getSource();
+
+	    // Create shortcut
+	    if (source == create_shortcut) {
+ 		MappingPrompt mp = new MappingPrompt(node.getFile());
+ 		mp.destroy();
+	    }
+
+	    // Delete shortcut
+  	    else if (source == delete_shortcut) {
+  		Gatherer.c_man.removeDirectoryMapping(node);
+  	    }
+
+	    // Collapse folder
+	    else if (source == collapse_folder) {
+		tree.collapsePath(selection_paths[0]);
+	    }
+
+	    // Expand folder
+	    else if (source == expand_folder) {
+		tree.expandPath(selection_paths[0]);
+	    }
+
+	    // Delete
+	    else if (source == delete) {
+		FileNode[] source_nodes = new FileNode[selection_paths.length];
+		for (int i = 0; i < selection_paths.length; i++) {
+		    source_nodes[i] = (FileNode) selection_paths[i].getLastPathComponent();
+		}
+
+		// Fire a delete action
+		Gatherer.f_man.action(tree, source_nodes, bin_button, null);
+	    }
+
+	    // Meta-audit
+	    else if (source == metaaudit) {
+ 		Gatherer.g_man.showMetaAuditBox();
+ 	    }
+
+	    // New folder
+  	    else if (source == new_folder) {
+ 		Gatherer.f_man.newFolder(tree, node);
+ 	    }
+  	}
+    }
+
 
     /** This class listens for certain key presses, such as [Enter] or [Delete], and responds appropriately. */
