Skip to content

Commit b6818ce

Browse files
committed
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
1 parent 6e934de commit b6818ce

20 files changed

+427
-385
lines changed

ide/jumpto/src/org/netbeans/modules/jumpto/SearchHistory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public SearchHistory(Class clazz, JTextField textField) {
7777
* @param textField a text field which is used for showing/storing history.
7878
*/
7979
public SearchHistory(String historyKey, JTextField textField) {
80-
assert historyKey != null && historyKey.trim().length() > 0;
80+
assert historyKey != null && !historyKey.isBlank();
8181
assert textField != null;
8282

8383
this.historyKey = historyKey;
@@ -115,7 +115,7 @@ private void addHistoryItem(String text) {
115115
}
116116

117117
private void addHistoryItem(String text, MoveOffset moveOffset) {
118-
if (text == null || text.trim().length() == 0) {
118+
if (text == null || text.isBlank()) {
119119
LOGGER.fine("String to store is empty => ignoring.");
120120
return;
121121
}
@@ -217,13 +217,13 @@ private void navigate(String oldText, MoveOffset moveOffset) {
217217
LOGGER.fine("New text is: " + newText);
218218
addHistoryItem(userText, moveOffset);
219219
}
220-
assert newText != null && newText.trim().length() > 0;
220+
assert newText != null && !newText.isBlank();
221221
textField.setText(newText);
222222
}
223223

224224
private List<String> readHistory() {
225225
String history = getPreferences().get(historyKey, null);
226-
if (history == null || history.trim().length() == 0) {
226+
if (history == null || history.isBlank()) {
227227
LOGGER.fine("No history found");
228228
return new ArrayList<String>(2 * HISTORY_LIMIT);
229229
}

ide/jumpto/src/org/netbeans/modules/jumpto/common/ItemRenderer.java

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@
2020

2121
import java.awt.Color;
2222
import java.awt.Component;
23-
import java.awt.Container;
2423
import java.awt.Dimension;
2524
import java.awt.Font;
2625
import java.awt.GridBagConstraints;
2726
import java.awt.GridBagLayout;
2827
import java.awt.Insets;
29-
import java.awt.event.ActionEvent;
30-
import java.awt.event.ActionListener;
3128
import java.lang.reflect.ParameterizedType;
3229
import java.lang.reflect.Type;
3330
import javax.swing.ButtonModel;
@@ -50,7 +47,6 @@
5047
import org.netbeans.api.editor.settings.FontColorSettings;
5148
import org.netbeans.modules.jumpto.EntityComparator;
5249
import org.netbeans.modules.jumpto.settings.GoToSettings;
53-
import org.openide.awt.HtmlRenderer;
5450
import org.openide.util.ImageUtilities;
5551
import org.openide.util.Parameters;
5652

@@ -72,7 +68,7 @@ public static interface Convertor<T> {
7268
}
7369

7470
public static final class Builder<T> {
75-
private final JList list;
71+
private final JList<T> list;
7672
private final ButtonModel caseSensitive;
7773
private final Convertor<T> convertor;
7874
private String separatorPattern;
@@ -146,7 +142,7 @@ public static <T> Builder<T> create(
146142
private final Color fgSelectionColor;
147143
private final Color bgColorGreener;
148144
private final Color bgColorDarkerGreener;
149-
private final JList jList;
145+
private final JList<T> jList;
150146
private final ButtonModel caseSensitive;
151147
private final ButtonModel colorPrefered;
152148
private final ButtonModel searchFolders;
@@ -173,10 +169,9 @@ private ItemRenderer(
173169
nameFormater = createNameFormatter(hs.getHighlightingType(), separatorPattern);
174170
this.jlName = new JLabel();
175171
resetNameLabel();
176-
Container container = list.getParent();
177-
if ( container instanceof JViewport ) {
178-
((JViewport)container).addChangeListener(this);
179-
stateChanged(new ChangeEvent(container));
172+
if (list.getParent() instanceof JViewport vp) {
173+
vp.addChangeListener(this);
174+
stateChanged(new ChangeEvent(vp));
180175
}
181176
rendererComponent = new MyPanel<>(convertor);
182177
rendererComponent.setLayout(new GridBagLayout());
@@ -252,7 +247,7 @@ private ItemRenderer(
252247
@NonNull
253248
@Override
254249
public Component getListCellRendererComponent(
255-
@NonNull final JList list,
250+
@NonNull final JList<?> list,
256251
@NullAllowed final Object value,
257252
final int index,
258253
final boolean isSelected,
@@ -361,8 +356,7 @@ private String getBoldText(String text) {
361356
}
362357

363358
private boolean isMainProject(String projectName) {
364-
return projectName != null && projectName.equals(mainProjectName) ?
365-
true : false;
359+
return projectName != null && projectName.equals(mainProjectName);
366360
}
367361

368362
private static class MyPanel<T> extends JPanel {
@@ -403,16 +397,11 @@ private void resetNameLabel() {
403397
}
404398

405399
private boolean shouldHighlight(final boolean selectedItem) {
406-
switch (highlightMode) {
407-
case NONE:
408-
return false;
409-
case ACTIVE:
410-
return selectedItem;
411-
case ALL:
412-
return true;
413-
default:
414-
throw new IllegalArgumentException(String.valueOf(selectedItem));
415-
}
400+
return switch (highlightMode) {
401+
case NONE -> false;
402+
case ACTIVE -> selectedItem;
403+
case ALL -> true;
404+
};
416405
}
417406

418407
@NonNull
@@ -442,13 +431,11 @@ private static HighlightingNameFormatter createNameFormatter(
442431
if (colors != null) {
443432
final AttributeSet attrs = colors.getFontColors("mark-occurrences"); //NOI18N
444433
if (attrs != null) {
445-
Object o = attrs.getAttribute(StyleConstants.Background);
446-
if (o instanceof Color) {
447-
back = (Color) o;
434+
if (attrs.getAttribute(StyleConstants.Background) instanceof Color bg) {
435+
back = bg;
448436
}
449-
o = attrs.getAttribute(StyleConstants.Foreground);
450-
if (o instanceof Color) {
451-
front = (Color) o;
437+
if (attrs.getAttribute(StyleConstants.Foreground) instanceof Color fg) {
438+
front = fg;
452439
}
453440
}
454441
}

ide/jumpto/src/org/netbeans/modules/jumpto/file/Bundle.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
CTL_FileSearchAction=Go to &File...
2020
editor-popup-CTL_FileSearchAction=File...
2121

22-
CTL_Open=&OK
22+
CTL_Open=OK
2323
CTL_SelectInProjects=&Select in Projects
24-
CTL_Close=&Close
24+
CTL_Close=Close
2525
# {0} = project name
2626
MSG_FileSearchDlgTitle=Go to File
2727
CTL_FileName=File &Name (prefix, wildcards: "?" "*", exact match: end with space):
@@ -37,10 +37,12 @@ TXT_SearchingOtherProjects=Searching Other Projects...
3737
TXT_PartialResults=Partial results, Searching...
3838

3939
LBL_HiddenFiles=Show &Hidden Files
40-
LBL_PreferMainProject=&Prefer Current Project
40+
LBL_PreferMainProject=Prefer &Current Project
41+
LBL_PreferOpenProjects=Prefer &Open Projects
4142
# {0} - display name of the current prject
4243
FMT_CurrentProjectLabel=Prefer Current Project ({0})
43-
LBL_CaseSensitive=&Case Sensitive
44+
LBL_CaseSensitive=Case &Sensitive
45+
LBL_SearchByPath=Search by &Path
4446

4547
AN_Location=Location
4648
AD_Location=Location

ide/jumpto/src/org/netbeans/modules/jumpto/file/FileComarator.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class FileComarator extends EntityComparator<FileDescriptor> imp
4444

4545
private final ChangeSupport support;
4646
protected final boolean caseSensitive;
47-
protected final boolean preferOpPrjs;
47+
protected boolean preferOpPrjs;
4848
protected boolean usePreferred;
4949

5050
private FileComarator(
@@ -61,10 +61,16 @@ boolean isUsePreferred() {
6161
return usePreferred;
6262
}
6363

64-
void setUsePreferred(final boolean usePreferred) {
65-
final boolean fire = this.usePreferred ^ usePreferred;
66-
this.usePreferred = usePreferred;
67-
if (fire) {
64+
void setUsePreferred(boolean usePreferred) {
65+
if (this.usePreferred != usePreferred) {
66+
this.usePreferred = usePreferred;
67+
support.fireChange();
68+
}
69+
}
70+
71+
void setPrefereOpenProjects(boolean prefereOpenProjects) {
72+
if (this.preferOpPrjs != prefereOpenProjects) {
73+
this.preferOpPrjs = prefereOpenProjects;
6874
support.fireChange();
6975
}
7076
}

ide/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class FileSearchAction extends AbstractAction implements FileSearchPanel.
104104
private static final char LINE_NUMBER_SEPARATOR = ':'; //NOI18N
105105
private static final Pattern PATTERN_WITH_LINE_NUMBER = Pattern.compile("(.*)"+LINE_NUMBER_SEPARATOR+"(\\d*)"); //NOI18N
106106

107-
private static final ListModel EMPTY_LIST_MODEL = new DefaultListModel();
107+
private static final ListModel<FileDescriptor> EMPTY_LIST_MODEL = new DefaultListModel<>();
108108
private static final RequestProcessor slidingRp = new RequestProcessor("FileSearchAction-sliding",1);
109109
//Threading: Throughput 1 required due to inherent sequential code in Work.Request.exclude
110110
private static final RequestProcessor rp = new RequestProcessor ("FileSearchAction-worker",1);
@@ -153,7 +153,7 @@ public void actionPerformed(ActionEvent arg0) {
153153
@Override
154154
@NonNull
155155
public ListCellRenderer getListCellRenderer(
156-
@NonNull final JList list,
156+
@NonNull final JList<FileDescriptor> list,
157157
@NonNull final Document nameDocument,
158158
@NonNull final ButtonModel caseSensitive,
159159
@NonNull final ButtonModel colorPrefered,
@@ -184,8 +184,8 @@ public boolean setListModel(final FileSearchPanel panel, String text ) {
184184
return false;
185185
}
186186
boolean exact = text.endsWith(" "); // NOI18N
187-
text = text.trim();
188-
if ( text.length() == 0 || !Utils.isValidInput(text)) {
187+
text = text.strip();
188+
if (text.isEmpty() || !Utils.isValidInput(text)) {
189189
currentSearch.filter(
190190
SearchType.EXACT_NAME,
191191
text,
@@ -218,6 +218,7 @@ public boolean setListModel(final FileSearchPanel panel, String text ) {
218218
}
219219
if (currentSearch.isNarrowing(searchType, text, getSearchScope(panel), true)) {
220220
itemsComparator.setUsePreferred(panel.isPreferedProject());
221+
itemsComparator.setPrefereOpenProjects(panel.isPrefereOpenProjects());
221222
itemsComparator.setText(text);
222223
filterFactory.setLineNumber(lineNr);
223224
filterFactory.setSearchByFolders(panel.isSearchByFolders());
@@ -478,7 +479,7 @@ private static Pair<String,Integer> splitNameLine(@NonNull String text) {
478479
// Private classes ---------------------------------------------------------
479480
private class DialogButtonListener implements ActionListener {
480481

481-
private FileSearchPanel panel;
482+
private final FileSearchPanel panel;
482483

483484
public DialogButtonListener(FileSearchPanel panel) {
484485
this.panel = panel;
@@ -590,12 +591,7 @@ public String getFileDisplayPath() {
590591
@Override
591592
public void run() {
592593
icon = delegate.getIcon();
593-
SwingUtilities.invokeLater(new Runnable() {
594-
@Override
595-
public void run() {
596-
refreshCallback.run();
597-
}
598-
});
594+
SwingUtilities.invokeLater(refreshCallback::run);
599595
}
600596

601597
}
@@ -684,7 +680,6 @@ void setLineNumber(final int lineNo) {
684680
@Override
685681
public Models.Filter<FileDescriptor> call() throws Exception {
686682
return new AbstractModelFilter<FileDescriptor>() {
687-
@NonNull
688683
@Override
689684
protected String getItemValue(@NonNull final FileDescriptor item) {
690685
return searchByFolders ? item.getOwnerPath() : item.getFileName();

0 commit comments

Comments
 (0)