Java Code Examples for com.intellij.openapi.actionSystem.PlatformDataKeys

The following are top voted examples for showing how to use com.intellij.openapi.actionSystem.PlatformDataKeys. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CodeGenerate   File: MainAction.java   View source code 6 votes vote down vote up
public void actionPerformed(AnActionEvent event) {
        Project project = event.getData(PlatformDataKeys.PROJECT);
        Editor editor = event.getData(PlatformDataKeys.EDITOR);
        PsiFile mFile = PsiUtilBase.getPsiFileInEditor(editor, project);
        PsiClass psiClass = getTargetClass(editor, mFile);
        GridMain gridMain = new GridMain(psiClass,mFile,project);
        //DBConn dbConn = new DBConn(psiClass,mFile,project);
//        JsonDialog jsonD = new JsonDialog(psiClass, mFile, project);
//        jsonD.setClass(psiClass);
//        jsonD.setFile(mFile);
//        jsonD.setProject(project);
//        jsonD.setSize(600, 400);
//        jsonD.setLocationRelativeTo(null);
//        jsonD.setVisible(true);

    }
 
Example 2
Project: idea-php-typo3-plugin   File: ExtensionUtility.java   View source code 6 votes vote down vote up
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 3
Project: OpenInExplorer-idea   File: RightAction.java   View source code 6 votes vote down vote up
@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());
    }
}
 
Example 4
Project: Specflow.Rider   File: SpecflowGenerateCodeTest.java   View source code 6 votes vote down vote up
@Test
public void actionFileReadFailDoesNotBubbleExcepted() throws IOException {

    AnActionEvent action = mock(AnActionEvent.class);
    ISpecflowAnalyzer lexer = mock(ISpecflowAnalyzer.class);
    FileFactory fileFactory = mock(FileFactory.class);
    DirectoryFactory directoryFactory = mock(DirectoryFactory.class);
    VirtualFile file = mock(VirtualFile.class);

    when(action.getData(PlatformDataKeys.VIRTUAL_FILE)).thenReturn(file);
    when(file.contentsToByteArray()).thenThrow(new IOException());

    SpecflowGenerateCode generator = new SpecflowGenerateCode(lexer, fileFactory, directoryFactory);
    generator.actionPerformed(action);

    verify(lexer, never()).analyze(anyString(), anyString());
}
 
Example 5
Project: GoogleTranslation   File: GoogleTranslation.java   View source code 6 votes vote down vote up
private void getTranslation(AnActionEvent event) {
    Editor editor = event.getData(PlatformDataKeys.EDITOR);
    if (editor == null) {
        return;
    }
    SelectionModel model = editor.getSelectionModel();
    String selectedText = model.getSelectedText();
    if (TextUtils.isEmpty(selectedText)) {
        selectedText = getCurrentWords(editor);
        if (TextUtils.isEmpty(selectedText)) {
            return;
        }
    }
    String queryText = strip(addBlanks(selectedText));
    new Thread(new RequestRunnable(mTranslator, editor, queryText)).start();
}
 
Example 6
Project: ReciteWords   File: ReciteWords.java   View source code 6 votes vote down vote up
private void getTranslation(AnActionEvent event) {
    Editor mEditor = event.getData(PlatformDataKeys.EDITOR);
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String basePath = project.getBasePath();

    if (null == mEditor) {
        return;
    }
    SelectionModel model = mEditor.getSelectionModel();
    String selectedText = model.getSelectedText();
    if (TextUtils.isEmpty(selectedText)) {
        selectedText = getCurrentWords(mEditor);
        if (TextUtils.isEmpty(selectedText)) {
            return;
        }
    }
    String queryText = strip(addBlanks(selectedText));
    new Thread(new RequestRunnable(mEditor, queryText,basePath)).start();
}
 
Example 7
Project: Android-ORM-ASPlugin   File: NewProviderAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(PlatformDataKeys.PROJECT);
    List<VirtualFile> javaFiles = Utils.getSelectJavaFiles(e, true);
    int size = javaFiles.size();
    for (int i = 0; i < javaFiles.size(); i++) {
        VirtualFile vf = javaFiles.get(i);
        if (!Utils.hasOrm(project, vf)) {
            javaFiles.remove(i);
            i--;
        }
    }

    // if (!javaFiles.isEmpty())
    {
        NewProviderDialog dialog = new NewProviderDialog();
        dialog.init(project, e.getData(PlatformDataKeys.VIRTUAL_FILE), javaFiles);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
        dialog.dispose();
    }
}
 
