mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-138603 "From File Template" is not always available
This commit is contained in:
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.intellij.ide.fileTemplates;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction;
|
||||
import com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup;
|
||||
import com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.testFramework.TestActionEvent;
|
||||
@@ -24,6 +26,8 @@ import com.intellij.testFramework.TestDataProvider;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class JavaFileTemplatesTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testCreateFromTemplateGroup() throws Exception {
|
||||
@@ -43,4 +47,23 @@ public class JavaFileTemplatesTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testManyTemplates() throws Exception {
|
||||
FileTemplateManagerImpl templateManager = (FileTemplateManagerImpl)FileTemplateManager.getInstance(getProject());
|
||||
templateManager.getState().RECENT_TEMPLATES.clear();
|
||||
FileTemplate[] before = templateManager.getAllTemplates();
|
||||
try {
|
||||
for (int i = 0; i < 30; i++) {
|
||||
templateManager.addTemplate("foo" + i, "java");
|
||||
}
|
||||
AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject())));
|
||||
assertEquals(3, children.length);
|
||||
assertTrue(IdeBundle.message("action.from.file.template").equals(children[0].getTemplatePresentation().getText()));
|
||||
}
|
||||
finally {
|
||||
templateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
|
||||
templateManager.getState().RECENT_TEMPLATES.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -57,8 +57,9 @@ public class CreateFromTemplateGroup extends ActionGroup implements DumbAware {
|
||||
@Override
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable AnActionEvent e){
|
||||
Project project;
|
||||
if (e == null || (project = CommonDataKeys.PROJECT.getData(e.getDataContext())) == null) return EMPTY_ARRAY;
|
||||
if (e == null) return EMPTY_ARRAY;
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) return EMPTY_ARRAY;
|
||||
FileTemplateManager manager = FileTemplateManager.getInstance(project);
|
||||
FileTemplate[] templates = manager.getAllTemplates();
|
||||
|
||||
@@ -106,7 +107,7 @@ public class CreateFromTemplateGroup extends ActionGroup implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
if (!result.isEmpty() || !showAll) {
|
||||
if (!showAll) {
|
||||
result.add(new CreateFromTemplatesAction(IdeBundle.message("action.from.file.template")));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user