use of com.intellij.ide.IdeView in project android by JetBrains.
the class CreateClassAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
DataContext context = event.getDataContext();
IdeView view = LangDataKeys.IDE_VIEW.getData(context);
if (view == null) {
return;
}
Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return;
}
final PsiDirectory directory = view.getOrChooseDirectory();
if (directory == null) {
return;
}
CreateFileFromTemplateDialog dialog = new CreateFileFromTemplateDialog(project, directory);
try {
PsiClass createdElement = dialog.show(new CreateFileFromTemplateDialog.FileCreator() {
@Override
public PsiClass createFile(@NotNull String name, @NotNull Map<String, String> creationOptions, @NotNull String templateName) {
String enteredPackageName = creationOptions.get(FileTemplate.ATTRIBUTE_PACKAGE_NAME);
PsiDirectory packageSubdirectory = createPackageSubdirectory(directory, enteredPackageName);
return checkOrCreate(name, packageSubdirectory, templateName, creationOptions);
}
@Override
@NotNull
public String getActionName(@NotNull String name, @NotNull String templateName) {
String packageDirectoryQualifiedName = myJavaDirectoryService.getPackage(directory).getQualifiedName();
return IdeBundle.message("progress.creating.class", StringUtil.getQualifiedName(packageDirectoryQualifiedName, name));
}
});
view.selectElement(createdElement);
CreateFromTemplateAction.moveCaretAfterNameIdentifier(createdElement);
if (dialog.isShowSelectOverridesDialogCheckBoxSelected()) {
showOverridesDialog(event);
}
} catch (CreateFileFromTemplateDialog.FailedToCreateFileException exception) {
Logger.getInstance(CreateClassAction.class).warn(exception);
}
}
use of com.intellij.ide.IdeView in project android by JetBrains.
the class JavaSourceAction method isAvailable.
protected static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null || view == null || view.getDirectories().length == 0 || AndroidFacet.getInstance(module) == null) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null && !dirService.getPackage(dir).getQualifiedName().isEmpty()) {
return true;
}
}
return false;
}
use of com.intellij.ide.IdeView in project android by JetBrains.
the class LegacyNewAndroidComponentAction method isAvailable.
private static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null || view == null || view.getDirectories().length == 0) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.requiresAndroidModel()) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null) {
return true;
}
}
return false;
}
use of com.intellij.ide.IdeView in project android by JetBrains.
the class LegacyNewAndroidComponentAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null) {
return;
}
final Module module = LangDataKeys.MODULE.getData(dataContext);
if (module == null)
return;
final AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
final PsiDirectory dir = view.getOrChooseDirectory();
if (dir == null)
return;
NewAndroidComponentDialog dialog = new NewAndroidComponentDialog(module, dir);
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
return;
}
final PsiElement[] createdElements = dialog.getCreatedElements();
for (PsiElement createdElement : createdElements) {
view.selectElement(createdElement);
}
}
use of com.intellij.ide.IdeView in project android by JetBrains.
the class TemplateManager method updateAction.
private static void updateAction(AnActionEvent event, String text, boolean visible) {
IdeView view = LangDataKeys.IDE_VIEW.getData(event.getDataContext());
final Module module = LangDataKeys.MODULE.getData(event.getDataContext());
final AndroidFacet facet = module != null ? AndroidFacet.getInstance(module) : null;
Presentation presentation = event.getPresentation();
boolean isProjectReady = facet != null && facet.getAndroidModel() != null;
presentation.setText(text + (isProjectReady ? "" : " (Project not ready)"));
presentation.setVisible(visible && view != null && facet != null && facet.requiresAndroidModel());
}
Aggregations