|
32 | 32 |
|
33 | 33 | import org.eclipse.core.resources.IProject; |
34 | 34 | import org.eclipse.core.resources.IResource; |
| 35 | + |
35 | 36 | import org.eclipse.jface.viewers.AbstractTreeViewer; |
36 | 37 | import org.eclipse.jface.viewers.ITreeContentProvider; |
37 | 38 | import org.eclipse.jface.viewers.Viewer; |
| 39 | + |
38 | 40 | import org.eclipse.search.ui.text.AbstractTextSearchResult; |
39 | 41 | import org.eclipse.search.ui.text.Match; |
40 | 42 | import org.eclipse.search.ui.text.MatchFilter; |
@@ -170,17 +172,27 @@ private boolean hasMatches(Object element) { |
170 | 172 | if (element instanceof LineElement) { |
171 | 173 | LineElement lineElement= (LineElement) element; |
172 | 174 | IResource resource = lineElement.getParent(); |
173 | | - if (getMatchCount(resource) > 0) { |
| 175 | + if (hasMatches(resource)) { |
174 | 176 | return lineElement.hasMatches(fResult); |
175 | 177 | } |
176 | 178 | } |
177 | 179 | return fPage.getDisplayedMatchCount(element) > 0; |
178 | 180 | } |
179 | 181 |
|
| 182 | + private boolean hasMatches(IResource element) { |
| 183 | + if (hasActiveMatchFilters()) { |
| 184 | + return fPage.getDisplayedMatchCount(element) > 0; |
| 185 | + } else { |
| 186 | + return fResult.hasMatches(); |
| 187 | + } |
| 188 | + } |
| 189 | + |
180 | 190 | private int getMatchCount(Object element) { |
181 | | - return fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0 |
182 | | - ? fPage.getDisplayedMatchCount(element) |
183 | | - : fResult.getMatchCount(); |
| 191 | + if (hasActiveMatchFilters()) { |
| 192 | + return fPage.getDisplayedMatchCount(element); |
| 193 | + } else { |
| 194 | + return fResult.getMatchCount(); |
| 195 | + } |
184 | 196 | } |
185 | 197 |
|
186 | 198 | private void removeFromSiblings(Object element, Object parent) { |
@@ -208,7 +220,11 @@ public Object[] getChildren(Object parentElement) { |
208 | 220 |
|
209 | 221 | @Override |
210 | 222 | public boolean hasChildren(Object element) { |
211 | | - return getChildren(element).length > 0; |
| 223 | + Set<Object> children = fChildrenMap.get(element); |
| 224 | + if (children == null) { |
| 225 | + return false; |
| 226 | + } |
| 227 | + return !children.isEmpty(); |
212 | 228 | } |
213 | 229 |
|
214 | 230 | static <T> Stream<T> toStream(Enumeration<T> e) { |
@@ -244,7 +260,7 @@ public synchronized void elementsChanged(Object[] updatedElements) { |
244 | 260 | Set<LineElement> lineMatches = Collections.emptySet(); |
245 | 261 | // if we have active match filters, we should only use non-filtered FileMatch |
246 | 262 | // objects to collect LineElements to update |
247 | | - if (fResult.getActiveMatchFilters() != null && fResult.getActiveMatchFilters().length > 0) { |
| 263 | + if (hasActiveMatchFilters()) { |
248 | 264 | lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance) |
249 | 265 | // only for distinct files: |
250 | 266 | .map(u -> ((LineElement) u).getParent()).distinct() |
@@ -293,6 +309,11 @@ public synchronized void elementsChanged(Object[] updatedElements) { |
293 | 309 | } |
294 | 310 | } |
295 | 311 |
|
| 312 | + private boolean hasActiveMatchFilters() { |
| 313 | + MatchFilter[] activeMatchFilters = fResult.getActiveMatchFilters(); |
| 314 | + return activeMatchFilters != null && activeMatchFilters.length > 0; |
| 315 | + } |
| 316 | + |
296 | 317 | @Override |
297 | 318 | public void clear() { |
298 | 319 | initialize(fResult); |
|
0 commit comments