com.intellij.ide.IdeView Java Examples
The following examples show how to use
com.intellij.ide.IdeView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewClassAction.java From json2java4idea with Apache License 2.0 | 6 votes |
@CheckReturnValue @VisibleForTesting @SuppressWarnings("WeakerAccess") static boolean isAvailable(@Nonnull AnActionEvent event) { final Project project = event.getProject(); if (project == null) { return false; } final IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view == null) { return false; } final ProjectRootManager rootManager = ProjectRootManager.getInstance(project); final ProjectFileIndex fileIndex = rootManager.getFileIndex(); final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories()) .filter(directory -> { final VirtualFile virtualFile = directory.getVirtualFile(); return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES); }) .findFirst(); return sourceDirectory.isPresent(); }
Example #2
Source File: GenerateAction.java From RIBs with Apache License 2.0 | 6 votes |
/** * Checked whether or not this action can be enabled. * <p> * <p>Requirements to be enabled: * User must be in a Java source folder. * * @param dataContext to figure out where the user is. * @return {@code true} when the action is available, {@code false} when the action is not * available. */ private boolean isAvailable(DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return false; } final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null || view.getDirectories().length == 0) { return false; } ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiDirectory dir : view.getDirectories()) { if (projectFileIndex.isUnderSourceRootOfType( dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && checkPackageExists(dir)) { return true; } } return false; }
Example #3
Source File: NewElementAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent e){ final Presentation presentation = e.getPresentation(); final DataContext context = e.getDataContext(); final Project project = context.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setEnabled(false); return; } if (Boolean.TRUE.equals(context.getData(LangDataKeys.NO_NEW_ACTION))) { presentation.setEnabled(false); return; } final IdeView ideView = context.getData(LangDataKeys.IDE_VIEW); if (ideView == null) { presentation.setEnabled(false); return; } presentation.setEnabled(!ActionGroupUtil.isGroupEmpty(getGroup(context), e)); }
Example #4
Source File: GraphQLCreateConfigFileAction.java From js-graphql-intellij-plugin with MIT License | 6 votes |
@Override public void update(AnActionEvent e) { boolean isAvailable = false; if (e.getProject() != null) { final DataContext dataContext = e.getDataContext(); final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view != null && view.getDirectories().length > 0) { final Module module = LangDataKeys.MODULE.getData(dataContext); if (module != null) { final VirtualFile actionDirectory = getActionDirectory(e); if (actionDirectory != null) { isAvailable = (actionDirectory.findChild(GraphQLConfigManager.GRAPHQLCONFIG) == null); } } } } final Presentation presentation = e.getPresentation(); presentation.setVisible(isAvailable); presentation.setEnabled(isAvailable); }
Example #5
Source File: CreateElementActionBase.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public final void actionPerformed(@Nonnull final AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); if (view == null) { return; } final Project project = e.getProject(); final PsiDirectory dir = view.getOrChooseDirectory(); if (dir == null) return; invokeDialog(project, dir, elements -> { for (PsiElement createdElement : elements) { view.selectElement(createdElement); } }); }
Example #6
Source File: CreateInDirectoryActionBase.java From consulo with Apache License 2.0 | 6 votes |
protected boolean isAvailable(final DataContext dataContext) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return false; } if (DumbService.getInstance(project).isDumb() && !isDumbAware()) { return false; } final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if (view == null || view.getDirectories().length == 0) { return false; } return true; }
Example #7
Source File: BundleClassGeneratorUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static PsiDirectory getBundleDirContext(@NotNull AnActionEvent event) { Project project = event.getData(PlatformDataKeys.PROJECT); if (project == null) { return null; } DataContext dataContext = event.getDataContext(); IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return null; } PsiDirectory[] directories = view.getDirectories(); if(directories.length == 0) { return null; } return FilesystemUtil.findParentBundleFolder(directories[0]); }
Example #8
Source File: ExtensionUtility.java From idea-php-typo3-plugin with MIT License | 6 votes |
public static PsiDirectory getExtensionDirectory(@NotNull AnActionEvent event) { Project project = event.getData(PlatformDataKeys.PROJECT); if (project == null) { return null; } DataContext dataContext = event.getDataContext(); IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return null; } PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0) { return null; } return FilesystemUtil.findParentExtensionDirectory(directories[0]); }
Example #9
Source File: NewFileAction.java From idea-gitignore with MIT License | 5 votes |
/** * Updates visibility of the action presentation in various actions list. * * @param e action event */ @Override public void update(@NotNull AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final PsiDirectory[] directory = view != null ? view.getDirectories() : null; if (directory == null || directory.length == 0 || project == null || !this.fileType.getIgnoreLanguage().isNewAllowed()) { e.getPresentation().setVisible(false); } }
Example #10
Source File: DirectoryChooserUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static PsiDirectory getOrChooseDirectory(@Nonnull IdeView view) { PsiDirectory[] dirs = view.getDirectories(); if (dirs.length == 0) return null; if (dirs.length == 1) { return dirs[0]; } else { Project project = dirs[0].getProject(); return selectDirectory(project, dirs, null, ""); } }
Example #11
Source File: CreateFromTemplateGroup.java From consulo with Apache License 2.0 | 5 votes |
static boolean canCreateFromTemplate(AnActionEvent e, FileTemplate template) { if (e == null) return false; DataContext dataContext = e.getDataContext(); IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if (view == null) return false; PsiDirectory[] dirs = view.getDirectories(); if (dirs.length == 0) return false; return FileTemplateUtil.canCreateFromTemplate(dirs, template); }
Example #12
Source File: CreateFromTemplateActionBase.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public final void actionPerformed(@Nonnull AnActionEvent e) { DataContext dataContext = e.getDataContext(); IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if (view == null) return; PsiDirectory dir = getTargetDirectory(dataContext, view); if (dir == null) return; Project project = dir.getProject(); FileTemplate selectedTemplate = getTemplate(project, dir); if (selectedTemplate != null) { AnAction action = getReplacedAction(selectedTemplate); if (action != null) { action.actionPerformed(e); } else { FileTemplateManager.getInstance(project).addRecentName(selectedTemplate.getName()); AttributesDefaults defaults = getAttributesDefaults(dataContext); Map<String, Object> properties = defaults != null ? defaults.getDefaultProperties() : null; CreateFromTemplateDialog dialog = new CreateFromTemplateDialog(dir, selectedTemplate, defaults, properties); PsiElement createdElement = dialog.create(); if (createdElement != null) { elementCreated(dialog, createdElement); view.selectElement(createdElement); if (selectedTemplate.isLiveTemplateEnabled() && createdElement instanceof PsiFile) { Map<String, String> defaultValues = getLiveTemplateDefaults(dataContext, ((PsiFile)createdElement)); startLiveTemplate((PsiFile)createdElement, notNull(defaultValues, Collections.emptyMap())); } } } } }
Example #13
Source File: CreateDirectoryOrPackageAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { IdeView view = e.getData(LangDataKeys.IDE_VIEW); Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); if (directory == null) { return; } Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> info = getInfo(directory); boolean isDirectory = info.getThird() == ChildType.Directory; CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, isDirectory, info.getThird().getSeparator()); String title = isDirectory ? IdeBundle.message("title.new.directory") : IdeBundle.message("title.new.package"); createLightWeightPopup(validator, title, element -> { if (element != null) { view.selectElement(element); } }).showCenteredInCurrentWindow(project); }
Example #14
Source File: CSharpCreateFileAction.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction private static Module findModule(DataContext dataContext) { Project project = dataContext.getData(CommonDataKeys.PROJECT); if(project == null) { return null; } final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if(view == null) { return null; } final PsiDirectory orChooseDirectory = view.getOrChooseDirectory(); if(orChooseDirectory == null) { return null; } Module resolve = CSharpCreateFromTemplateHandler.findModuleByPsiDirectory(orChooseDirectory); if(resolve != null) { return resolve; } return dataContext.getData(LangDataKeys.MODULE); }
Example #15
Source File: CSharpCreateFileAction.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess protected boolean isAvailable(DataContext dataContext) { Module module = findModule(dataContext); if(module != null) { DotNetModuleExtension extension = ModuleUtilCore.getExtension(module, DotNetModuleExtension.class); if(extension != null && extension.isAllowSourceRoots()) { final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if(view == null) { return false; } PsiDirectory orChooseDirectory = view.getOrChooseDirectory(); if(orChooseDirectory == null) { return false; } PsiPackage aPackage = PsiPackageManager.getInstance(module.getProject()).findPackage(orChooseDirectory, DotNetModuleExtension.class); if(aPackage == null) { return false; } } } return module != null && ModuleUtilCore.getExtension(module, CSharpSimpleModuleExtension.class) != null; }
Example #16
Source File: PolygeneCreateActionGroup.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private boolean shouldActionGroupVisible( AnActionEvent e ) { Module module = e.getData( LangDataKeys.MODULE ); if( module == null ) { return false; } // TODO: Enable this once PolygeneFacet can be automatically added/removed // if( PolygeneFacet.getInstance( module ) == null ) // { // return false; // } // Are we on IDE View and under project source folder? Project project = e.getData( PlatformDataKeys.PROJECT ); IdeView view = e.getData( LangDataKeys.IDE_VIEW ); if( view != null && project != null ) { ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance( project ).getFileIndex(); PsiDirectory[] dirs = view.getDirectories(); for( PsiDirectory dir : dirs ) { if( projectFileIndex.isInSourceContent( dir.getVirtualFile() ) && JavaDirectoryService.getInstance().getPackage( dir ) != null ) { return true; } } } return false; }
Example #17
Source File: NewBlazePackageAction.java From intellij with Apache License 2.0 | 5 votes |
private boolean isEnabled(AnActionEvent event) { Project project = event.getProject(); IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (project == null || view == null) { return false; } return view.getDirectories().length != 0; }
Example #18
Source File: NewBlazePackageAction.java From intellij with Apache License 2.0 | 5 votes |
@Override protected void actionPerformedInBlazeProject(Project project, AnActionEvent event) { IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view == null) { return; } PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); if (directory == null) { return; } CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, false, ".") { @Override protected void createDirectories(String subDirName) { super.createDirectories(subDirName); PsiFileSystemItem element = getCreatedElement(); if (element instanceof PsiDirectory) { createBuildFile(project, (PsiDirectory) element); } } }; Messages.showInputDialog( project, "Enter new package name:", String.format("New %s Package", Blaze.buildSystemName(project)), Messages.getQuestionIcon(), "", validator); PsiDirectory newDir = (PsiDirectory) validator.getCreatedElement(); if (newDir != null) { PsiFile buildFile = findBuildFile(project, newDir); if (buildFile != null) { view.selectElement(buildFile); OpenFileAction.openFile(buildFile.getViewProvider().getVirtualFile(), project); } } }
Example #19
Source File: GenerateAction.java From RIBs with Apache License 2.0 | 5 votes |
/** * @return gets the current package name for an executing action. */ protected final String getPackageName() { /** Preconditions have been validated by {@link GenerateAction#isAvailable(DataContext)}. */ final Project project = Preconditions.checkNotNull(CommonDataKeys.PROJECT.getData(dataContext)); final IdeView view = Preconditions.checkNotNull(LangDataKeys.IDE_VIEW.getData(dataContext)); final PsiDirectory directory = Preconditions.checkNotNull(view.getOrChooseDirectory()); final PsiPackage psiPackage = Preconditions.checkNotNull(JavaDirectoryService.getInstance().getPackage(directory)); return psiPackage.getQualifiedName(); }
Example #20
Source File: ActionUtil.java From idea-php-typo3-plugin with MIT License | 5 votes |
/** * Finds the directories on which an action was performed on. * * @param actionEvent The source action event * @return an array of directories the action was performed on */ public static PsiDirectory[] findDirectoryFromActionEvent(AnActionEvent actionEvent) { DataContext dataContext = actionEvent.getDataContext(); IdeView data = LangDataKeys.IDE_VIEW.getData(dataContext); if (data == null) { return new PsiDirectory[]{}; } return data.getDirectories(); }
Example #21
Source File: NewFileAction.java From idea-gitignore with MIT License | 4 votes |
/** * Creates new Gitignore file if it does not exist or uses an existing one and opens {@link GeneratorDialog}. * * @param e action event */ @Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); final IdeView view = e.getRequiredData(LangDataKeys.IDE_VIEW); VirtualFile fixedDirectory = fileType.getIgnoreLanguage().getFixedDirectory(project); PsiDirectory directory; if (fixedDirectory != null) { directory = PsiManager.getInstance(project).findDirectory(fixedDirectory); } else { directory = view.getOrChooseDirectory(); } if (directory == null) { return; } GeneratorDialog dialog; String filename = fileType.getIgnoreLanguage().getFilename(); PsiFile file = directory.findFile(filename); VirtualFile virtualFile = file == null ? directory.getVirtualFile().findChild(filename) : file.getVirtualFile(); if (file == null && virtualFile == null) { CreateFileCommandAction action = new CreateFileCommandAction(project, directory, fileType); dialog = new GeneratorDialog(project, action); } else { Notifications.Bus.notify(new Notification( fileType.getLanguageName(), IgnoreBundle.message("action.newFile.exists", fileType.getLanguageName()), IgnoreBundle.message("action.newFile.exists.in", virtualFile.getPath()), NotificationType.INFORMATION ), project); if (file == null) { file = Utils.getPsiFile(project, virtualFile); } dialog = new GeneratorDialog(project, file); } dialog.show(); file = dialog.getFile(); if (file != null) { Utils.openFile(project, file); } }
Example #22
Source File: ServiceActionUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
public static void buildFile(AnActionEvent event, final Project project, String templatePath) { String extension = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? "yml" : "xml" ; String fileName = Messages.showInputDialog(project, "File name (without extension)", String.format("Create %s Service", extension), Symfony2Icons.SYMFONY); if(fileName == null || StringUtils.isBlank(fileName)) { return; } FileType fileType = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? YAMLFileType.YML : XmlFileType.INSTANCE ; if(!fileName.endsWith("." + extension)) { fileName = fileName.concat("." + extension); } DataContext dataContext = event.getDataContext(); IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return; } PsiDirectory[] directories = view.getDirectories(); if(directories.length == 0) { return; } final PsiDirectory initialBaseDir = directories[0]; if (initialBaseDir == null) { return; } if(initialBaseDir.findFile(fileName) != null) { Messages.showInfoMessage("File exists", "Error"); return; } String content; try { content = StreamUtil.readText(ServiceActionUtil.class.getResourceAsStream(templatePath), "UTF-8").replace("\r\n", "\n"); } catch (IOException e) { e.printStackTrace(); return; } final PsiFileFactory factory = PsiFileFactory.getInstance(project); String bundleName = "Acme\\DemoBundle"; SymfonyBundleUtil symfonyBundleUtil = new SymfonyBundleUtil(project); SymfonyBundle symfonyBundle = symfonyBundleUtil.getContainingBundle(initialBaseDir); if(symfonyBundle != null) { bundleName = StringUtils.strip(symfonyBundle.getNamespaceName(), "\\"); } String underscoreBundle = bundleName.replace("\\", ".").toLowerCase(); if(underscoreBundle.endsWith("bundle")) { underscoreBundle = underscoreBundle.substring(0, underscoreBundle.length() - 6); } content = content.replace("{{ BundleName }}", bundleName).replace("{{ BundleNameUnderscore }}", underscoreBundle); final PsiFile file = factory.createFileFromText(fileName, fileType, content); ApplicationManager.getApplication().runWriteAction(() -> { CodeStyleManager.getInstance(project).reformat(file); initialBaseDir.add(file); }); PsiFile psiFile = initialBaseDir.findFile(fileName); if(psiFile != null) { view.selectElement(psiFile); } }
Example #23
Source File: HeavyIdeaTestFixtureImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nullable public Object getData(@Nonnull @NonNls Key<?> dataId) { if (CommonDataKeys.PROJECT == dataId) { return myProject; } else if (PlatformDataKeys.EDITOR == dataId || OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) { if (myProject == null) return null; return FileEditorManager.getInstance(myProject).getSelectedTextEditor(); } else { Editor editor = (Editor)getData(PlatformDataKeys.EDITOR); if (editor != null) { FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject); return manager.getData(dataId, editor, editor.getCaretModel().getCurrentCaret()); } else if (LangDataKeys.IDE_VIEW == dataId) { VirtualFile[] contentRoots = ProjectRootManager.getInstance(myProject).getContentRoots(); final PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(contentRoots[0]); if (contentRoots.length > 0) { return new IdeView() { @Override public void selectElement(PsiElement element) { } @Override public PsiDirectory[] getDirectories() { return new PsiDirectory[] {psiDirectory}; } @Override public PsiDirectory getOrChooseDirectory() { return psiDirectory; } }; } } return null; } }
Example #24
Source File: ServiceActionUtil.java From idea-php-shopware-plugin with MIT License | 4 votes |
public static void buildFile(AnActionEvent event, final Project project, String templatePath, String fileName) { DataContext dataContext = event.getDataContext(); IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return; } PsiDirectory[] directories = view.getDirectories(); if(directories.length == 0) { return; } final PsiDirectory initialBaseDir = directories[0]; if (initialBaseDir == null) { return; } if(initialBaseDir.findFile(fileName) != null) { Messages.showInfoMessage("File exists", "Error"); return; } String content; try { content = StreamUtil.readText(ServiceActionUtil.class.getResourceAsStream(templatePath), "UTF-8"); } catch (IOException e) { e.printStackTrace(); return; } final PsiFileFactory factory = PsiFileFactory.getInstance(project); final PsiFile file = factory.createFileFromText(fileName, XmlFileType.INSTANCE, content); ApplicationManager.getApplication().runWriteAction(() -> { CodeStyleManager.getInstance(project).reformat(file); initialBaseDir.add(file); }); PsiFile psiFile = initialBaseDir.findFile(fileName); if(psiFile != null) { view.selectElement(psiFile); } }
Example #25
Source File: CreateTemplateInPackageAction.java From consulo with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") protected boolean isAvailable(final DataContext dataContext) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if (project == null || view == null || view.getDirectories().length == 0) { return false; } final Module module = dataContext.getData(LangDataKeys.MODULE); if (module == null) { return false; } final Class moduleExtensionClass = getModuleExtensionClass(); if (moduleExtensionClass != null && ModuleUtilCore.getExtension(module, moduleExtensionClass) == null) { return false; } if (!myInSourceOnly) { return true; } PsiPackageSupportProvider[] extensions = PsiPackageSupportProvider.EP_NAME.getExtensions(); ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiDirectory dir : view.getDirectories()) { boolean accepted = false; for (PsiPackageSupportProvider provider : extensions) { if (provider.acceptVirtualFile(module, dir.getVirtualFile())) { accepted = true; break; } } if (accepted && projectFileIndex.isInSourceContent(dir.getVirtualFile()) && checkPackageExists(dir)) { return true; } } return false; }
Example #26
Source File: CreateDirectoryOrPackageAction.java From consulo with Apache License 2.0 | 4 votes |
@RequiredUIAccess @Override public void update(@Nonnull AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view == null) { presentation.setVisible(false); presentation.setEnabled(false); return; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0) { presentation.setVisible(false); presentation.setEnabled(false); return; } presentation.setVisible(true); presentation.setEnabled(true); // is more that one directories not show package support if (directories.length > 1) { presentation.setText(ChildType.Directory.getName()); presentation.setIcon(AllIcons.Nodes.TreeClosed); } else { Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> info = getInfo(directories[0]); presentation.setText(info.getThird().getName()); ContentFolderTypeProvider first = info.getFirst(); Image childIcon; if (first == null) { childIcon = AllIcons.Nodes.TreeClosed; } else { childIcon = first.getChildPackageIcon() == null ? first.getChildDirectoryIcon() : first.getChildPackageIcon(); } presentation.setIcon(childIcon); } }
Example #27
Source File: CreateFromTemplateAction.java From consulo with Apache License 2.0 | 4 votes |
protected boolean isAvailable(DataContext dataContext) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); return project != null && view != null && view.getDirectories().length != 0; }
Example #28
Source File: BxNewSectionAction.java From bxfs with MIT License | 4 votes |
@Override public void actionPerformed(@NotNull AnActionEvent event) { IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (view != null) { Project project = event.getProject(); if (project != null) { PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); if (directory != null) { CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, true, "\\/"); // Сообщение не нужно, так как заголовок окна и так близко. Они резонируют. Messages.showInputDialog(project, null, "Битрикс: Создание Нового Раздела", BitrixFramework.bxIcon, "", validator); PsiElement result = validator.getCreatedElement(); if (result instanceof PsiDirectory) { PsiDirectory createdDir = (PsiDirectory) result; FileTemplateManager templateManager = FileTemplateManager.getInstance(project); FileTemplate cfgTemplate = templateManager.findInternalTemplate("Битрикс - Раздел (настройки)"); FileTemplate idxTemplate = templateManager.findInternalTemplate("Битрикс - Раздел (титульная)"); Properties properties = FileTemplateManager.getInstance(project).getDefaultProperties(); try { PsiElement cfgFile = FileTemplateUtil.createFromTemplate(cfgTemplate, ".section", properties, createdDir); PsiElement idxFile = FileTemplateUtil.createFromTemplate(idxTemplate, "index", properties, createdDir); view.selectElement(idxFile); } catch (Exception e) { e.printStackTrace(); } } } } } }
Example #29
Source File: CreateFromTemplateActionBase.java From consulo with Apache License 2.0 | 4 votes |
@Nullable protected PsiDirectory getTargetDirectory(DataContext dataContext, IdeView view) { return DirectoryChooserUtil.getOrChooseDirectory(view); }