284
290
setPlacement(location);
287
// If the window is resized too small this will resize it again to the
288
// minimums. Adapted by Chris Lonnen from comments here:
289
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4320050
290
// as a fix for http://dev.processing.org/bugs/show_bug.cgi?id=25
291
final int minW = Preferences.getInteger("editor.window.width.min");
292
final int minH = Preferences.getInteger("editor.window.height.min");
293
addComponentListener(new java.awt.event.ComponentAdapter() {
294
public void componentResized(ComponentEvent event) {
295
setSize((getWidth() < minW) ? minW : getWidth(),
296
(getHeight() < minH) ? minH : getHeight());
293
// Set the minimum size for the editor window
294
setMinimumSize(new Dimension(Preferences.getInteger("editor.window.width.min"),
295
Preferences.getInteger("editor.window.height.min")));
300
296
// System.out.println("t3");
302
298
// Bring back the general options for the editor
503
500
fileMenu.add(item);
505
502
if (sketchbookMenu == null) {
506
sketchbookMenu = new JMenu("Sketchbook");
503
sketchbookMenu = new JMenu(_("Sketchbook"));
507
504
base.rebuildSketchbookMenu(sketchbookMenu);
509
506
fileMenu.add(sketchbookMenu);
511
508
if (examplesMenu == null) {
512
examplesMenu = new JMenu("Examples");
509
examplesMenu = new JMenu(_("Examples"));
513
510
base.rebuildExamplesMenu(examplesMenu);
515
512
fileMenu.add(examplesMenu);
517
item = Editor.newJMenuItem("Close", 'W');
514
item = Editor.newJMenuItem(_("Close"), 'W');
518
515
item.addActionListener(new ActionListener() {
519
516
public void actionPerformed(ActionEvent e) {
520
517
base.handleClose(Editor.this);
1232
1233
// TODO find next should only be enabled after a
1233
1234
// search has actually taken place
1234
item = newJMenuItem("Find Next", 'G');
1235
item.addActionListener(new ActionListener() {
1236
public void actionPerformed(ActionEvent e) {
1239
//FindReplace find = new FindReplace(Editor.this); //.show();
1235
item = newJMenuItem(_("Find Next"), 'G');
1236
item.addActionListener(new ActionListener() {
1237
public void actionPerformed(ActionEvent e) {
1245
item = newJMenuItemShift(_("Find Previous"), 'G');
1246
item.addActionListener(new ActionListener() {
1247
public void actionPerformed(ActionEvent e) {
1249
find.findPrevious();
1255
item = newJMenuItem(_("Use Selection For Find"), 'E');
1256
item.addActionListener(new ActionListener() {
1257
public void actionPerformed(ActionEvent e) {
1259
find = new FindReplace(Editor.this);
1261
find.setFindText( getSelectedText() );
1244
1264
menu.add(item);
1977
2003
// Pane formatting adapted from the quaqua guide
1978
2004
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
1979
2005
JOptionPane pane =
1980
new JOptionPane("<html> " +
1981
"<head> <style type=\"text/css\">"+
1982
"b { font: 13pt \"Lucida Grande\" }"+
1983
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
1984
"</style> </head>" +
1985
"<b>Do you want to save changes to this sketch<BR>" +
1986
" before closing?</b>" +
1987
"<p>If you don't save, your changes will be lost.",
2006
new JOptionPane(_("<html> " +
2007
"<head> <style type=\"text/css\">"+
2008
"b { font: 13pt \"Lucida Grande\" }"+
2009
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
2010
"</style> </head>" +
2011
"<b>Do you want to save changes to this sketch<BR>" +
2012
" before closing?</b>" +
2013
"<p>If you don't save, your changes will be lost."),
1988
2014
JOptionPane.QUESTION_MESSAGE);
1990
2016
String[] options = new String[] {
1991
"Save", "Cancel", "Don't Save"
2017
_("Save"), _("Cancel"), _("Don't Save")
1993
2019
pane.setOptions(options);
2040
2066
* modifications (if any) to the previous sketch need to be saved.
2042
2068
protected boolean handleOpenInternal(String path) {
2043
// rename .pde files to .ino
2044
File[] oldFiles = (new File(path)).getParentFile().listFiles(new FilenameFilter() {
2045
public boolean accept(File dir, String name) {
2046
return (name.toLowerCase().endsWith(".pde"));
2050
if (oldFiles != null && oldFiles.length > 0) {
2051
if (!Preferences.getBoolean("editor.update_extension")) {
2052
Object[] options = { "OK", "Cancel" };
2054
"In Arduino 1.0, the file extension for sketches changed\n" +
2055
"from \".pde\" to \".ino\". This version of the software only\n" +
2056
"supports the new extension. Rename the files in this sketch\n" +
2057
"(and future sketches) and continue?";
2059
int result = JOptionPane.showOptionDialog(this,
2062
JOptionPane.YES_NO_OPTION,
2063
JOptionPane.QUESTION_MESSAGE,
2067
if (result != JOptionPane.YES_OPTION) {
2071
Preferences.setBoolean("editor.update_extension", true);
2074
for (int i = 0; i < oldFiles.length; i++) {
2075
String oldPath = oldFiles[i].getPath();
2076
File newFile = new File(oldPath.substring(0, oldPath.length() - 4) + ".ino");
2078
Base.copyFile(oldFiles[i], newFile);
2079
} catch (IOException e) {
2080
Base.showWarning("Error", "Could not copy to a proper location.", e);
2084
// remove the original file, so user doesn't get confused
2085
oldFiles[i].delete();
2087
// update with the new path
2088
if (oldFiles[i].compareTo(new File(path)) == 0) {
2089
path = newFile.getAbsolutePath();
2094
2069
// check to make sure that this .pde file is
2095
2070
// in a folder of the same name
2096
2071
File file = new File(path);
2097
File parentFile = new File(file.getParent());
2098
String parentName = parentFile.getName();
2099
String pdeName = parentName + ".ino";
2100
File altFile = new File(file.getParent(), pdeName);
2072
String fileName = file.getName();
2073
File parent = file.getParentFile();
2074
String parentName = parent.getName();
2075
String pdeName = parentName + ".pde";
2076
File altPdeFile = new File(parent, pdeName);
2077
String inoName = parentName + ".ino";
2078
File altInoFile = new File(parent, pdeName);
2102
if (pdeName.equals(file.getName())) {
2080
if (pdeName.equals(fileName) || inoName.equals(fileName)) {
2103
2081
// no beef with this guy
2105
} else if (altFile.exists()) {
2106
// user selected a .java from the same sketch,
2107
// but open the .pde instead
2108
path = altFile.getAbsolutePath();
2109
//System.out.println("found alt file in same folder");
2111
} else if (!path.endsWith(".ino")) {
2112
Base.showWarning("Bad file selected",
2113
"Processing can only open its own sketches\n" +
2114
"and other files ending in .ino", null);
2083
} else if (altPdeFile.exists()) {
2084
// user selected a .java from the same sketch, but open the .pde instead
2085
path = altPdeFile.getAbsolutePath();
2086
} else if (altInoFile.exists()) {
2087
path = altInoFile.getAbsolutePath();
2088
} else if (!path.endsWith(".ino") && !path.endsWith(".pde")) {
2089
Base.showWarning(_("Bad file selected"),
2090
_("Processing can only open its own sketches\n" +
2091
"and other files ending in .ino or .pde"), null);
2118
2095
String properParent =
2119
file.getName().substring(0, file.getName().length() - 4);
2096
fileName.substring(0, fileName.length() - 4);
2121
Object[] options = { "OK", "Cancel" };
2123
"The file \"" + file.getName() + "\" needs to be inside\n" +
2124
"a sketch folder named \"" + properParent + "\".\n" +
2125
"Create this folder, move the file, and continue?";
2098
Object[] options = { _("OK"), _("Cancel") };
2099
String prompt = I18n.format(
2100
_("The file \"{0}\" needs to be inside\n" +
2101
"a sketch folder named \"{1}\".\n" +
2102
"Create this folder, move the file, and continue?"),
2127
2107
int result = JOptionPane.showOptionDialog(this,
2130
2110
JOptionPane.YES_NO_OPTION,
2131
2111
JOptionPane.QUESTION_MESSAGE,
2137
2117
// create properly named folder
2138
2118
File properFolder = new File(file.getParent(), properParent);
2139
2119
if (properFolder.exists()) {
2140
Base.showWarning("Error",
2141
"A folder named \"" + properParent + "\" " +
2142
"already exists. Can't open sketch.", null);
2120
Base.showWarning(_("Error"),
2122
_("A folder named \"{0}\" already exists. " +
2123
"Can't open sketch."),
2145
2129
if (!properFolder.mkdirs()) {
2146
2130
//throw new IOException("Couldn't create sketch folder");
2147
Base.showWarning("Error",
2148
"Could not create the sketch folder.", null);
2131
Base.showWarning(_("Error"),
2132
_("Could not create the sketch folder."), null);
2151
2135
// copy the sketch inside
2457
2455
protected void handleBurnBootloader() {
2458
2456
console.clear();
2459
statusNotice("Burning bootloader to I/O Board (this may take a minute)...");
2457
statusNotice(_("Burning bootloader to I/O Board (this may take a minute)..."));
2460
2458
SwingUtilities.invokeLater(new Runnable() {
2461
2459
public void run() {
2463
2461
Uploader uploader = new AvrdudeUploader();
2464
2462
if (uploader.burnBootloader()) {
2465
statusNotice("Done burning bootloader.");
2463
statusNotice(_("Done burning bootloader."));
2467
statusError("Error while burning bootloader.");
2465
statusError(_("Error while burning bootloader."));
2468
2466
// error message will already be visible
2470
2468
} catch (RunnerException e) {
2471
statusError("Error while burning bootloader.");
2469
statusError(_("Error while burning bootloader."));
2472
2470
e.printStackTrace();
2473
2471
//statusError(e);
2474
2472
} catch (Exception e) {
2475
statusError("Error while burning bootloader.");
2473
statusError(_("Error while burning bootloader."));
2476
2474
e.printStackTrace();
2616
2614
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2616
protected void onBoardOrPortChange() {
2617
Map<String, String> boardPreferences = Base.getBoardPreferences();
2618
lineStatus.setBoardName(boardPreferences.get("name"));
2619
lineStatus.setSerialPort(Preferences.get("serial.port"));
2620
lineStatus.repaint();
2620
2625
* Returns the edit popup menu.
2622
2627
class TextAreaPopup extends JPopupMenu {
2623
//String currentDir = System.getProperty("user.dir");
2624
String referenceFile = null;
2628
JMenuItem discourseItem;
2629
JMenuItem referenceItem;
2628
//private String currentDir = System.getProperty("user.dir");
2629
private String referenceFile = null;
2631
private JMenuItem cutItem;
2632
private JMenuItem copyItem;
2633
private JMenuItem discourseItem;
2634
private JMenuItem referenceItem;
2635
private JMenuItem openURLItem;
2636
private JSeparator openURLItemSeparator;
2638
private String clickedURL;
2632
2640
public TextAreaPopup() {
2635
cutItem = new JMenuItem("Cut");
2641
openURLItem = new JMenuItem(_("Open URL"));
2642
openURLItem.addActionListener(new ActionListener() {
2643
public void actionPerformed(ActionEvent e) {
2644
Base.openURL(clickedURL);
2649
openURLItemSeparator = new JSeparator();
2650
add(openURLItemSeparator);
2652
cutItem = new JMenuItem(_("Cut"));
2636
2653
cutItem.addActionListener(new ActionListener() {
2637
2654
public void actionPerformed(ActionEvent e) {
2643
copyItem = new JMenuItem("Copy");
2660
copyItem = new JMenuItem(_("Copy"));
2644
2661
copyItem.addActionListener(new ActionListener() {
2645
2662
public void actionPerformed(ActionEvent e) {
2651
discourseItem = new JMenuItem("Copy for Forum");
2668
discourseItem = new JMenuItem(_("Copy for Forum"));
2652
2669
discourseItem.addActionListener(new ActionListener() {
2653
2670
public void actionPerformed(ActionEvent e) {
2654
2671
handleDiscourseCopy();
2657
this.add(discourseItem);
2659
discourseItem = new JMenuItem("Copy as HTML");
2676
discourseItem = new JMenuItem(_("Copy as HTML"));
2660
2677
discourseItem.addActionListener(new ActionListener() {
2661
2678
public void actionPerformed(ActionEvent e) {
2662
2679
handleHTMLCopy();
2665
this.add(discourseItem);
2667
item = new JMenuItem("Paste");
2684
JMenuItem item = new JMenuItem(_("Paste"));
2668
2685
item.addActionListener(new ActionListener() {
2669
2686
public void actionPerformed(ActionEvent e) {
2675
item = new JMenuItem("Select All");
2692
item = new JMenuItem(_("Select All"));
2676
2693
item.addActionListener(new ActionListener() {
2677
2694
public void actionPerformed(ActionEvent e) {
2678
2695
handleSelectAll();
2683
this.addSeparator();
2685
item = new JMenuItem("Comment/Uncomment");
2702
item = new JMenuItem(_("Comment/Uncomment"));
2686
2703
item.addActionListener(new ActionListener() {
2687
2704
public void actionPerformed(ActionEvent e) {
2688
2705
handleCommentUncomment();
2693
item = new JMenuItem("Increase Indent");
2710
item = new JMenuItem(_("Increase Indent"));
2694
2711
item.addActionListener(new ActionListener() {
2695
2712
public void actionPerformed(ActionEvent e) {
2696
2713
handleIndentOutdent(true);
2701
item = new JMenuItem("Decrease Indent");
2718
item = new JMenuItem(_("Decrease Indent"));
2702
2719
item.addActionListener(new ActionListener() {
2703
2720
public void actionPerformed(ActionEvent e) {
2704
2721
handleIndentOutdent(false);
2709
this.addSeparator();
2711
referenceItem = new JMenuItem("Find in Reference");
2728
referenceItem = new JMenuItem(_("Find in Reference"));
2712
2729
referenceItem.addActionListener(new ActionListener() {
2713
2730
public void actionPerformed(ActionEvent e) {
2714
2731
handleFindReference();
2717
this.add(referenceItem);
2720
2737
// if no text is selected, disable copy and cut menu items
2721
2738
public void show(Component component, int x, int y) {
2739
int lineNo = textarea.getLineOfOffset(textarea.xyToOffset(x, y));
2740
int offset = textarea.xToOffset(lineNo, x);
2741
String line = textarea.getLineText(lineNo);
2742
clickedURL = textarea.checkClickedURL(line, offset);
2743
if (clickedURL != null) {
2744
openURLItem.setVisible(true);
2745
openURLItemSeparator.setVisible(true);
2747
openURLItem.setVisible(false);
2748
openURLItemSeparator.setVisible(false);
2722
2751
if (textarea.isSelectionActive()) {
2723
2752
cutItem.setEnabled(true);
2724
2753
copyItem.setEnabled(true);