Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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", true); //$NON-NLS-1$
}
/**
* The string matcher has been modified. The default implementation
* refreshes the view and selects the first matched element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -112,6 +116,7 @@ protected void createSettings(Composite composite) {
createStickyCyclePref(composite);
createHeapStatusPref(composite);
createLargeViewLimitPref(composite);
createAutocompletePref(composite);
}

/**
Expand Down Expand Up @@ -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, true);
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading