Java 类com.intellij.openapi.actionSystem.DataConstants 实例源码

项目:quicknotes    文件:AddToQuickNotes.java   
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 );
            }
        }
    }
}
项目:ADB-Duang    文件:PushAction.java   
@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;
}
项目:react-templates-plugin    文件:SwitchViewAction.java   
@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);
        }
    }
}
项目:jscs-plugin    文件:JscsFixAction.java   
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);
    }
项目:react-templates-plugin    文件:SwitchViewAction.java   
@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);
        }
    }
}
项目:ADB-Duang    文件:PushAction.java   
@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);
}
项目:ADB-Duang    文件:EditDbAction.java   
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;
}
项目:Rearranger    文件:RearrangerActionHandler.java   
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);
}
项目:Rearranger    文件:ProjectTreeActionHandler.java   
public RearrangeIt(final DataContext dc)
{
    this.dc = dc;
    if (dc != null) {
        this.project = (Project) dc.getData(DataConstants.PROJECT);
    }
    else this.project = null;
}
项目:Rearranger    文件:LiveRearrangerActionHandler.java   
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);
}
项目:Rearranger    文件:LiveRearrangerActionHandler.java   
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);
}
项目:Rearranger    文件:RearrangementResult31.java   
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);
}
项目:Rearranger    文件:RearrangementResult31.java   
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);
}
项目:Rearranger    文件:RearrangementTest31.java   
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);
}
项目:Rearranger    文件:RearrangementTest31.java   
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);
}
项目:intellij-ce-playground    文件:ContextConfigurationTest.java   
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());
}
项目:intellij-ce-playground    文件:ContextConfigurationTest.java   
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());
}
项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
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;
    }
  };
}
项目:react-templates-plugin    文件:SwitchViewAction.java   
@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);
    }
项目:intellij-perl-plugin    文件:RunPerlAction.java   
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());
        }
    }
}
项目:intellij-perl-plugin    文件:RunPerlAction.java   
@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 {
    }
}
项目:jscs-plugin    文件:JscsFixAction.java   
@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);
}
项目:react-templates-plugin    文件:SwitchViewAction.java   
@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);
    }
项目:eslint-plugin    文件:ESLintFixAction.java   
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();
                }
            }
        }
    }
项目:wso2-axis2    文件:Axis2PluginAction.java   
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);
}
项目:tools-idea    文件:BaseConfigurationTestCase.java   
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);
}
项目:tools-idea    文件:ContextConfigurationTest.java   
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());
}
项目:tools-idea    文件:ContextConfigurationTest.java   
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());
}
项目:Rearranger    文件:RearrangementTest30.java   
public RearrangeIt(final DataContext dc)
{
    this.dc      = dc;
    this.project = (Project) dc.getData(DataConstants.PROJECT);
}
项目:Rearranger    文件:SpaceTest4.java   
public RearrangeIt(final DataContext dc)
{
    this.dc      = dc;
    this.project = (Project) dc.getData(DataConstants.PROJECT);
}
项目:Rearranger    文件:SpaceResult4.java   
public RearrangeIt(final DataContext dc)
{
    this.dc      = dc;
    this.project = (Project) dc.getData(DataConstants.PROJECT);
}
项目:Rearranger    文件:RearrangementResult30.java   
public RearrangeIt(final DataContext dc)
{
    this.dc      = dc;
    this.project = (Project) dc.getData(DataConstants.PROJECT);
}
项目:PHPStorm-plugin    文件:EditorIntegration.java   
public static Editor getEditor() {
    return (Editor) DataManager.getInstance().getDataContext().getData(DataConstants.EDITOR);
}