Search in sources :

Example 1 with HostDictionary

use of ch.cyberduck.core.serializer.HostDictionary in project cyberduck by iterate-ch.

the class BrowserController method performDragOperation.

/**
 * NSDraggingDestination protocol implementation
 */
@Action
public boolean performDragOperation(final NSDraggingInfo sender) {
    for (Host bookmark : HostPasteboard.getPasteboard()) {
        final Host duplicate = new HostDictionary().deserialize(bookmark.serialize(SerializerFactory.get()));
        // Make sure a new UUID is assigned for duplicate
        duplicate.setUuid(null);
        bookmarks.add(0, duplicate);
    }
    return true;
}
Also used : HostDictionary(ch.cyberduck.core.serializer.HostDictionary) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 2 with HostDictionary

use of ch.cyberduck.core.serializer.HostDictionary in project cyberduck by iterate-ch.

the class BrowserController method duplicateBookmarkButtonClicked.

@Action
public void duplicateBookmarkButtonClicked(final ID sender) {
    final Host selected = bookmarkModel.getSource().get(bookmarkTable.selectedRow().intValue());
    this.selectBookmarks(BookmarkSwitchSegement.bookmarks);
    final Host duplicate = new HostDictionary().deserialize(selected.serialize(SerializerFactory.get()));
    // Make sure a new UUID is asssigned for duplicate
    duplicate.setUuid(null);
    this.addBookmark(duplicate);
}
Also used : HostDictionary(ch.cyberduck.core.serializer.HostDictionary) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 3 with HostDictionary

use of ch.cyberduck.core.serializer.HostDictionary in project cyberduck by iterate-ch.

the class BrowserController method newBrowserButtonClicked.

/**
 * Open a new browser with the current selected folder as the working directory
 *
 * @param sender Toolbar button
 */
@Action
public void newBrowserButtonClicked(final ID sender) {
    Path selected = this.getSelectedPath();
    if (null == selected || !selected.isDirectory()) {
        selected = workdir;
    }
    final BrowserController c = MainController.newDocument(true);
    final Host duplicate = new HostDictionary().deserialize(pool.getHost().serialize(SerializerFactory.get()));
    // Make sure a new UUID is assigned for duplicate
    duplicate.setUuid(null);
    duplicate.setDefaultPath(selected.getAbsolute());
    c.mount(duplicate);
}
Also used : HostDictionary(ch.cyberduck.core.serializer.HostDictionary) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 4 with HostDictionary

use of ch.cyberduck.core.serializer.HostDictionary in project cyberduck by iterate-ch.

the class BookmarkTableDataSource method tableView_acceptDrop_row_dropOperation.

/**
 * @param info contains details on this dragging operation.
 * @param row  The proposed location is row and action is operation. The data source should incorporate the data
 *             from the dragging pasteboard at this time.
 * @see NSTableView.DataSource Invoked by view when the mouse button is released over a table view that previously
 * decided to allow a drop.
 */
