Skip to content

Commit f913517

Browse files
Add "Copy To Clipboard" button for compile errors (Paul Stoffregen)
1 parent d66930f commit f913517

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

app/src/processing/app/EditorStatus.java

+36
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.awt.*;
2727
import java.awt.event.*;
2828
import javax.swing.*;
29+
import java.awt.datatransfer.*;
30+
import static processing.app.I18n._;
2931

3032

3133
/**
@@ -68,6 +70,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
6870
JButton okButton;
6971
JTextField editField;
7072
JProgressBar progressBar;
73+
JButton copyErrorButton;
7174

7275
//Thread promptThread;
7376
int response;
@@ -108,6 +111,7 @@ public void empty() {
108111
public void notice(String message) {
109112
mode = NOTICE;
110113
this.message = message;
114+
copyErrorButton.setVisible(false);
111115
//update();
112116
repaint();
113117
}
@@ -120,6 +124,7 @@ public void unnotice(String unmessage) {
120124
public void error(String message) {
121125
mode = ERR;
122126
this.message = message;
127+
copyErrorButton.setVisible(true);
123128
repaint();
124129
}
125130

@@ -177,6 +182,7 @@ public void progress(String message)
177182
this.message = message;
178183
progressBar.setIndeterminate(false);
179184
progressBar.setVisible(true);
185+
copyErrorButton.setVisible(false);
180186
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
181187
repaint();
182188
}
@@ -189,6 +195,7 @@ public void progressIndeterminate(String message)
189195
progressBar.setIndeterminate(true);
190196
progressBar.setValue(50);
191197
progressBar.setVisible(true);
198+
copyErrorButton.setVisible(false);
192199
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
193200
repaint();
194201
}
@@ -207,6 +214,7 @@ public void unprogress()
207214
if (Preferences.getBoolean("editor.beep.compile")) {
208215
Toolkit.getDefaultToolkit().beep();
209216
}
217+
if (progressBar == null) return;
210218
progressBar.setVisible(false);
211219
progressBar.setValue(0);
212220
setCursor(null);
@@ -216,6 +224,7 @@ public void unprogress()
216224

217225
public void progressUpdate(int value)
218226
{
227+
if (progressBar == null) return;
219228
progressBar.setValue(value);
220229
repaint();
221230
}
@@ -438,6 +447,29 @@ public void keyTyped(KeyEvent event) {
438447
add(progressBar);
439448
progressBar.setVisible(false);
440449

450+
copyErrorButton = new JButton(_("Copy To Clipboard"));
451+
add(copyErrorButton);
452+
//copyErrorButton.setVisible(true);
453+
copyErrorButton.setVisible(false);
454+
System.out.println("create copyErrorButton");
455+
copyErrorButton.addActionListener(new ActionListener() {
456+
public void actionPerformed(ActionEvent e) {
457+
String message="";
458+
if ((Preferences.getBoolean("build.verbose")) == false) {
459+
message = " " + _("This report would have more information with") + "\n";
460+
message += " \"" + _("Show verbose output during compilation") + "\"\n";
461+
message += " " + _("enabled in File > Preferences.") + "\n";
462+
}
463+
message += _("Arduino: ") + Base.VERSION_NAME + " (" + System.getProperty("os.name") + "), ";
464+
message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n";
465+
message += editor.console.consoleTextPane.getText().trim();
466+
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
467+
StringSelection data = new StringSelection(message);
468+
clipboard.setContents(data, null);
469+
Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection();
470+
if (unixclipboard != null) unixclipboard.setContents(data, null);
471+
}
472+
});
441473
}
442474
}
443475

@@ -470,6 +502,10 @@ protected void setButtonBounds() {
470502
editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop,
471503
editWidth, editHeight);
472504
progressBar.setBounds(noLeft, editTop, editWidth, editHeight);
505+
506+
Dimension copyErrorButtonSize = copyErrorButton.getPreferredSize();
507+
copyErrorButton.setLocation(sizeW - copyErrorButtonSize.width - 5, top);
508+
copyErrorButton.setSize(copyErrorButtonSize.width, Preferences.BUTTON_HEIGHT);
473509
}
474510

475511

0 commit comments

Comments
 (0)