From fa7a104900d27a9aecd74f6cc0f143a696bb967f Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 9 Oct 2025 08:29:45 +0200 Subject: [PATCH 1/2] Improve goto search functionality - make exact search mode follow the case sensitivity settings - add missing exact search instructions to file search label (other windows had those) - file search: selection should stick to first item until user changes selection. Async search could otherwise insert better matches above the selected item - disable "prefer opened projects" by default - CI: enabled tests - other minor improvements the "prefer opened projects" setting can lead to confusing results when good matches are displayed far away from the first (worse) match, potentially outside of the visible viewport. The implementation itself works correctly but it might be better to change it into a filter instead of model comparator in future and consolidate the UI/settings of the 3 search dialogs. --- .github/workflows/main.yml | 3 ++ ide/jumpto/nbproject/project.properties | 6 ++-- .../modules/jumpto/EntityComparator.java | 15 +++++---- .../jumpto/common/AbstractModelFilter.java | 3 +- .../netbeans/modules/jumpto/common/Utils.java | 3 +- .../modules/jumpto/file/Bundle.properties | 2 +- .../modules/jumpto/file/FileComarator.java | 15 ++++----- .../modules/jumpto/file/FileSearchAction.java | 28 ++++++++-------- .../modules/jumpto/file/FileSearchPanel.java | 1 + .../netbeans/modules/jumpto/file/Worker.java | 2 +- .../jumpto/quicksearch/GoToTypeWorker.java | 6 +--- .../modules/jumpto/settings/GoToSettings.java | 2 +- .../jumpto/symbol/SymbolComparator.java | 12 +++---- .../modules/jumpto/type/GoToTypeAction.java | 11 +++---- .../modules/jumpto/type/TypeComparator.java | 13 +++----- .../jumpto/support/NameMatcherFactory.java | 33 ++++++++----------- .../client/bindings/BaseSymbolProvider.java | 5 ++- 17 files changed, 72 insertions(+), 88 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f96386a4d702..f3a3d1c1ef42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -674,6 +674,9 @@ jobs: - name: ide/javascript2.debug run: ant $OPTS -f ide/javascript2.debug test + - name: ide/jumpto + run: ant $OPTS -f ide/jumpto test + - name: ide/languages.hcl run: ant $OPTS -f ide/languages.hcl test diff --git a/ide/jumpto/nbproject/project.properties b/ide/jumpto/nbproject/project.properties index 70d629c4c38b..45408a5da5d8 100644 --- a/ide/jumpto/nbproject/project.properties +++ b/ide/jumpto/nbproject/project.properties @@ -16,12 +16,12 @@ # under the License. javac.compilerargs=-Xlint:unchecked -javac.source=1.8 +javac.release=17 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml nbm.module.author=Andrei Badea, Petr Hrebejk spec.version.base=1.85.0 -test.config.stableBTD.includes=**/*Test.class -test.config.stableBTD.excludes=\ +test.config.default.includes=**/*Test.class +test.config.default.excludes=\ **/GoToTypeActionTest.class diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/EntityComparator.java b/ide/jumpto/src/org/netbeans/modules/jumpto/EntityComparator.java index 55cc9e766636..fed618f91315 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/EntityComparator.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/EntityComparator.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.List; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; @@ -43,7 +44,7 @@ public abstract class EntityComparator implements Comparator { Collection namesOfOpenProjects = getNamesOfOpenProjects(); /** - * Comparies its two strings for order. + * Compares its two strings for order. * @param s1 the first {@code String} to be compared (may be {@code null}). * @param s2 the second {@code String} to be compared (may be {@code null}). * @return the value 0 if the argument string is equal to @@ -65,8 +66,8 @@ protected int compare(String s1, String s2, boolean caseSensitive) { } /** - * Comparies its two project names for order. - * It establishes the folowing relation between projects: + * Compares its two project names for order. + * It establishes the following relation between projects: *
      * Main Project < Open Project < Not Open Project
      * 
