Search in sources :

Example 1 with NSAlert

use of ch.cyberduck.binding.application.NSAlert in project cyberduck by iterate-ch.

the class MainController method applicationDidFinishLaunching.

/**
 * Sent by the default notification center after the application has been launched and initialized but before it has
 * received its first event. aNotification is always an ApplicationDidFinishLaunchingNotification. You can retrieve
 * the NSApplication object in question by sending object to aNotification. The delegate can implement this method
 * to perform further initialization. If the user started up the application by double-clicking a file, the delegate
 * receives the applicationOpenFile message before receiving applicationDidFinishLaunching.
 * (applicationWillFinishLaunching is sent before applicationOpenFile.)
 */
@Override
public void applicationDidFinishLaunching(NSNotification notification) {
    // Opt-in of automatic window tabbing
    NSWindow.setAllowsAutomaticWindowTabbing(true);
    // Load main menu
    this.loadBundle();
    // Open default windows
    if (preferences.getBoolean("browser.open.untitled")) {
        final BrowserController c = newDocument();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("queue.window.open.default")) {
        TransferController c = TransferControllerFactory.get();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("browser.serialize")) {
        this.background(new AbstractBackgroundAction<Void>() {

            @Override
            public Void run() throws BackgroundException {
                sessions.load();
                return null;
            }

            @Override
            public void cleanup() {
                for (Host host : sessions) {
                    if (log.isInfoEnabled()) {
                        log.info(String.format("New browser for saved session %s", host));
                    }
                    final BrowserController browser = newDocument(true, host.getUuid());
                    browser.mount(host);
                }
                sessions.clear();
            }
        });
    }
    final AbstractHostCollection bookmarks = BookmarkCollection.defaultCollection();
    // Load all bookmarks in background
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            bookmarks.load();
            bookmarksSemaphore.countDown();
            return null;
        }

        @Override
        public void cleanup() {
            if (preferences.getBoolean("browser.open.untitled")) {
                if (preferences.getProperty("browser.open.bookmark.default") != null) {
                    openDefaultBookmark(newDocument());
                }
            }
            // Set delegate for NSService
            NSApplication.sharedApplication().setServicesProvider(MainController.this.id());
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final HistoryCollection history = HistoryCollection.defaultCollection();
            history.load();
            return null;
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final TransferCollection transfers = TransferCollection.defaultCollection();
            transfers.load();
            return null;
        }
    });
    final Rendezvous bonjour = RendezvousFactory.instance();
    bonjour.addListener(new NotificationRendezvousListener(bonjour));
    if (preferences.getBoolean("defaulthandler.reminder") && preferences.getInteger("uses") > 0) {
        if (!SchemeHandlerFactory.get().isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()), new Application(preferences.getProperty("application.identifier")))) {
            final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Set Cyberduck as default application for FTP and SFTP locations?", "Configuration"), LocaleFactory.localizedString("As the default application, Cyberduck will open when you click on FTP or SFTP links " + "in other applications, such as your web browser. You can change this setting in the Preferences later.", "Configuration"), // default
            LocaleFactory.localizedString("Change", "Configuration"), // other
            null, LocaleFactory.localizedString("Cancel", "Configuration"));
            alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
            alert.setShowsSuppressionButton(true);
            alert.suppressionButton().setTitle(LocaleFactory.localizedString("Don't ask again", "Configuration"));
            int choice = new AlertSheetReturnCodeMapper().getOption(alert.runModal());
            if (alert.suppressionButton().state() == NSCell.NSOnState) {
                // Never show again.
                preferences.setProperty("defaulthandler.reminder", false);
            }
            if (choice == SheetCallback.DEFAULT_OPTION) {
                SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()));
            }
        }
    }
    // NSWorkspace notifications are posted to a notification center provided by
    // the NSWorkspace object, instead of going through the application’s default
    // notification center as most notifications do. To receive NSWorkspace notifications,
    // your application must register an observer with the NSWorkspace notification center.
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillPowerOff:"), NSWorkspace.WorkspaceWillPowerOffNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillLogout:"), NSWorkspace.WorkspaceSessionDidResignActiveNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillSleep:"), NSWorkspace.WorkspaceWillSleepNotification, null);
    NSNotificationCenter.defaultCenter().addObserver(this.id(), Foundation.selector("applicationWillRestartAfterUpdate:"), "SUUpdaterWillRestartNotificationName", null);
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() {
            bonjour.init();
            return null;
        }
    });
    // Import thirdparty bookmarks.
    this.background(new ImporterBackgroundAction(bookmarks, bookmarksSemaphore));
    final CrashReporter reporter = CrashReporter.create();
    if (log.isInfoEnabled()) {
        log.info("Check for crash report");
    }
    reporter.checkForCrash(preferences.getProperty("website.crash"));
    if (updater.hasUpdatePrivileges()) {
        if (preferences.getBoolean("update.check")) {
            final long next = preferences.getLong("update.check.timestamp") + preferences.getLong("update.check.interval") * 1000;
            if (next < System.currentTimeMillis()) {
                updater.check(true);
            }
            updater.register();
        }
    }
    if (preferences.getBoolean("profiles.discovery.updater.enable")) {
        // Synchronize and register timer
        profiles.register();
    }
    // Register OAuth handler
    final String handler = preferences.getProperty("oauth.handler.scheme");
    if (log.isInfoEnabled()) {
        log.info(String.format("Register OAuth handler %s", handler));
    }
    SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Collections.singletonList(handler));
    NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID(this.id(), Foundation.selector("handleGetURLEvent:withReplyEvent:"), kInternetEventClass, kAEGetURL);
}
Also used : Rendezvous(ch.cyberduck.core.bonjour.Rendezvous) NotificationRendezvousListener(ch.cyberduck.core.bonjour.NotificationRendezvousListener) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) NSAlert(ch.cyberduck.binding.application.NSAlert) Application(ch.cyberduck.core.local.Application) NSApplication(ch.cyberduck.binding.application.NSApplication) AlertSheetReturnCodeMapper(ch.cyberduck.binding.application.AlertSheetReturnCodeMapper) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Example 2 with NSAlert