@Override
public boolean tableView_acceptDrop_row_dropOperation(final NSTableView view, final NSDraggingInfo info, final NSInteger row, final NSUInteger operation) {
    NSPasteboard draggingPasteboard = info.draggingPasteboard();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Accept drop at row %s", row));
    }
    view.deselectAll(null);
    final AbstractHostCollection source = this.getSource();
    if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.StringPboardType)) != null) {
        String o = draggingPasteboard.stringForType(NSPasteboard.StringPboardType);
        if (null == o) {
            return false;
        }
        final Host h;
        try {
            h = HostParser.parse(o);
        } catch (HostParserException e) {
            return false;
        }
        source.add(row.intValue(), h);
        view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), false);
        view.scrollRowToVisible(row);
        return true;
    } else if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.FilenamesPboardType)) != null) {
        // We get a drag from another application e.g. Finder.app proposing some files
        final NSObject object = draggingPasteboard.propertyListForType(NSPasteboard.FilenamesPboardType);
        if (object != null) {
            if (object.isKindOfClass(NSArray.CLASS)) {
                final NSArray elements = Rococoa.cast(object, NSArray.class);
                // If regular files are dropped, these will be uploaded to the dropped bookmark location
                final List<TransferItem> uploads = new ArrayList<TransferItem>();
                Host host = null;
                for (int i = 0; i < elements.count().intValue(); i++) {
                    final String filename = elements.objectAtIndex(new NSUInteger(i)).toString();
                    final Local f = LocalFactory.get(filename);
                    if (filename.endsWith(".duck")) {
                        // Adding a previously exported bookmark file from the Finder
                        try {
                            source.add(row.intValue(), HostReaderFactory.get().read(f));
                            view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), true);
                            view.scrollRowToVisible(row);
                        } catch (AccessDeniedException e) {
                            log.error(String.format("Failure reading bookmark from %s. %s", f, e.getMessage()));
                            continue;
                        }
                    } else {
                        // The bookmark this file has been dropped onto
                        final Host h = source.get(row.intValue());
                        if (null == host) {
                            host = h;
                        }
                        // Upload to the remote host this bookmark points to
                        uploads.add(new TransferItem(new Path(new Path(PathNormalizer.normalize(h.getDefaultPath()), EnumSet.of(Path.Type.directory)), f.getName(), EnumSet.of(Path.Type.file)), f));
                    }
                }
                if (!uploads.isEmpty()) {
                    // If anything has been added to the queue, then process the queue
                    final Transfer t = new UploadTransfer(host, uploads);
                    TransferControllerFactory.get().start(t, new TransferOptions());
                }
                return true;
            }
        }
    } else if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.URLPboardType)) != null) {
        final NSObject object = draggingPasteboard.propertyListForType(NSPasteboard.URLPboardType);
        if (object != null) {
            if (object.isKindOfClass(NSArray.CLASS)) {
                final NSArray elements = Rococoa.cast(object, NSArray.class);
                for (int i = 0; i < elements.count().intValue(); i++) {
                    final String url = elements.objectAtIndex(new NSUInteger(i)).toString();
                    if (StringUtils.isNotBlank(url)) {
                        final Host h;
                        try {
                            h = HostParser.parse(url);
                        } catch (HostParserException e) {
                            log.warn(e);
                            continue;
                        }
                        source.add(row.intValue(), h);
                        view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), true);
                        view.scrollRowToVisible(row);
                    }
                }
                return true;
            }
        }
        return false;
    } else if (!pasteboard.isEmpty()) {
        if (info.draggingSourceOperationMask().intValue() == NSDraggingInfo.NSDragOperationCopy.intValue()) {
            List<Host> duplicates = new ArrayList<Host>();
            for (Host bookmark : pasteboard) {
                final Host duplicate = new HostDictionary().deserialize(bookmark.serialize(SerializerFactory.get()));
                // Make sure a new UUID is assigned for duplicate
                duplicate.setUuid(null);
                source.add(row.intValue(), duplicate);
                duplicates.add(duplicate);
            }
            for (Host bookmark : duplicates) {
                int index = source.indexOf(bookmark);
                view.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(index)), true);
                view.scrollRowToVisible(new NSInteger(index));
            }
        } else {
            int insert = row.intValue();
            for (Host bookmark : pasteboard) {
                int previous = source.indexOf(bookmark);
                if (previous == insert) {
                    // No need to move
                    continue;
                }
                source.remove(previous);
                int moved;
                if (previous < insert) {
                    moved = insert - 1;
                } else {
                    moved = insert;
                }
                source.add(moved, bookmark);
            }
            for (Host bookmark : pasteboard) {
                int index = source.indexOf(bookmark);
                view.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(index)), true);
                view.scrollRowToVisible(new NSInteger(index));
            }
        }
        return true;
    }
    return false;
}
Also used : NSObject(ch.cyberduck.binding.foundation.NSObject) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) NSArray(ch.cyberduck.binding.foundation.NSArray) HostDictionary(ch.cyberduck.core.serializer.HostDictionary) NSPasteboard(ch.cyberduck.binding.application.NSPasteboard) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) HostParserException(ch.cyberduck.core.exception.HostParserException) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSInteger(org.rococoa.cocoa.foundation.NSInteger) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) ArrayList(java.util.ArrayList) List(java.util.List) TransferItem(ch.cyberduck.core.transfer.TransferItem)

Example 5 with HostDictionary

use of ch.cyberduck.core.serializer.HostDictionary 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);
}
Also used : HostDictionary(ch.cyberduck.core.serializer.HostDictionary) NSAlert(ch.cyberduck.binding.application.NSAlert) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) AlertSheetReturnCodeMapper(ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)

Aggregations

HostDictionary (ch.cyberduck.core.serializer.HostDictionary)5 Action (ch.cyberduck.binding.Action)3 BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)3 BrowserTransferBackgroundAction (ch.cyberduck.core.threading.BrowserTransferBackgroundAction)3 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)3 DisconnectBackgroundAction (ch.cyberduck.core.threading.DisconnectBackgroundAction)3 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)3 WorkerBackgroundAction (ch.cyberduck.core.threading.WorkerBackgroundAction)3 TransferAction (ch.cyberduck.core.transfer.TransferAction)3 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)2 AlertSheetReturnCodeMapper (ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)1 NSAlert (ch.cyberduck.binding.application.NSAlert)1 NSPasteboard (ch.cyberduck.binding.application.NSPasteboard)1 NSArray (ch.cyberduck.binding.foundation.NSArray)1 NSObject (ch.cyberduck.binding.foundation.NSObject)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 HostParserException (ch.cyberduck.core.exception.HostParserException)1 Transfer (ch.cyberduck.core.transfer.Transfer)1 TransferItem (ch.cyberduck.core.transfer.TransferItem)1 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)1