1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Merge branch 'wayoda-fix-find-dialog-layout' into ide-1.5.x

This commit is contained in:
Cristian Maglie
2015-01-13 23:29:42 +01:00
2 changed files with 177 additions and 209 deletions

View File

@ -28,6 +28,7 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import processing.app.helpers.OSUtils; import processing.app.helpers.OSUtils;
@ -50,68 +51,51 @@ import processing.app.helpers.OSUtils;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class FindReplace extends JFrame implements ActionListener { public class FindReplace extends JFrame implements ActionListener {
static final int EDGE = OSUtils.isMacOS() ? 20 : 13; private Editor editor;
static final int SMALL = 6;
static final int BUTTONGAP = 12; // 12 is correct for Mac, other numbers may be required for other platofrms
Editor editor; private JTextField findField;
private JTextField replaceField;
private static String findString;
private static String replaceString;
JTextField findField; private JButton replaceButton;
JTextField replaceField; private JButton replaceAllButton;
static String findString; private JButton replaceFindButton;
static String replaceString; private JButton previousButton;
private JButton findButton;
JButton replaceButton; private JCheckBox ignoreCaseBox;
JButton replaceAllButton; private static boolean ignoreCase = true;
JButton replaceFindButton;
JButton previousButton;
JButton findButton;
JCheckBox ignoreCaseBox; private JCheckBox wrapAroundBox;
static boolean ignoreCase = true; private static boolean wrapAround = true;
JCheckBox wrapAroundBox; private JCheckBox searchAllFilesBox;
static boolean wrapAround = true; private static boolean searchAllFiles = false;
JCheckBox searchAllFilesBox;
static boolean searchAllFiles = false;
public FindReplace(Editor editor) { public FindReplace(Editor editor) {
super("Find"); super(_("Find"));
setResizable(false);
this.editor = editor; this.editor = editor;
FlowLayout searchLayout = new FlowLayout(FlowLayout.RIGHT,5,0); JPanel contentPanel = new JPanel();
Container pane = getContentPane(); Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);
pane.setLayout(searchLayout); contentPanel.setBorder(padding);
setContentPane(contentPanel);
JLabel findLabel = new JLabel(_("Find:")); JLabel findLabel = new JLabel(_("Find:"));
findField = new JTextField(20);
JLabel replaceLabel = new JLabel(_("Replace with:")); JLabel replaceLabel = new JLabel(_("Replace with:"));
Dimension labelDimension = replaceLabel.getPreferredSize(); replaceField = new JTextField(20);
JPanel find = new JPanel();
find.add(findLabel);
find.add(findField = new JTextField(20));
pane.add(find);
JPanel replace = new JPanel();
replace.add(replaceLabel);
replace.add(replaceField = new JTextField(20));
pane.add(replace);
int fieldHeight = findField.getPreferredSize().height;
JPanel checkbox = new JPanel();
// Fill the findString with selected text if no previous value // Fill the findString with selected text if no previous value
if (editor.getSelectedText() != null && if (editor.getSelectedText() != null
editor.getSelectedText().length() > 0) && editor.getSelectedText().length() > 0)
findString = editor.getSelectedText(); findString = editor.getSelectedText();
if (findString != null) findField.setText(findString); if (findString != null)
if (replaceString != null) replaceField.setText(replaceString); findField.setText(findString);
//System.out.println("setting find str to " + findString); if (replaceString != null)
//findField.requestFocusInWindow(); replaceField.setText(replaceString);
ignoreCaseBox = new JCheckBox(_("Ignore Case")); ignoreCaseBox = new JCheckBox(_("Ignore Case"));
ignoreCaseBox.addActionListener(new ActionListener() { ignoreCaseBox.addActionListener(new ActionListener() {
@ -120,7 +104,6 @@ public class FindReplace extends JFrame implements ActionListener {
} }
}); });
ignoreCaseBox.setSelected(ignoreCase); ignoreCaseBox.setSelected(ignoreCase);
checkbox.add(ignoreCaseBox);
wrapAroundBox = new JCheckBox(_("Wrap Around")); wrapAroundBox = new JCheckBox(_("Wrap Around"));
wrapAroundBox.addActionListener(new ActionListener() { wrapAroundBox.addActionListener(new ActionListener() {
@ -129,7 +112,6 @@ public class FindReplace extends JFrame implements ActionListener {
} }
}); });
wrapAroundBox.setSelected(wrapAround); wrapAroundBox.setSelected(wrapAround);
checkbox.add(wrapAroundBox);
searchAllFilesBox = new JCheckBox(_("Search all Sketch Tabs")); searchAllFilesBox = new JCheckBox(_("Search all Sketch Tabs"));
searchAllFilesBox.addActionListener(new ActionListener() { searchAllFilesBox.addActionListener(new ActionListener() {
@ -138,119 +120,105 @@ public class FindReplace extends JFrame implements ActionListener {
} }
}); });
searchAllFilesBox.setSelected(searchAllFiles); searchAllFilesBox.setSelected(searchAllFiles);
checkbox.add(searchAllFilesBox);
pane.add(checkbox); JPanel checkboxPanel = new JPanel();
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.PAGE_AXIS));
checkboxPanel.add(ignoreCaseBox);
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
checkboxPanel.add(wrapAroundBox);
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
checkboxPanel.add(searchAllFilesBox);
JPanel buttons = new JPanel(); replaceAllButton = new JButton(_("Replace All"));
buttons.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONGAP, 0)); replaceAllButton.addActionListener(this);
replaceButton = new JButton(_("Replace"));
replaceButton.addActionListener(this);
replaceFindButton = new JButton(_("Replace & Find"));
replaceFindButton.addActionListener(this);
previousButton = new JButton(_("Previous"));
previousButton.addActionListener(this);
findButton = new JButton(_("Find"));
findButton.addActionListener(this);
// ordering is different on mac versus pc JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
// ordering of buttons is different on mac versus pc
if (OSUtils.isMacOS()) { if (OSUtils.isMacOS()) {
buttons.add(replaceAllButton = new JButton(_("Replace All"))); buttonPanel.add(replaceAllButton);
buttons.add(replaceButton = new JButton(_("Replace"))); buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttons.add(replaceFindButton = new JButton(_("Replace & Find"))); buttonPanel.add(replaceButton);
buttons.add(previousButton = new JButton(_("Previous"))); buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttons.add(findButton = new JButton(_("Find"))); buttonPanel.add(replaceFindButton);
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttonPanel.add(previousButton);
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttonPanel.add(findButton);
} else { } else {
buttons.add(findButton = new JButton(_("Find"))); buttonPanel.add(findButton);
buttons.add(previousButton = new JButton(_("Previous"))); // is this the right position for non-Mac? buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttons.add(replaceFindButton = new JButton(_("Replace & Find"))); buttonPanel.add(previousButton); // is this the right position for
buttons.add(replaceButton = new JButton(_("Replace"))); // non-Mac?
buttons.add(replaceAllButton = new JButton(_("Replace All"))); buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttonPanel.add(replaceFindButton);
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttonPanel.add(replaceButton);
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
buttonPanel.add(replaceAllButton);
} }
pane.add(buttons);
// to fix ugliness.. normally macosx java 1.3 puts an // to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off. // ugly white border around this object, so turn it off.
if (OSUtils.isMacOS()) { if (OSUtils.isMacOS()) {
buttons.setBorder(null); buttonPanel.setBorder(null);
} }
/* // Put all components onto the dialog window
findField.addFocusListener(new FocusListener() { GridBagLayout searchLayout = new GridBagLayout();
public void focusGained(FocusEvent e) { GridBagConstraints gbc = new GridBagConstraints();
System.out.println("Focus gained " + e.getOppositeComponent()); Container pane = getContentPane();
} pane.setLayout(searchLayout);
public void focusLost(FocusEvent e) { gbc.insets = new Insets(4, 4, 4, 4);
System.out.println("Focus lost "); // + e.getOppositeComponent()); gbc.gridx = 0;
if (e.getOppositeComponent() == null) { gbc.weightx = 0.0;
requestFocusInWindow(); gbc.weighty = 0.0;
} gbc.fill = GridBagConstraints.NONE;
} gbc.anchor = GridBagConstraints.LINE_END;
}); pane.add(findLabel, gbc);
*/ gbc.gridx = 1;
gbc.weightx = 1.0;
Dimension buttonsDimension = buttons.getPreferredSize(); gbc.fill = GridBagConstraints.HORIZONTAL;
int visibleButtonWidth = buttonsDimension.width - 2 * BUTTONGAP; gbc.anchor = GridBagConstraints.LINE_START;
int fieldWidth = visibleButtonWidth - (labelDimension.width + SMALL); pane.add(findField, gbc);
gbc.gridx = 0;
// +1 since it's better to tend downwards gbc.gridy = 1;
int yoff = (1 + fieldHeight - labelDimension.height) / 2; gbc.weightx = 0.0;
gbc.fill = GridBagConstraints.NONE;
int ypos = EDGE; gbc.anchor = GridBagConstraints.LINE_END;
pane.add(replaceLabel, gbc);
int labelWidth = findLabel.getPreferredSize().width; gbc.gridx = 1;
findLabel.setBounds(EDGE + (labelDimension.width-labelWidth), ypos + yoff, // + yoff was added to the wrong field gbc.weightx = 1.0;
labelWidth, labelDimension.height); gbc.fill = GridBagConstraints.HORIZONTAL;
findField.setBounds(EDGE + labelDimension.width + SMALL, ypos, gbc.anchor = GridBagConstraints.LINE_START;
fieldWidth, fieldHeight); pane.add(replaceField, gbc);
gbc.gridx = 1;
ypos += fieldHeight + SMALL; gbc.gridy = 2;
gbc.weighty = 0.0;
labelWidth = replaceLabel.getPreferredSize().width; gbc.fill = GridBagConstraints.NONE;
replaceLabel.setBounds(EDGE + (labelDimension.width-labelWidth), ypos + yoff, pane.add(checkboxPanel, gbc);
labelWidth, labelDimension.height); gbc.anchor = GridBagConstraints.CENTER;
replaceField.setBounds(EDGE + labelDimension.width + SMALL, ypos, gbc.gridwidth = 2;
fieldWidth, fieldHeight); gbc.gridx = 0;
gbc.gridy = 3;
ypos += fieldHeight + SMALL; gbc.insets = new Insets(12, 4, 4, 4);
pane.add(buttonPanel, gbc);
ignoreCaseBox.setBounds(EDGE + labelDimension.width + SMALL,
ypos,
(fieldWidth-SMALL)/4, fieldHeight);
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,
(fieldWidth-SMALL)/2, fieldHeight);
ypos += fieldHeight + SMALL;
buttons.setBounds(EDGE-BUTTONGAP, ypos,
buttonsDimension.width, buttonsDimension.height);
ypos += buttonsDimension.height;
// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int wide = visibleButtonWidth + EDGE*2;
int high = ypos; // butt.y + butt.height + EDGE*2 + SMALL;
pack(); pack();
Insets insets = getInsets(); setResizable(false);
//System.out.println("Insets = " + insets); // centers the dialog on thew screen
setSize(wide + insets.left + insets.right,high + insets.top + insets.bottom); setLocationRelativeTo(null);
setLocationRelativeTo( null ); // center
// setBounds((screen.width - wide) / 2, (screen.height - high) / 2, wide, high);
replaceButton.addActionListener(this);
replaceAllButton.addActionListener(this);
replaceFindButton.addActionListener(this);
findButton.addActionListener(this);
previousButton.addActionListener(this);
// you mustn't replace what you haven't found, my son
// semantics of replace are "replace the current selection with the replace field"
// so whether we have found before or not is irrelevent
// replaceButton.setEnabled(false);
// replaceFindButton.setEnabled(false);
// make the find button the blinky default // make the find button the blinky default
getRootPane().setDefaultButton(findButton); getRootPane().setDefaultButton(findButton);
@ -280,7 +248,6 @@ public class FindReplace extends JFrame implements ActionListener {
}); });
} }
public void handleClose() { public void handleClose() {
// System.out.println("handling close now"); // System.out.println("handling close now");
findString = findField.getText(); findString = findField.getText();
@ -290,7 +257,6 @@ public class FindReplace extends JFrame implements ActionListener {
setVisible(false); setVisible(false);
} }
/* /*
public void show() { public void show() {
findField.requestFocusInWindow(); findField.requestFocusInWindow();
@ -321,17 +287,18 @@ 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,boolean searchTabs,int originTab) { private boolean find(boolean wrap, boolean backwards, boolean searchTabs,
int originTab) {
// System.out.println("Find: " + originTab); // System.out.println("Find: " + originTab);
boolean wrapNeeded = false; 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
if (search.length() == 0) return false; if (search.length() == 0)
return false;
String text = editor.getText(); String text = editor.getText();
@ -378,8 +345,8 @@ public class FindReplace extends JFrame implements ActionListener {
originTab = realCurrentTab; originTab = realCurrentTab;
if (!wrap) if (!wrap)
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) || if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount())
(backwards && realCurrentTab - 1 < 0)) || (backwards && realCurrentTab - 1 < 0))
return false; // Can't continue without wrap return false; // Can't continue without wrap
if (backwards) { if (backwards) {
@ -399,7 +366,8 @@ public class FindReplace extends JFrame implements ActionListener {
} }
if (wrapNeeded) if (wrapNeeded)
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search,
0);
} }
if (nextIndex != -1) { if (nextIndex != -1) {
@ -410,10 +378,9 @@ public class FindReplace extends JFrame implements ActionListener {
return false; return false;
} }
/** /**
* Replace the current selection with whatever's in the * Replace the current selection with whatever's in the replacement text
* replacement text field. * field.
*/ */
public void replace() { public void replace() {
if (findField.getText().length() == 0) if (findField.getText().length() == 0)
@ -439,8 +406,8 @@ public class FindReplace extends JFrame implements ActionListener {
} }
/** /**
* Replace the current selection with whatever's in the * Replace the current selection with whatever's in the replacement text
* replacement text field, and then find the next match * field, and then find the next match
*/ */
public void replaceAndFindNext() { public void replaceAndFindNext() {
replace(); replace();
@ -448,8 +415,8 @@ public class FindReplace extends JFrame implements ActionListener {
} }
/** /**
* Replace everything that matches by doing find and replace * Replace everything that matches by doing find and replace alternately until
* alternately until nothing more found. * nothing more found.
*/ */
public void replaceAll() { public void replaceAll() {
if (findField.getText().length() == 0) if (findField.getText().length() == 0)

View File

@ -3,6 +3,7 @@ ARDUINO 1.6.0rc2
[ide] [ide]
* Reenabled speed of 38400 on serial monitor * Reenabled speed of 38400 on serial monitor
* Improved Find/Replace dialog layout (Eberhard Fahle)
[core] [core]
* Arduino "boolean" type is now mapped to "bool" instead of "uint8_t" (Christopher Andrews) * Arduino "boolean" type is now mapped to "bool" instead of "uint8_t" (Christopher Andrews)