Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1958)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/projects/CreateApplicationWizard.java

Issue 10021055: fix for creating new application in an open folder http://code.google.com/p/dart/issues/detail?id=2… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/projects/CreateApplicationWizard.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/projects/CreateApplicationWizard.java (revision 6693)
+++ editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/projects/CreateApplicationWizard.java (working copy)
@@ -17,28 +17,38 @@
import com.google.dart.tools.core.DartCore;
import com.google.dart.tools.core.generator.ApplicationGenerator;
import com.google.dart.tools.core.generator.DartIdentifierUtil;
+import com.google.dart.tools.core.internal.util.ResourceUtil;
import com.google.dart.tools.ui.DartToolsPlugin;
import com.google.dart.tools.ui.internal.projects.NewApplicationCreationPage.ProjectType;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.ide.undo.CreateFolderOperation;
import org.eclipse.ui.ide.undo.CreateProjectOperation;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.StatusUtil;
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
@@ -67,8 +77,15 @@
@Override
public boolean performFinish() {
- createNewProject();
+ IPath locationPath = new Path(page.getLocationURI().getPath());
+
+ if (isNestedByAnExistingProject(locationPath)) {
+ createFolder(locationPath);
+ } else {
+ createNewProject();
+ }
+
if (newProject == null) {
return false;
}
@@ -88,6 +105,60 @@
return true;
}
+ private void createFolder(IPath path) {
+
+ final ProjectType projectType = page.getProjectType();
+
+ IPath containerPath = path.removeLastSegments(1);
+
+ IResource container = ResourceUtil.getResource(containerPath.toFile());
+ IPath newFolderPath = container.getFullPath().append(path.lastSegment());
+
+ final IFolder newFolderHandle = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(
+ newFolderPath);
+
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ AbstractOperation op;
+ op = new CreateFolderOperation(newFolderHandle, null,
+ IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
+ try {
+
+ IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
+
+ if (status.isOK() && projectType != ProjectType.NONE) {
+ createdFile = createProjectContent(newProject,
+ newFolderHandle.getLocation().toOSString(), newFolderHandle.getName(), projectType);
+ }
+
+ } catch (ExecutionException e) {
+ throw new InvocationTargetException(e);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ };
+
+ try {
+ getContainer().run(true, true, op);
+ } catch (InterruptedException e) {
+
+ } catch (InvocationTargetException e) {
+ // ExecutionExceptions are handled above, but unexpected runtime
+ // exceptions and errors may still occur.
+ IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$
+ MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
+ IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle, NLS.bind(
+ IDEWorkbenchMessages.WizardNewFolder_internalError,
+ e.getTargetException().getMessage()), SWT.SHEET);
+
+ }
+
+ newProject = newFolderHandle.getProject();
+
+ }
+
/**
* Creates a new project resource with the selected name.
* <p>
@@ -127,7 +198,9 @@
IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
if (status.isOK() && projectType != ProjectType.NONE) {
- createdFile = createProjectContent(newProjectHandle, projectType);
+ createdFile = createProjectContent(newProjectHandle,
+ newProjectHandle.getLocation().toOSString(), newProjectHandle.getName(),
+ projectType);
}
} catch (ExecutionException e) {
throw new InvocationTargetException(e);
@@ -181,12 +254,12 @@
* @param projectType
* @throws CoreException
*/
- private IFile createProjectContent(IProject project, ProjectType projectType)
- throws CoreException {
+ private IFile createProjectContent(IProject project, String location, String name,
+ ProjectType projectType) throws CoreException {
ApplicationGenerator generator = new ApplicationGenerator(project);
- generator.setApplicationLocation(project.getLocation().toOSString());
- generator.setApplicationName(DartIdentifierUtil.createValidIdentifier(project.getName()));
+ generator.setApplicationLocation(location);
+ generator.setApplicationName(DartIdentifierUtil.createValidIdentifier(name));
generator.setWebApplication(projectType == ProjectType.WEB);
generator.execute(new NullProgressMonitor());
@@ -205,4 +278,15 @@
return description;
}
+ private boolean isNestedByAnExistingProject(IPath path) {
+ for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ IPath location = project.getLocation();
+ if (location.isPrefixOf(path)) {
+ newProject = project;
+ return true;
+ }
+ }
+ return false;
+ }
+
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698