Example 8
Project: ApiCreator   File: MainAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    // TODO: insert action logic here

    VirtualFile data = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    String path = data.getPath();
    String packagename = path.substring(path.indexOf("main/java") + 10, path.length()).replaceAll("/", ".");

    System.out.println(path);
    System.out.println(packagename);

    JsonDialog jsonDialog = new JsonDialog(path, packagename, e);
    jsonDialog.setSize(620, 440);
    jsonDialog.setAlwaysOnTop(true);
    jsonDialog.setVisible(true);


}
 
Example 9
Project: intellij-ce-playground   File: NavigatableRule.java   View source code 6 votes vote down vote up
@Override
public Object getData(DataProvider dataProvider) {
  final Navigatable navigatable = CommonDataKeys.NAVIGATABLE.getData(dataProvider);
  if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
    final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor)navigatable;

    if (openFileDescriptor.getFile().isValid()) {
      return openFileDescriptor;
    }
  }
  final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
  if (element instanceof Navigatable) {
    return element;
  }
  if (element != null) {
    return EditSourceUtil.getDescriptor(element);
  }

  final Object selection = PlatformDataKeys.SELECTED_ITEM.getData(dataProvider);
  if (selection instanceof Navigatable) {
    return selection;
  }

  return null;
}
 
Example 10
Project: MissingInActions   File: WordHighlightActionBase.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (editor != null) {
        Document document = editor.getDocument();
        CharSequence chars = document.getCharsSequence();
        Plugin plugin = Plugin.getInstance();

        for (Caret caret : editor.getCaretModel().getAllCarets()) {
            if (caret.hasSelection()) {
                boolean startWord = EditHelpers.isWordStart(chars, caret.getSelectionStart(),false);
                boolean endWord = EditHelpers.isWordEnd(chars, caret.getSelectionEnd(),false);
                if (myIsRemoveWord) {
                    plugin.removeHighlightWord(chars.subSequence(caret.getSelectionStart(), caret.getSelectionEnd()));
                } else {
                    plugin.addHighlightWord(chars.subSequence(caret.getSelectionStart(), caret.getSelectionEnd()), startWord, endWord, null);
                }
            }
        }
    }
}
 
Example 11
Project: intellij-ce-playground   File: ResourceBundleGrouper.java   View source code 6 votes vote down vote up
public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
  if (selected == null) return null;
  if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataName)) {
    for (AbstractTreeNode selectedElement : selected) {
      Object element = selectedElement.getValue();
      if (element instanceof ResourceBundle) {
        return new ResourceBundleDeleteProvider();
      }
    }
  } else if (ResourceBundle.ARRAY_DATA_KEY.is(dataName)) {
    final List<ResourceBundle> selectedElements = new ArrayList<ResourceBundle>();
    for (AbstractTreeNode node : selected) {
      final Object value = node.getValue();
      if (value instanceof ResourceBundle) {
        selectedElements.add((ResourceBundle)value);
      }
    }
    return selectedElements.isEmpty() ? null : selectedElements.toArray(new ResourceBundle[selectedElements.size()]);
  }
  return null;
}
 
Example 12
Project: DscTranslate   File: DscTranslate.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    //获取编辑器
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (editor != null){
        SelectionModel model = editor.getSelectionModel();
        //获取选中文本
        String selectedText = model.getSelectedText().toString();
        if (selectedText!=null){
            selectedText = addBlanks(selectedText);
            try {
                getTranslation(selectedText);
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
Example 13
Project: intellij-ce-playground   File: SearchBackAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        FindManager findManager = FindManager.getInstance(project);
        if(!findManager.selectNextOccurrenceWasPerformed() && findManager.findPreviousUsageInEditor(editor)) {
          return;
        }
        FindUtil.searchBack(project, editor, e.getDataContext());
      }
    },
    IdeBundle.message("command.find.previous"),
    null
  );
}
 
Example 14
Project: AndroidStudioPlugin   File: CreateDialogAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {

    // 获取编辑器中的文件
    Project project = e.getData(PlatformDataKeys.PROJECT);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);

    // 获取当前类
    PsiClass targetClass = getTargetClass(editor, file);
    // 获取元素操作的工厂类
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);

    // 生成代码
    new LayoutCreator(project, targetClass, factory, file).execute();
}
 
