mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[mod-commands] Better preview for create directory + move
GitOrigin-RevId: 846f75946e1bc26ce562f21e70bed0e2c9f3810d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0c604ad7e0
commit
6bb5aeda34
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -83,4 +84,18 @@ public final class ModCommandTest extends LightPlatformCodeInsightTestCase {
|
||||
String actual = html.content().toString();
|
||||
assertEquals("<p>Create directories:<br/>• a<br/>• a/b<br/>• a/c</p>", actual);
|
||||
}
|
||||
|
||||
public void testCreateDirectoriesAndMovePreview() {
|
||||
configureFromFileText("dummy.txt", "");
|
||||
VirtualFile vFile = getFile().getVirtualFile();
|
||||
FutureVirtualFile target = new FutureVirtualFile(vFile.getParent(), "a", null);
|
||||
ModCommand command = new ModCreateFile(target, new ModCreateFile.Directory())
|
||||
.andThen(new ModMoveFile(vFile, new FutureVirtualFile(target, vFile.getName(), vFile.getFileType())));
|
||||
IntentionPreviewInfo preview = ModCommandExecutor.getInstance().getPreview(command, ActionContext.from(null, getFile()));
|
||||
IntentionPreviewInfo.Html html = assertInstanceOf(preview, IntentionPreviewInfo.Html.class);
|
||||
String actual = html.content().toString();
|
||||
assertEquals("""
|
||||
Create directory 'a'<br/><br/><p><icon src="file"/> dummy.txt → \
|
||||
<icon src="dir"/> $src$a</p>""".replace("$", File.separator), actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +295,7 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
List<IntentionPreviewInfo.CustomDiff> customDiffList = new ArrayList<>();
|
||||
IntentionPreviewInfo navigateInfo = IntentionPreviewInfo.EMPTY;
|
||||
List<@NlsSafe String> createdDirs = new ArrayList<>();
|
||||
List<HtmlChunk> fsActions = new ArrayList<>();
|
||||
for (ModCommand command : modCommand.unpack()) {
|
||||
if (command instanceof ModUpdateFileText modFile) {
|
||||
VirtualFile vFile = modFile.file();
|
||||
@@ -359,11 +360,13 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
}
|
||||
else if (command instanceof ModMoveFile moveFile) {
|
||||
FutureVirtualFile targetFile = moveFile.targetFile();
|
||||
IntentionPreviewInfo.Html html;
|
||||
if (targetFile.getName().equals(moveFile.file().getName())) {
|
||||
navigateInfo = IntentionPreviewInfo.moveToDirectory(moveFile.file(), targetFile.getParent());
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.moveToDirectory(moveFile.file(), targetFile.getParent());
|
||||
} else {
|
||||
navigateInfo = IntentionPreviewInfo.rename(moveFile.file(), targetFile.getName());
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.rename(moveFile.file(), targetFile.getName());
|
||||
}
|
||||
fsActions.add(html.content());
|
||||
}
|
||||
else if (command instanceof ModUpdateSystemOptions options) {
|
||||
HtmlChunk preview = createOptionsPreview(context, options);
|
||||
@@ -372,17 +375,25 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
}
|
||||
customDiffList.sort(Comparator.comparing(diff -> diff.fileName() != null));
|
||||
if (customDiffList.isEmpty()) {
|
||||
HtmlBuilder builder = new HtmlBuilder();
|
||||
if (!createdDirs.isEmpty()) {
|
||||
if (createdDirs.size() == 1) {
|
||||
return new IntentionPreviewInfo.Html(text(AnalysisBundle.message("preview.create.directory", createdDirs.get(0))));
|
||||
builder.append(AnalysisBundle.message("preview.create.directory", createdDirs.get(0))).br();
|
||||
} else {
|
||||
builder.append(tag("p").addText(AnalysisBundle.message("preview.create.directories")).children(
|
||||
ContainerUtil.map(createdDirs, text -> new HtmlBuilder().br()
|
||||
.appendRaw("• ") //NON-NLS
|
||||
.append(text)
|
||||
.toFragment()))
|
||||
);
|
||||
}
|
||||
return new IntentionPreviewInfo.Html(
|
||||
tag("p").addText(AnalysisBundle.message("preview.create.directories")).children(
|
||||
ContainerUtil.map(createdDirs, text -> new HtmlBuilder().br()
|
||||
.appendRaw("• ") //NON-NLS
|
||||
.append(text)
|
||||
.toFragment()))
|
||||
);
|
||||
}
|
||||
if (!fsActions.isEmpty()) {
|
||||
if (!builder.isEmpty()) builder.br();
|
||||
fsActions.forEach(builder::append);
|
||||
}
|
||||
if (!builder.isEmpty()) {
|
||||
return new IntentionPreviewInfo.Html(builder.toFragment());
|
||||
}
|
||||
return navigateInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user