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;
}
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);
}
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);
}
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;
}
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);
}
Aggregations