Skip to content

Commit 082fa84

Browse files
committed
Fix #14: Added a search wrap function. Thanks to @giles7777; this is his pull request but with merge conflicts resolved. Somehow I messed up the merge so it's no longer part of his pull request, sorry!
1 parent 0b55d81 commit 082fa84

6 files changed

Lines changed: 62 additions & 11 deletions

File tree

RSTAUI/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assert JavaVersion.current().isJava8Compatible()
99
archivesBaseName = 'rstaui'
1010

1111
dependencies {
12-
api 'com.fifesoft:rsyntaxtextarea:3.0.8'
12+
api 'com.fifesoft:rsyntaxtextarea:3.0.9-SNAPSHOT'
1313
api 'com.fifesoft:autocomplete:3.0.5'
1414
testImplementation 'junit:junit:4.12'
1515
}

RSTAUI/src/main/java/org/fife/rsta/ui/search/AbstractFindReplaceDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ private void init() {
339339
temp.setLayout(new BoxLayout(temp, BoxLayout.PAGE_AXIS));
340340
temp.add(caseCheckBox);
341341
temp.add(wholeWordCheckBox);
342+
temp.add(wrapCheckBox);
342343
searchConditionsPanel.add(temp, BorderLayout.LINE_START);
343344
temp = new JPanel();
344345
temp.setLayout(new BoxLayout(temp, BoxLayout.PAGE_AXIS));

RSTAUI/src/main/java/org/fife/rsta/ui/search/AbstractSearchDialog.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class AbstractSearchDialog extends EscapableDialog
5858
protected JCheckBox caseCheckBox;
5959
protected JCheckBox wholeWordCheckBox;
6060
protected JCheckBox regexCheckBox;
61+
protected JCheckBox wrapCheckBox;
6162
protected JPanel searchConditionsPanel;
6263

6364
/**
@@ -130,13 +131,18 @@ public void actionPerformed(ActionEvent e) {
130131
context.setRegularExpression(useRegEx);
131132
break;
132133

134+
// They check/uncheck the "Wrap" checkbox on the Find dialog.
135+
case "FlipWrap":
136+
boolean wrap = wrapCheckBox.isSelected();
137+
context.setSearchWrap(wrap);
138+
break;
139+
133140
// If they press the "Cancel" button.
134141
case "Cancel":
135142
default: // SpotBugs
136143
setVisible(false);
137144
break;
138145
}
139-
140146
}
141147

142148

@@ -297,6 +303,16 @@ public final String getWholeWordCheckboxText() {
297303
return wholeWordCheckBox.getText();
298304
}
299305

306+
/**
307+
* Returns the text for the "Wrap" check box.
308+
*
309+
* @return The text for the "Wrap" check box.
310+
* @see #setWrapCheckboxText
311+
*/
312+
public final String getWrapCheckboxText() {
313+
return wrapCheckBox.getText();
314+
}
315+
300316

301317
/**
302318
* Called when the regex checkbox is clicked (or its value is modified
@@ -351,6 +367,10 @@ else if (SearchContext.PROPERTY_SEARCH_FOR.equals(prop)) {
351367
setSearchString(newValue);
352368
}
353369
}
370+
else if (SearchContext.PROPERTY_SEARCH_WRAP.equals(prop)) {
371+
boolean newValue = ((Boolean)e.getNewValue()).booleanValue();
372+
wrapCheckBox.setSelected(newValue);
373+
}
354374

355375
}
356376

@@ -400,6 +420,9 @@ private void init() {
400420
regexCheckBox = createCheckBox(MSG, "RegEx");
401421
searchConditionsPanel.add(regexCheckBox);
402422

423+
wrapCheckBox = createCheckBox(MSG, "Wrap");
424+
searchConditionsPanel.add(wrapCheckBox);
425+
403426
// Initialize any text fields.
404427
findTextCombo = new SearchComboBox(null, false);
405428

@@ -508,6 +531,7 @@ protected void refreshUIFromContext() {
508531
this.caseCheckBox.setSelected(context.getMatchCase());
509532
this.regexCheckBox.setSelected(context.isRegularExpression());
510533
this.wholeWordCheckBox.setSelected(context.getWholeWord());
534+
this.wrapCheckBox.setSelected(context.getSearchWrap());
511535
}
512536

513537

@@ -607,6 +631,15 @@ public final void setWholeWordCheckboxText(String text) {
607631
wholeWordCheckBox.setText(text);
608632
}
609633

634+
/**
635+
* Sets the text for the "Wrap" check box.
636+
*
637+
* @param text The text for the "Whole Word" check box.
638+
* @see #getWholeWordCheckboxText
639+
*/
640+
public final void setWrapCheckboxText(String text) {
641+
wrapCheckBox.setText(text);
642+
}
610643

611644
/**
612645
* Listens for properties changing in the search context.

RSTAUI/src/main/java/org/fife/rsta/ui/search/FindToolBar.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class FindToolBar extends JPanel {
6969
protected JCheckBox wholeWordCheckBox;
7070
protected JCheckBox regexCheckBox;
7171
protected JCheckBox markAllCheckBox;
72+
protected JCheckBox wrapCheckBox;
73+
private JLabel infoLabel;
7274
private Timer markAllTimer;
7375

7476
/**
@@ -126,7 +128,6 @@ public FindToolBar(SearchListener listener) {
126128

127129
// Get ready to go.
128130
applyComponentOrientation(orientation);
129-
130131
}
131132

132133

@@ -153,7 +154,7 @@ protected Container createButtonPanel() {
153154
filler.setBorder(BorderFactory.createEmptyBorder());
154155
filler.add(findButton);//bp);
155156
panel.add(filler);
156-
panel.add(Box.createHorizontalStrut(5));
157+
panel.add(Box.createHorizontalStrut(6));
157158

158159
matchCaseCheckBox = createCB("MatchCase");
159160
panel.add(matchCaseCheckBox);
@@ -167,6 +168,9 @@ protected Container createButtonPanel() {
167168
markAllCheckBox = createCB("MarkAll");
168169
panel.add(markAllCheckBox);
169170

171+
wrapCheckBox = createCB("Wrap");
172+
panel.add(wrapCheckBox);
173+
170174
return panel;
171175

172176
}
@@ -475,6 +479,7 @@ protected void initUIFromContext() {
475479
wholeWordCheckBox.setSelected(context.getWholeWord());
476480
regexCheckBox.setSelected(context.isRegularExpression());
477481
markAllCheckBox.setSelected(context.getMarkAll());
482+
wrapCheckBox.setSelected(context.getSearchWrap());
478483
}
479484

480485

@@ -669,6 +674,9 @@ else if (source==markAllCheckBox) {
669674
context.setMarkAll(markAllCheckBox.isSelected());
670675
fireMarkAllEvent(); // Force an event to be fired
671676
}
677+
else if (source == wrapCheckBox) {
678+
context.setSearchWrap(wrapCheckBox.isSelected());
679+
}
672680
else {
673681
handleSearchAction(e);
674682
}
@@ -736,6 +744,10 @@ else if (SearchContext.PROPERTY_REPLACE_WITH.equals(prop)) {
736744
settingFindTextFromEvent = false;
737745
}
738746
}
747+
else if (SearchContext.PROPERTY_SEARCH_WRAP.equals(prop)) {
748+
boolean newValue = ((Boolean)e.getNewValue()).booleanValue();
749+
wrapCheckBox.setSelected(newValue);
750+
}
739751

740752
}
741753

RSTAUI/src/main/java/org/fife/rsta/ui/search/ReplaceToolBar.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,30 @@ protected Container createButtonPanel() {
8585
regexCheckBox = createCB("RegEx");
8686
wholeWordCheckBox = createCB("WholeWord");
8787
markAllCheckBox = createCB("MarkAll");
88+
wrapCheckBox = createCB("Wrap");
8889
// We use a "spacing" middle row, instead of spacing in the call to
8990
// UIUtil.makeSpringCompactGrid(), as the latter adds trailing
9091
// spacing after the final "row", which screws up our alignment.
9192
Dimension spacing = new Dimension(1, 5);
9293
Component space1 = Box.createRigidArea(spacing);
9394
Component space2 = Box.createRigidArea(spacing);
95+
Component space3 = Box.createRigidArea(spacing);
96+
Component space4 = Box.createRigidArea(spacing);
9497

9598
ComponentOrientation orientation = ComponentOrientation.
9699
getOrientation(getLocale());
97100

98101
if (orientation.isLeftToRight()) {
99-
optionPanel.add(matchCaseCheckBox); optionPanel.add(wholeWordCheckBox);
100-
optionPanel.add(space1); optionPanel.add(space2);
101-
optionPanel.add(regexCheckBox); optionPanel.add(markAllCheckBox);
102+
optionPanel.add(matchCaseCheckBox); optionPanel.add(wholeWordCheckBox); optionPanel.add(wrapCheckBox);
103+
optionPanel.add(space1); optionPanel.add(space2); optionPanel.add(space3);
104+
optionPanel.add(regexCheckBox); optionPanel.add(markAllCheckBox); optionPanel.add(space4);
102105
}
103106
else {
104-
optionPanel.add(wholeWordCheckBox); optionPanel.add(matchCaseCheckBox);
105-
optionPanel.add(space2); optionPanel.add(space1);
106-
optionPanel.add(markAllCheckBox); optionPanel.add(regexCheckBox);
107+
optionPanel.add(wrapCheckBox); optionPanel.add(wholeWordCheckBox); optionPanel.add(matchCaseCheckBox);
108+
optionPanel.add(space3); optionPanel.add(space2); optionPanel.add(space1);
109+
optionPanel.add(space4); optionPanel.add(markAllCheckBox); optionPanel.add(regexCheckBox);
107110
}
108-
UIUtil.makeSpringCompactGrid(optionPanel, 3,2, 0,0, 0,0);
111+
UIUtil.makeSpringCompactGrid(optionPanel, 3,3, 0,0, 0,0);
109112
panel.add(optionPanel);
110113

111114
return panel;

RSTAUI/src/main/resources/org/fife/rsta/ui/search/Search.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ RegEx=Regex
1313
MatchCaseMnemonic=M
1414
WholeWordMnemonic=W
1515
RegExMnemonic=E
16+
Wrap=Wrap
17+
WrapMnemonic=Z
1618

1719
FindWhat=Find what:
1820
ReplaceWith=Replace with:

0 commit comments

Comments
 (0)