@Override protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { super.doExecute(editor, caret, dataContext); VirtualFile vf = (CommonDataKeys.VIRTUAL_FILE.getData(dataContext)); if (IMWindowFactory.getDefault() == null) { return; } String path = VFSUtils.getPath(vf); if (!TextUtils.isEmpty(path)) { String text = editor.getSelectionModel().getSelectedText(); int line = EditorUtils.getEditorLine(editor); ReviewDialog dialog = new ReviewDialog(); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setData(path, line, text); dialog.setVisible(true); dialog.dispose(); } }
public void actionPerformed(AnActionEvent e) { this.project = e.getData(CommonDataKeys.PROJECT); String description = this.showInputDialog(SlackChannel.getIdDescription(), null); if (!isValidField(description)) { errorMessage(); return; } String token = this.showInputDialog(SlackChannel.getTokenDescription(), null); if (!isValidField(token)) { errorMessage(); return; } String channel = this.showInputDialog(SlackChannel.getChanneNameDescription(), ""); SlackStorage.getInstance().registerChannel(new SlackChannel(token, description, channel)); Messages.showMessageDialog(this.project, "Settings Saved.", "Information", Messages.getInformationIcon()); }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); List<String> channelsId = SlackStorage.getInstance().getChannelsId(); if (channelsId.size() > 0) { String channelToRemove = Messages.showEditableChooseDialog( "Select the channel to remove", SlackChannel.getSettingsDescription(), SlackStorage.getSlackIcon(), channelsId.toArray(new String[channelsId.size()]), channelsId.get(0), null ); if (channelsId.contains(channelToRemove)) { SlackStorage.getInstance().removeChannelByDescription(channelToRemove); Messages.showMessageDialog(project, "Channel \"" + channelToRemove + "\" removed.", "Information", Messages.getInformationIcon()); } } }
@Override public void actionPerformed(AnActionEvent event) { // TODO: insert action logic here Project project = event.getData(PlatformDataKeys.PROJECT); Object nav = event.getData(CommonDataKeys.NAVIGATABLE); String path; try { if (nav instanceof PsiDirectory) { PsiDirectory directory = (PsiDirectory) nav; path = directory.getVirtualFile().getPath(); } else { PsiFile file = (PsiFile) nav; path = file.getVirtualFile().getPath(); } Toast.make(project, MessageType.INFO, "Open: " + path); Runtime.getRuntime().exec("cmd /c start " + path); } catch (Exception e) { e.printStackTrace(); if (nav instanceof PsiClass) { Toast.make(project, MessageType.ERROR, "Could not open the java file, double-click to open."); return; } Toast.make(project, MessageType.ERROR, e.getMessage()); } }
/** * Inserts the string generated by {@link #generateString()} at the caret(s) in the editor. * * @param event the performed action */ @Override public final void actionPerformed(final AnActionEvent event) { final Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor == null) { return; } final Project project = event.getData(CommonDataKeys.PROJECT); final Document document = editor.getDocument(); final CaretModel caretModel = editor.getCaretModel(); final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> { final int start = caret.getSelectionStart(); final int end = caret.getSelectionEnd(); final String string = generateString(); final int newEnd = start + string.length(); document.replaceString(start, end, string); caret.setSelection(start, newEnd); }); WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections); }
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setEnabledAndVisible(false); Project project = e.getProject(); if (project == null) { return; } if (!CCUtils.isCourseCreator(project)) { return; } DataContext context = e.getDataContext(); VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context); if (file == null ) { return; } TaskFile taskFile = StudyUtils.getTaskFile(project, file); if (taskFile == null || taskFile.getAnswerPlaceholders().isEmpty()) { return; } presentation.setEnabledAndVisible(true); }
@Nullable protected CCState getState(@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project == null || !CCUtils.isCourseCreator(project)) { return null; } final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(e.getDataContext()); if (psiFile == null) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) { return null; } final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); if (editor == null) { return null; } TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile); if (taskFile == null) { return null; } AnswerPlaceholder answerPlaceholder = StudyUtils.getAnswerPlaceholder(editor.getCaretModel().getOffset(), getPlaceholders(taskFile)); return new CCState(taskFile, answerPlaceholder, psiFile, editor, project); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } final String courseId = Messages.showInputDialog("Please, enter course id", "Get Course From Stepik", null); if (StringUtil.isNotEmpty(courseId)) { ProgressManager.getInstance().run(new Task.Modal(project, "Creating Course", true) { @Override public void run(@NotNull final ProgressIndicator indicator) { createCourse(project, courseId); } }); } }
@Override public void update(@NotNull AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setEnabledAndVisible(false); Project project = e.getProject(); if (project == null) { return; } if (!CCUtils.isCourseCreator(project)) { return; } final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext()); if (file != null && StudyUtils.getTaskFile(project, file.getVirtualFile()) != null) { presentation.setEnabledAndVisible(true); } }
private static TaskWithSubtasks getTask(@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null || !CCUtils.isCourseCreator(project)) { return null; } VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); if (virtualFile == null) { return null; } while (virtualFile.getName().equals(EduNames.SRC) || !virtualFile.isDirectory()) { VirtualFile parent = virtualFile.getParent(); if (parent != null) { virtualFile = parent; } } final Task task = StudyUtils.getTask(project, virtualFile); return task instanceof TaskWithSubtasks ? (TaskWithSubtasks)task : null; }
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (virtualFile == null || project == null || editor == null) { return; } Task task = StudyUtils.getTaskForFile(project, virtualFile); if (task == null) return; if (!(task instanceof TaskWithSubtasks)) { task = convertToTaskWithSubtasks(task, project); } addSubtask((TaskWithSubtasks)task, project); }
@Override public void update(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Presentation presentation = e.getPresentation(); presentation.setEnabledAndVisible(false); VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (virtualFile == null || project == null) { return; } if (!CCUtils.isCourseCreator(project)) { return; } if (StudyUtils.getTaskForFile(project, virtualFile) != null || StudyUtils.getTask(project, virtualFile) != null) { presentation.setEnabledAndVisible(true); } }
@Override public boolean canMove(DataContext dataContext) { if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) { return false; } IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return false; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0 || directories.length > 1) { return false; } final PsiDirectory sourceDirectory = directories[0]; return CCUtils.isLessonDir(sourceDirectory); }
@Override public boolean canMove(DataContext dataContext) { if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) { return false; } IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return false; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0 || directories.length > 1) { return false; } final PsiDirectory sourceDirectory = directories[0]; return isTaskDir(sourceDirectory); }
/** * Checked whether or not this action can be enabled. * * <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; }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); final PsiFile psiFile = e.getRequiredData(CommonDataKeys.PSI_FILE); CommandProcessor.getInstance().executeCommand(project, () -> { try { MultiHighlightHandler.invoke(project, editor, psiFile); } catch (IndexNotReadyException ex) { DumbService.getInstance(project) .showDumbModeNotification("MultiHighlight requires indices " + "and cannot be performed until they are built"); } }, "MultiHighlight", null); }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); final HighlightManager highlightManager = HighlightManager.getInstance(project); final RangeHighlighter[] highlighters = ((HighlightManagerImpl) highlightManager).getHighlighters(editor); for (RangeHighlighter highlighter : highlighters) { final TextAttributes ta = highlighter.getTextAttributes(); if (ta != null && ta instanceof NamedTextAttr && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) { highlightManager.removeSegmentHighlighter(editor, highlighter); } } }
public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); final Change[] changes = e.getData(VcsDataKeys.CHANGES); if ((changes == null) || (changes.length == 0)) return; String commitMessage = null; ShelvedChangeList[] shelvedChangeLists = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY); if (shelvedChangeLists != null && shelvedChangeLists.length > 0) { commitMessage = shelvedChangeLists [0].DESCRIPTION; } else { ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS); if (changeLists != null && changeLists.length > 0) { commitMessage = changeLists [0].getComment(); } } if (commitMessage == null) { commitMessage = e.getData(VcsDataKeys.PRESET_COMMIT_MESSAGE); } if (commitMessage == null) { commitMessage = ""; } List<Change> changeCollection = new ArrayList<Change>(); Collections.addAll(changeCollection, changes); createPatch(project, commitMessage, changeCollection); }
@Override public void actionPerformed(AnActionEvent anActionEvent) { logger.debug("Loading sample!"); final Project project = anActionEvent.getProject(); final PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE); VirtualFile sample = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), project, null); if (sample == null) return; try { final String text = new String(sample.contentsToByteArray(), sample.getCharset()); new WriteCommandAction.Simple(project, psiFile) { @Override protected void run() throws Throwable { document.setText(text); } }.execute(); } catch (Exception e) { logger.error(e); } }
@Nullable public Object getData(@NonNls String dataId) { if (CommonDataKeys.NAVIGATABLE.is(dataId)) { final Project project = myVCS.getProject(); if (project == null || project.isDefault()) { return null; } final VirtualFile vcsFile = getSelectedVcsFile(); // do not return OpenFileDescriptor instance here as in that case SelectInAction will be enabled and its invocation (using keyboard) // will raise error - see IDEA-104113 - because of the following operations inside SelectInAction.actionPerformed(): // - at first VcsVirtualFile content will be loaded which for svn results in showing progress dialog // - then DataContext from SelectInAction will still be accessed which results in error as current event count has already changed // (because of progress dialog) return vcsFile != null ? new NavigatableAdapter() { @Override public void navigate(boolean requestFocus) { navigate(project, vcsFile, requestFocus); } } : null; } else if (CommonDataKeys.PROJECT.is(dataId)) { return myVCS.getProject(); } return null; }
@Override public void actionPerformed(AnActionEvent event) { virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); project = event.getProject(); SelectPackageTemplateDialog dialog = new SelectPackageTemplateDialog(event.getProject()) { @Override public void onSuccess(PackageTemplate pt) { if (!FileTemplateHelper.isCurrentSchemeValid(project, pt.getFileTemplateSource())) { return; } if (pt.isSkipDefiningNames()) { executeTemplateSilently(pt, project, virtualFile); } else { showDialog(pt, project, virtualFile); } } }; dialog.show(); }
@Override public void actionPerformed(AnActionEvent event) { VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); Project project = event.getProject(); PackageTemplate pt = getPackageTemplateByName(packageTemplate.getName()); if(pt == null){ // TODO: 29.09.2016 template not found msg Logger.log("action: pt == null"); return; } packageTemplate = GsonFactory.cloneObject(pt, PackageTemplate.class); if (packageTemplate.isSkipDefiningNames()) { NewPackageTemplateAction.executeTemplateSilently(packageTemplate, project, virtualFile); } else { NewPackageTemplateAction.showDialog(packageTemplate, project, virtualFile); } }
@Override public void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent())); if (project == null) { return; } Document document = editor.getDocument(); final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, caret, dataContext); } return; } PsiDocumentManager.getInstance(project).commitAllDocuments(); doAction(editor, file); }
@Override public void update(AnActionEvent e) { DataContext dataContext = e.getDataContext(); e.getPresentation().setEnabled(false); Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (editor == null) return; final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project); if (psiFile == null) return; if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return; e.getPresentation().setEnabled(true); }
private void installProjectDisposer() { final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (c != null) { final DataContext context = DataManager.getInstance().getDataContext(c); final Project project = CommonDataKeys.PROJECT.getData(context); if (project != null) { myProjectDisposable = new Disposable() { @Override public void dispose() { if (!AbstractPopup.this.isDisposed()) { Disposer.dispose(AbstractPopup.this); } } }; Disposer.register(project, myProjectDisposable); } } }
@Nullable @Override public PsiElement getTarget(@NotNull DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return null; PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (element == null) { Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (editor != null) { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return null; element = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.LOOKUP_ITEM_ACCEPTED); if (element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile) { return element; } element = file.findElementAt(editor.getCaretModel().getOffset()); } } return PsiTreeUtil.getNonStrictParentOfType(element, PyFunction.class, PyClass.class, PyFile.class); }
@Override public void update(final AnActionEvent e) { Presentation presentation = e.getPresentation(); final EditorEx editor = (EditorEx) CommonDataKeys.EDITOR.getData(e.getDataContext()); boolean enabled = false; if (editor != null) { LineSelectionManager manager = LineSelectionManager.getInstance(editor); RangeLimitedCaretSpawningHandler spawningHandler = manager.getCaretSpawningHandler(); if (spawningHandler != null) { enabled = true; presentation.setText(spawningHandler.getPattern()); } } if (!enabled) { presentation.setText("RegEx"); } presentation.setEnabled(enabled); super.update(e); e.getPresentation().setVisible(!ApplicationSettings.getInstance().isHideDisabledButtons() || e.getPresentation().isEnabled()); }
@Override public void actionPerformed(AnActionEvent e) { //Get required data keys final Project project = e.getData(CommonDataKeys.PROJECT); final Editor editor = e.getData(CommonDataKeys.EDITOR); //Generate the autoQuery String autoQuery = project.getComponent(TermStatComponent.class).generateQuery(editor); //Execute Search and Open Tool Window ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("StackInTheFlow"); SearchToolWindowGUI toolWindowGUI = project.getComponent(ToolWindowComponent.class).getSearchToolWindowGUI(); toolWindowGUI.autoQuery(autoQuery, true, "action"); toolWindow.activate(() -> { }); }
private static boolean isActionEnabled(final AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return false; Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor == null) return false; int offset = editor.getCaretModel().getOffset(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return false; PsiElement element = file.findElementAt(offset); if (element == null) return false; PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); if (psiClass == null) return false; if (PsiMethodUtil.findMainMethod(psiClass) != null) return false; if (FormClassIndex.findFormsBoundToClass(project, psiClass).isEmpty()) return false; return true; }
@Override public void update(final AnActionEvent e) { e.getPresentation().setVisible(false); VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (files != null && files.length > 1) { virtualFile = null; } if (virtualFile == null || virtualFile.isDirectory()) return; Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(virtualFile); if (provider instanceof ConfigurableTemplateLanguageFileViewProvider) { final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider)provider; e.getPresentation().setText(LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName())); e.getPresentation().setEnabled(true); e.getPresentation().setVisible(true); } }
public void actionPerformed(AnActionEvent e) { FileDocumentManager.getInstance().saveAllDocuments(); Change[] changes = e.getData(VcsDataKeys.CHANGES); Project project = e.getData(CommonDataKeys.PROJECT); final ChangesBrowser browser = e.getData(ChangesBrowser.DATA_KEY); if (browser != null) { browser.setDataIsDirty(true); } RollbackChangesDialog.rollbackChanges(project, Arrays.asList(changes), true, new Runnable() { public void run() { if (browser != null) { browser.rebuildList(); browser.setDataIsDirty(false); } } }); }
private boolean thereAreUnversionedFiles(AnActionEvent e) { List<VirtualFile> unversionedFiles = getFromChangesView(e); if (unversionedFiles != null && !unversionedFiles.isEmpty()) { return true; } VirtualFile[] files = getFromSelection(e); Project project = e.getData(CommonDataKeys.PROJECT); if (files == null || project == null) { return false; } ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); FileStatusManager fileStatusManager = FileStatusManager.getInstance(project); for (VirtualFile file : files) { if (isFileUnversioned(file, vcsManager, fileStatusManager)) { return true; } } return false; }
@Override public final void update(AnActionEvent e) { super.update(e); Presentation presentation = e.getPresentation(); Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { presentation.setEnabled(false); return; } ToolWindowManager mgr=ToolWindowManager.getInstance(project); String id=mgr.getActiveToolWindowId(); if (id == null) { presentation.setEnabled(false); return; } ToolWindow window = mgr.getToolWindow(id); if (window == null) { presentation.setEnabled(false); return; } update(window, presentation); }
@Nullable private static PsiElement getPsiElement(DataContext dataContext, Project project, Editor editor) { PsiElement psiElement = null; if (editor == null) { psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext); } else { final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); final Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file); if (injectedEditor != null) { PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(injectedEditor, project); psiElement = psiFile != null ? psiFile.findElementAt(injectedEditor.getCaretModel().getOffset()) : null; } if (file != null && psiElement == null) { psiElement = file.findElementAt(editor.getCaretModel().getOffset()); } } return psiElement; }
@Override public void actionPerformed(@NotNull AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } final Course course = CCProjectService.getInstance(project).getCourse(); if (course == null) { return; } PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view); if (lessonDir == null || !lessonDir.getName().contains("lesson")) { return; } final Lesson lesson = course.getLesson(lessonDir.getName()); if (lesson == null) { return; } ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Lesson", true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setText("Uploading lesson to http://stepic.org"); EduStepicConnector.updateLesson(project, lesson, indicator); }}); }
@Override public boolean isAvailableOnDataContext(DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return false; } final ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext); if (bundle == null) { return false; } final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext); if (fileEditor == null || !(fileEditor instanceof ResourceBundleEditor)) { return false; } final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); return !(virtualFile == null || !(virtualFile instanceof ResourceBundleAsVirtualFile)); }
@Override public void actionPerformed(AnActionEvent e) { PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); if (psiFile != null) { PsiClass psiClass = JavaDirectoryService.getInstance().createClass(psiFile.getContainingDirectory(), getClassName(psiFile)); WriteCommandAction.runWriteCommandAction(e.getProject(), () -> { try { generateFields(psiFile, psiClass); } catch (IOException | SAXException | ParserConfigurationException e1) { e1.printStackTrace(); } }); } }
@Override public void update(AnActionEvent e) { e.getPresentation().setEnabledAndVisible(false); PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); if (psiFile != null) { if (psiFile.getOriginalFile().getName().endsWith(".fxml")) { e.getPresentation().setEnabledAndVisible(true); } } }
public void update(AnActionEvent event) { Project project = getEventProject(event); if (project == null) { this.setStatus(event, false); return; } if (DumbService.isDumb(project)) { this.setStatus(event, false); return; } DataContext dataContext = event.getDataContext(); final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); final PhpClass targetClass = editor == null || file == null ? null : PhpCodeEditUtil.findClassAtCaret(editor, file); if (targetClass == null) { setStatus(event, false); return; } if (ExtensionUtility.getExtensionDirectory(event) == null) { this.setStatus(event, false); return; } this.setStatus(event, PhpElementsUtil.hasSuperClass(targetClass, "\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController")); }
/** * @param event Carries information on the invocation place */ @Override public void actionPerformed(AnActionEvent event) { final Project project = getEventProject(event); if (project == null) { this.setStatus(event, false); return; } DataContext dataContext = event.getDataContext(); final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); final PhpClass targetClass = editor == null || file == null ? null : PhpCodeEditUtil.findClassAtCaret(editor, file); if (targetClass == null) { JOptionPane.showMessageDialog(null, "Could not find containing class"); return; } String actionName = Messages.showInputDialog(project, "New action name:", "New Extbase ActionController Action", TYPO3CMSIcons.TYPO3_ICON); if (StringUtils.isBlank(actionName)) { return; } actionName = Character.toLowerCase(actionName.charAt(0)) + actionName.substring(1); if (!actionName.endsWith("Action")) { actionName += "Action"; } if (!PhpNameUtil.isValidMethodName(actionName)) { JOptionPane.showMessageDialog(null, "Invalid method name"); return; } write(project, targetClass, actionName); }