Skip to content

Commit

Permalink
Fix #5790.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Mar 17, 2011
1 parent f18d71f commit 2cec697
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions source/ch/cyberduck/ui/cocoa/MainController.java
Expand Up @@ -481,7 +481,7 @@ public void showActivityWindowClicked(final ID sender) {
*/
public boolean application_openFile(NSApplication app, String filename) {
log.debug("applicationOpenFile:" + filename);
Local f = LocalFactory.createLocal(filename);
final Local f = LocalFactory.createLocal(filename);
if(f.exists()) {
if("duck".equals(f.getExtension())) {
final Host host = HostReaderFactory.instance().read(f);
Expand Down Expand Up @@ -542,7 +542,28 @@ else if("cyberduckprofile".equals(f.getExtension())) {
}
else {
// Upload file
return this.upload(f);
this.background(new AbstractBackgroundAction() {
public void run() {
// Wait until bookmarks are loaded
try {
loader.await();
}
catch(InterruptedException e) {
log.error(e.getMessage());
}
}

@Override
public void cleanup() {
upload(f);
}

@Override
public String getActivity() {
return "Open File";
}
});
return true;
}
}
return false;
Expand All @@ -568,9 +589,18 @@ private boolean upload(final List<Local> files) {
if(controller.isMounted()) {
open = controller.getSession().getHost();
workdir = controller.workdir().getAbsolute();
if(1 == MainController.getBrowsers().size()) {
// If only one browser window upload to current working directory with no bookmark selection
this.upload(open, files, workdir);
return true;
}
break;
}
}
if(BookmarkCollection.defaultCollection().isEmpty()) {
log.warn("No bookmark for upload");
return false;
}
final NSPopUpButton bookmarksPopup = NSPopUpButton.buttonWithFrame(new NSRect(0, 26));
bookmarksPopup.setToolTip(Locale.localizedString("Bookmarks"));
for(Host b : BookmarkCollection.defaultCollection()) {
Expand Down Expand Up @@ -635,12 +665,7 @@ public void callback(int returncode) {
parent = bookmark.getDefaultPath();
}
}
final Session session = SessionFactory.createSession(bookmark);
List<Path> roots = new ArrayList<Path>();
for(Local file : files) {
roots.add(PathFactory.createPath(session, parent, file));
}
t.startTransfer(new UploadTransfer(roots));
upload(bookmark, files, parent);
break;
}
}
Expand All @@ -657,6 +682,21 @@ protected boolean validateInput() {
return true;
}

/**
* @param bookmark
* @param files
* @param destination
*/
private void upload(Host bookmark, List<Local> files, String destination) {
final Session session = SessionFactory.createSession(bookmark);
List<Path> roots = new ArrayList<Path>();
for(Local file : files) {
roots.add(PathFactory.createPath(session, destination, file));
}
final TransferController t = TransferController.instance();
t.startTransfer(new UploadTransfer(roots));
}

/**
* Sent directly by theApplication to the delegate. The method should attempt to open the file filename,
* returning true if the file is successfully opened, and false otherwise. By design, a
Expand Down Expand Up @@ -769,6 +809,9 @@ public boolean applicationShouldHandleReopen_hasVisibleWindows(NSApplication app
return false;
}

// User bookmarks and thirdparty applications
private final CountDownLatch loader = new CountDownLatch(2);

/**
* 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
Expand Down Expand Up @@ -807,8 +850,6 @@ public void cleanup() {
}
});
}
// User bookmarks and thirdparty applications
final CountDownLatch loader = new CountDownLatch(2);

this.background(new AbstractBackgroundAction() {
public void run() {
Expand Down

0 comments on commit 2cec697

Please sign in to comment.