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
This commit is contained in:
Shaverdova Elena
2016-06-22 15:43:57 +02:00
committed by Shaverdova Elena
parent bfcb31edd2
commit 3879e775c9
@@ -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<Boolean> 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<Boolean> 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);
}
}