Search in sources :

Example 1 with BackgroundActionRegistry

use of ch.cyberduck.core.threading.BackgroundActionRegistry 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;
}
Also used : SheetCallback(ch.cyberduck.binding.application.SheetCallback) BackgroundActionRegistry(ch.cyberduck.core.threading.BackgroundActionRegistry) NSAlert(ch.cyberduck.binding.application.NSAlert) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction)

Aggregations

NSAlert (ch.cyberduck.binding.application.NSAlert)1 SheetCallback (ch.cyberduck.binding.application.SheetCallback)1 BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)1 BackgroundActionRegistry (ch.cyberduck.core.threading.BackgroundActionRegistry)1