public void actionPerformed( AnActionEvent e ) { Editor editor = ( Editor ) e.getDataContext().getData( "editor" ); SelectionModel selectionModel = editor.getSelectionModel(); if ( selectionModel != null ) { String selectedText = selectionModel.getSelectedText(); if ( selectedText != null && selectedText.trim().length() > 0 ) { Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT ); String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID ); QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid ); if ( quickNotesPanel != null ) { FileDocumentManager manager = FileDocumentManager.getInstance(); VirtualFile virtualFile = manager.getFile( editor.getDocument() ); quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText ); } } } }
@Override protected boolean runEnable(AnActionEvent anActionEvent) { Object o = anActionEvent.getDataContext().getData(DataConstants.PSI_FILE); if (o instanceof XmlFileImpl) { parentFileName = ((XmlFileImpl) o).getVirtualFile().getParent().getName(); if (isPreference(parentFileName)) { return true; } } else if (o instanceof PsiFile) { parentFileName = ((PsiFile) o).getVirtualFile().getParent().getName(); if (isDataBase(parentFileName)) { return true; } } return false; }
@Override public void actionPerformed(@NotNull final AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); if (file == null) { RTFile[] rtFiles = RTFile.DATA_KEY.getData(e.getDataContext()); if (rtFiles == null || rtFiles.length == 0) { System.out.println("No file for rt compile"); return; } // handle all files for (RTFile rtFile : rtFiles) { FileEditorManager.getInstance(project).openFile(rtFile.getController().getVirtualFile(), true, true); } } else { VirtualFile vfs = file.getParent().findChild(RTMergerTreeStructureProvider.getJSControllerName(file)); if (vfs != null) { FileEditorManager.getInstance(project).openFile(vfs, true, true); } } }
public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); JscsProjectComponent component = project.getComponent(JscsProjectComponent.class); // JscsConfigFileListener.start(collectedInfo.project); // actualFile = ActualFile2.getOrCreateActualFile(JSCS_TEMP_FILE_KEY, file, collectedInfo.fileContent); // if (actualFile == null || actualFile.getActualFile() == null) { // return null; // } // File cwd = new File(project.getBasePath()); // if (actualFile instanceof ActualFile2.TempActualFile) { // cwd = ((ActualFile2.TempActualFile) actualFile).getTempFile().file.getParentFile(); // } // String relativeFile = actualFile.getActualFile().getName(); // File cwd = actualFile.getActualFile().getParentFile(); // String relativeFile = FileUtils.makeRelative(cwd, actualFile.getActualFile()); String rc = JscsExternalAnnotator.getRC(project, component.jscsRcFile); LintResult result = JscsRunner.fix(project.getBasePath(), file.getPath(), component.nodeInterpreter, component.jscsExecutable, rc, component.preset, component.settings.esnext, component.settings.esprima); file.refresh(true, false); }
@Override protected String getAndroidFacetName(AnActionEvent anActionEvent) { Object o = anActionEvent.getDataContext().getData(DataConstants.PSI_FILE); if (o instanceof XmlFileImpl) { return ((XmlFileImpl) o).getVirtualFile().getParent().getParent().getName(); } else if (o instanceof PsiFile) { return parentFileName = ((PsiFile) o).getVirtualFile().getParent().getParent().getName(); } return super.getAndroidFacetName(anActionEvent); }
protected boolean runEnable(AnActionEvent anActionEvent) { Object o = anActionEvent.getDataContext().getData(DataConstants.PSI_FILE); if (o instanceof PsiFile) { targetFilePath = ((PsiFile) o).getVirtualFile().getPath(); if (isDataBase(((PsiFile) o).getVirtualFile().getParent().getName())) { if (isMacOs()) return true; } } return false; }
private static PsiFile getFile(final Editor editor , final DataContext context ) { final Project project = (Project) context.getData(DataConstants.PROJECT); final Document document = editor.getDocument(); final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); final VirtualFile virtualFile = fileDocumentManager.getFile(document); final PsiManager psiManager = PsiManager.getInstance(project); return psiManager.findFile(virtualFile); }
public RearrangeIt(final DataContext dc) { this.dc = dc; if (dc != null) { this.project = (Project) dc.getData(DataConstants.PROJECT); } else this.project = null; }
public final void execute(final Editor editor, final DataContext context) { if (editor == null) { return; } final Project project = (Project) context.getData(DataConstants.PROJECT); logger.debug("project=" + project); logger.debug("editor=" + editor); final Document document = editor.getDocument(); final CaretModel caret = editor.getCaretModel(); int cursorOffset = caret.getOffset(); final PsiFile psiFile = getFile(editor, context); if (!psiFile.getName().endsWith(".java")) { logger.debug("not a .java file -- skipping " + psiFile.getName()); return; } if (!RearrangerActionHandler.isFileWritable(psiFile)) { logger.debug("not a writable .java file -- skipping " + psiFile.getName()); return; } logger.debug("inProgress=" + inProgress); if (!useDialog) { if (inProgress) { return; } setInProgress(true); } buildLiveRearrangerData(project, document, psiFile, cursorOffset); }
private static PsiFile getFile(final Editor editor, final DataContext context) { final Project project = (Project) context.getData(DataConstants.PROJECT); final Document document = editor.getDocument(); final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); final VirtualFile virtualFile = fileDocumentManager.getFile(document); final PsiManager psiManager = PsiManager.getInstance(project); return psiManager.findFile(virtualFile); }
public final void execute(final Editor editor, final DataContext context) { if (editor == null) { return; } final Project project = (Project) context.getData(DataConstants.PROJECT); logger.debug("project=" + project); logger.debug("editor=" + editor); final Document document = editor.getDocument(); final CaretModel caret = editor.getCaretModel(); int cursorOffset = caret.getOffset(); final PsiFile psiFile = getFile(editor, context); if (!psiFile.getName().endsWith(".java")) { logger.debug("not a .java file -- skipping " + psiFile.getName()); return; } if (!psiFile.isWritable()) { logger.debug("not a writable .java file -- skipping " + psiFile.getName()); return; } logger.debug("inProgress=" + inProgress); if (inProgress) { return; } setInProgress(true); buildLiveRearrangerData(project, document, psiFile, cursorOffset); }
public void testJUnitPackage() { PsiClass psiClass = findClass(getModule1(), CLASS_NAME); PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass); final MapDataContext dataContext = new MapDataContext(); final Module module = ModuleUtil.findModuleForPsiElement(psiClass); dataContext.put(DataConstants.MODULE, module); JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, dataContext); checkTestObject(JUnitConfiguration.TEST_PACKAGE, configuration); checkPackage(PACKAGE_NAME, configuration); checkGeneretedName(configuration, PACKAGE_NAME + " in " + module.getName()); }
public void testJUnitDefaultPackage() { PsiClass psiClass = findClass(getModule1(), CLASS_NAME); PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass); PsiPackage defaultPackage = psiPackage.getParentPackage(); final Module module = ModuleUtil.findModuleForPsiElement(psiClass); final MapDataContext dataContext = new MapDataContext(); dataContext.put(DataConstants.MODULE, module); JUnitConfiguration configuration = createJUnitConfiguration(defaultPackage, AllInPackageConfigurationProducer.class, dataContext); checkTestObject(JUnitConfiguration.TEST_PACKAGE, configuration); checkPackage("", configuration); checkGeneretedName(configuration, "All in " + module.getName()); }
private DataContext createDataContextFor(final Editor editor) { return new DataContext() { @Override public Object getData(String dataId) { if (dataId.equals(DataConstants.EDITOR)) return editor; if (dataId.equals(DataConstants.PROJECT)) return getProject(); return null; } }; }
@Override public void update(@NotNull AnActionEvent e) { boolean enabled = false; Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); boolean rtEnabled = RTActionUtil.isRTEnabled(project); if (project != null) { final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); enabled = rtEnabled && (RTFileUtil.isRTFile(file) || BuildTemplateAction.isRtFileContext(e.getDataContext())); // if (file != null) { // e.getPresentation().setText("Switch to Code Behind file '" + file.getName() + '\''); // } } e.getPresentation().setVisible(enabled); }
public void actionPerformed(AnActionEvent e) { if (Utils.debug) { Utils.print("running perl script action from context..."); } VirtualFile[] files = (VirtualFile[]) e.getDataContext().getData(DataConstants.VIRTUAL_FILE_ARRAY); if (isInvalid(e.getProject(), files)) return; for (int i = 0; i < files.length; i++) { if (files[i].getExtension().equals("pl")) { PerlCli.runFile(e.getProject(), files[i].getPath()); } } }
@Override public void update(AnActionEvent e) { try { super.update(e); VirtualFile[] files = (VirtualFile[]) e.getDataContext().getData(DataConstants.VIRTUAL_FILE_ARRAY); if (isInvalid(e.getProject(), files)) return; //check pl file in order to update display boolean visible = false; String perlScriptName = ""; for (int i = 0; i < files.length; i++) { VirtualFile file = files[i]; if (file != null && file.getExtension().equals("pl")) { visible = true; if (perlScriptName.isEmpty()) { perlScriptName = file.getName(); } else { perlScriptName += ", " + file.getName(); } } } e.getPresentation().setVisible(true);// Visibility e.getPresentation().setEnabled(visible);// Enable or disable e.getPresentation().setText("Run '" + ((perlScriptName.isEmpty()) ? "..." : perlScriptName) + "'");// Update text }finally { } }
@Override public void update(@NotNull AnActionEvent e) { boolean enabled = false; Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); boolean pluginEnabled = isJscsEnabled(project); if (project != null) { final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); enabled = pluginEnabled && isJSFile(file); // || isRtFileContext(e.getDataContext())); if (file != null) { e.getPresentation().setText("JSCS Fix '" + file.getName() + '\''); } } e.getPresentation().setVisible(enabled); }
public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); // TODO handle multiple selection if (file == null) { // File[] rtFiles = RTFile.DATA_KEY.getData(e.getDataContext()); // if (rtFiles == null || rtFiles.length == 0) { // System.out.println("No file for rt compile"); // return; // } // // handle all files // for (RTFile rtFile : rtFiles) { // RTFileListener.compile(rtFile.getRtFile().getVirtualFile(), project); // } } else { ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class); if (!component.isSettingsValid() || !component.isEnabled()) { return; } // Result result = ESLintRunner.lint(project.getBasePath(), relativeFile, component.nodeInterpreter, component.eslintExecutable, component.eslintRcFile, component.customRulesPath); if (project.getBasePath() != null) { ESLintRunner.ESLintSettings settings = ESLintRunner.buildSettings(project.getBasePath(), file.getPath(), component); try { ESLintRunner.fix(settings); file.refresh(false, false); } catch (ExecutionException e1) { e1.printStackTrace(); } } } }
public void actionPerformed(AnActionEvent anActionEvent) { Application application = ApplicationManager.getApplication(); Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT); Axis2IdeaPlugin axis2component = (Axis2IdeaPlugin) application.getComponent(Axis2IdeaPlugin.class); axis2component.showTool(project); }
public ConfigurationContext createContext(PsiElement psiClass, MapDataContext dataContext) { dataContext.put(DataConstants.PROJECT, myProject); if (dataContext.getData(DataConstants.MODULE) == null) { dataContext.put(DataConstants.MODULE, ModuleUtilCore.findModuleForPsiElement(psiClass)); } dataContext.put(Location.LOCATION, PsiLocation.fromPsiElement(psiClass)); return ConfigurationContext.getFromContext(dataContext); }
public RearrangeIt(final DataContext dc) { this.dc = dc; this.project = (Project) dc.getData(DataConstants.PROJECT); }
public static Editor getEditor() { return (Editor) DataManager.getInstance().getDataContext().getData(DataConstants.EDITOR); }