mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Merge branch 'feature/Search_and_replace_improved_dialog' of github.com:eried/Arduino into eried-feature/Search_and_replace_improved_dialog
This commit is contained in:
commit
064fc45ba5
@ -69,6 +69,9 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
JCheckBox wrapAroundBox;
|
JCheckBox wrapAroundBox;
|
||||||
static boolean wrapAround = true;
|
static boolean wrapAround = true;
|
||||||
|
|
||||||
|
JCheckBox searchAllFilesBox;
|
||||||
|
static boolean searchAllFiles = false;
|
||||||
|
|
||||||
public FindReplace(Editor editor) {
|
public FindReplace(Editor editor) {
|
||||||
super("Find");
|
super("Find");
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
@ -88,6 +91,10 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
pain.add(replaceField = new JTextField(20));
|
pain.add(replaceField = new JTextField(20));
|
||||||
int fieldHeight = findField.getPreferredSize().height;
|
int fieldHeight = findField.getPreferredSize().height;
|
||||||
|
|
||||||
|
// Fill the findString with selected text if no previous value
|
||||||
|
if(editor.getSelectedText()!=null && editor.getSelectedText().length()>0)
|
||||||
|
findString = editor.getSelectedText();
|
||||||
|
|
||||||
if (findString != null) findField.setText(findString);
|
if (findString != null) findField.setText(findString);
|
||||||
if (replaceString != null) replaceField.setText(replaceString);
|
if (replaceString != null) replaceField.setText(replaceString);
|
||||||
//System.out.println("setting find str to " + findString);
|
//System.out.println("setting find str to " + findString);
|
||||||
@ -111,6 +118,15 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
wrapAroundBox.setSelected(wrapAround);
|
wrapAroundBox.setSelected(wrapAround);
|
||||||
pain.add(wrapAroundBox);
|
pain.add(wrapAroundBox);
|
||||||
|
|
||||||
|
searchAllFilesBox = new JCheckBox(_("Search all Sketch Tabs"));
|
||||||
|
searchAllFilesBox.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
searchAllFiles = searchAllFilesBox.isSelected();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
searchAllFilesBox.setSelected(searchAllFiles);
|
||||||
|
pain.add(searchAllFilesBox);
|
||||||
|
|
||||||
JPanel buttons = new JPanel();
|
JPanel buttons = new JPanel();
|
||||||
|
|
||||||
buttons.setLayout(new FlowLayout(FlowLayout.CENTER,BUTTONGAP,0));
|
buttons.setLayout(new FlowLayout(FlowLayout.CENTER,BUTTONGAP,0));
|
||||||
@ -180,9 +196,13 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
ignoreCaseBox.setBounds(EDGE + labelDimension.width + SMALL,
|
ignoreCaseBox.setBounds(EDGE + labelDimension.width + SMALL,
|
||||||
ypos,
|
ypos,
|
||||||
(fieldWidth-SMALL)/2, fieldHeight);
|
(fieldWidth-SMALL)/4, fieldHeight);
|
||||||
|
|
||||||
wrapAroundBox.setBounds(EDGE + labelDimension.width + SMALL + (fieldWidth-SMALL)/2 + SMALL,
|
wrapAroundBox.setBounds(EDGE + labelDimension.width + SMALL + (fieldWidth-SMALL)/4 + SMALL,
|
||||||
|
ypos,
|
||||||
|
(fieldWidth-SMALL)/4, fieldHeight);
|
||||||
|
|
||||||
|
searchAllFilesBox.setBounds(EDGE + labelDimension.width + SMALL + (int)((fieldWidth-SMALL)/1.9) + SMALL,
|
||||||
ypos,
|
ypos,
|
||||||
(fieldWidth-SMALL)/2, fieldHeight);
|
(fieldWidth-SMALL)/2, fieldHeight);
|
||||||
|
|
||||||
@ -291,8 +311,9 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
// look for the next instance of the find string to be found
|
// look for the next instance of the find string to be found
|
||||||
// once found, select it (and go to that line)
|
// once found, select it (and go to that line)
|
||||||
|
|
||||||
private boolean find(boolean wrap,boolean backwards ) {
|
private boolean find(boolean wrap,boolean backwards,boolean searchTabs,int originTab) {
|
||||||
|
//System.out.println("Find: " + originTab);
|
||||||
|
boolean wrapNeeded = false;
|
||||||
String search = findField.getText();
|
String search = findField.getText();
|
||||||
//System.out.println("finding for " + search + " " + findString);
|
//System.out.println("finding for " + search + " " + findString);
|
||||||
// this will catch "find next" being called when no search yet
|
// this will catch "find next" being called when no search yet
|
||||||
@ -313,7 +334,7 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
nextIndex = text.indexOf(search, selectionEnd);
|
nextIndex = text.indexOf(search, selectionEnd);
|
||||||
if (wrap && nextIndex == -1) {
|
if (wrap && nextIndex == -1) {
|
||||||
// if wrapping, a second chance is ok, start from beginning
|
// if wrapping, a second chance is ok, start from beginning
|
||||||
nextIndex = text.indexOf(search, 0);
|
wrapNeeded = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//int selectionStart = editor.textarea.getSelectionStart();
|
//int selectionStart = editor.textarea.getSelectionStart();
|
||||||
@ -326,16 +347,58 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
}
|
}
|
||||||
if (wrap && nextIndex == -1) {
|
if (wrap && nextIndex == -1) {
|
||||||
// if wrapping, a second chance is ok, start from the end
|
// if wrapping, a second chance is ok, start from the end
|
||||||
nextIndex = text.lastIndexOf(search);
|
wrapNeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextIndex != -1) {
|
if (nextIndex == -1) {
|
||||||
editor.setSelection(nextIndex, nextIndex + search.length());
|
//Nothing found on this tab: Search other tabs if required
|
||||||
} else {
|
if(searchTabs)
|
||||||
//Toolkit.getDefaultToolkit().beep();
|
{
|
||||||
|
//editor.
|
||||||
|
Sketch sketch = editor.getSketch();
|
||||||
|
if(sketch.getCodeCount()>1)
|
||||||
|
{
|
||||||
|
int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
|
||||||
|
|
||||||
|
if(originTab!=realCurrentTab)
|
||||||
|
{
|
||||||
|
if(originTab <0)
|
||||||
|
originTab = realCurrentTab;
|
||||||
|
|
||||||
|
if(!wrap)
|
||||||
|
if((!backwards && realCurrentTab+1 >= sketch.getCodeCount()) || (backwards && realCurrentTab-1 < 0))
|
||||||
|
return false; // Can't continue without wrap
|
||||||
|
|
||||||
|
if(backwards)
|
||||||
|
{
|
||||||
|
sketch.handlePrevCode();
|
||||||
|
this.setVisible(true);
|
||||||
|
int l = editor.getText().length()-1;
|
||||||
|
editor.setSelection(l,l);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sketch.handleNextCode();
|
||||||
|
this.setVisible(true);
|
||||||
|
editor.setSelection(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return find(wrap,backwards,searchTabs,originTab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wrapNeeded)
|
||||||
|
nextIndex = backwards? text.lastIndexOf(search):text.indexOf(search, 0);
|
||||||
}
|
}
|
||||||
return nextIndex != -1;
|
|
||||||
|
if (nextIndex != -1) {
|
||||||
|
editor.setSelection(nextIndex, nextIndex + search.length());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -344,6 +407,8 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
* replacement text field.
|
* replacement text field.
|
||||||
*/
|
*/
|
||||||
public void replace() {
|
public void replace() {
|
||||||
|
if(findField.getText().length()==0)
|
||||||
|
return;
|
||||||
editor.setSelectedText(replaceField.getText());
|
editor.setSelectedText(replaceField.getText());
|
||||||
editor.getSketch().setModified(true); // TODO is this necessary?
|
editor.getSketch().setModified(true); // TODO is this necessary?
|
||||||
}
|
}
|
||||||
@ -362,12 +427,14 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
* alternately until nothing more found.
|
* alternately until nothing more found.
|
||||||
*/
|
*/
|
||||||
public void replaceAll() {
|
public void replaceAll() {
|
||||||
|
if(findField.getText().length()==0)
|
||||||
|
return;
|
||||||
// move to the beginning
|
// move to the beginning
|
||||||
editor.setSelection(0, 0);
|
editor.setSelection(0, 0);
|
||||||
|
|
||||||
boolean foundAtLeastOne = false;
|
boolean foundAtLeastOne = false;
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
if ( find(false,false) ) {
|
if ( find(false,false,searchAllFiles,-1)) {
|
||||||
foundAtLeastOne = true;
|
foundAtLeastOne = true;
|
||||||
replace();
|
replace();
|
||||||
} else {
|
} else {
|
||||||
@ -385,13 +452,13 @@ public class FindReplace extends JFrame implements ActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void findNext() {
|
public void findNext() {
|
||||||
if ( !find( wrapAround, false ) ) {
|
if ( !find( wrapAround, false, searchAllFiles,-1 ) ) {
|
||||||
Toolkit.getDefaultToolkit().beep();
|
Toolkit.getDefaultToolkit().beep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findPrevious() {
|
public void findPrevious() {
|
||||||
if ( !find( wrapAround, true ) ) {
|
if ( !find( wrapAround, true, searchAllFiles,-1 ) ) {
|
||||||
Toolkit.getDefaultToolkit().beep();
|
Toolkit.getDefaultToolkit().beep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user