From 4716ed273e93acc9db109bbd8899c01640d6c447 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Fri, 17 Jun 2022 17:14:17 +0200 Subject: [PATCH] Avoid duplicate quick access entry (fixes #152) When you have used quick access previously, the dialog adds matching entries from "previous" at the top. Afterwards the same entries may appear from their "normal" provider (e.q. views, commands, ...). Since the logic of adding entries seems quite complex, this change fixes the duplicate entry by detecting the exact situation (same single entry in first and second provider list), and then removes the duplicate entry list. --- .../quickaccess/QuickAccessContents.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java index f9f72e807b7..ee2fdc14dd9 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java @@ -281,6 +281,16 @@ private void refreshTable(QuickAccessElement perfectMatch, List entries.length && table.getItemCount() - entries.length > 20) { table.removeAll(); } + int count = 0; + for (List list : entries) { + System.out.println("---"); //$NON-NLS-1$ + for (QuickAccessEntry entry : list) { + System.out.println(entry.getLabel()); + } + if (count++ >= 2) { + break; + } + } TableItem[] items = table.getItems(); int selectionIndex = -1; int index = 0; @@ -530,6 +540,14 @@ public IStatus runInUIThread(IProgressMonitor monitor) { QuickAccessEntry.MATCH_PERFECT))); } res.addAll(entriesPerProvider.values()); + + // if one category provides the same single entry like "previous", we can avoid + // showing the duplicate second list + if (res.size() >= 2 && res.get(0).size() == 1 && res.get(1).size() == 1 + && (res.get(0).get(0).element.equals(res.get(1).get(0).element))) { + res.remove(1); + } + return (List[]) res.toArray(new List[res.size()]); }