From 3f43f4638e04efb72d15ef0193e80e57da268b54 Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Fri, 26 Sep 2025 00:06:43 +0530 Subject: [PATCH] optional autocomplete support in chevron pop up Add Autocomplete support in chevron popup with preference toggle in the eclipse Settings->Preference->General page Introduced a new autocomplete behavior for the chevron popup filter text. As the user types, matching editor names are suggested and the remaining part is auto-filled, improving navigation efficiency within the chevron pop up. This is an enhancement done for filtertext and users can enable or disable the autocomplete option based on their preference. This behaviour is controlled through a new preference flag `ENABLE_AUTOCOMPLETE_IN_CHEVRON` stored under `org.eclipse.ui.workbench`. Users can enable or disable the feature in the Workbench Preferences. When disabled, the chevron fitering falls back to the standard filtering behavior. Key changes: - Added `chevronAutocompleteBehavior()` to implement auto completion with suggestion. - Retained existing `normalFilterBehavior()` for plain text filtering incase the user wanted to disable the auto complete feature. - Updated `installFilter()` to switch between behaviors based on user preference - Added `isAutocompleteEnabled()` method to check the preference state --- .../swt/AbstractTableInformationControl.java | 59 ++++++++++++++++++- .../ui/internal/WorkbenchMessages.java | 7 ++- .../dialogs/WorkbenchPreferencePage.java | 26 +++++++- .../eclipse/ui/internal/messages.properties | 3 + 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java index f4333185d8f..fc18d7bde42 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2018 IBM Corporation and others. + * Copyright (c) 2003, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.internal.workbench.renderers.swt; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.ui.workbench.swt.internal.copy.SearchPattern; import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages; import org.eclipse.jface.preference.JFacePreferences; @@ -25,6 +27,8 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; @@ -312,6 +316,19 @@ public TableViewer getTableViewer() { return fTableViewer; } + private String suggestCompletionFromTable(String Text) { + if (Text == null || Text.isEmpty()) { + return null; + } + for (TableItem item : fTableViewer.getTable().getItems()) { + String textTable = item.getText(); + if (textTable.toLowerCase().startsWith(Text.toLowerCase())) { + return textTable; + } + } + return null; + } + protected Text createFilterText(Composite parent) { fFilterText = new Text(parent, SWT.NONE); @@ -371,16 +388,54 @@ private void setInfoSystemColor() { setBackgroundColor(background); } - private void installFilter() { + private void chevronAutocompleteBehavior() { fFilterText.setMessage(WorkbenchSWTMessages.FilteredTree_FilterMessage); fFilterText.setText(""); //$NON-NLS-1$ + setMatcherString(""); //$NON-NLS-1$ + fTableViewer.refresh(); + + fFilterText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + int cursor = fFilterText.getSelection().x; + String input = fFilterText.getText().substring(0, cursor); + setMatcherString(input); + fTableViewer.refresh(); + + if (e.keyCode == SWT.BS || e.keyCode == SWT.DEL || !Character.isLetterOrDigit(e.character)) + return; + + String suggestion = suggestCompletionFromTable(input); + if (suggestion != null && suggestion.length() > input.length()) { + fFilterText.setText(suggestion); + fFilterText.setSelection(input.length(), suggestion.length()); + } + } + }); + } + private void normalFilterBehavior() { + fFilterText.setMessage(WorkbenchSWTMessages.FilteredTree_FilterMessage); + fFilterText.setText(""); //$NON-NLS-1$ fFilterText.addModifyListener(e -> { String text = ((Text) e.widget).getText(); setMatcherString(text); + fTableViewer.refresh(); }); } + private void installFilter() { + if (isAutocompleteEnabled()) { + chevronAutocompleteBehavior(); + } else { + normalFilterBehavior(); + } + } + + private boolean isAutocompleteEnabled() { + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.ui.workbench"); //$NON-NLS-1$ + return prefs.getBoolean("ENABLE_AUTOCOMPLETE_IN_CHEVRON", false); //$NON-NLS-1$ + } /** * The string matcher has been modified. The default implementation * refreshes the view and selects the first matched element diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java index 4592061f679..fc4e40b7289 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2020 IBM Corporation and others. + * Copyright (c) 2005, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -453,6 +453,11 @@ public class WorkbenchMessages extends NLS { public static String PreferenceExportWarning_continue; public static String PreferenceExportWarning_applyAndContinue; + public static String Preference_Enable_Autocomplete_ChevronPopUp; + public static String Preference_Autocomplete; + + public static String Preference_Enable_Autocomplete_ChevronPopUp_ToolTip; + // --- Workbench --- public static String WorkbenchPreference_allowInplaceEditingButton; public static String WorkbenchPreference_useIPersistableEditorButton; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java index 1c6cd5b371c..0de53031fe1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2020 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,6 +18,8 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.jface.preference.FieldEditor; @@ -80,6 +82,8 @@ public class WorkbenchPreferencePage extends PreferencePage implements IWorkbenc private Button showInlineRenameButton; + private Button enableAutocompleteButton; + protected static int MAX_SAVE_INTERVAL = 9999; protected static int MAX_VIEW_LIMIT = 1_000_000; @@ -112,6 +116,7 @@ protected void createSettings(Composite composite) { createStickyCyclePref(composite); createHeapStatusPref(composite); createLargeViewLimitPref(composite); + createAutocompletePref(composite); } /** @@ -388,6 +393,25 @@ protected IPreferenceStore doGetPreferenceStore() { return WorkbenchPlugin.getDefault().getPreferenceStore(); } + protected void createAutocompletePref(Composite parent) { + enableAutocompleteButton = new Button(parent, SWT.CHECK); + enableAutocompleteButton.setText(WorkbenchMessages.Preference_Enable_Autocomplete_ChevronPopUp); + enableAutocompleteButton.setToolTipText(WorkbenchMessages.Preference_Enable_Autocomplete_ChevronPopUp_ToolTip); + + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.ui.workbench"); //$NON-NLS-1$ + boolean enabled = prefs.getBoolean(WorkbenchMessages.Preference_Autocomplete, false); + enableAutocompleteButton.setSelection(enabled); + + enableAutocompleteButton.addListener(SWT.Selection, e -> { + prefs.putBoolean(WorkbenchMessages.Preference_Autocomplete, enableAutocompleteButton.getSelection()); + try { + prefs.flush(); + } catch (Exception ex) { + ex.printStackTrace(); + } + }); + } + /** * @see IWorkbenchPreferencePage */ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties index 3cb4caeadc2..bfe52913ebb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties @@ -409,6 +409,9 @@ PreferenceExportWarning_title = Possible Unapplied Changes PreferenceExportWarning_message = If you changed preferences and want to export them, ensure you click 'Apply and Continue' before the export. PreferenceExportWarning_continue = &Continue PreferenceExportWarning_applyAndContinue = &Apply and Continue +Preference_Enable_Autocomplete_ChevronPopUp = Enable autocomplete option in chevron popup +Preference_Enable_Autocomplete_ChevronPopUp_ToolTip = Enable autocomplete option to complete text as you type in the chevron popup +Preference_Autocomplete=ENABLE_AUTOCOMPLETE_IN_CHEVRON # --- Workbench --- WorkbenchPreference_allowInplaceEditingButton = Allow in-place &system editors