Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed May 4, 2007
1 parent e71f221 commit cd5f944
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions source/ch/cyberduck/core/AbstractPath.java
Expand Up @@ -243,6 +243,13 @@ public void mkdir() {
*/
public abstract void delete();

/**
* @return True if the directory contains no childs items
*/
public boolean isEmpty() {
return this.childs().size() == 0;
}

/**
* @param name Must be an absolute path
*/
Expand Down
20 changes: 17 additions & 3 deletions source/ch/cyberduck/ui/cocoa/odb/Editor.java
Expand Up @@ -21,6 +21,7 @@
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Preferences;
import ch.cyberduck.core.AbstractPath;
import ch.cyberduck.ui.cocoa.CDBrowserController;
import ch.cyberduck.ui.cocoa.CDController;
import ch.cyberduck.ui.cocoa.growl.Growl;
Expand All @@ -35,6 +36,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.io.File;

/**
* @version $Id$
Expand Down Expand Up @@ -120,14 +122,21 @@ public void open(Path f, final String bundleIdentifier) {
open(bundleIdentifier);
}

/**
*
*/
private static Local TEMPORARY_DIRECTORY = new Local(NSPathUtilities.temporaryDirectory());

private void open(final String bundleIdentifier) {
String parent = NSPathUtilities.temporaryDirectory();
String filename = path.getAbsolute().replace('/', '_');
Local folder = new Local(new File(TEMPORARY_DIRECTORY.getAbsolute(), path.getParent().getAbsolute()));
folder.mkdir(true);

String filename = path.getName();
String proposal = filename;
int no = 0;
int index = filename.lastIndexOf(".");
do {
path.setLocal(new Local(parent, proposal));
path.setLocal(new Local(folder, proposal));
no++;
if(index != -1 && index != 0) {
proposal = filename.substring(0, index) + "-" + no + filename.substring(index);
Expand Down Expand Up @@ -168,6 +177,11 @@ private void edit(final String bundleIdentifier) {
public void didCloseFile() {
if(!uploadInProgress) {
path.getLocal().delete();
for(AbstractPath parent = path.getLocal().getParent(); !parent.equals(TEMPORARY_DIRECTORY); parent = parent.getParent()) {
if(parent.isEmpty()) {
parent.delete();
}
}
this.invalidate();
}
else {
Expand Down

0 comments on commit cd5f944

Please sign in to comment.