Add support for 'Favourites' to Spring Symbols View
... the list of favourites is still hard-coded.
This commit is contained in:
@@ -29,10 +29,10 @@ import org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin;
|
||||
import org.springsource.ide.eclipse.commons.core.util.FuzzyMatcher;
|
||||
import org.springsource.ide.eclipse.commons.core.util.StringUtil;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression.AsyncMode;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.HighlightedText;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.ObservableSet;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.HighlightedText;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -40,7 +40,22 @@ import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class GotoSymbolDialogModel {
|
||||
|
||||
|
||||
public static class Favourite {
|
||||
public final String name; //Descriptive name
|
||||
public final String query; //The 'search string' it corresponds to
|
||||
public Favourite(String name, String query) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return query + " ("+name+")";
|
||||
}
|
||||
}
|
||||
|
||||
public static class Match<T> {
|
||||
final double score;
|
||||
final String query;
|
||||
@@ -181,6 +196,8 @@ public class GotoSymbolDialogModel {
|
||||
private String keyBindings;
|
||||
private OKHandler okHandler = DEFAULT_OK_HANDLER;
|
||||
|
||||
private Favourite[] favourites = null;
|
||||
|
||||
public GotoSymbolDialogModel(String keyBindings, SymbolsProvider... symbolsProviders) {
|
||||
this.keyBindings = keyBindings;
|
||||
Assert.isLegal(symbolsProviders.length>0);
|
||||
@@ -195,6 +212,15 @@ public class GotoSymbolDialogModel {
|
||||
filteredSymbols.addListener((e, v) -> debug("filtered = "+summary(filteredSymbols.getValue())));
|
||||
}
|
||||
}
|
||||
|
||||
public GotoSymbolDialogModel setFavourites(Favourite... favourites) {
|
||||
this.favourites = favourites;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Favourite[] getFavourites() {
|
||||
return favourites;
|
||||
}
|
||||
|
||||
private List<String> summary(Collection<Match<Either<SymbolInformation, DocumentSymbol>>> collection) {
|
||||
return collection.stream().map(match -> match.value.isLeft() ? match.value.getLeft().getName() : match.value.getRight().getName()).collect(Collectors.toList());
|
||||
@@ -248,6 +274,4 @@ public class GotoSymbolDialogModel {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,16 +44,26 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.KeyAdapter;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialogModel.Favourite;
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialogModel.Match;
|
||||
import org.springsource.ide.eclipse.commons.core.util.FuzzyMatcher;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.UIValueListener;
|
||||
import org.springsource.ide.eclipse.commons.livexp.ui.Disposable;
|
||||
import org.springsource.ide.eclipse.commons.livexp.ui.IPageWithSections;
|
||||
@@ -208,8 +218,19 @@ public class GotoSymbolSection extends WizardPageSection {
|
||||
}
|
||||
});
|
||||
|
||||
//Favourites pulldown
|
||||
Composite sbComposite = dialogArea;
|
||||
if (model.getFavourites()!=null) {
|
||||
sbComposite = new Composite(dialogArea, SWT.NONE);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
layout.marginWidth = 0; layout.marginHeight = 0;
|
||||
sbComposite.setLayout(layout);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(sbComposite);
|
||||
createFavouritesPulldown(sbComposite, model.getFavourites(), model.getSearchBox());
|
||||
}
|
||||
|
||||
//Search box:
|
||||
Text pattern = new Text(dialogArea, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
|
||||
Text pattern = new Text(sbComposite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
|
||||
// pattern.getAccessible().addAccessibleListener(new AccessibleAdapter() {
|
||||
// public void getName(AccessibleEvent e) {
|
||||
// e.result = LegacyActionTools.removeMnemonics(headerLabel)
|
||||
@@ -274,6 +295,31 @@ public class GotoSymbolSection extends WizardPageSection {
|
||||
viewer.setInput(model);
|
||||
}
|
||||
|
||||
private void createFavouritesPulldown(Composite parent, Favourite[] favourites, LiveVariable<String> searchBox) {
|
||||
Button btn = new Button(parent, SWT.ARROW | SWT.DOWN);
|
||||
btn.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
super.widgetSelected(e);
|
||||
Menu menu = new Menu(btn);
|
||||
for (Favourite f : favourites) {
|
||||
MenuItem item = new MenuItem(menu, SWT.PUSH);
|
||||
item.setText(f.toString());
|
||||
item.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
searchBox.setValue(f.query);
|
||||
}
|
||||
});
|
||||
}
|
||||
Point loc = btn.getLocation();
|
||||
Rectangle rect = btn.getBounds();
|
||||
Point mLoc = new Point(loc.x-1, loc.y+rect.height);
|
||||
menu.setLocation(btn.getDisplay().map(btn.getParent(), null, mLoc));
|
||||
menu.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void installWidgetListeners(Text pattern, TreeViewer list) {
|
||||
pattern.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
@@ -16,21 +16,25 @@ import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialo
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.InFileSymbolsProvider;
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.InProjectSymbolsProvider;
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.InWorkspaceSymbolsProvider;
|
||||
import org.springframework.tooling.ls.eclipse.gotosymbol.dialogs.GotoSymbolDialogModel.Favourite;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
|
||||
|
||||
public class SpringSymbolsViewModel {
|
||||
|
||||
|
||||
public final LiveVariable<IResource> currentResource = new LiveVariable<>();
|
||||
public final LiveExpression<IProject> currentProject = currentResource.apply(r -> r==null ? null : r.getProject());
|
||||
public final GotoSymbolDialogModel gotoSymbols = new GotoSymbolDialogModel(null,
|
||||
InWorkspaceSymbolsProvider.createFor(currentProject::getValue),
|
||||
InProjectSymbolsProvider.createFor(currentProject),
|
||||
InFileSymbolsProvider.createFor(currentResource)
|
||||
)
|
||||
.setFavourites(
|
||||
new Favourite("Request Mappings", "@/"),
|
||||
new Favourite("Beans", "@+"),
|
||||
new Favourite("All Spring Elements", "@")
|
||||
);
|
||||
|
||||
{
|
||||
{
|
||||
gotoSymbols.unfilteredSymbols.dependsOn(currentProject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user