Messages.setLanguageText(itemExplore, "MyTorrentsView.menu."
+ (use_open_containing_folder ? "open_parent_folder" : "explore"));
itemExplore.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (int i = data_sources.length - 1; i >= 0; i--) {
DiskManagerFileInfo info = (DiskManagerFileInfo) data_sources[i];
if (info != null) {
ManagerUtils.open(info, use_open_containing_folder);
}
}
}
});
itemExplore.setEnabled(hasSelection);
MenuItem itemRenameOrRetarget = null, itemRename = null, itemRetarget = null;
itemRenameOrRetarget = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRenameOrRetarget, "FilesView.menu.rename");
itemRenameOrRetarget.setData("rename", Boolean.valueOf(true));
itemRenameOrRetarget.setData("retarget", Boolean.valueOf(true));
itemRename = new MenuItem(menu, SWT.PUSH);
itemRetarget = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRename, "FilesView.menu.rename_only");
Messages.setLanguageText(itemRetarget, "FilesView.menu.retarget");
itemRename.setData("rename", Boolean.valueOf(true));
itemRename.setData("retarget", Boolean.valueOf(false));
itemRetarget.setData("rename", Boolean.valueOf(false));
itemRetarget.setData("retarget", Boolean.valueOf(true));
final MenuItem itemPriority = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(itemPriority, "FilesView.menu.setpriority");
final Menu menuPriority = new Menu(shell, SWT.DROP_DOWN);
itemPriority.setMenu(menuPriority);
final MenuItem itemHigh = new MenuItem(menuPriority, SWT.CASCADE);
itemHigh.setData("Priority", PRIORITY_HIGH);
Messages.setLanguageText(itemHigh, "FilesView.menu.setpriority.high");
final MenuItem itemLow = new MenuItem(menuPriority, SWT.CASCADE);
itemLow.setData("Priority", PRIORITY_NORMAL);
Messages.setLanguageText(itemLow, "FilesView.menu.setpriority.normal");
final MenuItem itemNumeric = new MenuItem(menuPriority, SWT.CASCADE);
itemNumeric.setData("Priority", PRIORITY_NUMERIC);
Messages.setLanguageText(itemNumeric, "FilesView.menu.setpriority.numeric");
final MenuItem itemSkipped = new MenuItem(menuPriority, SWT.CASCADE);
itemSkipped.setData("Priority", PRIORITY_SKIPPED);
Messages.setLanguageText(itemSkipped, "FilesView.menu.setpriority.skipped");
final MenuItem itemDelete = new MenuItem(menuPriority, SWT.CASCADE);
itemDelete.setData("Priority", PRIORITY_DELETE);
Messages.setLanguageText(itemDelete, "wizard.multitracker.delete"); // lazy but we're near release
new MenuItem(menu, SWT.SEPARATOR);
if (!hasSelection) {
itemOpen.setEnabled(false);
itemPriority.setEnabled(false);
itemRenameOrRetarget.setEnabled(false);
itemRename.setEnabled(false);
itemRetarget.setEnabled(false);
return;
}
boolean open = true;
boolean all_compact = true;
boolean all_skipped = true;
boolean all_priority = true;
boolean all_not_priority = true;
DiskManagerFileInfo[] dmi_array = new DiskManagerFileInfo[data_sources.length];
System.arraycopy(data_sources, 0, dmi_array, 0, data_sources.length);
int[] storage_types = manager.getStorageType(dmi_array);
for (int i = 0; i < dmi_array.length; i++) {
DiskManagerFileInfo file_info = dmi_array[i];
if (open && file_info.getAccessMode() != DiskManagerFileInfo.READ) {
open = false;
}
if (all_compact && storage_types[i] != DiskManagerFileInfo.ST_COMPACT && storage_types[i] != DiskManagerFileInfo.ST_REORDER_COMPACT ) {
all_compact = false;
}
if (all_skipped || all_priority || all_not_priority) {
if (file_info.isSkipped()) {
all_priority = false;
all_not_priority = false;
} else {
all_skipped = false;
// Only do this check if we need to.
if (all_not_priority || all_priority) {
if (file_info.getPriority() > 0 ) {
all_not_priority = false;
} else {
all_priority = false;
}
}
}
}
}
// we can only open files if they are read-only
itemOpen.setEnabled(open);
// can't rename files for non-persistent downloads (e.g. shares) as these
// are managed "externally"
itemRenameOrRetarget.setEnabled(manager.isPersistent());
itemRename.setEnabled(manager.isPersistent());
itemRetarget.setEnabled(manager.isPersistent());
itemSkipped.setEnabled(!all_skipped);
itemHigh.setEnabled(!all_priority);
itemLow.setEnabled(!all_not_priority);
itemDelete.setEnabled(!all_compact);
itemOpen.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (int i = 0; i < data_sources.length; i++) {
DiskManagerFileInfo info = (DiskManagerFileInfo) data_sources[i];
if (info != null && info.getAccessMode() == DiskManagerFileInfo.READ) {
Utils.launch(info);
}
}
}
});