Example 15
Project: AndroidPixelDimenGenerator   File: MainAnAction.java   View source code 6 votes vote down vote up
@Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Project project = anActionEvent.getData(PlatformDataKeys.PROJECT);

//        PsiFile psiFile = anActionEvent.getData(LangDataKeys.PSI_FILE);
//        Editor editor = anActionEvent.getData(PlatformDataKeys.EDITOR);
//        Application application = ApplicationManager.getApplication();
//        MyApplicationComponent myApplicationComponent = application.getComponent(MyApplicationComponent.class);

        MyDialog myDialog = new MyDialog(project);
        myDialog.show();
        if (myDialog.isOK()) {
            Messages.showMessageDialog(project, "生成像素dimen文件成功\nGenerate pixel dimen file success",
                    PROJECT_NAME, Messages.getInformationIcon());
        }
//        String txt = Messages.showMultilineInputDialog(project,
//                "请按照示例添加所需的分辨率",
//                "AutoGeneratePixelDimen",
//                "1920 1080\n1280 720", Messages.getQuestionIcon(), null);
    }
 
Example 16
Project: deltahex-intellij-plugin   File: OpenAsHexAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return;
    }
    VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
    if (virtualFile != null && virtualFile.isValid() && !virtualFile.isDirectory()) {
        DeltaHexVirtualFile deltaHexVirtualFile = new DeltaHexVirtualFile(virtualFile);
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, deltaHexVirtualFile, 0);
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        List<FileEditor> editors = fileEditorManager.openEditor(descriptor, true);
        fileEditorManager.setSelectedEditor(virtualFile, DeltaHexWindowProvider.DELTAHEX_EDITOR_TYPE_ID);
        for (FileEditor fileEditor : editors) {
            if (fileEditor instanceof DeltaHexFileEditor) {
                ((DeltaHexFileEditor) fileEditor).openFile(deltaHexVirtualFile);
            }
        }
    }
}
 
Example 17
Project: phpstorm-plugin   File: Run.java   View source code 6 votes vote down vote up
@Nullable
protected PhpClass getCurrentTestClass(AnActionEvent e) {
    Object psiFile = e.getData(PlatformDataKeys.PSI_FILE);

    if (null == psiFile) {
        return null;
    }

    if (!(psiFile instanceof PhpFile)) {
        return null;
    }
    PhpFile phpFile = ((PhpFile) psiFile);

    PhpClass currentClass = Utils.getFirstClassFromFile(phpFile);
    if (null == currentClass) {
        return null;
    }

    if (!Utils.isClassAtoumTest(currentClass)) {
        return Utils.locateTestClass(e.getProject(), currentClass);
    }

    return currentClass;
}
 
Example 18
Project: intellij-ce-playground   File: ResourceBundleFromEditorRenameHandler.java   View source code 6 votes vote down vote up
@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));
}
 
Example 19
Project: android-xml-sorter   File: XmlInstantSorterAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {

    final Project project = getEventProject(event);
    final Editor editor = event.getData(PlatformDataKeys.EDITOR);
    XmlSorterDialog dialog = new XmlSorterDialog(project);

    PropertiesComponent pc = PropertiesComponent.getInstance();
    execute(project,
            editor,
            pc.getInt(PC_KEY_INPUT_CASE, 0) == 0,
            dialog.getPrefixSpacePositionValueAt(pc.getInt(PC_KEY_PREFIX_SPACE_POS, 0)),
            pc.getBoolean(PC_KEY_SPACE_BETWEEN_PREFIX, true),
            pc.getBoolean(PC_KEY_INSERT_XML_INFO, true),
            pc.getBoolean(PC_KEY_DELETE_COMMENT, false),
            dialog.getCodeIndentValueAt(pc.getInt(PC_KEY_CODE_INDENT, 1)));
}
 
