int nbVolumes = volumes.length;
final MainFrame mainFrame = folderPanel.getMainFrame();
MnemonicHelper mnemonicHelper = new MnemonicHelper(); // Provides mnemonics and ensures uniqueness
JMenuItem item;
MuAction action;
String volumeName;
boolean useExtendedDriveNames = fileSystemView!=null;
ArrayList<JMenuItem> itemsV = new ArrayList<JMenuItem>();
for(int i=0; i<nbVolumes; i++) {
action = new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), volumes[i]);
volumeName = volumes[i].getName();
// If several volumes have the same filename, use the volume's path for the action's label instead of the
// volume's path, to disambiguate
for(int j=0; j<nbVolumes; j++) {
if(j!=i && volumes[j].getName().equalsIgnoreCase(volumeName)) {
action.setLabel(volumes[i].getAbsolutePath());
break;
}
}
item = popupMenu.add(action);
setMnemonic(item, mnemonicHelper);
// Set icon from cache
Icon icon = iconCache.get(volumes[i]);
if (icon!=null) {
item.setIcon(icon);
}
if(useExtendedDriveNames) {
// Use the last known value (if any) while we update it in a separate thread
String previousExtendedName = extendedNameCache.get(volumes[i]);
if(previousExtendedName!=null)
item.setText(previousExtendedName);
}
itemsV.add(item); // JMenu offers no way to retrieve a particular JMenuItem, so we have to keep them
}
new RefreshDriveNamesAndIcons(popupMenu, itemsV).start();
popupMenu.add(new JSeparator());
// Add boookmarks
java.util.List<Bookmark> bookmarks = BookmarkManager.getBookmarks();
int nbBookmarks = bookmarks.size();
Bookmark b;
if(nbBookmarks>0) {
for(int i=0; i<nbBookmarks; i++) {
b = bookmarks.get(i);
item = popupMenu.add(new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), b));
setMnemonic(item, mnemonicHelper);
}
}
else {
// No bookmark : add a disabled menu item saying there is no bookmark
popupMenu.add(Translator.get("bookmarks_menu.no_bookmark")).setEnabled(false);
}
popupMenu.add(new JSeparator());
// Add 'Network shares' shortcut
if(FileFactory.isRegisteredProtocol(FileProtocols.SMB)) {
action = new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), new Bookmark(Translator.get("drive_popup.network_shares"), "smb:///"));
action.setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.NETWORK_ICON_NAME));
setMnemonic(popupMenu.add(action), mnemonicHelper);
}
// Add Bonjour services menu
setMnemonic(popupMenu.add(new BonjourMenu() {