Skip to content

Commit b49086d

Browse files
committed
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
1 parent b431a28 commit b49086d

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.e4.ui.internal.workbench.renderers.swt;
1515

16+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17+
import org.eclipse.core.runtime.preferences.InstanceScope;
1618
import org.eclipse.e4.ui.workbench.swt.internal.copy.SearchPattern;
1719
import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages;
1820
import org.eclipse.jface.preference.JFacePreferences;
@@ -25,6 +27,8 @@
2527
import org.eclipse.jface.viewers.Viewer;
2628
import org.eclipse.jface.viewers.ViewerFilter;
2729
import org.eclipse.swt.SWT;
30+
import org.eclipse.swt.events.KeyAdapter;
31+
import org.eclipse.swt.events.KeyEvent;
2832
import org.eclipse.swt.events.KeyListener;
2933
import org.eclipse.swt.events.MouseEvent;
3034
import org.eclipse.swt.events.MouseListener;
@@ -312,6 +316,19 @@ public TableViewer getTableViewer() {
312316
return fTableViewer;
313317
}
314318

319+
private String suggestCompletionFromTable(String Text) {
320+
if (Text == null || Text.isEmpty()) {
321+
return null;
322+
}
323+
for (TableItem item : fTableViewer.getTable().getItems()) {
324+
String textTable = item.getText();
325+
if (textTable.toLowerCase().startsWith(Text.toLowerCase())) {
326+
return textTable;
327+
}
328+
}
329+
return null;
330+
}
331+
315332
protected Text createFilterText(Composite parent) {
316333
fFilterText = new Text(parent, SWT.NONE);
317334

@@ -371,16 +388,54 @@ private void setInfoSystemColor() {
371388
setBackgroundColor(background);
372389
}
373390

374-
private void installFilter() {
391+
private void chevronAutocompleteBehavior() {
375392
fFilterText.setMessage(WorkbenchSWTMessages.FilteredTree_FilterMessage);
376393
fFilterText.setText(""); //$NON-NLS-1$
394+
setMatcherString(""); //$NON-NLS-1$
395+
fTableViewer.refresh();
396+
397+
fFilterText.addKeyListener(new KeyAdapter() {
398+
@Override
399+
public void keyReleased(KeyEvent e) {
400+
int cursor = fFilterText.getSelection().x;
401+
String input = fFilterText.getText().substring(0, cursor);
402+
setMatcherString(input);
403+
fTableViewer.refresh();
404+
405+
if (e.keyCode == SWT.BS || e.keyCode == SWT.DEL || !Character.isLetterOrDigit(e.character))
406+
return;
407+
408+
String suggestion = suggestCompletionFromTable(input);
409+
if (suggestion != null && suggestion.length() > input.length()) {
410+
fFilterText.setText(suggestion);
411+
fFilterText.setSelection(input.length(), suggestion.length());
412+
}
413+
}
414+
});
415+
}
377416

417+
private void normalFilterBehavior() {
418+
fFilterText.setMessage(WorkbenchSWTMessages.FilteredTree_FilterMessage);
419+
fFilterText.setText(""); //$NON-NLS-1$
378420
fFilterText.addModifyListener(e -> {
379421
String text = ((Text) e.widget).getText();
380422
setMatcherString(text);
423+
fTableViewer.refresh();
381424
});
382425
}
383426

427+
private void installFilter() {
428+
if (isAutocompleteEnabled()) {
429+
chevronAutocompleteBehavior();
430+
} else {
431+
normalFilterBehavior();
432+
}
433+
}
434+
435+
private boolean isAutocompleteEnabled() {
436+
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.ui.workbench"); //$NON-NLS-1$
437+
return prefs.getBoolean("ENABLE_AUTOCOMPLETE_IN_CHEVRON", true); //$NON-NLS-1$
438+
}
384439
/**
385440
* The string matcher has been modified. The default implementation
386441
* refreshes the view and selects the first matched element

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ public class WorkbenchMessages extends NLS {
455455
public static String PreferenceExportWarning_continue;
456456
public static String PreferenceExportWarning_applyAndContinue;
457457

458+
public static String Preference_Enable_Autocomplete_ChevronPopUp;
459+
public static String Preference_Autocomplete;
460+
461+
public static String Preference_Enable_Autocomplete_ChevronPopUp_ToolTip;
462+
458463
// --- Workbench ---
459464
public static String WorkbenchPreference_allowInplaceEditingButton;
460465
public static String WorkbenchPreference_useIPersistableEditorButton;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
2020

21+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
22+
import org.eclipse.core.runtime.preferences.InstanceScope;
2123
import org.eclipse.jface.dialogs.IDialogConstants;
2224
import org.eclipse.jface.layout.LayoutConstants;
2325
import org.eclipse.jface.preference.FieldEditor;
@@ -80,6 +82,8 @@ public class WorkbenchPreferencePage extends PreferencePage implements IWorkbenc
8082

8183
private Button showInlineRenameButton;
8284

85+
private Button enableAutocompleteButton;
86+
8387
protected static int MAX_SAVE_INTERVAL = 9999;
8488
protected static int MAX_VIEW_LIMIT = 1_000_000;
8589

@@ -112,6 +116,7 @@ protected void createSettings(Composite composite) {
112116
createStickyCyclePref(composite);
113117
createHeapStatusPref(composite);
114118
createLargeViewLimitPref(composite);
119+
createAutocompletePref(composite);
115120
}
116121

117122
/**
@@ -388,6 +393,25 @@ protected IPreferenceStore doGetPreferenceStore() {
388393
return WorkbenchPlugin.getDefault().getPreferenceStore();
389394
}
390395

396+
protected void createAutocompletePref(Composite parent) {
397+
enableAutocompleteButton = new Button(parent, SWT.CHECK);
398+
enableAutocompleteButton.setText(WorkbenchMessages.Preference_Enable_Autocomplete_ChevronPopUp);
399+
enableAutocompleteButton.setToolTipText(WorkbenchMessages.Preference_Enable_Autocomplete_ChevronPopUp_ToolTip);
400+
401+
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.ui.workbench"); //$NON-NLS-1$
402+
boolean enabled = prefs.getBoolean(WorkbenchMessages.Preference_Autocomplete, true);
403+
enableAutocompleteButton.setSelection(enabled);
404+
405+
enableAutocompleteButton.addListener(SWT.Selection, e -> {
406+
prefs.putBoolean(WorkbenchMessages.Preference_Autocomplete, enableAutocompleteButton.getSelection());
407+
try {
408+
prefs.flush();
409+
} catch (Exception ex) {
410+
ex.printStackTrace();
411+
}
412+
});
413+
}
414+
391415
/**
392416
* @see IWorkbenchPreferencePage
393417
*/

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ PreferenceExportWarning_title = Possible Unapplied Changes
409409
PreferenceExportWarning_message = If you changed preferences and want to export them, ensure you click 'Apply and Continue' before the export.
410410
PreferenceExportWarning_continue = &Continue
411411
PreferenceExportWarning_applyAndContinue = &Apply and Continue
412+
Preference_Enable_Autocomplete_ChevronPopUp = Enable autocomplete option in chevron popup
413+
Preference_Enable_Autocomplete_ChevronPopUp_ToolTip = Enable autocomplete option to complete text as you type in the chevron popup
414+
Preference_Autocomplete=ENABLE_AUTOCOMPLETE_IN_CHEVRON
412415

413416
# --- Workbench ---
414417
WorkbenchPreference_allowInplaceEditingButton = Allow in-place &system editors

0 commit comments

Comments
 (0)