Configure Kotlin: restore all changed files in undo action
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
## 1.0.2
|
## 1.0.2
|
||||||
- Show only changed files in notification "Kotlin not configured"
|
- Show only changed files in notification "Kotlin not configured"
|
||||||
|
- Configure Kotlin: restore all changed files in undo action
|
||||||
|
|
||||||
### JVM
|
### JVM
|
||||||
- Remove the compiler option "Xmultifile-facades-open"
|
- Remove the compiler option "Xmultifile-facades-open"
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.idea.configuration;
|
|||||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||||
import com.intellij.ide.actions.OpenFileAction;
|
import com.intellij.ide.actions.OpenFileAction;
|
||||||
import com.intellij.openapi.application.Result;
|
import com.intellij.openapi.application.Result;
|
||||||
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.command.WriteCommandAction;
|
import com.intellij.openapi.command.WriteCommandAction;
|
||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.DependencyScope;
|
import com.intellij.openapi.roots.DependencyScope;
|
||||||
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
||||||
import com.intellij.openapi.roots.FileIndexFacade;
|
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.vfs.VfsUtil;
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
@@ -84,13 +84,16 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(@NotNull Project project, Collection<Module> excludeModules) {
|
public void configure(@NotNull final Project project, Collection<Module> excludeModules) {
|
||||||
ConfigureDialogWithModulesAndVersion dialog =
|
final ConfigureDialogWithModulesAndVersion dialog =
|
||||||
new ConfigureDialogWithModulesAndVersion(project, this, excludeModules);
|
new ConfigureDialogWithModulesAndVersion(project, this, excludeModules);
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
if (!dialog.isOK()) return;
|
if (!dialog.isOK()) return;
|
||||||
|
|
||||||
|
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project);
|
NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project);
|
||||||
Set<GroovyFile> changedFiles = new HashSet<GroovyFile>();
|
Set<GroovyFile> changedFiles = new HashSet<GroovyFile>();
|
||||||
GroovyFile projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project));
|
GroovyFile projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project));
|
||||||
@@ -119,6 +122,8 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
collector.showNotification();
|
collector.showNotification();
|
||||||
}
|
}
|
||||||
|
}, "Configure Kotlin", null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void addKotlinLibraryToModule(final Module module, final DependencyScope scope, final ExternalLibraryDescriptor libraryDescriptor) {
|
public static void addKotlinLibraryToModule(final Module module, final DependencyScope scope, final ExternalLibraryDescriptor libraryDescriptor) {
|
||||||
String gradleFilePath = getModuleFilePath(module);
|
String gradleFilePath = getModuleFilePath(module);
|
||||||
@@ -257,8 +262,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
||||||
Module module = FileIndexFacade.getInstance(file.getProject()).getModuleForFile(file.getVirtualFile());
|
wasModified |= addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false);
|
||||||
wasModified |= addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false, !ConfigureKotlinInProjectUtilsKt.hasKotlinRuntimeInScope(module));
|
|
||||||
|
|
||||||
wasModified |= addSourceSetsBlock(file);
|
wasModified |= addSourceSetsBlock(file);
|
||||||
|
|
||||||
@@ -383,11 +387,11 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
protected static boolean addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
return addExpressionInBlockIfNeeded(text, block, false, false);
|
return addExpressionInBlockIfNeeded(text, block, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
private static boolean addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
return addExpressionInBlockIfNeeded(text, block, true, false);
|
return addExpressionInBlockIfNeeded(text, block, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -405,8 +409,8 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst, boolean forceInsert) {
|
private static boolean addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst) {
|
||||||
if (!forceInsert && block.getText().contains(text)) return false;
|
if (block.getText().contains(text)) return false;
|
||||||
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
||||||
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
||||||
GrStatement[] statements = block.getStatements();
|
GrStatement[] statements = block.getStatements();
|
||||||
|
|||||||
Reference in New Issue
Block a user