use of ch.cyberduck.binding.application.AlertSheetReturnCodeMapper in project cyberduck by iterate-ch.
the class SheetController method closeSheet.
/**
* This must be the target action for any button in the sheet dialog. Will validate the input
* and close the sheet; #sheetDidClose will be called afterwards
*
* @param sender A button in the sheet dialog
*/
@Action
public void closeSheet(final NSButton sender) {
if (log.isDebugEnabled()) {
log.debug(String.format("Close sheet with button %s", sender.title()));
}
final int option = new AlertSheetReturnCodeMapper().getOption(sender);
this.closeSheetWithOption(option);
}
use of ch.cyberduck.binding.application.AlertSheetReturnCodeMapper 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);
}
use of ch.cyberduck.binding.application.AlertSheetReturnCodeMapper in project cyberduck by iterate-ch.
the class MainController method applicationShouldTerminate.
/**
* Invoked from within the terminate method immediately before the application terminates. sender is the
* NSApplication to be terminated. If this method returns false, the application is not terminated, and control
* returns to the main event loop.
*
* @param app Application instance
* @return Return true to allow the application to terminate.
*/
@Override
public NSUInteger applicationShouldTerminate(final NSApplication app) {
if (log.isDebugEnabled()) {
log.debug("Application should quit with notification");
}
// Determine if there are any running transfers
final NSUInteger result = TransferControllerFactory.applicationShouldTerminate(app);
if (!result.equals(NSApplication.NSTerminateNow)) {
return result;
}
// Determine if there are any open connections
for (BrowserController browser : MainController.getBrowsers()) {
if (preferences.getBoolean("browser.serialize")) {
if (browser.isMounted()) {
// The workspace should be saved. Serialize all open browser sessions
final Host serialized = new HostDictionary().deserialize(browser.getSession().getHost().serialize(SerializerFactory.get()));
serialized.setWorkdir(browser.workdir());
sessions.add(serialized);
browser.window().saveFrameUsingName(serialized.getUuid());
}
}
if (browser.isConnected()) {
if (preferences.getBoolean("browser.disconnect.confirm")) {
final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Quit"), LocaleFactory.localizedString("You are connected to at least one remote site. Do you want to review open browsers?"), // default
LocaleFactory.localizedString("Quit Anyway"), // other
LocaleFactory.localizedString("Cancel"), LocaleFactory.localizedString("Review…"));
alert.setAlertStyle(NSAlert.NSWarningAlertStyle);
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("browser.disconnect.confirm", false);
}
if (choice == SheetCallback.ALTERNATE_OPTION) {
// Cancel. Quit has been interrupted. Delete any saved sessions so far.
sessions.clear();
return NSApplication.NSTerminateCancel;
}
if (choice == SheetCallback.CANCEL_OPTION) {
// This will iterate over all mounted browsers.
if (NSApplication.NSTerminateNow.equals(BrowserController.applicationShouldTerminate(app))) {
return this.applicationShouldTerminateAfterDonationPrompt(app);
}
return NSApplication.NSTerminateLater;
}
if (choice == SheetCallback.DEFAULT_OPTION) {
// Quit immediatly
return this.applicationShouldTerminateAfterDonationPrompt(app);
}
} else {
browser.windowShouldClose(browser.window());
}
}
}
return this.applicationShouldTerminateAfterDonationPrompt(app);
}
use of ch.cyberduck.binding.application.AlertSheetReturnCodeMapper in project cyberduck by iterate-ch.
the class MainController method application_openFile.
@Override
public boolean application_openFile(final NSApplication app, final String filename) {
if (log.isDebugEnabled()) {
log.debug(String.format("Open file %s", filename));
}
final Local f = LocalFactory.get(filename);
if (f.exists()) {
if ("duck".equals(f.getExtension())) {
final Host bookmark;
try {
newDocument().mount(HostReaderFactory.get().read(f));
return true;
} catch (AccessDeniedException e) {
log.error(String.format("Failure reading bookmark from %s. %s", f, e.getMessage()));
return false;
}
} else if ("cyberducklicense".equals(f.getExtension())) {
final License l = LicenseFactory.get(f);
if (l.verify(new DisabledLicenseVerifierCallback())) {
try {
f.copy(LocalFactory.get(SupportDirectoryFinderFactory.get().find(), f.getName()));
final NSAlert alert = NSAlert.alert(l.toString(), LocaleFactory.localizedString("Thanks for your support! Your contribution helps to further advance development to make Cyberduck even better.", "License") + "\n\n" + LocaleFactory.localizedString("Your donation key has been copied to the Application Support folder.", "License"), // default
LocaleFactory.localizedString("Continue", "License"), // other
null, null);
alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
if (new AlertSheetReturnCodeMapper().getOption(alert.runModal()) == SheetCallback.DEFAULT_OPTION) {
for (BrowserController c : MainController.getBrowsers()) {
c.removeDonateWindowTitle();
}
this.updateLicenseMenu();
}
} catch (AccessDeniedException e) {
log.error(e.getMessage());
return false;
}
} else {
final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Not a valid registration key", "License"), LocaleFactory.localizedString("This donation key does not appear to be valid.", "License"), // default
LocaleFactory.localizedString("Continue", "License"), // other
null, null);
alert.setAlertStyle(NSAlert.NSWarningAlertStyle);
alert.setShowsHelp(true);
alert.setDelegate(new ProxyController() {
@Action
public boolean alertShowHelp(NSAlert alert) {
BrowserLauncherFactory.get().open(ProviderHelpServiceFactory.get().help());
return true;
}
}.id());
alert.runModal();
}
return true;
} else if ("cyberduckprofile".equals(f.getExtension())) {
try {
final Profile profile = ProfileReaderFactory.get().read(f);
if (profile.isEnabled()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Register profile %s", profile));
}
final ProtocolFactory protocols = ProtocolFactory.get();
protocols.register(profile);
final Host host = new Host(profile, profile.getDefaultHostname(), profile.getDefaultPort());
newDocument().addBookmark(host);
// Register in application support
final Local profiles = LocalFactory.get(SupportDirectoryFinderFactory.get().find(), preferences.getProperty("profiles.folder.name"));
if (!profiles.exists()) {
new DefaultLocalDirectoryFeature().mkdir(profiles);
}
f.copy(LocalFactory.get(profiles, f.getName()));
}
} catch (AccessDeniedException e) {
log.error(String.format("Failure reading profile from %s. %s", f, e));
return false;
}
} else {
// Upload file
this.background(new AbstractBackgroundAction<Void>() {
@Override
public Void run() {
// Wait until bookmarks are loaded
Uninterruptibles.awaitUninterruptibly(bookmarksSemaphore);
return null;
}
@Override
public void cleanup() {
upload(f);
}
@Override
public String getActivity() {
return "Open File";
}
});
return true;
}
}
return false;
}
Aggregations