<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.actions;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiNameHelper;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.ListSpeedSearch;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ui.accessibility.ScreenReader;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.idea.devkit.util.ActionData;
import org.jetbrains.idea.devkit.util.ActionType;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NewActionDialog extends DialogWrapper implements ActionData {
  private JPanel myRootPanel;
  private JList<ActionGroup> myGroupList;
  private JList<AnAction> myActionList;
  private JTextField myActionClassNameEdit;
  private JTextField myActionIdEdit;
  private JTextField myActionNameEdit;
  private JTextField myActionDescriptionEdit;
  private JRadioButton myAnchorFirstRadio;
  private JRadioButton myAnchorLastRadio;
  private JRadioButton myAnchorBeforeRadio;
  private JRadioButton myAnchorAfterRadio;
  private JPanel myShortcutPanel;
  private JPanel myFirstKeystrokeEditPlaceholder;
  private JPanel mySecondKeystrokeEditPlaceholder;
  private JButton myClearFirstKeystroke;
  private JButton myClearSecondKeystroke;
  private final ShortcutTextField myFirstKeystrokeEdit;
  private final ShortcutTextField mySecondKeystrokeEdit;
  private final Project myProject;
  private final PsiDirectory myDirectory;
  private ButtonGroup myAnchorButtonGroup;


  public NewActionDialog(@NotNull PsiClass actionClass) {
    this(actionClass.getProject(), null);

    myActionClassNameEdit.setText(actionClass.getQualifiedName());
    myActionClassNameEdit.setEditable(false);
    myActionIdEdit.setText(actionClass.getQualifiedName());
    if (ActionType.GROUP.isOfType(actionClass)) {
      myShortcutPanel.setVisible(false);
    }
  }

  NewActionDialog(Project project, PsiDirectory directory) {
    super(project, false);
    myProject = project;
    myDirectory = directory;
    init();
    setTitle(DevKitBundle.message("new.action.dialog.title"));
    ActionManager actionManager = ActionManager.getInstance();
    List<String> actionIds = actionManager.getActionIdList("");
    actionIds.sort(null);
    List<ActionGroup> actionGroups = new ArrayList<>();
    for(String actionId: actionIds) {
      if (actionManager.isGroup(actionId)) {
        AnAction anAction = actionManager.getAction(actionId);
        if (anAction instanceof DefaultActionGroup) {
          actionGroups.add((ActionGroup) anAction);
        }
      }
    }
    myGroupList.setListData(actionGroups.toArray(new ActionGroup[0]));
    myGroupList.setCellRenderer(new MyActionRenderer());
    myGroupList.addListSelectionListener(new ListSelectionListener() {
      @Override
      public void valueChanged(ListSelectionEvent e) {
        ActionGroup group = myGroupList.getSelectedValue();
        if (group == null) {
          myActionList.setListData(AnAction.EMPTY_ARRAY);
        }
        else {
          AnAction[] actions = group.getChildren(null);
          // filter out actions that don't have IDs - they can't be used for anchoring in plugin.xml
          List<AnAction> realActions = new ArrayList<>();
          for(AnAction action: actions) {
            if (actionManager.getId(action) != null) {
              realActions.add(action);
            }
          }
          myActionList.setListData(realActions.toArray(AnAction.EMPTY_ARRAY));
        }
      }
    });
    new ListSpeedSearch<>(myGroupList, o -> ActionManager.getInstance().getId(o));

    myActionList.setCellRenderer(new MyActionRenderer());<commit_msg>IDEA-245277 "New action" dialog: hide anonymous groups<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.actions;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.ListSpeedSearch;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ui.accessibility.ScreenReader;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.idea.devkit.dom.index.IdeaPluginRegistrationIndex;
import org.jetbrains.idea.devkit.util.ActionData;
import org.jetbrains.idea.devkit.util.ActionType;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NewActionDialog extends DialogWrapper implements ActionData {
  private JPanel myRootPanel;
  private JList<ActionGroup> myGroupList;
  private JList<AnAction> myActionList;
  private JTextField myActionClassNameEdit;
  private JTextField myActionIdEdit;
  private JTextField myActionNameEdit;
  private JTextField myActionDescriptionEdit;
  private JRadioButton myAnchorFirstRadio;
  private JRadioButton myAnchorLastRadio;
  private JRadioButton myAnchorBeforeRadio;
  private JRadioButton myAnchorAfterRadio;
  private JPanel myShortcutPanel;
  private JPanel myFirstKeystrokeEditPlaceholder;
  private JPanel mySecondKeystrokeEditPlaceholder;
  private JButton myClearFirstKeystroke;
  private JButton myClearSecondKeystroke;
  private final ShortcutTextField myFirstKeystrokeEdit;
  private final ShortcutTextField mySecondKeystrokeEdit;
  private final Project myProject;
  private final PsiDirectory myDirectory;
  private ButtonGroup myAnchorButtonGroup;


  public NewActionDialog(@NotNull PsiClass actionClass) {
    this(actionClass.getProject(), null);

    myActionClassNameEdit.setText(actionClass.getQualifiedName());
    myActionClassNameEdit.setEditable(false);
    myActionIdEdit.setText(actionClass.getQualifiedName());
    if (ActionType.GROUP.isOfType(actionClass)) {
      myShortcutPanel.setVisible(false);
    }
  }

  NewActionDialog(Project project, PsiDirectory directory) {
    super(project, false);
    myProject = project;
    myDirectory = directory;
    init();
    setTitle(DevKitBundle.message("new.action.dialog.title"));
    ActionManager actionManager = ActionManager.getInstance();

    List<String> actionIds = actionManager.getActionIdList("");
    actionIds.sort(null);
    List<ActionGroup> actionGroups = new ArrayList<>();
    for (String actionId : actionIds) {
      if (actionManager.isGroup(actionId)) {
        AnAction anAction = actionManager.getAction(actionId);
        if (anAction instanceof DefaultActionGroup) {
          boolean hasDefinedId = !IdeaPluginRegistrationIndex.processGroup(project, actionId, GlobalSearchScope.allScope(project),
                                                                           group -> false);
          if (hasDefinedId) {
            actionGroups.add((ActionGroup)anAction);
          }
        }
      }
    }
    myGroupList.setListData(actionGroups.toArray(new ActionGroup[0]));
    myGroupList.setCellRenderer(new MyActionRenderer());
    myGroupList.addListSelectionListener(new ListSelectionListener() {
      @Override
      public void valueChanged(ListSelectionEvent e) {
        ActionGroup group = myGroupList.getSelectedValue();
        if (group == null) {
          myActionList.setListData(AnAction.EMPTY_ARRAY);
        }
        else {
          AnAction[] actions = group.getChildren(null);
          // filter out actions that don't have IDs - they can't be used for anchoring in plugin.xml
          List<AnAction> realActions = new ArrayList<>();
          for(AnAction action: actions) {
            if (actionManager.getId(action) != null) {
              realActions.add(action);
            }
          }
          myActionList.setListData(realActions.toArray(AnAction.EMPTY_ARRAY));
        }
      }
    });
    new ListSpeedSearch<>(myGroupList, o -> ActionManager.getInstance().getId(o));

    myActionList.setCellRenderer(new MyActionRenderer());
{'fraction_non_alphanumeric': 0.0886650868878357, 'fraction_numerical': 0.002764612954186414, 'mean_word_length': 4.484028153762859, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4439413', 'n_tokens_mistral': 2890, 'n_tokens_neox': 2835, 'n_words': 572}