use of ch.cyberduck.binding.application.SheetCallback in project cyberduck by iterate-ch.
the class MoveController method rename.
/**
* Displays a warning dialog about files to be moved
*
* @param selected A map with the original files as the key and the destination
* files as the value
* @param action Background task
*/
private void rename(final Map<Path, Path> selected, final DefaultMainAction action) {
if (preferences.getBoolean("browser.move.confirm")) {
StringBuilder alertText = new StringBuilder(LocaleFactory.localizedString("Do you want to move the selected files?", "Duplicate"));
int i = 0;
boolean rename = false;
Iterator<Map.Entry<Path, Path>> iter;
for (iter = selected.entrySet().iterator(); i < 10 && iter.hasNext(); ) {
final Map.Entry<Path, Path> next = iter.next();
if (next.getKey().getParent().equals(next.getValue().getParent())) {
rename = true;
}
alertText.append(String.format("\n%s %s", Character.toString('\u2022'), next.getKey().getName()));
i++;
}
if (iter.hasNext()) {
alertText.append(String.format("\n%s …)", Character.toString('\u2022')));
}
final NSAlert alert = NSAlert.alert(// title
rename ? LocaleFactory.localizedString("Rename", "Transfer") : LocaleFactory.localizedString("Move", "Transfer"), alertText.toString(), // default button
rename ? LocaleFactory.localizedString("Rename", "Transfer") : LocaleFactory.localizedString("Move", "Transfer"), // alternative button
LocaleFactory.localizedString("Cancel"), // other button
null);
alert.setShowsSuppressionButton(true);
alert.suppressionButton().setTitle(LocaleFactory.localizedString("Don't ask again", "Configuration"));
parent.alert(alert, new SheetCallback() {
@Override
public void callback(final int returncode) {
if (alert.suppressionButton().state() == NSCell.NSOnState) {
// Never show again.
preferences.setProperty("browser.move.confirm", false);
}
if (returncode == DEFAULT_OPTION) {
new OverwriteController(parent).overwrite(new ArrayList<Path>(selected.values()), action);
}
}
});
} else {
new OverwriteController(parent, cache).overwrite(new ArrayList<Path>(selected.values()), action);
}
}
use of ch.cyberduck.binding.application.SheetCallback in project cyberduck by iterate-ch.
the class OverwriteController method overwrite.
/**
* Displays a warning dialog about already existing files
*
* @param selected The files to check
*/
public void overwrite(final List<Path> selected, final MainAction action) {
StringBuilder alertText = new StringBuilder(LocaleFactory.localizedString("A file with the same name already exists. Do you want to replace the existing file?"));
int i = 0;
Iterator<Path> iter;
boolean shouldWarn = false;
for (iter = selected.iterator(); iter.hasNext(); ) {
final Path item = iter.next();
if (cache.get(item.getParent()).contains(item)) {
if (i < 10) {
alertText.append('\n').append('\u2022').append(' ').append(item.getName());
}
shouldWarn = true;
}
i++;
}
if (i >= 10) {
alertText.append('\n').append('\u2022').append(' ').append('…');
}
if (shouldWarn) {
NSAlert alert = NSAlert.alert(// title
LocaleFactory.localizedString("Overwrite"), alertText.toString(), // defaultbutton
LocaleFactory.localizedString("Overwrite"), // alternative button
LocaleFactory.localizedString("Cancel"), // other button
null);
parent.alert(alert, new SheetCallback() {
@Override
public void callback(final int returncode) {
if (returncode == DEFAULT_OPTION) {
action.run();
}
}
});
} else {
action.run();
}
}
use of ch.cyberduck.binding.application.SheetCallback in project cyberduck by iterate-ch.
the class CopyController method copy.
/**
* Displays a warning dialog about files to be moved
*
* @param selected A map with the original files as the key and the destination
* files as the value
* @param action Background task
*/
private void copy(final Map<Path, Path> selected, final DefaultMainAction action) {
if (preferences.getBoolean("browser.copy.confirm")) {
StringBuilder alertText = new StringBuilder(LocaleFactory.localizedString("Do you want to copy the selected files?", "Duplicate"));
int i = 0;
Iterator<Map.Entry<Path, Path>> iter;
for (iter = selected.entrySet().iterator(); i < 10 && iter.hasNext(); ) {
final Map.Entry<Path, Path> next = iter.next();
alertText.append(String.format("\n%s %s", Character.toString('\u2022'), next.getKey().getName()));
i++;
}
if (iter.hasNext()) {
alertText.append(String.format("\n%s …)", Character.toString('\u2022')));
}
final NSAlert alert = NSAlert.alert(// title
LocaleFactory.localizedString("Copy", "Transfer"), alertText.toString(), // default button
LocaleFactory.localizedString("Copy", "Transfer"), // alternative button
LocaleFactory.localizedString("Cancel"), // other button
null);
alert.setShowsSuppressionButton(true);
alert.suppressionButton().setTitle(LocaleFactory.localizedString("Don't ask again", "Configuration"));
parent.alert(alert, new SheetCallback() {
@Override
public void callback(final int returncode) {
if (alert.suppressionButton().state() == NSCell.NSOnState) {
// Never show again.
preferences.setProperty("browser.copy.confirm", false);
}
if (returncode == DEFAULT_OPTION) {
new OverwriteController(parent).overwrite(new ArrayList<Path>(selected.values()), action);
}
}
});
} else {
new OverwriteController(parent, cache).overwrite(new ArrayList<Path>(selected.values()), action);
}
}
use of ch.cyberduck.binding.application.SheetCallback in project cyberduck by iterate-ch.
the class DeleteController method delete.
/**
* Recursively deletes the files
*
* @param selected The files selected in the browser to delete
*/
public void delete(final List<Path> selected) {
final List<Path> normalized = PathNormalizer.normalize(selected);
if (normalized.isEmpty()) {
return;
}
final StringBuilder alertText = new StringBuilder(MessageFormat.format(LocaleFactory.localizedString("Delete {0} files"), selected.size()));
int i = 0;
Iterator<Path> iter;
for (iter = normalized.iterator(); i < 10 && iter.hasNext(); ) {
alertText.append('\n').append('\u2022').append(' ').append(iter.next().getName());
i++;
}
if (iter.hasNext()) {
alertText.append('\n').append('\u2022').append(' ').append('…');
}
final NSAlert alert = // title
NSAlert.alert(// title
LocaleFactory.localizedString("Delete"), alertText.toString(), // defaultbutton
LocaleFactory.localizedString("Delete"), // alternative button
LocaleFactory.localizedString("Cancel"), // other button
null);
parent.alert(alert, new SheetCallback() {
@Override
public void callback(final int returncode) {
if (returncode == DEFAULT_OPTION) {
run(normalized);
}
}
});
}
use of ch.cyberduck.binding.application.SheetCallback in project cyberduck by iterate-ch.
the class TransferControllerFactory method applicationShouldTerminate.
/**
* @param app Singleton
* @return NSApplication.TerminateLater or NSApplication.TerminateNow depending if there are
* running transfers to be checked first
*/
public static NSUInteger applicationShouldTerminate(final NSApplication app) {
if (null == shared) {
return NSApplication.NSTerminateNow;
}
// Saving state of transfer window
PreferencesFactory.get().setProperty("queue.window.open.default", shared.isVisible());
if (TransferCollection.defaultCollection().numberOfRunningTransfers() > 0) {
final NSAlert alert = // title
NSAlert.alert(// title
LocaleFactory.localizedString("Transfer in progress"), // message
LocaleFactory.localizedString("There are files currently being transferred. Quit anyway?"), // defaultbutton
LocaleFactory.localizedString("Quit"), // alternative button
LocaleFactory.localizedString("Cancel"), // other button
null);
shared.alert(alert, new SheetCallback() {
@Override
public void callback(int returncode) {
if (returncode == DEFAULT_OPTION) {
// Quit
final BackgroundActionRegistry registry = shared.getRegistry();
for (BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) {
action.cancel();
}
app.replyToApplicationShouldTerminate(true);
}
if (returncode == CANCEL_OPTION) {
// Cancel
app.replyToApplicationShouldTerminate(false);
}
}
});
// break
return NSApplication.NSTerminateLater;
}
return NSApplication.NSTerminateNow;
}
Aggregations