Skip to content

Commit e69ed28

Browse files
ptzieglervogella
authored andcommitted
Implement search-by-category for Import/Export wizard
This adapts the WizardPatternFilter to also show the wizards, if the search string matches one of its containing categories. Amends 532c0fb Fixes #2576
1 parent b97ea88 commit e69ed28

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2015 IBM Corporation and others.
2+
* Copyright (c) 2005, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,8 +15,11 @@
1515
package org.eclipse.ui.internal.dialogs;
1616

1717
import java.util.ArrayList;
18+
import java.util.function.Function;
19+
import java.util.stream.Stream;
1820
import org.eclipse.jface.viewers.Viewer;
1921
import org.eclipse.ui.dialogs.PatternFilter;
22+
import org.eclipse.ui.wizards.IWizardCategory;
2023

2124
/**
2225
* A class that handles filtering wizard node items based on a supplied matching
@@ -39,27 +42,21 @@ public boolean isElementSelectable(Object element) {
3942

4043
@Override
4144
protected boolean isLeafMatch(Viewer viewer, Object element) {
42-
if (element instanceof WizardCollectionElement) {
43-
return false;
44-
}
45-
46-
if (element instanceof WorkbenchWizardElement) {
47-
WorkbenchWizardElement desc = (WorkbenchWizardElement) element;
48-
String text = desc.getLabel();
49-
if (wordMatches(text)) {
50-
return true;
51-
}
52-
String wizDesc = desc.getDescription();
53-
if (wordMatches(wizDesc)) {
54-
return true;
55-
}
45+
return element instanceof WorkbenchWizardElement desc &&
46+
Stream.of(getWizardCategories(desc.getCategory()), //
47+
Stream.of(desc.getLabel(), desc.getDescription()), //
48+
Stream.of(desc.getKeywordLabels())) //
49+
// Only works for finite streams
50+
.flatMap(Function.identity())
51+
.anyMatch(this::wordMatches);
52+
}
5653

57-
for (String keywordLabel : desc.getKeywordLabels()) {
58-
if (wordMatches(keywordLabel))
59-
return true;
60-
}
54+
private Stream<String> getWizardCategories(IWizardCategory category) {
55+
if (category == null) {
56+
return Stream.empty();
6157
}
62-
return false;
58+
return Stream.iterate(category, current -> current.getParent() != null, IWizardCategory::getParent)
59+
.map(IWizardCategory::getLabel);
6360
}
6461

6562
@Override

0 commit comments

Comments
 (0)