Cleanup (formatting; messages; warnings)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 16 Oct 2014 17:38:07 +0000 (19:38 +0200)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 16 Oct 2014 17:52:42 +0000 (19:52 +0200)
platform/platform-impl/src/com/intellij/platform/NewDirectoryProjectAction.java
platform/platform-resources-en/src/messages/ActionsBundle.properties

index 33b26e894cb90530c84d158c1917d036ab050b9a..7a48c2cc02929cb9dcbe2d5872e27d30a86552de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package com.intellij.platform;
 
 import com.intellij.ide.GeneralSettings;
+import com.intellij.idea.ActionsBundle;
 import com.intellij.internal.statistic.UsageTrigger;
 import com.intellij.internal.statistic.beans.ConvertUsagesUtil;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.projectImport.ProjectOpenedCallback;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
@@ -43,25 +44,21 @@ import java.io.File;
 public class NewDirectoryProjectAction extends AnAction implements DumbAware {
   private static final Logger LOG = Logger.getInstance(NewDirectoryProjectAction.class);
 
-  public void actionPerformed(final AnActionEvent e) {
-    Project project = e.getData(CommonDataKeys.PROJECT);
+  public void actionPerformed(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
     NewDirectoryProjectDialog dlg = new NewDirectoryProjectDialog(project);
     dlg.show();
-    if (dlg.getExitCode() != DialogWrapper.OK_EXIT_CODE) return;
-    generateProject(project, dlg);
-  }
-
-  protected Object showSettings(DirectoryProjectGenerator generator, VirtualFile baseDir)
-      throws ProcessCanceledException {
-    return generator.showGenerationSettings(baseDir);
+    if (dlg.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
+      generateProject(project, dlg);
+    }
   }
 
   @Nullable
   protected Project generateProject(Project project, NewDirectoryProjectDialog dlg) {
-    final DirectoryProjectGenerator generator = dlg.getProjectGenerator();
     final File location = new File(dlg.getNewProjectLocation());
     if (!location.exists() && !location.mkdirs()) {
-      Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project");
+      String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location);
+      Messages.showErrorDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"));
       return null;
     }
 
@@ -70,27 +67,31 @@ public class NewDirectoryProjectAction extends AnAction implements DumbAware {
         return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location);
       }
     });
-    LOG.assertTrue(baseDir != null, "Couldn't find '" + location + "' in VFS");
+    if (baseDir == null) {
+      LOG.error("Couldn't find '" + location + "' in VFS");
+      return null;
+    }
     baseDir.refresh(false, true);
 
     if (baseDir.getChildren().length > 0) {
-      int rc = Messages.showYesNoDialog(project,
-                                        "The directory '" + location +
-                                        "' is not empty. Would you like to create a project from existing sources instead?",
-                                        "Create New Project", Messages.getQuestionIcon());
+      String message = ActionsBundle.message("action.NewDirectoryProject.not.empty", location);
+      int rc = Messages.showYesNoDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"), Messages.getQuestionIcon());
       if (rc == Messages.YES) {
         return PlatformProjectOpenProcessor.getInstance().doOpenProject(baseDir, null, false);
       }
     }
 
+    @SuppressWarnings("unchecked") final DirectoryProjectGenerator<Object> generator = dlg.getProjectGenerator();
+
     String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName());
     UsageTrigger.trigger("NewDirectoryProjectAction." + generatorName);
+
     Object settings = null;
     if (generator != null) {
       try {
         settings = showSettings(generator, baseDir);
       }
-      catch (ProcessCanceledException e1) {
+      catch (ProcessCanceledException e) {
         return null;
       }
     }
@@ -105,4 +106,8 @@ public class NewDirectoryProjectAction extends AnAction implements DumbAware {
       }
     }, false);
   }
+
+  protected Object showSettings(DirectoryProjectGenerator generator, VirtualFile baseDir) throws ProcessCanceledException {
+    return generator.showGenerationSettings(baseDir);
+  }
 }
index b3cd91e349153d39d1502642935073e33fa3793e..1cabaf3e0c7562d4e03d4a730c7c2ec7f80c76db 100644 (file)
@@ -1243,6 +1243,9 @@ action.WelcomeScreen.CreateDirectoryProject.text=Create New Project
 action.WelcomeScreen.CreateDirectoryProject.description=Create a new project.
 action.NewDirectoryProject.text=New Project...
 action.NewDirectoryProject.description=Create a new project
+action.NewDirectoryProject.title=Create Project
+action.NewDirectoryProject.cannot.create.dir=Cannot create directory ''{0}''.
+action.NewDirectoryProject.not.empty=The directory ''{0}'' is not empty. Would you like to create a project from existing sources instead?
 
 action.SliceBackward.text=Analyze Data Flow _to Here
 action.SliceBackward.description=Search for values which can be assigned to selected expression