Example 20
Project: intellij-ce-playground   File: PsiElementFromSelectionsRule.java   View source code 6 votes vote down vote up
@Override
public Object getData(DataProvider dataProvider) {
  final Object[] objects = (Object[])dataProvider.getData(PlatformDataKeys.SELECTED_ITEMS.getName());
  if (objects != null) {
    final PsiElement[] elements = new PsiElement[objects.length];
    for (int i = 0, objectsLength = objects.length; i < objectsLength; i++) {
      Object object = objects[i];
      if (!(object instanceof PsiElement)) return null;
      if (!((PsiElement)object).isValid()) return null;
      elements[i] = (PsiElement)object;
    }

    return elements;
  }
  return null;
}
 
Example 21
Project: intellij-ce-playground   File: MaximizeToolWindowAction.java   View source code 6 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
  e.getPresentation().setEnabled(true);
  Project project = e.getProject();
  if (project == null || project.isDisposed()) {
    e.getPresentation().setEnabled(false);
    return;
  }
  ToolWindow toolWindow = e.getData(PlatformDataKeys.TOOL_WINDOW);
  if (toolWindow == null) {
    e.getPresentation().setEnabled(false);
    return;
  }
  ToolWindowManager manager = ToolWindowManager.getInstance(project);
  e.getPresentation().setText(manager.isMaximized(toolWindow) ?
                              ActionsBundle.message("action.ResizeToolWindowMaximize.text.alternative") :
                              ActionsBundle.message("action.ResizeToolWindowMaximize.text"));
}
 
Example 22
Project: intellij-ce-playground   File: EditorComposite.java   View source code 6 votes vote down vote up
@Override
public final Object getData(String dataId){
  if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
    return getSelectedEditor();
  }
  else if(CommonDataKeys.VIRTUAL_FILE.is(dataId)){
    return myFile.isValid() ? myFile : null;
  }
  else if(CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)){
    return myFile.isValid() ? new VirtualFile[] {myFile} : null;
  }
  else{
    JComponent component = getPreferredFocusedComponent();
    if(component instanceof DataProvider && component != this){
      return ((DataProvider)component).getData(dataId);
    }
    else{
      return null;
    }
  }
}
 
Example 23
Project: intellij-ce-playground   File: IpnbMoveCellUpAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
  final DataContext context = event.getDataContext();
  final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
  if (editor instanceof IpnbFileEditor) {
    final IpnbFilePanel ipnbFilePanel = ((IpnbFileEditor)editor).getIpnbFilePanel();
    CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(), new Runnable() {
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          public void run() {
            ipnbFilePanel.moveCell(false);
          }
        });
      }
    }, "Ipnb.moveCell", new Object());

  }
}
 
Example 24
Project: intellij-ce-playground   File: MergePanel2.java   View source code 6 votes vote down vote up
public Object getData(String dataId) {
  if (FocusDiffSide.DATA_KEY.is(dataId)) {
    int index = getFocusedEditorIndex();
    if (index < 0) return null;
    switch (index) {
      case 0:
        return new BranchFocusedSide(FragmentSide.SIDE1);
      case 1:
        return new MergeFocusedSide();
      case 2:
        return new BranchFocusedSide(FragmentSide.SIDE2);
    }
  }
  else if (PlatformDataKeys.DIFF_VIEWER.is(dataId)) return MergePanel2.this;
  return super.getData(dataId);
}
 
Example 25
Project: intellij-ce-playground   File: DiffPanelOuterComponent.java   View source code 6 votes vote down vote up
public Object getData(String dataId) {
  if (PlatformDataKeys.SOURCE_NAVIGATION_LOCKED.is(dataId)) {
    return Boolean.TRUE;
  }
  if (myDataProvider == null) {
    return null;
  }
  if (CommonDataKeys.EDITOR.is(dataId)) {
    if (myBottomComponent != null) {
      // we don't want editor actions to be executed when the bottom component has focus
      final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
      if (myBottomComponent.isAncestorOf(focusOwner)) {
        return null;
      }
    }
    final FocusDiffSide side = (FocusDiffSide)myDataProvider.getData(FocusDiffSide.DATA_KEY.getName());
    if (side != null) {
      final Editor editor = side.getEditor();
      return editor != null && editor.getComponent().hasFocus() ? editor : null;
    }
  }
  return myDataProvider.getData(dataId);
}
 
Example 26
Project: intellij-ce-playground   File: MacroManager.java   View source code 6 votes vote down vote up
private static DataContext getCorrectContext(DataContext dataContext) {
  if (PlatformDataKeys.FILE_EDITOR.getData(dataContext) != null) {
    return dataContext;
  }
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return dataContext;
  }
  FileEditorManager editorManager = FileEditorManager.getInstance(project);
  VirtualFile[] files = editorManager.getSelectedFiles();
  if (files.length == 0) {
    return dataContext;
  }
  FileEditor fileEditor = editorManager.getSelectedEditor(files[0]);
  return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent());
}
 
Example 27
Project: intellij-ce-playground   File: ContentManagerUtil.java   View source code 6 votes vote down vote up
/**
 * This is utility method. It returns <code>ContentManager</code> from the current context.
 */
public static ContentManager getContentManagerFromContext(DataContext dataContext, boolean requiresVisibleToolWindow){
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return null;
  }

  ToolWindowManagerEx mgr=ToolWindowManagerEx.getInstanceEx(project);

  String id = mgr.getActiveToolWindowId();
  if (id == null) {
    if(mgr.isEditorComponentActive()){
      id = mgr.getLastActiveToolWindowId();
    }
  }

  ToolWindowEx toolWindow = id != null ? (ToolWindowEx)mgr.getToolWindow(id) : null;
  if (requiresVisibleToolWindow && (toolWindow == null || !toolWindow.isVisible())) {
    return null;
  }

  ContentManager fromToolWindow = toolWindow != null ? toolWindow.getContentManager() : null;
  ContentManager fromContext = PlatformDataKeys.CONTENT_MANAGER.getData(dataContext);
  return ObjectUtils.chooseNotNull(fromContext, fromToolWindow);
}
 
Example 28
Project: intellij-ce-playground   File: SearchAgainAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
  if (editor == null || project == null) return;
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
        FindManager findManager = FindManager.getInstance(project);
        if(!findManager.selectNextOccurrenceWasPerformed() && findManager.findNextUsageInEditor(editor)) {
          return;
        }

        FindUtil.searchAgain(project, editor, e.getDataContext());
      }
    },
    IdeBundle.message("command.find.next"),
    null
  );
}
 
Example 29
Project: intellij-ce-playground   File: ShowContentAction.java   View source code 6 votes vote down vote up
@Nullable
private ToolWindow getWindow(AnActionEvent event) {
  if (myWindow != null) return myWindow;

  Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
  if (project == null) return null;

  ToolWindowManager manager = ToolWindowManager.getInstance(project);

  final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId());
  if (window == null) return null;

  final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext());
  if (context == null) return null;

  return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null;
}
 
Example 30
Project: intellij-ce-playground   File: UndoRedoAction.java   View source code 6 votes vote down vote up
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);

  // do not allow global undo in dialogs
  if (editor == null) {
    final Boolean isModalContext = PlatformDataKeys.IS_MODAL_CONTEXT.getData(dataContext);
    if (isModalContext != null && isModalContext) {
      presentation.setEnabled(false);
      return;
    }
  }

  UndoManager undoManager = getUndoManager(editor, dataContext);
  if (undoManager == null) {
    presentation.setEnabled(false);
    return;
  }
  presentation.setEnabled(isAvailable(editor, undoManager));

  Pair<String, String> pair = getActionNameAndDescription(editor, undoManager);

  presentation.setText(pair.first);
  presentation.setDescription(pair.second);
}
 
Example 31
Project: intellij-ce-playground   File: IpnbMoveCellDownAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
  final DataContext context = event.getDataContext();
  final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
  if (editor instanceof IpnbFileEditor) {
    final IpnbFilePanel ipnbFilePanel = ((IpnbFileEditor)editor).getIpnbFilePanel();
    CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(), new Runnable() {
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          public void run() {
            ipnbFilePanel.moveCell(true);
          }
        });
      }
    }, "Ipnb.moveCell", new Object());

  }
}
 
Example 32
Project: intellij-ce-playground   File: AnnotateRevisionAction.java   View source code 6 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
  if (Boolean.TRUE.equals(e.getData(PlatformDataKeys.IS_MODAL_CONTEXT))) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  if (myAnnotation.getFile() == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }

  if (getRevisions() == null) {
    e.getPresentation().setEnabledAndVisible(false);
    return;
  }
  e.getPresentation().setVisible(true);

  super.update(e);
}
 
Example 33
Project: intellij-ce-playground   File: ShowChangeAbstractAction.java   View source code 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final ChangeRequestChain chain = e.getData(VcsDataKeys.DIFF_REQUEST_CHAIN);
  if (project == null || chain == null || !isEnabled(chain)) {
    return;
  }

  DiffViewer diffViewer = e.getData(PlatformDataKeys.COMPOSITE_DIFF_VIEWER);
  if (diffViewer == null) {
    diffViewer = e.getData(PlatformDataKeys.DIFF_VIEWER);
  }
  if (diffViewer == null) {
    return;
  }

  actionPerformed(e, project, chain, diffViewer);
}
 
Example 34
Project: intellij-ce-playground   File: IgnoreIncompletePropertyPropertiesFilesAction.java   View source code 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(e.getDataContext());
  if (fileEditor instanceof ResourceBundleEditor) {
    ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor)fileEditor;
    final Project project = getEventProject(e);
    if (project != null) {
      if (!processSelectedIncompleteProperties(new Processor<IProperty>() {
        @Override
        public boolean process(IProperty property) {
          return false;
        }
      }, resourceBundleEditor, project)) {
        e.getPresentation().setEnabledAndVisible(true);
        return;
      }
    }
  }
  e.getPresentation().setEnabledAndVisible(false);
}
 
Example 35
Project: OkHttpParamsGet   File: GetParamsAction.java   View source code 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    // TODO: insert action logic here
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Project project = e.getProject();
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    TypePickDialog dialog = new TypePickDialog();
    dialog.setListener(type -> {build(type, psiFile, project, editor);});
    dialog.pack();
    dialog.setVisible(true);
}
 
Example 36
Project: react-native-console   File: BaseAction.java   View source code 5 votes vote down vote up
@Override
    public void actionPerformed(AnActionEvent anActionEvent) {
//        DocumentUtil.saveDocument();
        this.anActionEvent = anActionEvent;
        this.currentProject = PlatformDataKeys.PROJECT.getData(anActionEvent.getDataContext());
        this.projectDir = new File(currentProject.getBasePath());
        actionPerformed();
    }
 
Example 37
Project: mybatis-log-plugin   File: GoogleTranslateAction.java   View source code 5 votes vote down vote up
public void actionPerformed(AnActionEvent var1) {
    DataContext var2 = var1.getDataContext();
    CopyProvider var3 = (CopyProvider) PlatformDataKeys.COPY_PROVIDER.getData(var2);
    if (var3 != null) {
        var3.performCopy(var2);
        String var4 = (String) CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
        if (StringUtil.isNotEmpty(var4)) {
            BrowserUtil.browse("https://translate.google.com/#en/zh-CN/" + URLEncoder.encode(var4));
        }
    }
}
 
Example 38
Project: mybatis-log-plugin   File: GoogleTranslateAction.java   View source code 5 votes vote down vote up
public void update(AnActionEvent var1) {
    Presentation var2 = var1.getPresentation();
    DataContext var3 = var1.getDataContext();
    CopyProvider var4 = (CopyProvider) PlatformDataKeys.COPY_PROVIDER.getData(var3);
    boolean var5 = var4 != null && var4.isCopyEnabled(var3) && var4.isCopyVisible(var3);
    var2.setEnabled(var5);
    var2.setVisible(var5);
}
 
Example 39
Project: mybatis-log-plugin   File: BaiduSearchAction.java   View source code 5 votes vote down vote up
public void actionPerformed(AnActionEvent var1) {
    DataContext var2 = var1.getDataContext();
    CopyProvider var3 = (CopyProvider) PlatformDataKeys.COPY_PROVIDER.getData(var2);
    if (var3 != null) {
        var3.performCopy(var2);
        String var4 = (String) CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
        if (StringUtil.isNotEmpty(var4)) {
            BrowserUtil.browse("https://www.baidu.com/s?wd=" + URLEncoder.encode(var4));
        }
    }
}
 
Example 40
Project: mybatis-log-plugin   File: BaiduSearchAction.java   View source code 5 votes vote down vote up
public void update(AnActionEvent var1) {
    Presentation var2 = var1.getPresentation();
    DataContext var3 = var1.getDataContext();
    CopyProvider var4 = (CopyProvider) PlatformDataKeys.COPY_PROVIDER.getData(var3);
    boolean var5 = var4 != null && var4.isCopyEnabled(var3) && var4.isCopyVisible(var3);
    var2.setEnabled(var5);
    var2.setVisible(var5);
}