@Override public void actionPerformed(@Nonnull AnActionEvent event) { if (!isAvailable(event)) { return; } project = event.getProject(); ideView = event.getData(DataKeys.IDE_VIEW); final Injector injector = GuiceManager.getInstance(project).getInjector(); injector.injectMembers(this); // 'selected' is null when directory selection is canceled although multiple directories are chosen. final PsiDirectory selected = ideView.getOrChooseDirectory(); if (selected == null) { return; } final NewClassDialog dialog = NewClassDialog.builder(project, bundle) .nameValidator(nameValidatorProvider.get()) .jsonValidator(jsonValidatorProvider.get()) .actionListener(this) .build(); dialog.show(); }
@Override public void actionPerformed(AnActionEvent e) { project = e.getProject(); selectGroup = DataKeys.VIRTUAL_FILE.getData(e.getDataContext()); String className = Messages.showInputDialog(project, "请输入类名称", "NewMvpGroup", Messages.getQuestionIcon()); if (className == null || className.equals("")) { System.out.print("没有输入类名"); return; } if (className.equals("base") || className.equals("BASE") || className.equals("Base")) { createMvpBase(); } else { createClassMvp(className); } project.getBaseDir().refresh(false, true); }
private ActionListener createEditBtnListener() { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final File file = new File(AzurePlugin.prefFilePath); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); if (vf != null) { try { vf.setWritable(true); DataContext dataContext = DataManager.getInstance().getDataContext(); Project project = DataKeys.PROJECT.getData(dataContext); FileEditorManager.getInstance(project).openFile(vf, true); } catch (IOException ex) { AzurePlugin.log(message("error"), ex); } } } }); } }; }
@Override public void actionPerformed(@NotNull AnActionEvent event) { Project project = getEventProject(event); VirtualFile assetRoot = SettingsHelper.getAssetPath(IconPack.ANDROID_ICONS); if (assetRoot == null) { Messages.showMessageDialog( project, "You have to select the Android Icons asset folder in the settings!", "Error", Messages.getErrorIcon()); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } ShowSettingsUtil.getInstance().showSettingsDialog(project, "Android Drawable Importer"); } else { Module module = event.getData(DataKeys.MODULE); AndroidIconsImporter dialog = new AndroidIconsImporter(project, module); dialog.show(); } }
@Override public void actionPerformed(@NotNull AnActionEvent event) { Project project = getEventProject(event); VirtualFile assetRoot = SettingsHelper.getAssetPath(IconPack.MATERIAL_ICONS); if (assetRoot == null) { Messages.showMessageDialog( project, "You have to select the Material Icons root folder in the settings!", "Error", Messages.getErrorIcon()); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } ShowSettingsUtil.getInstance().showSettingsDialog(project, "Android Drawable Importer"); } else { Module module = event.getData(DataKeys.MODULE); MaterialIconsImporter dialog = new MaterialIconsImporter(project, module); dialog.show(); } }
/** * Invoked when the user clicks on a popup menu item. * * @param event Popup menu click event */ public void actionPerformed(ActionEvent event) { IdeaPlugin plugin = IdeaPlugin.getInstance(ideaEvent.getData(DataKeys.PROJECT)); if (event.getActionCommand().equals(IdeaPlugin.ACTION_CLEAR_RESPONSE)) { plugin.clearResponse(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_RESET_ALL)) { plugin.resetAll(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_RESET_TO_LAST)) { plugin.resetToLast(); } }
/** * Invoked when the user clicks on a popup menu item. * * @param event Popup menu click event */ public void actionPerformed(ActionEvent event) { IdeaPlugin plugin = IdeaPlugin.getInstance(ideaEvent.getData(DataKeys.PROJECT)); if (event.getActionCommand().equals(IdeaPlugin.ACTION_PASSWORD_ENCODER_DECODER)) { plugin.passwordEncodeDecode(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_START_TRACE_SERVER)) { plugin.startTraceServer(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_STOP_TRACE_SERVER)) { plugin.stopTraceServer(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_INSERT_TRACE_URL)) { plugin.insertTraceServerUrl(); } else if (event.getActionCommand().equals(IdeaPlugin.METHOD_OPTIONS)) { plugin.options(event); } }
public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); Module module = e.getData(DataKeys.MODULE); final PsiJavaFile psiFile = (PsiJavaFile) getPsiFile(e); final VirtualFile sourceRoot = ProjectFileIndex.SERVICE.getInstance(module.getProject()).getSourceRootForFile(psiFile.getVirtualFile()); PackageChooserPopup packageChooserPopup = new PackageChooserPopup(project, sourceRoot); JBPopup popup = packageChooserPopup.createPopup(new PackageChooserPopup.OnPackageSelectedListener() { @Override public void onPackageSelected(String qualifiedPackageName) { Scheme scheme = SchemeManager.getScheme(psiFile, qualifiedPackageName); VirtualFile generatedFile = SchemeFileGenerator.generate(scheme, sourceRoot); if(generatedFile!=null) { generatedFile.refresh(false, false); } FileEditorManager.getInstance(project).openFile(generatedFile, true); } }); popup.showCenteredInCurrentWindow(project); }
/** * validate operation available * * @param e action event */ @Override public void update(AnActionEvent e) { super.update(e); PsiFile psiFile = e.getData(DataKeys.PSI_FILE); Editor editor = e.getData(DataKeys.EDITOR); if ((psiFile != null && psiFile instanceof XmlFile) && editor != null) { PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset()); if (psiElement != null) { XmlTag tag = getResultMapTag(psiElement); if (tag != null) { e.getPresentation().setEnabled(true); e.getPresentation().setVisible(true); return; } } } e.getPresentation().setEnabled(false); e.getPresentation().setVisible(false); }
/** * validate action is available * * @param event action event */ public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); Module module = event.getData(DataKeys.MODULE); PsiElement psiElement = event.getData(DataKeys.PSI_ELEMENT); if (psiElement instanceof PsiDirectory) { PsiDirectory psiDirectory = (PsiDirectory) psiElement; if (JavaDirectoryService.getInstance().getPackage(psiDirectory) != null) { DataSource dataSource = JavadocTableNameReferenceProvider.getDataSourceForIbatis(module); if (dataSource != null) { presentation.setEnabled(true); presentation.setVisible(true); return; } } } presentation.setEnabled(false); presentation.setVisible(false); }
private void handleClickOnError(BuckTreeNodeDetailError node) { TreeNode parentNode = node.getParent(); if (parentNode instanceof BuckTreeNodeFileError) { BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode; DataContext dataContext = DataManager.getInstance().getDataContext(); Project project = DataKeys.PROJECT.getData(dataContext); String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), ""); VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath); OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1); openFileDescriptor.navigate(true); } }
private void triggerConfigChange() { DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult(); Project project = DataKeys.PROJECT.getData(dataContext); if (project != null) { MessageBus messageBus = project.getMessageBus(); messageBus.connect(); ConfigChangeNotifier configChangeNotifier = messageBus.syncPublisher(ConfigChangeNotifier.CONFIG_TOPIC); configChangeNotifier.configChanged(activeCheckBox.isSelected()); } }
@Override public void actionPerformed(AnActionEvent e) { VirtualFile[] data = e.getData(DataKeys.VIRTUAL_FILE_ARRAY); // TODO: insert action logic here PatcherDialog dialog = new PatcherDialog(e); dialog.setSize(600, 400); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.requestFocus(); }
private void createUIComponents() { VirtualFile[] data = event.getData(DataKeys.VIRTUAL_FILE_ARRAY); fieldList = new JBList(data); fieldList.setEmptyText("No File Selected!"); ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList); filePanel = decorator.createPanel(); }
@Override public void actionPerformed(AnActionEvent e) { try { com.intellij.openapi.actionSystem.DataContext dataContext = e.getDataContext(); PsiJavaFile javaFile = (PsiJavaFile) ((PsiFile) DataKeys.PSI_FILE.getData(dataContext)).getContainingFile(); String sourceName = javaFile.getName(); Module module = (Module) DataKeys.MODULE.getData(dataContext); String compileRoot = CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath(); getVirtualFile(sourceName, CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getChildren(), compileRoot); VirtualFileManager.getInstance().syncRefresh(); } catch (Exception ex) { ex.printStackTrace(); Messages.showErrorDialog("Please build your module or project!!!", "error"); } }
@Override public void update(AnActionEvent e) { super.update(e); VirtualFile currentFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext()); final Presentation presentation = e.getPresentation(); if (currentFile != null && currentFile.getName().endsWith(".ecore")) { presentation.setEnabledAndVisible(true); } else { presentation.setEnabledAndVisible(false); } }
@Override public void actionPerformed(AnActionEvent event) { VirtualFile file = DataKeys.VIRTUAL_FILE.getData(event.getDataContext()); Project project = event.getProject(); if (file == null || project == null) return; VirtualFile folder = file.isDirectory() ? file : file.getParent(); WriteCommandAction.runWriteCommandAction(project, () -> { createData(folder); createDomain(folder); createPresentation(folder); }); }
@Override public void update(AnActionEvent event) { //在Action显示之前,根据选中文件扩展名判定是否显示此Action VirtualFile file = DataKeys.VIRTUAL_FILE.getData(event.getDataContext()); boolean show = file.isDirectory() || isYamlFile(file.getExtension()); this.getTemplatePresentation().setEnabled(show); this.getTemplatePresentation().setVisible(show); }
public void actionPerformed(AnActionEvent e) { PsiElement data = DataKeys.PSI_ELEMENT.getData(e.getDataContext()); if (!(data instanceof PsiClass)){ showError("必须选择一个类"); return; } Table table = class2TableConverter.convert((PsiClass) data); String createSql = sqlGenerator.generate(table); showInfo("生成成功,sql已复制到剪切板"); Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(createSql); clip.setContents(tText, null); }
public Project findCurrentProject() { logger.info("Trying to findCurrentProject. @ObjectFinder"); DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult(); if (dataContext == null) { Project[] projects = ProjectManager.getInstance().getOpenProjects(); if (projects.length > 0) { return projects[projects.length - 1]; } return null; } return DataKeys.PROJECT.getData(dataContext); }
@Override public final void actionPerformed(AnActionEvent anActionEvent) { DocumentUtil.saveDocument(); this.anActionEvent = anActionEvent; this.currentProject = DataKeys.PROJECT.getData(anActionEvent.getDataContext()); this.projectDir = new File(currentProject.getBasePath()); actionPerformed(); }
private String getCurrentPath(AnActionEvent e) { VirtualFile currentFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext()); if (currentFile != null) { return currentFile.getPath(); } return null; }
private void addProject(com.samebug.clients.common.tracking.RawEvent e) { // get project from focus DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult(); Project project = DataKeys.PROJECT.getData(dataContext); if (project != null) { e.withField("projectName", project.getName()); } }
private static boolean isEnabled(AnActionEvent e) { PsiFile file = e.getData(DataKeys.PSI_FILE); if (file == null || file.getLanguage() != GroovyLanguage.INSTANCE) { return false; } final VirtualFile virtualFile = file.getVirtualFile(); return virtualFile != null && !GroovyCompilerConfiguration.getExcludeConfiguration(file.getProject()).isExcluded(virtualFile); }
public static void showBalloonPopup(DataContext dataContext, String htmlText, MessageType messageType) { StatusBar statusBar = WindowManager.getInstance().getStatusBar(DataKeys.PROJECT.getData(dataContext)); JBPopupFactory.getInstance() .createHtmlTextBalloonBuilder(htmlText, messageType, null) .setFadeoutTime(7500) .createBalloon() .show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight); }
@Override public void actionPerformed(@NotNull AnActionEvent event) { Project project = getEventProject(event); Module module = event.getData(DataKeys.MODULE); AndroidMultiDrawableImporter dialog = new AndroidMultiDrawableImporter(project, module); dialog.show(); }
@Override public void actionPerformed(@NotNull AnActionEvent event) { Project project = getEventProject(event); Module module = event.getData(DataKeys.MODULE); AndroidBatchScaleImporter dialog = new AndroidBatchScaleImporter(project, module); dialog.show(); }
/** * Invoked when the user clicks on a popup menu item. * * @param event Popup menu click event */ public void actionPerformed(ActionEvent event) { IdeaPlugin plugin = IdeaPlugin.getInstance(ideaEvent.getData(DataKeys.PROJECT)); if (event.getActionCommand().equals(IdeaPlugin.METHOD_OPEN_REQUEST)) { plugin.openRequest(); } else if (event.getActionCommand().equals(IdeaPlugin.METHOD_OPEN_RESPONSE)) { plugin.openResponse(); } else if (event.getActionCommand().equals(IdeaPlugin.METHOD_OPEN_ARCHIVE)) { plugin.openArchive(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_SAVE_REQUEST)) { plugin.saveRequest(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_SAVE_RESPONSE)) { plugin.saveResponse(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_SAVE_RESPONSE_BODY)) { plugin.saveResponseBody(); } else if (event.getActionCommand().equals(IdeaPlugin.ACTION_SAVE_REQ_RES_ARCHIVE)) { plugin.saveReqResArchive(); } }
/** * Invoked when the user clicks on the menu icon. Displays a popup menu of choices. * * @param event IDEA action event */ public void actionPerformed(AnActionEvent event) { ideaEvent = event; IdeaPlugin restPlugin = IdeaPlugin.getInstance(event.getData(DataKeys.PROJECT)); popup.show(restPlugin.getPluginPanel(), 31, getVerticalLocation()); }
/** * Invoked when the user clicks on a popup menu item. * * @param event Popup menu click event */ public void actionPerformed(ActionEvent event) { IdeaPlugin plugin = IdeaPlugin.getInstance(ideaEvent.getData(DataKeys.PROJECT)); if (event.getActionCommand().equals(IdeaPlugin.METHOD_ABOUT)) { plugin.showAboutDialog(); } else if (event.getActionCommand().equals(IdeaPlugin.METHOD_ABOUT_PLUGIN)) { plugin.showAboutPluginDialog(); } }
public void performPaste(@NotNull final DataContext dataContext) { final Project project = DataKeys.PROJECT.getData(dataContext); final IdeView ideView = DataKeys.IDE_VIEW.getData(dataContext); if (project == null || ideView == null) return; final PsiJavaFile javaFile = createJavaFileFromClipboardContent(project); if (javaFile == null) return; final PsiClass[] classes = javaFile.getClasses(); if (classes.length < 1) return; final PsiDirectory targetDir = ideView.getOrChooseDirectory(); if (targetDir == null) return; PsiClass publicClass = classes[0]; for (PsiClass aClass : classes) { if (aClass.hasModifierProperty(PsiModifier.PUBLIC)) { publicClass = aClass; break; } } final PsiClass mainClass = publicClass; new WriteCommandAction(project, "Paste class '" + mainClass.getName() + "'") { @Override protected void run(Result result) throws Throwable { PsiFile file; try { file = targetDir.createFile(mainClass.getName() + ".java"); } catch (IncorrectOperationException e) { return; } final Document document = PsiDocumentManager.getInstance(project).getDocument(file); document.setText(javaFile.getText()); PsiDocumentManager.getInstance(project).commitDocument(document); if (file instanceof PsiJavaFile) { updatePackageStatement((PsiJavaFile) file, targetDir); } new OpenFileDescriptor(project, file.getVirtualFile()).navigate(true); } }.execute(); }
public boolean isPasteEnabled(@NotNull final DataContext dataContext) { final Project project = DataKeys.PROJECT.getData(dataContext); final IdeView ideView = DataKeys.IDE_VIEW.getData(dataContext); if (project == null || ideView == null || ideView.getDirectories().length == 0) { return false; } PsiJavaFile file = createJavaFileFromClipboardContent(project); return file != null && file.getClasses().length >= 1; }
@Override public void update(final AnActionEvent e) { super.update(e); final ModuleGroup[] moduleGroups = ModuleGroup.ARRAY_DATA_KEY.getData(e.getDataContext()); final Module[] modules = e.getData(DataKeys.MODULE_CONTEXT_ARRAY); e.getPresentation().setVisible((moduleGroups != null && moduleGroups.length > 0) || (modules != null && modules.length > 0)); }
private static boolean isEnabled(AnActionEvent e) { PsiFile file = e.getData(DataKeys.PSI_FILE); if (file == null || file.getLanguage() != GroovyFileType.GROOVY_LANGUAGE) { return false; } final VirtualFile virtualFile = file.getVirtualFile(); return virtualFile != null && !GroovyCompilerConfiguration.getExcludeConfiguration(file.getProject()).isExcluded(virtualFile); }
public void actionPerformed(AnActionEvent e) { // todo: turn this into a sort all property files method final Editor editor = e.getData(DataKeys.EDITOR); final String fileText = e.getData(DataKeys.FILE_TEXT); MessageWindowComponent messageWindowComponent = getMessageComponent(); if (fileText != null) { try { Properties properties = stringPropertyConverter.convertString(fileText); List<String> sortedKeys = propertySorter.getSortedKeys(properties); final String newDocumentContent = stringPropertyConverter.sortAndConvertProperties(properties, sortedKeys); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { final Document document = editor.getDocument(); CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { public void run() { document.replaceString(0, document.getTextLength(), stringPropertyConverter.mergeComments(newDocumentContent, fileText)); } }, "Property Sorter Plugin", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION); } }); messageWindowComponent.say("Properties were sorted."); } catch (ConvertException convertException) { messageWindowComponent.say("There are lines containing non property styled text. File was not changed."); } } else { messageWindowComponent.say("Please select an editor window with a properties file."); } }
public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); PsiFile psiFile = event.getData(DataKeys.PSI_FILE); if (psiFile != null && psiFile instanceof XmlFile) { final DomFileElement fileElement = DomManager.getDomManager(psiFile.getProject()).getFileElement((XmlFile) psiFile, DomElement.class); if (fileElement != null && fileElement.getRootElement() instanceof AbatorConfiguration) { presentation.setEnabled(true); presentation.setVisible(true); return; } } presentation.setEnabled(false); presentation.setVisible(false); }
/** * execute sql generation and copy task * * @param e action event */ public void actionPerformed(AnActionEvent e) { PsiFile psiFile = e.getData(DataKeys.PSI_FILE); Editor editor = e.getData(DataKeys.EDITOR); if ((psiFile != null && psiFile instanceof XmlFile) && editor != null) { PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset()); if (psiElement != null) { XmlTag xmlTag = getResultMapTag(psiElement); if (xmlTag != null) { DomElement domElement = DomManager.getDomManager(psiFile.getProject()).getDomElement(xmlTag); if (domElement != null && domElement instanceof ResultMap) { List<String> columns = new ArrayList<String>(); ResultMap resultMap = (ResultMap) domElement; List<Result> allResults = resultMap.getAllResults(); for (Result result : allResults) { String columnName = result.getColumn().getValue(); if (columnName != null && columnName.length() > 0 && !columns.contains(columnName)) { columns.add(columnName); } } PsiClass psiClass = resultMap.getClazz().getValue(); if (psiClass != null) { String tableName = "table_name_here"; String select = "*"; DatabaseTableData tableData = TableColumnReferenceProvider.getDatabaseTableData(psiClass); if (tableData != null) { tableName = tableData.getName(); } if (columns.size() > 0) { select = StringUtil.join(columns, ", "); } String sentenceSQL = "select " + select + " from " + tableName; CopyPasteManager copyPasteManager = CopyPasteManager.getInstance(); copyPasteManager.setContents(new StringSelection(sentenceSQL)); } } } } } }
public BaseRefactorHandler(DataContext dataContext, Project project) { this.project = project; editor = PlatformDataKeys.EDITOR.getData(dataContext); PsiFile psiFile = DataKeys.PSI_FILE.getData(dataContext); PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, psiFile, false); List<EncapsulatableClassMember> classMembers = getEncapsulatableClassMembers(psiClass); chooser = new MemberChooser<ClassMember>( classMembers.toArray(new ClassMember[classMembers.size()]), true, true, project); chooser.setTitle(getChooserTitle()); chooser.setCopyJavadocVisible(false); }
public CommandListPopupCallBack(AnActionEvent event) { this.project = event.getData(DataKeys.PROJECT); this.editor = event.getData(DataKeys.EDITOR); this.component = event.getData(DataKeys.CONTEXT_COMPONENT); VirtualFile[] files = event.getData(DataKeys.VIRTUAL_FILE_ARRAY); // If no file is selected, then set project directory as selection if (files == null || files.length == 0) { files = new VirtualFile[] { event.getData(DataKeys.PROJECT_FILE_DIRECTORY) }; } this.selectedFiles = files; }
public static boolean isInsideProjectSources(AnActionEvent event) { ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(event.getProject()).getFileIndex(); final IdeView view = event.getData(DataKeys.IDE_VIEW); for (PsiDirectory dir : view.getDirectories()) { if (projectFileIndex.isInSourceContent(dir.getVirtualFile()) && JavaDirectoryService.getInstance().getPackage(dir) != null) { return true; } } return false; }