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

The following are top voted examples for showing how to use com.intellij.openapi.actionSystem.CommonDataKeys. 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: SmartQQ4IntelliJ   File: ReviewHandler.java   Source Code and License 6 votes vote down vote up
@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();
    }
}
 
Example 2
Project: watchMe   File: SlackSettings.java   Source Code and License 6 votes vote down vote up
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());
}
 
Example 3
Project: watchMe   File: SlackSettings.java   Source Code and License 6 votes vote down vote up
@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());
        }
    }
}
 
Example 4
Project: OpenInExplorer-idea   File: RightAction.java   Source Code and License 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 5
Project: intellij-randomness   File: DataInsertAction.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 6
Project: hybris-integration-intellij-idea-plugin   File: ImportImpexAction.java   Source Code and License 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor != null) {
        final SelectionModel selectionModel = editor.getSelectionModel();
        final ImportImpexHttpClient client = new ImportImpexHttpClient();
        final String selectedText = selectionModel.getSelectedText();
        if (StringUtils.isNotEmpty(selectedText)) {
            final HybrisHttpResult hybrisHttpResult = client.importImpex(selectedText);

            ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
        }
    }
}
 
Example 7
Project: educational-plugin   File: CCDeleteAllAnswerPlaceholdersAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 8
Project: educational-plugin   File: CCAnswerPlaceholderAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 9
Project: educational-plugin   File: CCGetCourseFromStepic.java   Source Code and License 6 votes vote down vote up
@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);
      }
    });
  }
}
 
Example 10
Project: educational-plugin   File: CCShowPreview.java   Source Code and License 6 votes vote down vote up
@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);
  }
}
 
Example 11
Project: educational-plugin   File: CCSwitchSubtask.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 12
Project: educational-plugin   File: CCNewSubtaskAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 13
Project: educational-plugin   File: CCNewSubtaskAction.java   Source Code and License 6 votes vote down vote up
@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);
  }
}
 
Example 14
Project: educational-plugin   File: CCLessonMoveHandlerDelegate.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 15
Project: educational-plugin   File: CCTaskMoveHandlerDelegate.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 16
Project: RIBs   File: GenerateAction.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 17
Project: MultiHighlight   File: MultiHighlightAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 18
Project: MultiHighlight   File: MultiHighlightClearAction.java   Source Code and License 6 votes vote down vote up
@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);
        }
    }
}
 
Example 19
Project: intellij-ce-playground   File: CreatePatchFromChangesAction.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 20
Project: mule-intellij-plugins   File: OpenSampleAction.java   Source Code and License 6 votes vote down vote up
@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);
    }

}
 
Example 21
Project: intellij-ce-playground   File: RepositoryBrowserComponent.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 22
Project: PackageTemplates   File: NewPackageTemplateAction.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 23
Project: PackageTemplates   File: RunTemplateAction.java   Source Code and License 6 votes vote down vote up
@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);
    }

}
 
Example 24
Project: intellij-ce-playground   File: UnSelectWordHandler.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 25
Project: intellij-ce-playground   File: BaseCodeCompletionAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 26
Project: intellij-ce-playground   File: AbstractPopup.java   Source Code and License 6 votes vote down vote up
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);
    }
  }
}
 
Example 27
Project: intellij-ce-playground   File: PyCallHierarchyProvider.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 28
Project: MissingInActions   File: PatternAction.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 29
Project: stack-intheflow   File: AutoQueryAction.java   Source Code and License 6 votes vote down vote up
@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(() -> {
    });
}
 
Example 30
Project: intellij-ce-playground   File: GenerateMainAction.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 31
Project: intellij-ce-playground   File: ChangeTemplateDataLanguageAction.java   Source Code and License 6 votes vote down vote up
@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);
  }

}
 
Example 32
Project: intellij-ce-playground   File: RollbackDialogAction.java   Source Code and License 6 votes vote down vote up
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);
      }
    }
  });
}
 
Example 33
Project: intellij-ce-playground   File: ScheduleForAdditionAction.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 34
Project: intellij-ce-playground   File: BaseToolWindowToggleAction.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 35
Project: intellij-ce-playground   File: ShowByteCodeAction.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 36
Project: intellij-ce-playground   File: CCPushLesson.java   Source Code and License 6 votes vote down vote up
@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);
    }});
}
 
Example 37
Project: intellij-ce-playground   File: ResourceBundleFromEditorRenameHandler.java   Source Code and License 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 38
Project: FXMLHelper   File: ControllerGeneratorAction.java   Source Code and License 5 votes vote down vote up
@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();
            }
        });
    }
}
 
Example 39
Project: FXMLHelper   File: ControllerGeneratorAction.java   Source Code and License 5 votes vote down vote up
@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);
        }
    }
}
 
Example 40
Project: idea-php-typo3-plugin   File: ExtbaseControllerActionAction.java   Source Code and License 5 votes vote down vote up
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"));
}