IDEADEV-41383 Inject language intention: "Add library" dialog is shown under popup

This commit is contained in:
Gregory Shrago
2009-11-16 23:44:47 +03:00
parent ab18050c08
commit 44fbf87e45
3 changed files with 13 additions and 5 deletions
@@ -326,11 +326,11 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
});
}
public static void ensureAnnotationsJarInPath(final Module module, String annotationName) {
if (module == null) return;
public static boolean ensureAnnotationsJarInPath(final Module module, String annotationName) {
if (module == null) return false;
final PsiClass psiClass = JavaPsiFacade.getInstance(module.getProject())
.findClass(annotationName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
if (psiClass != null) return;
if (psiClass != null) return true;
final LocateLibraryDialog dialog = new LocateLibraryDialog(
module, PathManager.getLibPath(), "annotations.jar",
QuickFixBundle.message("add.library.annotations.description"));
@@ -341,6 +341,8 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
addJarToRoots(dialog.getResultingLibraryPath(), module, null);
}
}.execute();
return true;
}
return false;
}
}
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.ide.DataManager;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.lang.Language;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.FileType;
@@ -82,6 +83,7 @@ public class InjectLanguageAction implements IntentionAction {
assert host != null;
doChooseLanguageToInject(new Processor<String>() {
public boolean process(final String languageId) {
if (project.isDisposed()) return false;
if (defaultFunctionalityWorked(host, languageId)) return false;
final Language language = InjectedLanguage.findLanguageById(languageId);
try {
@@ -146,7 +148,11 @@ public class InjectLanguageAction implements IntentionAction {
@Override
public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
if (finalChoice) {
myFinalStepProcessor.process(selectedValue);
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
myFinalStepProcessor.process(selectedValue);
}
});
return FINAL_CHOICE;
}
return new MyPopupStep(myMap, myMap.get(selectedValue), myFinalStepProcessor);
@@ -203,7 +203,7 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
static boolean doAddLanguageAnnotation(final Project project, final PsiModifierListOwner modifierListOwner,
final String languageId) {
if (modifierListOwner.getModifierList() == null || !PsiUtil.getLanguageLevel(modifierListOwner).hasEnumKeywordAndAutoboxing()) return false;
OrderEntryFix.ensureAnnotationsJarInPath(ModuleUtil.findModuleForPsiElement(modifierListOwner), AnnotationUtil.LANGUAGE);
if (!OrderEntryFix.ensureAnnotationsJarInPath(ModuleUtil.findModuleForPsiElement(modifierListOwner), AnnotationUtil.LANGUAGE)) return false;
new WriteCommandAction(project, modifierListOwner.getContainingFile()) {
protected void run(final Result result) throws Throwable {
final PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory()