use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class HgBranchPopup method getInstance.
/**
* @param currentRepository Current repository, which means the repository of the currently open or selected file.
*/
public static HgBranchPopup getInstance(@NotNull Project project, @NotNull HgRepository currentRepository) {
HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
HgProjectSettings hgProjectSettings = ServiceManager.getService(project, HgProjectSettings.class);
HgMultiRootBranchConfig hgMultiRootBranchConfig = new HgMultiRootBranchConfig(manager.getRepositories());
Condition<AnAction> preselectActionCondition = new Condition<AnAction>() {
@Override
public boolean value(AnAction action) {
return false;
}
};
return new HgBranchPopup(currentRepository, manager, hgMultiRootBranchConfig, hgProjectSettings, preselectActionCondition);
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class MavenKeymapExtension method createGroup.
@Override
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(TasksBundle.message("maven.tasks.action.group.name"), MavenIcons.MavenLogo);
if (project == null)
return result;
Comparator<MavenProject> projectComparator = (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
Map<MavenProject, Set<Pair<String, String>>> projectToActionsMapping = new TreeMap<>(projectComparator);
ActionManager actionManager = ActionManager.getInstance();
//noinspection TestOnlyProblems
for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
AnAction eachAction = actionManager.getAction(eachId);
if (!(eachAction instanceof MavenGoalAction))
continue;
if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
continue;
MavenGoalAction mavenAction = (MavenGoalAction) eachAction;
MavenProject mavenProject = mavenAction.getMavenProject();
Set<Pair<String, String>> actions = projectToActionsMapping.get(mavenProject);
if (actions == null) {
final List<String> projectGoals = collectGoals(mavenProject);
actions = new TreeSet<>((o1, o2) -> {
String goal1 = o1.getFirst();
String goal2 = o2.getFirst();
int index1 = projectGoals.indexOf(goal1);
int index2 = projectGoals.indexOf(goal2);
if (index1 == index2)
return goal1.compareToIgnoreCase(goal2);
return (index1 < index2 ? -1 : 1);
});
projectToActionsMapping.put(mavenProject, actions);
}
actions.add(Pair.create(mavenAction.getGoal(), eachId));
}
for (Map.Entry<MavenProject, Set<Pair<String, String>>> each : projectToActionsMapping.entrySet()) {
Set<Pair<String, String>> goalsToActionIds = each.getValue();
for (Pair<String, String> eachGoalToActionId : goalsToActionIds) {
result.addActionId(eachGoalToActionId.getSecond());
}
}
Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
((Group) result).addHyperlink(new Hyperlink(icon, "Choose a phase/goal to assign a shortcut") {
@Override
public void onClick(MouseEvent e) {
SelectMavenGoalDialog dialog = new SelectMavenGoalDialog(project);
if (dialog.showAndGet() && dialog.getResult() != null) {
MavenProjectsStructure.GoalNode goalNode = dialog.getResult();
String goal = goalNode.getGoal();
String actionId = MavenShortcutsManager.getInstance(project).getActionId(goalNode.getProjectPath(), goal);
getOrRegisterAction(goalNode.getMavenProject(), actionId, goal);
ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
if (keymapPanel != null) {
// clear actions filter
keymapPanel.showOption("");
keymapPanel.selectAction(actionId);
}
}
}
});
return result;
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class JavaFxLocationReferenceProvider method collectRefs.
private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
final int atSignIndex = value.indexOf('@');
if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
value = value.substring(atSignIndex + 1);
startInElement += atSignIndex + 1;
}
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = item.getVirtualFile();
if (virtualFile == null)
return false;
final FileType fileType = virtualFile.getFileType();
return myAcceptedFileTypes.contains(fileType);
};
}
};
if (value.startsWith("/")) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return set.getAllReferences();
}
use of com.intellij.openapi.util.Condition in project kotlin by JetBrains.
the class AbstractUnwrapRemoveTest method doTest.
private void doTest(@NotNull String path, final Class<? extends Unwrapper> unwrapperClass) throws Exception {
configureByFile(path);
String fileText = FileUtil.loadFile(new File(path), true);
String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
String option = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// OPTION: ");
Integer optionIndex = option != null ? Integer.parseInt(option) : 0;
List<Pair<PsiElement, Unwrapper>> unwrappersWithPsi = new KotlinUnwrapDescriptor().collectUnwrappers(getProject(), getEditor(), getFile());
if (isApplicableExpected) {
final Pair<PsiElement, Unwrapper> selectedUnwrapperWithPsi = unwrappersWithPsi.get(optionIndex);
assertEquals(unwrapperClass, selectedUnwrapperWithPsi.second.getClass());
final PsiElement first = selectedUnwrapperWithPsi.first;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
selectedUnwrapperWithPsi.second.unwrap(getEditor(), first);
}
});
checkResultByFile(path + ".after");
} else {
assertTrue(ContainerUtil.and(unwrappersWithPsi, new Condition<Pair<PsiElement, Unwrapper>>() {
@Override
public boolean value(Pair<PsiElement, Unwrapper> pair) {
return pair.second.getClass() != unwrapperClass;
}
}));
}
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class TreeFileChooserDialog method filterFiles.
private Object[] filterFiles(final Object[] list) {
Condition<PsiFile> condition = psiFile -> {
if (myFilter != null && !myFilter.accept(psiFile)) {
return false;
}
boolean accepted = myFileType == null || psiFile.getFileType() == myFileType;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null && !accepted) {
accepted = virtualFile.getFileType() == myFileType;
}
return accepted;
};
final List<Object> result = new ArrayList<>(list.length);
for (Object o : list) {
final PsiFile psiFile;
if (o instanceof PsiFile) {
psiFile = (PsiFile) o;
} else if (o instanceof PsiFileNode) {
psiFile = ((PsiFileNode) o).getValue();
} else {
psiFile = null;
}
if (psiFile != null && !condition.value(psiFile)) {
continue;
} else {
if (o instanceof ProjectViewNode) {
final ProjectViewNode projectViewNode = (ProjectViewNode) o;
if (!projectViewNode.canHaveChildrenMatching(condition)) {
continue;
}
}
}
result.add(o);
}
return ArrayUtil.toObjectArray(result);
}
Aggregations