From 05fe3272a3b5dca51657ba164f47d174522c42bd Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Tue, 9 Jun 2020 11:51:43 -0700 Subject: [PATCH] Add support for 'Favourites' to Spring Symbols View ... the list of favourites is still hard-coded. --- .../dialogs/GotoSymbolDialogModel.java | 32 +++++++++++-- .../gotosymbol/dialogs/GotoSymbolSection.java | 48 ++++++++++++++++++- .../view/SpringSymbolsViewModel.java | 12 +++-- 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java index 18293f30b..a3588d2c9 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolDialogModel.java @@ -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 { 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 summary(Collection>> 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; } - - } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java index f18dfb04a..bbafd0a68 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/GotoSymbolSection.java @@ -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 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) { diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/view/SpringSymbolsViewModel.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/view/SpringSymbolsViewModel.java index 8afe284cf..08f5bec84 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/view/SpringSymbolsViewModel.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/view/SpringSymbolsViewModel.java @@ -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 currentResource = new LiveVariable<>(); public final LiveExpression 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); } - }