Skip to content

Commit

Permalink
In New PyDev Project wizard, fix project creation bug & use recursive…
Browse files Browse the repository at this point in the history
… search for Python files.

Make the following improvements to the New PyDev Project wizard (specifically, its first page):

1. Fix a bug where it was possible to create a new project in a workspace folder with the
"use default" setting chosen in the project creation wizard, even if that folder contained
a .project file.

2. When searching for existing Python files in the project location, now recursively search
existing folders in the location for Python files too.
  • Loading branch information
Andrew Ferrazzutti committed Aug 12, 2013
1 parent 8389c25 commit 69e7985
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ private void handleLocationBrowseButtonPressed() {
* content directory points to an existing project
*/
private boolean isDotProjectFileInLocation() {
IPath path = getLocationPath();
// Want to get the path of the containing folder, even if workspace location is used
IPath path = new Path(getProjectLocationFieldValue());
path = path.append(IProjectDescription.DESCRIPTION_FILE_NAME);
return path.toFile().exists();
}
Expand Down Expand Up @@ -700,24 +701,41 @@ protected boolean validatePage() {
}
if (locPath.toFile().exists()) {
File[] listFiles = locPath.toFile().listFiles();
boolean foundPy = false;
boolean foundInit = false;
for (File file : listFiles) {
if (file.getName().equals("__init__.py")) {
foundPy = true;
foundInit = true;
setMessage("Project location contains an __init__.py file. Consider using the location's parent folder instead.");
break;
}
if (file.getName().endsWith(".py") && !foundPy) {
foundPy = true;
setMessage("Project location contains existing Python files. The created project will include them.");
}
}
if (!foundInit && hasPyFile(locPath.toFile())) {
setMessage("Project location contains existing Python files. The created project will include them.");
}
}
}

return true;
}

private boolean hasPyFile(File file) {
if (file.isDirectory()) {
File[] listFiles = file.listFiles();
if (listFiles == null) {
return false;
}
for (File innerFile : listFiles) {
if (hasPyFile(innerFile)) {
return true;
}
}
return false;
}
else {
return file.getName().endsWith(".py");
}
}

/*
* see @DialogPage.setVisible(boolean)
*/
Expand Down

0 comments on commit 69e7985

Please sign in to comment.