From 3879e775c95d550ddb8a40f2b093a9a047316b6c Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Wed, 22 Jun 2016 14:49:19 +0200 Subject: [PATCH] project name listener for WI-30937 Create composer.json data servise and WI-30286 use composer.json as a source and storage for project settings --- .../renameProject/RenameProjectHandler.java | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/platform/renameProject/RenameProjectHandler.java b/platform/lang-impl/src/com/intellij/platform/renameProject/RenameProjectHandler.java index c3be64d2c5f2..a94d7248d616 100644 --- a/platform/lang-impl/src/com/intellij/platform/renameProject/RenameProjectHandler.java +++ b/platform/lang-impl/src/com/intellij/platform/renameProject/RenameProjectHandler.java @@ -43,10 +43,6 @@ import com.intellij.refactoring.rename.RenameHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * @author lene - * Date: 30.09.11 - */ public class RenameProjectHandler implements RenameHandler, TitledHandler { private static final Logger LOG = Logger.getInstance("#" + RenameProjectHandler.class.getName()); @@ -104,42 +100,46 @@ public class RenameProjectHandler implements RenameHandler, TitledHandler { @Override public boolean canClose(final String inputString) { - if (shouldRenameProject(inputString)) { - myProject.setProjectName(inputString); - myProject.save(); - } + return renameProject(myProject, myModule, inputString); + } + } - if (myModule != null && !inputString.equals(myModule.getName())) { - final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(myProject).getModifiableModel(); - try { - modifiableModel.renameModule(myModule, inputString); - } - catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) { - Messages.showErrorDialog(myProject, IdeBundle.message("error.module.already.exists", inputString), - IdeBundle.message("title.rename.module")); - return false; - } - final Ref success = Ref.create(Boolean.TRUE); - CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> modifiableModel.commit())), IdeBundle.message("command.renaming.module", myModule.getName()), null); - return success.get().booleanValue(); + public static boolean renameProject(@NotNull ProjectEx project, @Nullable Module module, String newName){ + if (shouldRenameProject(project, module, newName)) { + project.setProjectName(newName); + project.save(); + } + + if (module != null && !newName.equals(module.getName())) { + final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel(); + try { + modifiableModel.renameModule(module, newName); } + catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) { + Messages.showErrorDialog(project, IdeBundle.message("error.module.already.exists", newName), + IdeBundle.message("title.rename.module")); + return false; + } + final Ref success = Ref.create(Boolean.TRUE); + CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> modifiableModel.commit())), IdeBundle.message("command.renaming.module", module.getName()), null); + return success.get().booleanValue(); + } + return true; + } + + private static boolean shouldRenameProject(@NotNull Project project, @Nullable Module module, String inputString) { + if (inputString.equals(project.getName())) { + return false; + } + + if (module == null) { return true; } - private boolean shouldRenameProject(String inputString) { - if (inputString.equals(myProject.getName())) { - return false; - } - - if (myModule == null) { - return true; - } - - if (ProjectAttachProcessor.canAttachToProject()) { - return myModule == ModuleAttachProcessor.getPrimaryModule(myProject); - } - - return myModule == ModuleAttachProcessor.findModuleInBaseDir(myProject); + if (ProjectAttachProcessor.canAttachToProject()) { + return module == ModuleAttachProcessor.getPrimaryModule(project); } + + return module == ModuleAttachProcessor.findModuleInBaseDir(project); } }