use of ch.cyberduck.binding.application.NSAlert 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);
    }
}
Also used : Path(ch.cyberduck.core.Path) ArrayList(java.util.ArrayList) SheetCallback(ch.cyberduck.binding.application.SheetCallback) NSAlert(ch.cyberduck.binding.application.NSAlert) Map(java.util.Map)

Example 3 with NSAlert

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

Example 4 with NSAlert

use of ch.cyberduck.binding.application.NSAlert in project cyberduck by iterate-ch.

the class FolderController method loadBundle.

@Override
public void loadBundle() {
    final NSAlert alert = NSAlert.alert();
    alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
    alert.setMessageText(LocaleFactory.localizedString("Create new folder", "Folder"));
    final String message = LocaleFactory.localizedString("Enter the name for the new folder", "Folder");
    alert.setInformativeText(new StringAppender().append(message).toString());
    alert.addButtonWithTitle(LocaleFactory.localizedString("Create", "Folder"));
    alert.addButtonWithTitle(LocaleFactory.localizedString("Cancel", "Folder"));
    alert.setIcon(IconCacheFactory.<NSImage>get().iconNamed("folderplus.tiff", 64));
    super.loadBundle(alert);
}
Also used : NSImage(ch.cyberduck.binding.application.NSImage) StringAppender(ch.cyberduck.core.StringAppender) NSAlert(ch.cyberduck.binding.application.NSAlert)

Example 5 with NSAlert

use of ch.cyberduck.binding.application.NSAlert in project cyberduck by iterate-ch.

the class ProgressAlertController method loadBundle.

@Override
public void loadBundle() {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Load alert for message %s", message));
    }
    final NSAlert alert = NSAlert.alert();
    alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
    alert.setMessageText(title);
    alert.setInformativeText(new StringAppender().append(message).toString());
    alert.addButtonWithTitle(LocaleFactory.localizedString("Cancel"));
    alert.setShowsHelp(true);
    alert.setShowsSuppressionButton(false);
    super.loadBundle(alert);
}
Also used : StringAppender(ch.cyberduck.core.StringAppender) NSAlert(ch.cyberduck.binding.application.NSAlert)

Aggregations

NSAlert (ch.cyberduck.binding.application.NSAlert)28 StringAppender (ch.cyberduck.core.StringAppender)10 NSImage (ch.cyberduck.binding.application.NSImage)8 SheetCallback (ch.cyberduck.binding.application.SheetCallback)5 Path (ch.cyberduck.core.Path)4 AlertSheetReturnCodeMapper (ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)3 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Action (ch.cyberduck.binding.Action)1 AlertController (ch.cyberduck.binding.AlertController)1 ProxyController (ch.cyberduck.binding.ProxyController)1 NSApplication (ch.cyberduck.binding.application.NSApplication)1 NSPopUpButton (ch.cyberduck.binding.application.NSPopUpButton)1 DisabledLicenseVerifierCallback (ch.cyberduck.core.aquaticprime.DisabledLicenseVerifierCallback)1 License (ch.cyberduck.core.aquaticprime.License)1 NotificationRendezvousListener (ch.cyberduck.core.bonjour.NotificationRendezvousListener)1 Rendezvous (ch.cyberduck.core.bonjour.Rendezvous)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1