From 360601f01384f81229c4a583e49eeadcff29b0aa 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 | 57 ++++++++++++++++++- .../ui/internal/WorkbenchMessages.java | 5 ++ .../dialogs/WorkbenchPreferencePage.java | 24 ++++++++ .../eclipse/ui/internal/messages.properties | 3 + 4 files changed, 88 insertions(+), 1 deletion(-) 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..abd44286f94 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 @@ -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 7f1f1435b4f..9ad38ed7f50 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 @@ -455,6 +455,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..3f1aeb856a2 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 @@ -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 aa3e02edf00..e34a58e3a9b 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