Skip to content

Commit

Permalink
Drop Down menu in Quick Search implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisCode committed Nov 28, 2024
1 parent 570c48c commit 26d4c40
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -87,6 +88,8 @@ public class DialogSettings implements IDialogSettings {

// A Map with all the keys mapped to array of strings.
private Map<String, String[]> arrayItems;
private LinkedList<String> lastFiveSearches;
private static final int SEARCHES_DISPLAYED = 5;

private static final String TAG_SECTION = "section";//$NON-NLS-1$

Expand All @@ -113,6 +116,7 @@ public DialogSettings(String sectionName) {
items = new LinkedHashMap<>();
arrayItems = new LinkedHashMap<>();
sections = new LinkedHashMap<>();
lastFiveSearches = new LinkedList<>();
}

@Override
Expand Down Expand Up @@ -364,6 +368,30 @@ public void put(String key, String value) {
}
}

public void inputNewSearchFilter(String SearchIn) {
lastFiveSearches.addFirst(SearchIn);

int index = -1;
for (int i = 1; i < lastFiveSearches.size(); i++) {
if (lastFiveSearches.get(i).equals(SearchIn)) {
index = i;
}
}
if (index != -1)
lastFiveSearches.remove(index);

if (lastFiveSearches.size() > SEARCHES_DISPLAYED) {
lastFiveSearches.removeLast();
}
}

public LinkedList<String> getLastFilters() {
if (lastFiveSearches.isEmpty()) {
return null;
}
return lastFiveSearches;
}

@Override
public void put(String key, boolean value) {
put(key, String.valueOf(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import static org.eclipse.jface.resource.JFaceResources.TEXT_FONT;

import java.awt.event.ItemEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -41,6 +42,7 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.LegacyActionTools;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.layout.GridDataFactory;
Expand Down Expand Up @@ -83,6 +85,7 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -369,7 +372,7 @@ public void update(ViewerCell cell) {
private Label headerLabel;

private IWorkbenchWindow window;
private Text searchIn;
private Combo searchIn;
private Label listLabel;

/**
Expand Down Expand Up @@ -409,16 +412,21 @@ public void create() {
*/
protected void restoreDialog(IDialogSettings settings) {
try {
if (initialPatternText==null) {
String lastSearch = settings.get(DIALOG_LAST_QUERY);
DialogSettings dialogSettings = (DialogSettings) settings;

if (initialPatternText==null && dialogSettings.getLastFilters() != null) {
String lastSearch = dialogSettings.getLastFilters().getFirst();

if (lastSearch==null) {
lastSearch = EMPTY_STRING;
}
pattern.setText(lastSearch);
pattern.selectAll();
}
if (settings.get(DIALOG_PATH_FILTER)!=null) {
String filter = settings.get(DIALOG_PATH_FILTER);
if (dialogSettings.getLastFilters() != null) {
String filter = dialogSettings.getLastFilters().getFirst();

searchIn.setItems(searchInStrings(dialogSettings.getLastFilters()));
searchIn.setText(filter);
}

Expand Down Expand Up @@ -452,6 +460,14 @@ protected void restoreDialog(IDialogSettings settings) {
}
}

private String[] searchInStrings (List<String> list) {
String[] strings = new String[list.size()];
for(int i = 0; i < list.size(); i++) {
strings[i] = list.get(i);
}
return strings;
}

private class ToggleKeepOpenAction extends Action {
public ToggleKeepOpenAction(IDialogSettings settings) {
super(
Expand Down Expand Up @@ -531,9 +547,10 @@ public boolean close() {
* settings used to store dialog
*/
protected void storeDialog(IDialogSettings settings) {
String currentSearch = pattern.getText();
settings.put(DIALOG_LAST_QUERY, currentSearch);
settings.put(DIALOG_PATH_FILTER, searchIn.getText());
DialogSettings dialogSettings = (DialogSettings) settings;
dialogSettings.inputNewSearchFilter(searchIn.getText());
settings.put(DIALOG_LAST_QUERY, pattern.getText());

if (toggleCaseSensitiveAction!=null) {
settings.put(CASE_SENSITIVE, toggleCaseSensitiveAction.isChecked());
}
Expand Down Expand Up @@ -755,7 +772,7 @@ public void getName(AccessibleEvent e) {
Label searchInLabel = new Label(searchInComposite, SWT.NONE);
searchInLabel.setText(Messages.QuickSearchDialog_In);
GridDataFactory.swtDefaults().indent(5, 0).applyTo(searchInLabel);
searchIn = new Text(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
searchIn = new Combo(searchInComposite, SWT.SINGLE | SWT.BORDER | SWT.ICON_CANCEL);
searchIn.setToolTipText(Messages.QuickSearchDialog_InTooltip);
GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(searchIn);

Expand Down

0 comments on commit 26d4c40

Please sign in to comment.