Search in sources :

Example 1 with NSEvent

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

the class BookmarkTableDataSource method tableView_writeRowsWithIndexes_toPasteboard.

/**
 * @param rowIndexes is the list of row numbers that will be participating in the drag.
 * @return To refuse the drag, return false. To start a drag, return true and place the drag data onto pboard (data,
 * owner, and so on).
 * @see NSTableView.DataSource Invoked by view after it has been determined that a drag should begin, but before the
 * drag has been started. The drag image and other drag-related information will be set up and provided by the table
 * view once this call returns with true.
 */
@Override
public boolean tableView_writeRowsWithIndexes_toPasteboard(final NSTableView view, final NSIndexSet rowIndexes, final NSPasteboard pboard) {
    for (NSUInteger index = rowIndexes.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = rowIndexes.indexGreaterThanIndex(index)) {
        pasteboard.add(this.getSource().get(index.intValue()));
    }
    NSEvent event = NSApplication.sharedApplication().currentEvent();
    if (event != null) {
        NSPoint dragPosition = view.convertPoint_fromView(event.locationInWindow(), null);
        NSRect imageRect = new NSRect(new NSPoint(dragPosition.x.doubleValue() - 16, dragPosition.y.doubleValue() - 16), new NSSize(32, 32));
        // Writing a promised file of the host as a bookmark file to the clipboard
        if (!view.dragPromisedFilesOfTypes(NSArray.arrayWithObject("duck"), imageRect, this.id(), true, event)) {
            log.warn(String.format("Failure for drag promise operation of %s", event));
            return false;
        }
        return true;
    }
    return false;
}
Also used : NSSize(org.rococoa.cocoa.foundation.NSSize) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSRect(org.rococoa.cocoa.foundation.NSRect) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) NSEvent(ch.cyberduck.binding.application.NSEvent)

Example 2 with NSEvent

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

the class BrowserOutlineViewDataSource method outlineView_numberOfChildrenOfItem.

/**
 * @see NSOutlineView.DataSource
 */
@Override
public NSInteger outlineView_numberOfChildrenOfItem(final NSOutlineView view, final NSObject item) {
    if (log.isTraceEnabled()) {
        log.trace("outlineView_numberOfChildrenOfItem:" + item);
    }
    if (controller.isMounted()) {
        if (null == item) {
            return new NSInteger(this.get(controller.workdir()).size());
        }
        NSEvent event = NSApplication.sharedApplication().currentEvent();
        if (event != null) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Current application event is %d", event.type()));
            }
            if (NSEvent.NSLeftMouseDragged == event.type()) {
                final int draggingColumn = view.columnAtPoint(view.convertPoint_fromView(event.locationInWindow(), null)).intValue();
                if (draggingColumn != 0) {
                    log.debug("Returning 0 to #outlineViewNumberOfChildrenOfItem for column:" + draggingColumn);
                    // See ticket #60
                    return new NSInteger(0);
                }
                if (!PreferencesFactory.get().getBoolean("browser.view.autoexpand")) {
                    log.debug("Returning 0 to #outlineViewNumberOfChildrenOfItem while dragging because browser.view.autoexpand == false");
                    // See tickets #98 and #633
                    return new NSInteger(0);
                }
            }
        }
        final Path lookup = cache.lookup(new NSObjectPathReference(item));
        if (null == lookup) {
            return new NSInteger(0);
        }
        return new NSInteger(this.get(lookup).size());
    }
    return new NSInteger(0);
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger) Path(ch.cyberduck.core.Path) NSObjectPathReference(ch.cyberduck.core.NSObjectPathReference) NSEvent(ch.cyberduck.binding.application.NSEvent)

Example 3 with NSEvent

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

the class BrowserTableDataSource method writeItemsToPasteBoard.

public boolean writeItemsToPasteBoard(final NSTableView view, final List<Path> selected, final NSPasteboard pboard) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Write items to pasteboard %s", pboard));
    }
    if (controller.isMounted()) {
        if (selected.size() > 0) {
            // The fileTypes argument is the list of fileTypes being promised.
            // The array elements can consist of file extensions and HFS types encoded
            // with the NSHFSFileTypes method fileTypeForHFSTypeCode. If promising a directory
            // of files, only include the top directory in the array.
            final Set<String> fileTypes = new LinkedHashSet<>();
            final PathPasteboard pasteboard = controller.getPasteboard();
            for (final Path f : selected) {
                if (f.isFile()) {
                    if (StringUtils.isNotBlank(f.getExtension())) {
                        fileTypes.add(f.getExtension());
                    } else {
                        fileTypes.add(NSFileManager.NSFileTypeRegular);
                    }
                } else if (f.isDirectory()) {
                    // NSFileTypeForHFSTypeCode('fldr')
                    fileTypes.add("'fldr'");
                } else {
                    fileTypes.add(NSFileManager.NSFileTypeUnknown);
                }
                // Writing data for private use when the item gets dragged to the transfer queue.
                pasteboard.add(f);
            }
            NSEvent event = NSApplication.sharedApplication().currentEvent();
            if (event != null) {
                NSPoint dragPosition = view.convertPoint_fromView(event.locationInWindow(), null);
                NSRect imageRect = new NSRect(new NSPoint(dragPosition.x.doubleValue() - 16, dragPosition.y.doubleValue() - 16), new NSSize(32, 32));
                if (!view.dragPromisedFilesOfTypes(NSMutableArray.arrayWithObject(fileTypes.iterator().next()), imageRect, this.id(), true, event)) {
                    log.warn(String.format("Failure for drag promise operation of %s", event));
                    return false;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(ch.cyberduck.core.Path) PathPasteboard(ch.cyberduck.core.pasteboard.PathPasteboard) NSSize(org.rococoa.cocoa.foundation.NSSize) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) NSRect(org.rococoa.cocoa.foundation.NSRect) NSEvent(ch.cyberduck.binding.application.NSEvent)

Aggregations

NSEvent (ch.cyberduck.binding.application.NSEvent)3 Path (ch.cyberduck.core.Path)2 NSPoint (org.rococoa.cocoa.foundation.NSPoint)2 NSRect (org.rococoa.cocoa.foundation.NSRect)2 NSSize (org.rococoa.cocoa.foundation.NSSize)2 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)1 NSObjectPathReference (ch.cyberduck.core.NSObjectPathReference)1 PathPasteboard (ch.cyberduck.core.pasteboard.PathPasteboard)1 LinkedHashSet (java.util.LinkedHashSet)1 NSInteger (org.rococoa.cocoa.foundation.NSInteger)1 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)1