@@ -168,10 +169,10 @@ public static String getMainProjectName() { * @return a collection of the names. */ private static Collection getNamesOfOpenProjects() { - ArrayList names = new ArrayList(10); - for(Project p: OpenProjects.getDefault().getOpenProjects()) { - String pName = ProjectUtils.getInformation(p).getDisplayName(); - names.add(pName); + Project[] projects = OpenProjects.getDefault().getOpenProjects(); + List names = new ArrayList<>(projects.length); + for(Project p : projects) { + names.add(ProjectUtils.getInformation(p).getDisplayName()); } return names; } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/common/AbstractModelFilter.java b/ide/jumpto/src/org/netbeans/modules/jumpto/common/AbstractModelFilter.java index 03049e0e6541..f3c560d9e9e1 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/common/AbstractModelFilter.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/common/AbstractModelFilter.java @@ -18,7 +18,6 @@ */ package org.netbeans.modules.jumpto.common; -import java.util.Collections; import java.util.Map; import javax.swing.event.ChangeListener; import org.netbeans.api.annotations.common.CheckForNull; @@ -111,7 +110,7 @@ private static NameMatcher createNameMatcher ( NameMatcherFactory.createNameMatcher( searchText, searchType, - options == null ? Collections.emptyMap() : options) : + options == null ? Map.of() : options) : null; } } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java b/ide/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java index 5aa0c39f2ad4..2c7bfad95b61 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java @@ -69,8 +69,7 @@ public static SearchType getSearchType( @NullAllowed final String camelCasePart) { int wildcard = Utils.containsWildCard(text); if (exact) { - //nameKind = isCaseSensitive ? SearchType.EXACT_NAME : SearchType.CASE_INSENSITIVE_EXACT_NAME; - return SearchType.EXACT_NAME; + return isCaseSensitive ? SearchType.EXACT_NAME : SearchType.CASE_INSENSITIVE_EXACT_NAME; } else if (wildcard != -1) { return isCaseSensitive ? SearchType.REGEXP : SearchType.CASE_INSENSITIVE_REGEXP; } else if ((Utils.isAllUpper(text) && text.length() > 1) || Queries.isCamelCase(text, camelCaseSeparator, camelCasePart)) { diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties index 655f24ef8ccc..a068f7a8af28 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties @@ -24,7 +24,7 @@ CTL_SelectInProjects=&Select in Projects CTL_Close=&Close # {0} = project name MSG_FileSearchDlgTitle=Go to File -CTL_FileName=File &Name (prefix, wildcards: "?" "*"): +CTL_FileName=File &Name (prefix, wildcards: "?" "*", exact match: end with space): CTL_MatchingFiles=&Matching Files CTL_CaseSensitive=&Case Sensitive diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java index 0ded318005ce..cc7a89f526d4 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java @@ -71,6 +71,7 @@ void setUsePreferred(final boolean usePreferred) { abstract void setText(@NonNull final String text); + @Override public abstract int compare(FileDescriptor e1, FileDescriptor e2); void fireChange() { @@ -86,6 +87,7 @@ private static final class Alphabet extends FileComarator { super(usePreferred, caseSensitive, preferOpPrjs); } + @Override void setText(@NonNull final String text) { } @@ -147,6 +149,7 @@ private static final class Levenshtein extends FileComarator { this.text = text; } + @Override void setText(@NonNull final String text) { final boolean fire = !Objects.equals(this.text, text); this.text = text; @@ -253,14 +256,10 @@ public static FileComarator create( final boolean usePreferred, final boolean caseSensitive, final boolean preferOpPrjs) { - switch (kind) { - case LEXICOGRAPHIC: - return new Alphabet(usePreferred, caseSensitive, preferOpPrjs); - case LEVENSHTEIN: - return new Levenshtein(text, usePreferred, caseSensitive, preferOpPrjs); - default: - throw new IllegalArgumentException(String.valueOf(kind)); - } + return switch (kind) { + case LEXICOGRAPHIC -> new Alphabet(usePreferred, caseSensitive, preferOpPrjs); + case LEVENSHTEIN -> new Levenshtein(text, usePreferred, caseSensitive, preferOpPrjs); + }; } } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java index e9482547ade1..20c516f74259 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java @@ -31,7 +31,6 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; import java.util.logging.Level; @@ -58,7 +57,6 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.editor.JumpList; -import org.netbeans.modules.jumpto.EntityComparator; import org.netbeans.modules.jumpto.common.AbstractModelFilter; import org.netbeans.modules.jumpto.common.ItemRenderer; import org.netbeans.modules.jumpto.common.Models; @@ -95,18 +93,14 @@ public class FileSearchAction extends AbstractAction implements FileSearchPanel. /* package */ static final String CAMEL_CASE_SEPARATOR = "\\p{javaUpperCase}|-|_|\\."; //NOI18N /* package */ static final String CAMEL_CASE_PART_CASE_SENSITIVE = "\\p{javaLowerCase}|\\p{Digit}|\\$"; //NOI18N /* package */ static final String CAMEL_CASE_PART_CASE_INSENSITIVE = "\\p{javaLowerCase}|\\p{Digit}|\\p{javaUpperCase}|\\$"; //NOI18N - /* package */ static final Map SEARCH_OPTIONS_CASE_SENSITIVE; - /* package */ static final Map SEARCH_OPTIONS_CASE_INSENSITIVE; - static { - Map m = new HashMap<>(); - m.put(Queries.OPTION_CAMEL_CASE_SEPARATOR, CAMEL_CASE_SEPARATOR); - m.put(Queries.OPTION_CAMEL_CASE_PART, CAMEL_CASE_PART_CASE_SENSITIVE); - SEARCH_OPTIONS_CASE_SENSITIVE = Collections.unmodifiableMap(m); - m = new HashMap<>(); - m.put(Queries.OPTION_CAMEL_CASE_SEPARATOR, CAMEL_CASE_SEPARATOR); - m.put(Queries.OPTION_CAMEL_CASE_PART, CAMEL_CASE_PART_CASE_INSENSITIVE); - SEARCH_OPTIONS_CASE_INSENSITIVE = Collections.unmodifiableMap(m); - } + /* package */ static final Map SEARCH_OPTIONS_CASE_SENSITIVE = Map.of( + Queries.OPTION_CAMEL_CASE_SEPARATOR, CAMEL_CASE_SEPARATOR, + Queries.OPTION_CAMEL_CASE_PART, CAMEL_CASE_PART_CASE_SENSITIVE + ); + /* package */ static final Map SEARCH_OPTIONS_CASE_INSENSITIVE = Map.of( + Queries.OPTION_CAMEL_CASE_SEPARATOR, CAMEL_CASE_SEPARATOR, + Queries.OPTION_CAMEL_CASE_PART, CAMEL_CASE_PART_CASE_INSENSITIVE + ); private static final char LINE_NUMBER_SEPARATOR = ':'; //NOI18N private static final Pattern PATTERN_WITH_LINE_NUMBER = Pattern.compile("(.*)"+LINE_NUMBER_SEPARATOR+"(\\d*)"); //NOI18N @@ -217,7 +211,11 @@ public boolean setListModel(final FileSearchPanel panel, String text ) { // Compute in other thread synchronized(this) { - final SearchType searchType = Utils.toSearchType(nameKind); + SearchType searchType = Utils.toSearchType(nameKind); + // todo: QuerySupport.Kind has no case insensitive exact mode + if (!panel.isCaseSensitive() && searchType == SearchType.EXACT_NAME) { + searchType = SearchType.CASE_INSENSITIVE_EXACT_NAME; + } if (currentSearch.isNarrowing(searchType, text, getSearchScope(panel), true)) { itemsComparator.setUsePreferred(panel.isPreferedProject()); itemsComparator.setText(text); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java index 3bedc7a837b6..15004ada5d0b 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java @@ -223,6 +223,7 @@ public void run() { Level.FINE, "Select first item."); //NOI18N resultList.setSelectedIndex(0); + selectedItems = null; } else if (selectedItems != null && !selectedItems.isEmpty()) { LOG.log( Level.FINE, diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Worker.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Worker.java index 4fa71c71486c..839d67c6dc82 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Worker.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Worker.java @@ -661,7 +661,7 @@ void execute(@NonNull final Request request, @NonNull final Worker worker) { final NameMatcher matcher = NameMatcherFactory.createNameMatcher( request.getText(), jumpToSearchType, - Utils.isCaseSensitive(Utils.toSearchType(request.getSearchKind())) ? + Utils.isCaseSensitive(jumpToSearchType) ? FileSearchAction.SEARCH_OPTIONS_CASE_SENSITIVE : FileSearchAction.SEARCH_OPTIONS_CASE_INSENSITIVE); final List files = new ArrayList(); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/quicksearch/GoToTypeWorker.java b/ide/jumpto/src/org/netbeans/modules/jumpto/quicksearch/GoToTypeWorker.java index cb285ea7f882..b9e8bc71548a 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/quicksearch/GoToTypeWorker.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/quicksearch/GoToTypeWorker.java @@ -135,11 +135,7 @@ private void cleanUp (final Collection providers) { try { tp.cleanup(); } catch (Throwable t) { - if (t instanceof ThreadDeath) { - throw (ThreadDeath) t; - } else { - Exceptions.printStackTrace(t); - } + Exceptions.printStackTrace(t); } } } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java index c5c0c5913a9a..463189b83669 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java @@ -235,7 +235,7 @@ void setSortingType(@NonNull final SortingType type) { } public boolean isSortingPreferOpenProjects() { - return getSortingNode().getBoolean(KEY_SORTING_PRJ, true); + return getSortingNode().getBoolean(KEY_SORTING_PRJ, false); } public void setSortingPreferOpenProjects(final boolean value) { diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolComparator.java b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolComparator.java index bfb511158658..96f862e459d1 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolComparator.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/SymbolComparator.java @@ -223,14 +223,10 @@ public static SymbolComparator create( @NonNull final String text, final boolean caseSensitive, final boolean preferOpPrjs) { - switch (kind) { - case LEXICOGRAPHIC: - return new Alphabet(caseSensitive, preferOpPrjs); - case LEVENSHTEIN: - return new Levenshtein(text, caseSensitive, preferOpPrjs); - default: - throw new IllegalArgumentException(String.valueOf(kind)); - } + return switch (kind) { + case LEXICOGRAPHIC -> new Alphabet(caseSensitive, preferOpPrjs); + case LEVENSHTEIN -> new Levenshtein(text, caseSensitive, preferOpPrjs); + }; } @NonNull diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java index bbe39a3e4eae..99d61523b1fd 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java @@ -35,14 +35,12 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -62,7 +60,6 @@ import org.netbeans.api.jumpto.type.TypeBrowser; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.editor.JumpList; -import org.netbeans.modules.jumpto.EntityComparator; import org.netbeans.modules.jumpto.common.AbstractModelFilter; import org.netbeans.modules.jumpto.common.CurrentSearch; import org.netbeans.modules.jumpto.common.ItemRenderer; @@ -125,7 +122,7 @@ public GoToTypeAction(String title, TypeBrowser.Filter typeFilter, boolean multi putValue("PopupMenuText", NbBundle.getBundle(GoToTypeAction.class).getString("editor-popup-TXT_GoToType")); // NOI18N this.title = title; this.typeFilter = typeFilter; - this.implicitTypeProviders = typeProviders.length == 0 ? null : Collections.unmodifiableCollection(Arrays.asList(typeProviders)); + this.implicitTypeProviders = typeProviders.length == 0 ? null : List.of(typeProviders); this.multiSelection = multiSelection; this.currentSearch = new CurrentSearch(() -> new AbstractModelFilter() { @Override @@ -164,7 +161,7 @@ public Iterable getSelectedTypes(final boolean visible } public Iterable getSelectedTypes(final boolean visible, String initSearchText) { - Iterable result = Collections.emptyList(); + Iterable result = List.of(); try { panel = new GoToPanel(this, multiSelection); dialog = createDialog(panel); @@ -257,7 +254,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { currentSearch.filter( SearchType.EXACT_NAME, text, - Collections.singletonMap(AbstractModelFilter.OPTION_CLEAR, Boolean.TRUE)); + Map.of(AbstractModelFilter.OPTION_CLEAR, Boolean.TRUE)); panel.revalidateModel(); return false; } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/TypeComparator.java b/ide/jumpto/src/org/netbeans/modules/jumpto/type/TypeComparator.java index 0f8265d71855..3ed3b74d0414 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/TypeComparator.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/TypeComparator.java @@ -63,6 +63,7 @@ public void removeChangeListener(@NonNull final ChangeListener listener) { support.removeChangeListener(listener); } + @Override public abstract int compare(TypeDescriptor e1, TypeDescriptor e2); abstract void setText(@NonNull final String text); @@ -231,13 +232,9 @@ public static TypeComparator create( @NonNull final String text, final boolean caseSensitive, final boolean preferOpPrjs) { - switch (kind) { - case LEVENSHTEIN: - return new Levenshtein(text, caseSensitive, preferOpPrjs); - case LEXICOGRAPHIC: - return new Alphabet(caseSensitive, preferOpPrjs); - default: - throw new IllegalArgumentException(String.valueOf(kind)); - } + return switch (kind) { + case LEVENSHTEIN -> new Levenshtein(text, caseSensitive, preferOpPrjs); + case LEXICOGRAPHIC -> new Alphabet(caseSensitive, preferOpPrjs); + }; } } diff --git a/ide/jumpto/src/org/netbeans/spi/jumpto/support/NameMatcherFactory.java b/ide/jumpto/src/org/netbeans/spi/jumpto/support/NameMatcherFactory.java index 5ba13c05f2bc..52788aa2373f 100644 --- a/ide/jumpto/src/org/netbeans/spi/jumpto/support/NameMatcherFactory.java +++ b/ide/jumpto/src/org/netbeans/spi/jumpto/support/NameMatcherFactory.java @@ -18,8 +18,6 @@ */ package org.netbeans.spi.jumpto.support; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -37,22 +35,19 @@ */ public final class NameMatcherFactory { - private static final Map RE_SPECIALS; - static { - final Map m = new HashMap<>(); - m.put('{',"\\{"); //NOI18N - m.put('}',"\\}"); //NOI18N - m.put('[',"\\["); //NOI18N - m.put(']',"\\]"); //NOI18N - m.put('(',"\\("); //NOI18N - m.put(')',"\\)"); //NOI18N - m.put('\\',"\\\\"); //NOI18N - m.put('.', "\\."); //NOI18N - m.put('+',"\\+"); //NOI18N - m.put('*', ".*" ); //NOI18N - m.put('?', "."); //NOI18N - RE_SPECIALS = Collections.unmodifiableMap(m); - } + private static final Map RE_SPECIALS = Map.ofEntries( + Map.entry('{', "\\{"), //NOI18N + Map.entry('}', "\\}"), //NOI18N + Map.entry('[', "\\["), //NOI18N + Map.entry(']', "\\]"), //NOI18N + Map.entry('(', "\\("), //NOI18N + Map.entry(')', "\\)"), //NOI18N + Map.entry('\\', "\\\\"), //NOI18N + Map.entry('.', "\\."), //NOI18N + Map.entry('+', "\\+"), //NOI18N + Map.entry('*', ".*"), //NOI18N + Map.entry('?', ".") //NOI18N + ); private NameMatcherFactory() { } @@ -164,7 +159,7 @@ public final boolean accept(String name) { */ @NonNull public static NameMatcher createNameMatcher(@NonNull final String text, @NonNull final SearchType type) throws IllegalArgumentException { - return createNameMatcher(text, type, Collections.emptyMap()); + return createNameMatcher(text, type, Map.of()); } /** diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BaseSymbolProvider.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BaseSymbolProvider.java index 4c2357ffae55..a634d80a4a97 100644 --- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BaseSymbolProvider.java +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BaseSymbolProvider.java @@ -81,6 +81,10 @@ public void computeSymbolNames(SearchType searchType, String searchText, BiConsu queries.add(b.getWorkspaceService().symbol(new WorkspaceSymbolParams(searchText))); } + if (queries.isEmpty()) { + return; + } + NameMatcher matcher = NameMatcherFactory.createNameMatcher(searchText, searchType); while (!queries.isEmpty()) { @@ -88,7 +92,6 @@ public void computeSymbolNames(SearchType searchType, String searchText, BiConsu return ; } - try { currentQuery = queries.remove(queries.size() - 1); From 7d9ed0e7725552bfbe25ac0b05c11851229552e3 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 10 Oct 2025 04:43:55 +0200 Subject: [PATCH 2/2] Move "Prefer Open Projects" setting into search panels - removed the setting from global options and moved it to the three search windows - generics and related language renovationss - file search: renamed "Search by Folder" to "Search by Path" - updated mnemonics --- .../modules/jumpto/SearchHistory.java | 8 +- .../modules/jumpto/common/ItemRenderer.java | 45 ++-- .../modules/jumpto/file/Bundle.properties | 10 +- .../modules/jumpto/file/FileComarator.java | 16 +- .../modules/jumpto/file/FileSearchAction.java | 19 +- .../modules/jumpto/file/FileSearchPanel.form | 49 +++-- .../modules/jumpto/file/FileSearchPanel.java | 201 ++++++++---------- .../modules/jumpto/settings/Bundle.properties | 1 - .../modules/jumpto/settings/GoToSettings.java | 2 +- .../modules/jumpto/settings/JumpToPanel.form | 63 +++--- .../modules/jumpto/settings/JumpToPanel.java | 69 +++--- .../modules/jumpto/symbol/Bundle.properties | 1 + .../jumpto/symbol/ContentProviderImpl.java | 4 +- .../modules/jumpto/symbol/GoToPanel.java | 4 +- .../modules/jumpto/symbol/GoToPanelImpl.form | 24 ++- .../modules/jumpto/symbol/GoToPanelImpl.java | 107 ++++++---- .../modules/jumpto/type/Bundle.properties | 2 + .../modules/jumpto/type/GoToPanel.form | 29 ++- .../modules/jumpto/type/GoToPanel.java | 146 +++++++------ .../modules/jumpto/type/GoToTypeAction.java | 12 +- 20 files changed, 427 insertions(+), 385 deletions(-) diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/SearchHistory.java b/ide/jumpto/src/org/netbeans/modules/jumpto/SearchHistory.java index d698c2057867..9e233b9f4842 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/SearchHistory.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/SearchHistory.java @@ -77,7 +77,7 @@ public SearchHistory(Class clazz, JTextField textField) { * @param textField a text field which is used for showing/storing history. */ public SearchHistory(String historyKey, JTextField textField) { - assert historyKey != null && historyKey.trim().length() > 0; + assert historyKey != null && !historyKey.isBlank(); assert textField != null; this.historyKey = historyKey; @@ -115,7 +115,7 @@ private void addHistoryItem(String text) { } private void addHistoryItem(String text, MoveOffset moveOffset) { - if (text == null || text.trim().length() == 0) { + if (text == null || text.isBlank()) { LOGGER.fine("String to store is empty => ignoring."); return; } @@ -217,13 +217,13 @@ private void navigate(String oldText, MoveOffset moveOffset) { LOGGER.fine("New text is: " + newText); addHistoryItem(userText, moveOffset); } - assert newText != null && newText.trim().length() > 0; + assert newText != null && !newText.isBlank(); textField.setText(newText); } private List readHistory() { String history = getPreferences().get(historyKey, null); - if (history == null || history.trim().length() == 0) { + if (history == null || history.isBlank()) { LOGGER.fine("No history found"); return new ArrayList(2 * HISTORY_LIMIT); } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/common/ItemRenderer.java b/ide/jumpto/src/org/netbeans/modules/jumpto/common/ItemRenderer.java index 4ae17c2adf0c..67bfcde89d32 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/common/ItemRenderer.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/common/ItemRenderer.java @@ -20,14 +20,11 @@ import java.awt.Color; import java.awt.Component; -import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import javax.swing.ButtonModel; @@ -50,7 +47,6 @@ import org.netbeans.api.editor.settings.FontColorSettings; import org.netbeans.modules.jumpto.EntityComparator; import org.netbeans.modules.jumpto.settings.GoToSettings; -import org.openide.awt.HtmlRenderer; import org.openide.util.ImageUtilities; import org.openide.util.Parameters; @@ -72,7 +68,7 @@ public static interface Convertor { } public static final class Builder { - private final JList list; + private final JList list; private final ButtonModel caseSensitive; private final Convertor convertor; private String separatorPattern; @@ -146,7 +142,7 @@ public static Builder create( private final Color fgSelectionColor; private final Color bgColorGreener; private final Color bgColorDarkerGreener; - private final JList jList; + private final JList jList; private final ButtonModel caseSensitive; private final ButtonModel colorPrefered; private final ButtonModel searchFolders; @@ -173,10 +169,9 @@ private ItemRenderer( nameFormater = createNameFormatter(hs.getHighlightingType(), separatorPattern); this.jlName = new JLabel(); resetNameLabel(); - Container container = list.getParent(); - if ( container instanceof JViewport ) { - ((JViewport)container).addChangeListener(this); - stateChanged(new ChangeEvent(container)); + if (list.getParent() instanceof JViewport vp) { + vp.addChangeListener(this); + stateChanged(new ChangeEvent(vp)); } rendererComponent = new MyPanel<>(convertor); rendererComponent.setLayout(new GridBagLayout()); @@ -252,7 +247,7 @@ private ItemRenderer( @NonNull @Override public Component getListCellRendererComponent( - @NonNull final JList list, + @NonNull final JList list, @NullAllowed final Object value, final int index, final boolean isSelected, @@ -361,8 +356,7 @@ private String getBoldText(String text) { } private boolean isMainProject(String projectName) { - return projectName != null && projectName.equals(mainProjectName) ? - true : false; + return projectName != null && projectName.equals(mainProjectName); } private static class MyPanel extends JPanel { @@ -403,16 +397,11 @@ private void resetNameLabel() { } private boolean shouldHighlight(final boolean selectedItem) { - switch (highlightMode) { - case NONE: - return false; - case ACTIVE: - return selectedItem; - case ALL: - return true; - default: - throw new IllegalArgumentException(String.valueOf(selectedItem)); - } + return switch (highlightMode) { + case NONE -> false; + case ACTIVE -> selectedItem; + case ALL -> true; + }; } @NonNull @@ -442,13 +431,11 @@ private static HighlightingNameFormatter createNameFormatter( if (colors != null) { final AttributeSet attrs = colors.getFontColors("mark-occurrences"); //NOI18N if (attrs != null) { - Object o = attrs.getAttribute(StyleConstants.Background); - if (o instanceof Color) { - back = (Color) o; + if (attrs.getAttribute(StyleConstants.Background) instanceof Color bg) { + back = bg; } - o = attrs.getAttribute(StyleConstants.Foreground); - if (o instanceof Color) { - front = (Color) o; + if (attrs.getAttribute(StyleConstants.Foreground) instanceof Color fg) { + front = fg; } } } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties index a068f7a8af28..22e65142573d 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties @@ -19,9 +19,9 @@ CTL_FileSearchAction=Go to &File... editor-popup-CTL_FileSearchAction=File... -CTL_Open=&OK +CTL_Open=OK CTL_SelectInProjects=&Select in Projects -CTL_Close=&Close +CTL_Close=Close # {0} = project name MSG_FileSearchDlgTitle=Go to File CTL_FileName=File &Name (prefix, wildcards: "?" "*", exact match: end with space): @@ -37,10 +37,12 @@ TXT_SearchingOtherProjects=Searching Other Projects... TXT_PartialResults=Partial results, Searching... LBL_HiddenFiles=Show &Hidden Files -LBL_PreferMainProject=&Prefer Current Project +LBL_PreferMainProject=Prefer &Current Project +LBL_PreferOpenProjects=Prefer &Open Projects # {0} - display name of the current prject FMT_CurrentProjectLabel=Prefer Current Project ({0}) -LBL_CaseSensitive=&Case Sensitive +LBL_CaseSensitive=Case &Sensitive +LBL_SearchByPath=Search by &Path AN_Location=Location AD_Location=Location diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java index cc7a89f526d4..018041f060b0 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java @@ -44,7 +44,7 @@ public abstract class FileComarator extends EntityComparator imp private final ChangeSupport support; protected final boolean caseSensitive; - protected final boolean preferOpPrjs; + protected boolean preferOpPrjs; protected boolean usePreferred; private FileComarator( @@ -61,10 +61,16 @@ boolean isUsePreferred() { return usePreferred; } - void setUsePreferred(final boolean usePreferred) { - final boolean fire = this.usePreferred ^ usePreferred; - this.usePreferred = usePreferred; - if (fire) { + void setUsePreferred(boolean usePreferred) { + if (this.usePreferred != usePreferred) { + this.usePreferred = usePreferred; + support.fireChange(); + } + } + + void setPrefereOpenProjects(boolean prefereOpenProjects) { + if (this.preferOpPrjs != prefereOpenProjects) { + this.preferOpPrjs = prefereOpenProjects; support.fireChange(); } } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java index 20c516f74259..57afd5878d7f 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java @@ -104,7 +104,7 @@ public class FileSearchAction extends AbstractAction implements FileSearchPanel. private static final char LINE_NUMBER_SEPARATOR = ':'; //NOI18N private static final Pattern PATTERN_WITH_LINE_NUMBER = Pattern.compile("(.*)"+LINE_NUMBER_SEPARATOR+"(\\d*)"); //NOI18N - private static final ListModel EMPTY_LIST_MODEL = new DefaultListModel(); + private static final ListModel EMPTY_LIST_MODEL = new DefaultListModel<>(); private static final RequestProcessor slidingRp = new RequestProcessor("FileSearchAction-sliding",1); //Threading: Throughput 1 required due to inherent sequential code in Work.Request.exclude private static final RequestProcessor rp = new RequestProcessor ("FileSearchAction-worker",1); @@ -153,7 +153,7 @@ public void actionPerformed(ActionEvent arg0) { @Override @NonNull public ListCellRenderer getListCellRenderer( - @NonNull final JList list, + @NonNull final JList list, @NonNull final Document nameDocument, @NonNull final ButtonModel caseSensitive, @NonNull final ButtonModel colorPrefered, @@ -184,8 +184,8 @@ public boolean setListModel(final FileSearchPanel panel, String text ) { return false; } boolean exact = text.endsWith(" "); // NOI18N - text = text.trim(); - if ( text.length() == 0 || !Utils.isValidInput(text)) { + text = text.strip(); + if (text.isEmpty() || !Utils.isValidInput(text)) { currentSearch.filter( SearchType.EXACT_NAME, text, @@ -218,6 +218,7 @@ public boolean setListModel(final FileSearchPanel panel, String text ) { } if (currentSearch.isNarrowing(searchType, text, getSearchScope(panel), true)) { itemsComparator.setUsePreferred(panel.isPreferedProject()); + itemsComparator.setPrefereOpenProjects(panel.isPrefereOpenProjects()); itemsComparator.setText(text); filterFactory.setLineNumber(lineNr); filterFactory.setSearchByFolders(panel.isSearchByFolders()); @@ -478,7 +479,7 @@ private static Pair splitNameLine(@NonNull String text) { // Private classes --------------------------------------------------------- private class DialogButtonListener implements ActionListener { - private FileSearchPanel panel; + private final FileSearchPanel panel; public DialogButtonListener(FileSearchPanel panel) { this.panel = panel; @@ -590,12 +591,7 @@ public String getFileDisplayPath() { @Override public void run() { icon = delegate.getIcon(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - refreshCallback.run(); - } - }); + SwingUtilities.invokeLater(refreshCallback::run); } } @@ -684,7 +680,6 @@ void setLineNumber(final int lineNo) { @Override public Models.Filter call() throws Exception { return new AbstractModelFilter() { - @NonNull @Override protected String getItemValue(@NonNull final FileDescriptor item) { return searchByFolders ? item.getOwnerPath() : item.getFileName(); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.form b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.form index 6ffe33a1e8fc..b85cd09373eb 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.form +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.form @@ -37,10 +37,11 @@ - + + - + @@ -161,6 +162,9 @@ + + + @@ -191,14 +195,31 @@ - + - + - + + + + + + + + + + + + + + + + + + @@ -208,19 +229,19 @@ - + - + - + - + @@ -230,18 +251,20 @@ - + - + - + + + @@ -250,7 +273,7 @@ - + diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java index 15004ada5d0b..980879ec472d 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java @@ -23,7 +23,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; -import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -44,8 +43,6 @@ import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.text.AbstractDocument; import javax.swing.text.BadLocationException; import javax.swing.text.Document; @@ -56,11 +53,11 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.jumpto.SearchHistory; import org.netbeans.modules.jumpto.common.UiUtils; +import org.netbeans.modules.jumpto.settings.GoToSettings; import org.netbeans.spi.jumpto.file.FileDescriptor; import org.openide.util.ImageUtilities; import org.openide.util.Mutex; import org.openide.util.NbBundle; -import org.openide.util.NbCollections; import org.openide.util.Pair; /** @@ -85,7 +82,7 @@ public class FileSearchPanel extends javax.swing.JPanel implements ActionListene private List selectedItems; /* package */ long time; - private FileDescriptor[] selectedFile; + private FileDescriptor[] selectedFiles; private final SearchHistory searchHistory; @@ -117,6 +114,7 @@ public FileSearchPanel(ContentProvider contentProvider, Project currentProject) caseSensitiveCheckBox.setSelected(FileSearchOptions.getCaseSensitive()); hiddenFilesCheckBox.setSelected(FileSearchOptions.getShowHiddenFiles()); mainProjectCheckBox.setSelected(FileSearchOptions.getPreferMainProject()); + preferOpenCheckBox.setSelected(GoToSettings.getDefault().isSortingPreferOpenProjects()); searchByFolders.setSelected(FileSearchOptions.getSearchByFolders()); if ( currentProject == null ) { @@ -130,6 +128,7 @@ public FileSearchPanel(ContentProvider contentProvider, Project currentProject) } mainProjectCheckBox.addActionListener(this); + preferOpenCheckBox.addActionListener(this); caseSensitiveCheckBox.addActionListener(this); hiddenFilesCheckBox.addActionListener(this); hiddenFilesCheckBox.setVisible(false); @@ -141,27 +140,25 @@ public FileSearchPanel(ContentProvider contentProvider, Project currentProject) caseSensitiveCheckBox.getModel(), mainProjectCheckBox.getModel(), searchByFolders.getModel())); - resultList.addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - selectedItems = resultList.getSelectedValuesList(); - LOG.log( - Level.FINE, - "New selected items: {0}", //NOI18N - selectedItems); - } + + resultList.addListSelectionListener(e -> { + selectedItems = resultList.getSelectedValuesList(); + LOG.log(Level.FINE, "New selected items: {0}", selectedItems); //NOI18N }); contentProvider.setListModel( this, null ); fileNameTextField.getDocument().addDocumentListener(new DocumentListener() { + @Override public void changedUpdate(DocumentEvent e) { update(); } + @Override public void insertUpdate(DocumentEvent e) { update(); } + @Override public void removeUpdate(DocumentEvent e) { // handling http://netbeans.org/bugzilla/show_bug.cgi?id=203119 if (pastedFromClipboard) { @@ -188,20 +185,15 @@ void revalidateModel(final boolean done) { //Good for setting model form any thread void setModel( - @NonNull final ListModel model, + @NonNull final ListModel model, final boolean done) { // XXX measure time here - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - LOG.log( - Level.FINE, - "Reset selected items"); //NOI18N - selectedItems = null; - resultList.setModel(model); - if (done) { - setListPanelContent(null,false); - } + SwingUtilities.invokeLater(() -> { + LOG.log(Level.FINE, "Reset selected items"); //NOI18N + selectedItems = null; + resultList.setModel(model); + if (done) { + setListPanelContent(null,false); } }); } @@ -304,6 +296,10 @@ public boolean isPreferedProject() { return mainProjectCheckBox.isSelected(); } + public boolean isPrefereOpenProjects() { + return preferOpenCheckBox.isSelected(); + } + public boolean isCaseSensitive() { return caseSensitiveCheckBox.isSelected(); } @@ -346,11 +342,12 @@ private void initComponents() { resultLabel = new javax.swing.JLabel(); listPanel = new javax.swing.JPanel(); resultScrollPane = new javax.swing.JScrollPane(); - resultList = new javax.swing.JList(); + resultList = new javax.swing.JList<>(); jLabelWarningMessage = new javax.swing.JLabel(); caseSensitiveCheckBox = new javax.swing.JCheckBox(); - hiddenFilesCheckBox = new javax.swing.JCheckBox(); + preferOpenCheckBox = new javax.swing.JCheckBox(); mainProjectCheckBox = new javax.swing.JCheckBox(); + hiddenFilesCheckBox = new javax.swing.JCheckBox(); searchByFolders = new javax.swing.JCheckBox(); jLabelLocation = new javax.swing.JLabel(); jTextFieldLocation = new javax.swing.JTextField(); @@ -370,11 +367,7 @@ private void initComponents() { add(fileNameLabel, gridBagConstraints); fileNameTextField.setFont(new java.awt.Font("Monospaced", 0, getFontSize())); - fileNameTextField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - fileNameTextFieldActionPerformed(evt); - } - }); + fileNameTextField.addActionListener(this::fileNameTextFieldActionPerformed); fileNameTextField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { fileNameTextFieldKeyPressed(evt); @@ -407,11 +400,7 @@ public void mouseReleased(java.awt.event.MouseEvent evt) { resultListMouseReleased(evt); } }); - resultList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { - public void valueChanged(javax.swing.event.ListSelectionEvent evt) { - resultListValueChanged(evt); - } - }); + resultList.addListSelectionListener(this::resultListValueChanged); resultScrollPane.setViewportView(resultList); resultList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AN_MatchingList")); // NOI18N resultList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AD_MatchingList")); // NOI18N @@ -430,33 +419,40 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) { caseSensitiveCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0); add(caseSensitiveCheckBox, gridBagConstraints); caseSensitiveCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AD_CaseSensitive")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(hiddenFilesCheckBox, org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "LBL_HiddenFiles")); // NOI18N - hiddenFilesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + org.openide.awt.Mnemonics.setLocalizedText(preferOpenCheckBox, org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "LBL_PreferOpenProjects")); // NOI18N + preferOpenCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0); - add(hiddenFilesCheckBox, gridBagConstraints); - hiddenFilesCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AD_HiddenFiles")); // NOI18N + gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0); + add(preferOpenCheckBox, gridBagConstraints); org.openide.awt.Mnemonics.setLocalizedText(mainProjectCheckBox, org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "LBL_PreferMainProject")); // NOI18N mainProjectCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0); + gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0); add(mainProjectCheckBox, gridBagConstraints); mainProjectCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AD_PreferMainProject")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(searchByFolders, "Search by Folders"); + org.openide.awt.Mnemonics.setLocalizedText(hiddenFilesCheckBox, org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "LBL_HiddenFiles")); // NOI18N + hiddenFilesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0); + add(hiddenFilesCheckBox, gridBagConstraints); + hiddenFilesCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "AD_HiddenFiles")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(searchByFolders, org.openide.util.NbBundle.getMessage(FileSearchPanel.class, "LBL_SearchByPath")); // NOI18N searchByFolders.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0); + gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0); add(searchByFolders, gridBagConstraints); jLabelLocation.setLabelFor(jTextFieldLocation); @@ -478,39 +474,37 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) { add(jTextFieldLocation, gridBagConstraints); }// //GEN-END:initComponents -private void fileNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileNameTextFieldActionPerformed - if (contentProvider.hasValidContent()) { - contentProvider.closeDialog(); - setSelectedFile(); - } -}//GEN-LAST:event_fileNameTextFieldActionPerformed + private void fileNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileNameTextFieldActionPerformed + if (contentProvider.hasValidContent()) { + contentProvider.closeDialog(); + setSelectedFile(); + } + }//GEN-LAST:event_fileNameTextFieldActionPerformed -private void resultListMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultListMouseReleased - if ( evt.getClickCount() == 2 ) { - fileNameTextFieldActionPerformed(null); - } -}//GEN-LAST:event_resultListMouseReleased + private void resultListMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultListMouseReleased + if (evt.getClickCount() == 2) { + fileNameTextFieldActionPerformed(null); + } + }//GEN-LAST:event_resultListMouseReleased -private void resultListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_resultListValueChanged - final Object svObject = resultList.getSelectedValue(); - if ( svObject instanceof FileDescriptor ) { - jTextFieldLocation.setText(((FileDescriptor)svObject).getFileDisplayPath()); + private void resultListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_resultListValueChanged + FileDescriptor selected = resultList.getSelectedValue(); + if (selected != null) { + jTextFieldLocation.setText(selected.getFileDisplayPath()); } else { jTextFieldLocation.setText(""); //NOI18N } -}//GEN-LAST:event_resultListValueChanged + }//GEN-LAST:event_resultListValueChanged @CheckForNull - private Pair listActionFor(KeyEvent ev) { + private Pair listActionFor(KeyEvent ev) { InputMap map = resultList.getInputMap(); - Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, resultList); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String str) { + return Pair.of(str, resultList); } map = resultScrollPane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, resultScrollPane); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String string) { + return Pair.of(string, resultScrollPane); } return null; } @@ -561,20 +555,17 @@ else if ( "selectPreviousRow".equals(actionKey) && if (isListScrollAction) { assert actionTarget != null; final Action a = actionTarget.getActionMap().get(actionKey); - a.actionPerformed(new ActionEvent(actionTarget, 0, (String)actionKey)); + a.actionPerformed(new ActionEvent(actionTarget, 0, actionKey)); evt.consume(); } else { //handling http://netbeans.org/bugzilla/show_bug.cgi?id=203119 Object o = fileNameTextField.getInputMap().get(KeyStroke.getKeyStrokeForEvent(evt)); - if (o instanceof String) { - String action = (String) o; - if ("paste-from-clipboard".equals(action)) { - String selectedTxt = fileNameTextField.getSelectedText(); - String txt = fileNameTextField.getText(); - if (selectedTxt != null && txt != null) { - if (selectedTxt.length() == txt.length()) { - pastedFromClipboard = true; - } + if (o instanceof String action && "paste-from-clipboard".equals(action)) { + String selectedTxt = fileNameTextField.getSelectedText(); + String txt = fileNameTextField.getText(); + if (selectedTxt != null && txt != null) { + if (selectedTxt.length() == txt.length()) { + pastedFromClipboard = true; } } } @@ -591,12 +582,14 @@ else if ( "selectPreviousRow".equals(actionKey) && private javax.swing.JTextField jTextFieldLocation; private javax.swing.JPanel listPanel; private javax.swing.JCheckBox mainProjectCheckBox; + private javax.swing.JCheckBox preferOpenCheckBox; private javax.swing.JLabel resultLabel; - private javax.swing.JList resultList; + private javax.swing.JList resultList; private javax.swing.JScrollPane resultScrollPane; private javax.swing.JCheckBox searchByFolders; // End of variables declaration//GEN-END:variables + @Override public void actionPerformed(ActionEvent e) { if ( e.getSource() == caseSensitiveCheckBox ) { FileSearchOptions.setCaseSensitive(caseSensitiveCheckBox.isSelected()); @@ -610,22 +603,23 @@ else if ( e.getSource() == mainProjectCheckBox ) { else if ( e.getSource() == searchByFolders ) { FileSearchOptions.setSearchByFolders(searchByFolders.isSelected()); } + else if ( e.getSource() == preferOpenCheckBox ) { + GoToSettings.getDefault().setSortingPreferOpenProjects(preferOpenCheckBox.isSelected()); + } update(); } /** Sets the initial text to find in case the user did not start typing yet. */ public void setInitialText( final String text ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - String textInField = fileNameTextField.getText(); - if ( textInField == null || textInField.trim().length() == 0 ) { - fileNameTextField.setText(text); - final int len = fileNameTextField.getText().length(); //The text may be changed by DocumentFilter - fileNameTextField.setCaretPosition(len); - fileNameTextField.setSelectionStart(0); - fileNameTextField.setSelectionEnd(len); - } + SwingUtilities.invokeLater(() -> { + String textInField = fileNameTextField.getText(); + if (textInField == null || textInField.isBlank()) { + fileNameTextField.setText(text); + final int len = fileNameTextField.getText().length(); //The text may be changed by DocumentFilter + fileNameTextField.setCaretPosition(len); + fileNameTextField.setSelectionStart(0); + fileNameTextField.setSelectionEnd(len); } }); } @@ -644,34 +638,21 @@ private int getFontSize () { } public void setSelectedFile() { - List list = NbCollections.checkedListByCopy(Arrays.asList(resultList.getSelectedValues()), FileDescriptor.class, true); - selectedFile = list.toArray(new FileDescriptor[0]); + selectedFiles = resultList.getSelectedValuesList().toArray(FileDescriptor[]::new); } public FileDescriptor[] getSelectedFiles() { - return selectedFile; + return selectedFiles; } - public Project getCurrentProject() { + public Project getCurrentProject() { return currentProject; - } - -// public boolean accept(Object obj) { -// if ( obj instanceof FileDescription ) { -// FileDescription fd = (FileDescription)obj; -// return isShowHiddenFiles() ? true : fd.isVisible(); -// } -// return true; -// } -// -// public void scheduleUpdate(Runnable run) { -// SwingUtilities.invokeLater( run ); -// } + } public static interface ContentProvider { - public ListCellRenderer getListCellRenderer( - @NonNull JList list, + public ListCellRenderer getListCellRenderer( + @NonNull JList list, @NonNull Document nameDocument, @NonNull ButtonModel caseSensitive, @NonNull ButtonModel colorPrefered, diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/Bundle.properties b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/Bundle.properties index d7ba3e22c5b8..7cae2f5b1d0c 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/Bundle.properties +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/Bundle.properties @@ -34,4 +34,3 @@ AdvancedOption_DisplayName_GoTo=Go To AdvancedOption_Keywords_GoTo=goto,symbol,file,type JumpToPanel.orderByLabel.text=&Order by: JumpToPanel.jLabel4.text=Go To Dialog Sorting -JumpToPanel.preferOpenPrj.text=Prefer Open &Projects diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java index 463189b83669..1a92ddb7a089 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/GoToSettings.java @@ -198,7 +198,7 @@ private static SortingType getDefault() { private static final String KEY_HIGHLIGHTING_MODE = "mode"; //NOI18N private static final String KEY_HIGHLIGHTING_TYPE = "type"; //NOI18N private static final String KEY_SORTING_TYPE = "type"; //NOI18N - private static final String KEY_SORTING_PRJ = "preffer-projects"; //NOI18N + private static final String KEY_SORTING_PRJ = "prefer-projects"; //NOI18N private static final GoToSettings INSTANCE = new GoToSettings(); private GoToSettings() { diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.form b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.form index 49e39da577d5..0a080a99a924 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.form +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.form @@ -51,40 +51,36 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - @@ -111,9 +107,7 @@ - - - + @@ -140,6 +134,9 @@ + + + @@ -172,6 +169,9 @@ + + + @@ -197,12 +197,5 @@ - - - - - - - diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.java b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.java index ce6f229718a8..8c6c32e66e47 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/settings/JumpToPanel.java @@ -25,10 +25,11 @@ import javax.swing.DefaultListCellRenderer; import javax.swing.JList; import org.netbeans.api.options.OptionsDisplayer; +import org.netbeans.modules.jumpto.settings.GoToSettings.HighlightingMode; +import org.netbeans.modules.jumpto.settings.GoToSettings.HighlightingType; import org.netbeans.spi.options.OptionsPanelController; - @OptionsPanelController.Keywords(keywords = {"#AdvancedOption_Keywords_GoTo"}, location = OptionsDisplayer.EDITOR, tabTitle="#AdvancedOption_DisplayName_GoTo") final class JumpToPanel extends javax.swing.JPanel implements ActionListener { @@ -44,7 +45,6 @@ final class JumpToPanel extends javax.swing.JPanel implements ActionListener { highlight.addActionListener(this); by.addActionListener(this); orderBy.addActionListener(this); - preferOpenPrj.addActionListener(this); } /** @@ -56,15 +56,14 @@ final class JumpToPanel extends javax.swing.JPanel implements ActionListener { private void initComponents() { jLabel1 = new javax.swing.JLabel(); - highlight = new javax.swing.JComboBox(); + highlight = new javax.swing.JComboBox<>(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); - by = new javax.swing.JComboBox(); + by = new javax.swing.JComboBox<>(); jSeparator1 = new javax.swing.JSeparator(); orderByLabel = new javax.swing.JLabel(); orderBy = new javax.swing.JComboBox<>(); jLabel4 = new javax.swing.JLabel(); - preferOpenPrj = new javax.swing.JCheckBox(); setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)); @@ -86,8 +85,6 @@ private void initComponents() { org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(JumpToPanel.class, "JumpToPanel.jLabel4.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(preferOpenPrj, org.openide.util.NbBundle.getMessage(JumpToPanel.class, "JumpToPanel.preferOpenPrj.text")); // NOI18N - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -98,30 +95,26 @@ private void initComponents() { .addComponent(jSeparator1)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(orderByLabel) - .addGap(51, 51, 51) - .addComponent(orderBy, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(jLabel3)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(highlight, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(by, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(orderByLabel) + .addGap(51, 51, 51) + .addComponent(orderBy, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(47, 47, 47)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(highlight, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(by, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addComponent(jLabel4)) .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(preferOpenPrj) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -143,9 +136,7 @@ private void initComponents() { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(orderBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(orderByLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(preferOpenPrj) - .addContainerGap(37, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); highlight.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JumpToPanel.class, "AD_Highlight")); // NOI18N @@ -157,7 +148,6 @@ void load() { highlight.setSelectedItem(settings.getHighlightingMode()); by.setSelectedItem(settings.getHighlightingType()); orderBy.setSelectedItem(settings.getSortingType()); - preferOpenPrj.setSelected(settings.isSortingPreferOpenProjects()); } void store() { @@ -165,7 +155,6 @@ void store() { settings.setHighlightingMode((GoToSettings.HighlightingMode)highlight.getSelectedItem()); settings.setHighlightingType((GoToSettings.HighlightingType)by.getSelectedItem()); settings.setSortingType((GoToSettings.SortingType)orderBy.getSelectedItem()); - settings.setSortingPreferOpenProjects(preferOpenPrj.isSelected()); } boolean valid() { @@ -173,8 +162,8 @@ boolean valid() { } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JComboBox by; - private javax.swing.JComboBox highlight; + private javax.swing.JComboBox by; + private javax.swing.JComboBox highlight; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; @@ -182,7 +171,6 @@ boolean valid() { private javax.swing.JSeparator jSeparator1; private javax.swing.JComboBox orderBy; private javax.swing.JLabel orderByLabel; - private javax.swing.JCheckBox preferOpenPrj; // End of variables declaration//GEN-END:variables @Override @@ -191,8 +179,7 @@ public void actionPerformed(ActionEvent e) { GoToSettings settings = GoToSettings.getDefault(); if (highlight.getSelectedItem() != settings.getHighlightingMode() || by.getSelectedItem() != settings.getHighlightingType() - || orderBy.getSelectedItem() != settings.getSortingType() - || preferOpenPrj.isSelected() ^ settings.isSortingPreferOpenProjects()) { + || orderBy.getSelectedItem() != settings.getSortingType()) { isChanged = true; } controller.changed(isChanged); @@ -202,8 +189,8 @@ private static final class SortingTypeRenderer extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value instanceof GoToSettings.SortingType) { - value = ((GoToSettings.SortingType)value).getDisplayName(); + if (value instanceof GoToSettings.SortingType sortingType) { + value = sortingType.getDisplayName(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/Bundle.properties b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/Bundle.properties index 07153ae7fd02..51ad0ed41efa 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/Bundle.properties +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/Bundle.properties @@ -25,6 +25,7 @@ TXT_GoToSymbol_TypeName_Label=Symbol &Name (prefix, camel case: "AA" or "AbcAb", TXT_GoToSymbol_MatchesList_Label=Symbols &Found : LBL_GoToSymbol_LocationJLabel=Location: CTL_CaseSensitive=&Case Sensitive +CTL_PreferOpenProjects=Prefer &Open Projects AD_CaseSensitive=Case Sensitive MSG_DeclaredIn=in {0} TXT_PartialResults=Partial results, Searching... diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java index a7e86f9ae372..5052b8b33e7f 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; @@ -45,7 +44,6 @@ import javax.swing.event.ChangeListener; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; -import org.netbeans.modules.jumpto.EntityComparator; import org.netbeans.modules.jumpto.common.AbstractModelFilter; import org.netbeans.modules.jumpto.common.CurrentSearch; import org.netbeans.modules.jumpto.common.Factory; @@ -177,7 +175,7 @@ public boolean setListModel(GoToPanel panel, String text) { } final boolean exact = text.endsWith(" "); // NOI18N final boolean isCaseSensitive = panel.isCaseSensitive(); - text = text.trim(); + text = text.strip(); if ( text.isEmpty() || !Utils.isValidInput(text)) { currentSearch.filter( SearchType.EXACT_NAME, diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanel.java b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanel.java index 7f0dd522f822..bc50fe49f3d1 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanel.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanel.java @@ -24,9 +24,9 @@ * GoToPanel interface for UnitTest mocks. * @author Tomas Zezula */ -interface GoToPanel { +interface GoToPanel { boolean isCaseSensitive(); - boolean setModel(ListModel model, boolean finished); + boolean setModel(ListModel model, boolean finished); boolean revalidateModel(boolean finished); void setWarning(String warningMessage); long getStartTime(); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.form b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.form index 17368df8bc4c..71ecd2f10855 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.form +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.form @@ -39,10 +39,10 @@ - + - + @@ -156,6 +156,9 @@ + + + @@ -187,7 +190,22 @@ - + + + + + + + + + + + + + + + + diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.java b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.java index f143967147e5..6ed4dc30c7db 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/symbol/GoToPanelImpl.java @@ -26,7 +26,6 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyAdapter; @@ -63,6 +62,7 @@ import org.netbeans.api.annotations.common.NonNull; import org.netbeans.modules.jumpto.SearchHistory; import org.netbeans.modules.jumpto.common.UiUtils; +import org.netbeans.modules.jumpto.settings.GoToSettings; import org.netbeans.modules.jumpto.type.UiOptions; import org.netbeans.spi.jumpto.symbol.SymbolDescriptor; import org.openide.awt.Mnemonics; @@ -74,15 +74,15 @@ * * @author Petr Hrebejk */ -class GoToPanelImpl extends javax.swing.JPanel implements GoToPanel { +class GoToPanelImpl extends JPanel implements GoToPanel { - private static Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N - private static Icon WARN_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/warning.png", false); // NOI18N + private static final Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N + private static final Icon WARN_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/warning.png", false); // NOI18N private static final int BRIGHTER_COLOR_COMPONENT = 10; - private ContentProvider contentProvider; + private final ContentProvider contentProvider; private boolean containsScrollPane; - private JLabel messageLabel; + private final JLabel messageLabel; private SymbolDescriptor selectedSymbol; // Time when the serach stared (for debugging purposes) @@ -131,6 +131,8 @@ public GoToPanelImpl( ContentProvider contentProvider ) throws IOException { matchesList.addListSelectionListener(pl); caseSensitive.setSelected(UiOptions.GoToSymbolDialog.getCaseSensitive()); caseSensitive.addItemListener(pl); + preferOpen.setSelected(GoToSettings.getDefault().isSortingPreferOpenProjects()); + preferOpen.addItemListener(pl); searchHistory = new SearchHistory(GoToPanelImpl.class, nameField); } @@ -145,6 +147,10 @@ public void removeNotify() { public boolean isCaseSensitive () { return this.caseSensitive.isSelected(); } + + private boolean isPreferOpenProjects() { + return this.preferOpen.isSelected(); + } @Override public long getStartTime() { @@ -163,7 +169,7 @@ public boolean setModel( final boolean finished) { assert SwingUtilities.isEventDispatchThread(); matchesList.setModel(model); - if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) { + if (model.getSize() > 0 || getText() == null || getText().isBlank() ) { matchesList.setSelectedIndex(0); setListPanelContent(null,false); if ( time != -1 ) { @@ -194,21 +200,19 @@ public boolean revalidateModel (final boolean finished) { /** Sets the initial text to find in case the user did not start typing yet. */ public void setInitialText( final String text ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - String textInField = nameField.getText(); - if ( textInField == null || textInField.trim().length() == 0 ) { - nameField.setText(text); - nameField.setCaretPosition(text.length()); - nameField.setSelectionStart(0); - nameField.setSelectionEnd(text.length()); - } + SwingUtilities.invokeLater(() -> { + String textInField = nameField.getText(); + if (textInField == null || textInField.isBlank()) { + nameField.setText(text); + nameField.setCaretPosition(text.length()); + nameField.setSelectionStart(0); + nameField.setSelectionEnd(text.length()); } }); } public void setSelectedSymbol() { - selectedSymbol = ((SymbolDescriptor) matchesList.getSelectedValue()); + selectedSymbol = matchesList.getSelectedValue(); } public SymbolDescriptor getSelectedSymbol() { @@ -242,9 +246,10 @@ private void initComponents() { jLabelList = new JLabel(); listPanel = new JPanel(); matchesScrollPane1 = new JScrollPane(); - matchesList = new JList(); + matchesList = new JList<>(); jLabelWarning = new JLabel(); caseSensitive = new JCheckBox(); + preferOpen = new JCheckBox(); jLabelLocation = new JLabel(); jTextFieldLocation = new JTextField(); @@ -265,11 +270,7 @@ private void initComponents() { nameField.setFont(new Font("Monospaced", 0, getFontSize())); nameField.setBorder(BorderFactory.createEtchedBorder()); - nameField.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - nameFieldActionPerformed(evt); - } - }); + nameField.addActionListener(this::nameFieldActionPerformed); nameField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { nameFieldKeyPressed(evt); @@ -330,13 +331,18 @@ public void mouseReleased(MouseEvent evt) { Mnemonics.setLocalizedText(caseSensitive, NbBundle.getMessage(GoToPanelImpl.class, "CTL_CaseSensitive")); // NOI18N gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; - gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = GridBagConstraints.WEST; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new Insets(0, 0, 8, 0); add(caseSensitive, gridBagConstraints); caseSensitive.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(GoToPanelImpl.class, "AD_CaseSensitive")); // NOI18N + Mnemonics.setLocalizedText(preferOpen, NbBundle.getMessage(GoToPanelImpl.class, "CTL_PreferOpenProjects")); // NOI18N + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new Insets(0, 0, 8, 0); + add(preferOpen, gridBagConstraints); + jLabelLocation.setText(NbBundle.getMessage(GoToPanelImpl.class, "LBL_GoToSymbol_LocationJLabel")); // NOI18N gridBagConstraints = new GridBagConstraints(); gridBagConstraints.anchor = GridBagConstraints.WEST; @@ -408,9 +414,10 @@ private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR private JLabel jLabelWarning; private JTextField jTextFieldLocation; private JPanel listPanel; - private JList matchesList; + private JList matchesList; private JScrollPane matchesScrollPane1; private JTextField nameField; + private JCheckBox preferOpen; // End of variables declaration//GEN-END:variables private String getText() { @@ -453,14 +460,12 @@ else if ( message != null ) { @CheckForNull private Pair listActionFor(KeyEvent ev) { InputMap map = matchesList.getInputMap(); - Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, matchesList); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String str) { + return Pair.of(str, matchesList); } map = matchesScrollPane1.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, matchesScrollPane1); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String str) { + return Pair.of(str, matchesScrollPane1); } return null; } @@ -514,22 +519,18 @@ private static class PatternListener implements DocumentListener, ListSelectionL private final GoToPanelImpl dialog; - - PatternListener( GoToPanelImpl dialog ) { this.dialog = dialog; } - PatternListener( DocumentEvent e, GoToPanelImpl dialog ) { - this.dialog = dialog; - } - // DocumentListener ---------------------------------------------------- + @Override public void changedUpdate( DocumentEvent e ) { update(); } + @Override public void removeUpdate( DocumentEvent e ) { // handling http://netbeans.org/bugzilla/show_bug.cgi?id=203528 if (dialog.pastedFromClipboard) { @@ -539,13 +540,20 @@ public void removeUpdate( DocumentEvent e ) { } } + @Override public void insertUpdate( DocumentEvent e ) { update(); } + @Override public void itemStateChanged(ItemEvent e) { UiOptions.GoToSymbolDialog.setCaseSensitive(dialog.isCaseSensitive()); - update(); + boolean restart = false; + if (GoToSettings.getDefault().isSortingPreferOpenProjects() != dialog.isPreferOpenProjects()) { + GoToSettings.getDefault().setSortingPreferOpenProjects(dialog.isPreferOpenProjects()); + restart = true; // todo comparator should be able to handle this without restart + } + update(restart); } // ListSelectionListener ----------------------------------------------- @@ -553,18 +561,23 @@ public void itemStateChanged(ItemEvent e) { @Override public void valueChanged(@NonNull final ListSelectionEvent ev) { // got "Not computed yet" text sometimes - final Object obj = dialog.matchesList.getSelectedValue(); - if (obj instanceof SymbolDescriptor) { - final SymbolDescriptor selectedValue = ((SymbolDescriptor) obj); - final String fileName = selectedValue.getFileDisplayPath(); - dialog.jTextFieldLocation.setText(fileName); + SymbolDescriptor selected = dialog.matchesList.getSelectedValue(); + if (selected != null) { + dialog.jTextFieldLocation.setText(selected.getFileDisplayPath()); } else { dialog.jTextFieldLocation.setText(""); //NOI18N } } - + private void update() { + this.update(false); + } + + private void update(boolean restart) { dialog.time = System.currentTimeMillis(); + if (restart) { + dialog.contentProvider.setListModel(dialog, null); + } String text = dialog.getText(); if (dialog.contentProvider.setListModel(dialog,text)) { dialog.setListPanelContent(NbBundle.getMessage(GoToPanelImpl.class, "TXT_Searching"),true); // NOI18N @@ -575,7 +588,7 @@ private void update() { public static interface ContentProvider { - public ListCellRenderer getListCellRenderer(JList list, ButtonModel caseSensitive); + public ListCellRenderer getListCellRenderer(JList list, ButtonModel caseSensitive); public boolean setListModel( GoToPanel panel, String text ); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties b/ide/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties index 91180a605838..e8f7c471690e 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties @@ -42,10 +42,12 @@ TXT_GoToType_MatchesList_Label=Types &Found : LBL_GoToType_LocationJLabel=Location\: TXT_GoToType_CaseSensitive=Case &Sensitive +TXT_GoToType_PreferOpenProjects=Prefer &Open Projects LBL_Computing=Computing... CTL_OK=OK GoToPanel.caseSensitive.AccessibleContext.accessibleDescription=Case Sensitive +GoToPanel.prefereOpen.AccessibleContext.accessibleDescription=Prefer Open Projects GoToPanel.jLabelText.AccessibleContext.accessibleDescription=Type Name GoToPanel.matchesList.AccessibleContext.accessibleDescription=List of Types diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form index 88eccae6b54c..52a84da98455 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form @@ -40,7 +40,7 @@ - + @@ -165,6 +165,9 @@ + + + @@ -196,7 +199,27 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -208,7 +231,7 @@ - + diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java index 563699b6451a..b2d28a0dd9d2 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java @@ -28,8 +28,6 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseListener; import java.io.IOException; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; import javax.swing.Action; import javax.swing.BorderFactory; @@ -37,7 +35,6 @@ import javax.swing.Icon; import javax.swing.InputMap; import javax.swing.JComponent; -import static javax.swing.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.KeyStroke; @@ -57,25 +54,28 @@ import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.modules.jumpto.SearchHistory; import org.netbeans.modules.jumpto.common.UiUtils; +import org.netbeans.modules.jumpto.settings.GoToSettings; import org.netbeans.spi.jumpto.type.TypeDescriptor; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; import org.openide.util.Pair; +import static javax.swing.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT; + /** * * @author Petr Hrebejk */ public class GoToPanel extends javax.swing.JPanel { - private static Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N - private static Icon WARN_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/warning.png", false); // NOI18N + private static final Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N + private static final Icon WARN_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/warning.png", false); // NOI18N private static final int BRIGHTER_COLOR_COMPONENT = 10; - private ContentProvider contentProvider; + private final ContentProvider contentProvider; private boolean containsScrollPane; JLabel messageLabel; - private Iterable selectedTypes = Collections.emptyList(); + private Iterable selectedTypes = List.of(); private String oldMessage; // Time when the serach stared (for debugging purposes) @@ -117,15 +117,20 @@ public GoToPanel( ContentProvider contentProvider, boolean multiSelection ) thro // matchesScrollPane1.setBackground( bgColorBrighter ); matchesList.setCellRenderer( contentProvider.getListCellRenderer( matchesList, - caseSensitive.getModel())); + caseSensitive.getModel() + )); contentProvider.setListModel( this, null ); PatternListener pl = new PatternListener( this ); nameField.getDocument().addDocumentListener(pl); + caseSensitive.setSelected(UiOptions.GoToTypeDialog.getCaseSensitive()); caseSensitive.addItemListener(pl); - matchesList.addListSelectionListener(pl); + prefereOpen.setSelected(GoToSettings.getDefault().isSortingPreferOpenProjects()); + prefereOpen.addItemListener(pl); + matchesList.addListSelectionListener(pl); + searchHistory = new SearchHistory(GoToPanel.class, nameField); } @@ -135,12 +140,12 @@ public void removeNotify() { super.removeNotify(); } - /** Sets the model from different therad + /** Sets the model from different thread */ boolean setModel( final ListModel model) { assert SwingUtilities.isEventDispatchThread(); matchesList.setModel(model); - if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) { + if (model.getSize() > 0 || getText() == null || getText().isBlank()) { matchesList.setSelectedIndex(0); setListPanelContent(null,false); if ( time != -1 ) { @@ -160,25 +165,19 @@ boolean revalidateModel () { /** Sets the initial text to find in case the user did not start typing yet. */ public void setInitialText( final String text ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - String textInField = nameField.getText(); - if ( textInField == null || textInField.trim().length() == 0 ) { - nameField.setText(text); - nameField.setCaretPosition(text.length()); - nameField.setSelectionStart(0); - nameField.setSelectionEnd(text.length()); - } + SwingUtilities.invokeLater(() -> { + String textInField = nameField.getText(); + if (textInField == null || textInField.isBlank()) { + nameField.setText(text); + nameField.setCaretPosition(text.length()); + nameField.setSelectionStart(0); + nameField.setSelectionEnd(text.length()); } }); } public void setSelectedTypes() { - final List types = new LinkedList(); - for (Object td : matchesList.getSelectedValues()) { - types.add((TypeDescriptor)td); - } - selectedTypes = Collections.unmodifiableCollection(types); + selectedTypes = List.copyOf(matchesList.getSelectedValuesList()); } public Iterable getSelectedTypes() { @@ -190,8 +189,8 @@ void setWarning(String warningMessage) { jLabelWarning.setIcon(WARN_ICON); jLabelWarning.setBorder(BorderFactory.createEmptyBorder(3, 1, 1, 1)); } else { - jLabelWarning.setIcon(null); - jLabelWarning.setBorder(null); + jLabelWarning.setIcon(null); + jLabelWarning.setBorder(null); } jLabelWarning.setText(warningMessage); } @@ -218,9 +217,10 @@ private void initComponents() { jLabelList = new javax.swing.JLabel(); listPanel = new javax.swing.JPanel(); matchesScrollPane1 = new javax.swing.JScrollPane(); - matchesList = new javax.swing.JList(); + matchesList = new javax.swing.JList<>(); jLabelWarning = new javax.swing.JLabel(); caseSensitive = new javax.swing.JCheckBox(); + prefereOpen = new javax.swing.JCheckBox(); jLabelLocation = new javax.swing.JLabel(); jTextFieldLocation = new javax.swing.JTextField(); @@ -242,11 +242,7 @@ private void initComponents() { nameField.setFont(new java.awt.Font("Monospaced", 0, getFontSize())); nameField.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - nameField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - nameFieldActionPerformed(evt); - } - }); + nameField.addActionListener(this::nameFieldActionPerformed); nameField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { nameFieldKeyPressed(evt); @@ -305,14 +301,22 @@ public void mouseReleased(java.awt.event.MouseEvent evt) { org.openide.awt.Mnemonics.setLocalizedText(caseSensitive, org.openide.util.NbBundle.getMessage(GoToPanel.class, "TXT_GoToType_CaseSensitive")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); add(caseSensitive, gridBagConstraints); caseSensitive.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GoToPanel.class, "GoToPanel.caseSensitive.AccessibleContext.accessibleDescription")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(prefereOpen, org.openide.util.NbBundle.getMessage(GoToPanel.class, "TXT_GoToType_PreferOpenProjects")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); + add(prefereOpen, gridBagConstraints); + prefereOpen.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GoToPanel.class, "GoToPanel.prefereOpen.AccessibleContext.accessibleDescription")); // NOI18N + jLabelLocation.setText(org.openide.util.NbBundle.getMessage(GoToPanel.class, "LBL_GoToType_LocationJLabel")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); @@ -352,15 +356,12 @@ private void nameFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event } else { //handling http://netbeans.org/bugzilla/show_bug.cgi?id=203512 Object o = nameField.getInputMap().get(KeyStroke.getKeyStrokeForEvent(evt)); - if (o instanceof String) { - String action = (String) o; - if ("paste-from-clipboard".equals(action)) { - String selectedTxt = nameField.getSelectedText(); - String txt = nameField.getText(); - if (selectedTxt != null && txt != null) { - if (selectedTxt.length() == txt.length()) { - pastedFromClipboard = true; - } + if (o instanceof String action && "paste-from-clipboard".equals(action)) { + String selectedTxt = nameField.getSelectedText(); + String txt = nameField.getText(); + if (selectedTxt != null && txt != null) { + if (selectedTxt.length() == txt.length()) { + pastedFromClipboard = true; } } } @@ -383,9 +384,10 @@ private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR private javax.swing.JLabel jLabelWarning; private javax.swing.JTextField jTextFieldLocation; private javax.swing.JPanel listPanel; - private javax.swing.JList matchesList; + private javax.swing.JList matchesList; private javax.swing.JScrollPane matchesScrollPane1; javax.swing.JTextField nameField; + private javax.swing.JCheckBox prefereOpen; // End of variables declaration//GEN-END:variables private String getText() { @@ -402,9 +404,13 @@ private int getFontSize () { return this.jLabelList.getFont().getSize(); } - public boolean isCaseSensitive () { + public boolean isCaseSensitive() { return this.caseSensitive.isSelected(); } + + public boolean isPreferOpenProjects() { + return this.prefereOpen.isSelected(); + } void updateMessage(@NullAllowed final String message) { if (message == null ? oldMessage != null : !message.equals(oldMessage)) { @@ -441,16 +447,14 @@ void setListPanelContent( String message ,boolean waitIcon ) { } @CheckForNull - private Pair listActionFor(KeyEvent ev) { + private Pair listActionFor(KeyEvent ev) { InputMap map = matchesList.getInputMap(); - Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, matchesList); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String str) { + return Pair.of(str, matchesList); } map = matchesScrollPane1.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - o = map.get(KeyStroke.getKeyStrokeForEvent(ev)); - if (o instanceof String) { - return Pair.of((String)o, matchesScrollPane1); + if (map.get(KeyStroke.getKeyStrokeForEvent(ev)) instanceof String str) { + return Pair.of(str, matchesScrollPane1); } return null; } @@ -506,17 +510,15 @@ private static class PatternListener implements DocumentListener, ItemListener, PatternListener( GoToPanel dialog ) { this.dialog = dialog; } - - PatternListener( DocumentEvent e, GoToPanel dialog ) { - this.dialog = dialog; - } - + // DocumentListener ---------------------------------------------------- + @Override public void changedUpdate( DocumentEvent e ) { update(); } + @Override public void removeUpdate( DocumentEvent e ) { // handling http://netbeans.org/bugzilla/show_bug.cgi?id=203512 if (dialog.pastedFromClipboard) { @@ -526,15 +528,22 @@ public void removeUpdate( DocumentEvent e ) { } } + @Override public void insertUpdate( DocumentEvent e ) { update(); } // Item Listener ------------------------------------------------------- + @Override public void itemStateChanged (final ItemEvent e) { UiOptions.GoToTypeDialog.setCaseSensitive(dialog.isCaseSensitive()); - update(); + boolean restart = false; + if (GoToSettings.getDefault().isSortingPreferOpenProjects() != dialog.isPreferOpenProjects()) { + GoToSettings.getDefault().setSortingPreferOpenProjects(dialog.isPreferOpenProjects()); + restart = true; // todo comparator should be able to handle this without restart + } + update(restart); } // ListSelectionListener ----------------------------------------------- @@ -542,19 +551,24 @@ public void itemStateChanged (final ItemEvent e) { @Override public void valueChanged(@NonNull final ListSelectionEvent ev) { // got "Not computed yet" text sometimes - final Object obj = dialog.matchesList.getSelectedValue(); - if (obj instanceof TypeDescriptor) { - final TypeDescriptor selectedValue = (TypeDescriptor) obj; - final String fileName = selectedValue.getFileDisplayPath(); - dialog.jTextFieldLocation.setText(fileName); + TypeDescriptor selected = dialog.matchesList.getSelectedValue(); + if (selected != null) { + dialog.jTextFieldLocation.setText(selected.getFileDisplayPath()); } else { dialog.jTextFieldLocation.setText(""); //NOI18N } } - + private void update() { + this.update(false); + } + + private void update(boolean restart) { dialog.time = System.currentTimeMillis(); final String text = dialog.getText(); + if (restart) { + dialog.contentProvider.setListModel(dialog, null); + } if (dialog.contentProvider.setListModel(dialog, text)) { dialog.updateMessage(NbBundle.getMessage(GoToPanel.class, "TXT_Searching")); } @@ -565,8 +579,8 @@ private void update() { public static interface ContentProvider { @NonNull - public ListCellRenderer getListCellRenderer( - @NonNull JList list, + public ListCellRenderer getListCellRenderer( + @NonNull JList list, @NonNull ButtonModel caseSensitive); public boolean setListModel( GoToPanel panel, String text ); diff --git a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java index 99d61523b1fd..1a053ed2c8d9 100644 --- a/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java +++ b/ide/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java @@ -126,7 +126,6 @@ public GoToTypeAction(String title, TypeBrowser.Filter typeFilter, boolean multi this.multiSelection = multiSelection; this.currentSearch = new CurrentSearch(() -> new AbstractModelFilter() { @Override - @NonNull protected String getItemValue(@NonNull final TypeDescriptor item) { return item.getSimpleName(); } @@ -204,18 +203,19 @@ public boolean isEnabled () { @Override - public ListCellRenderer getListCellRenderer( - @NonNull final JList list, + @SuppressWarnings("unchecked") + public ListCellRenderer getListCellRenderer( + @NonNull final JList list, @NonNull final ButtonModel caseSensitive) { Parameters.notNull("list", list); //NOI18N Parameters.notNull("caseSensitive", caseSensitive); //NOI18N - return ItemRenderer.Builder.create( + ItemRenderer renderer = ItemRenderer.Builder.create( list, caseSensitive, new TypeDescriptorConvertor()).build(); + return (ListCellRenderer) renderer; } - @Override public boolean setListModel( GoToPanel panel, String text ) { assert SwingUtilities.isEventDispatchThread(); @@ -249,7 +249,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { } final boolean exact = text.endsWith(" "); // NOI18N - text = text.trim(); + text = text.strip(); if ( text.isEmpty() || !Utils.isValidInput(text)) { currentSearch.filter( SearchType.EXACT_NAME,