From f9135178d1ce2fa59b09f960247b6ea4236f53d9 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 22 Apr 2013 14:17:38 -0700 Subject: [PATCH] Add "Copy To Clipboard" button for compile errors (Paul Stoffregen) --- app/src/processing/app/EditorStatus.java | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index 57b7fba0ff..fbcd3fdb16 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -26,6 +26,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; +import java.awt.datatransfer.*; +import static processing.app.I18n._; /** @@ -68,6 +70,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { JButton okButton; JTextField editField; JProgressBar progressBar; + JButton copyErrorButton; //Thread promptThread; int response; @@ -108,6 +111,7 @@ public void empty() { public void notice(String message) { mode = NOTICE; this.message = message; + copyErrorButton.setVisible(false); //update(); repaint(); } @@ -120,6 +124,7 @@ public void unnotice(String unmessage) { public void error(String message) { mode = ERR; this.message = message; + copyErrorButton.setVisible(true); repaint(); } @@ -177,6 +182,7 @@ public void progress(String message) this.message = message; progressBar.setIndeterminate(false); progressBar.setVisible(true); + copyErrorButton.setVisible(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); repaint(); } @@ -189,6 +195,7 @@ public void progressIndeterminate(String message) progressBar.setIndeterminate(true); progressBar.setValue(50); progressBar.setVisible(true); + copyErrorButton.setVisible(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); repaint(); } @@ -207,6 +214,7 @@ public void unprogress() if (Preferences.getBoolean("editor.beep.compile")) { Toolkit.getDefaultToolkit().beep(); } + if (progressBar == null) return; progressBar.setVisible(false); progressBar.setValue(0); setCursor(null); @@ -216,6 +224,7 @@ public void unprogress() public void progressUpdate(int value) { + if (progressBar == null) return; progressBar.setValue(value); repaint(); } @@ -438,6 +447,29 @@ public void keyTyped(KeyEvent event) { add(progressBar); progressBar.setVisible(false); + copyErrorButton = new JButton(_("Copy To Clipboard")); + add(copyErrorButton); + //copyErrorButton.setVisible(true); + copyErrorButton.setVisible(false); + System.out.println("create copyErrorButton"); + copyErrorButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String message=""; + if ((Preferences.getBoolean("build.verbose")) == false) { + message = " " + _("This report would have more information with") + "\n"; + message += " \"" + _("Show verbose output during compilation") + "\"\n"; + message += " " + _("enabled in File > Preferences.") + "\n"; + } + message += _("Arduino: ") + Base.VERSION_NAME + " (" + System.getProperty("os.name") + "), "; + message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n"; + message += editor.console.consoleTextPane.getText().trim(); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection data = new StringSelection(message); + clipboard.setContents(data, null); + Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection(); + if (unixclipboard != null) unixclipboard.setContents(data, null); + } + }); } } @@ -470,6 +502,10 @@ protected void setButtonBounds() { editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop, editWidth, editHeight); progressBar.setBounds(noLeft, editTop, editWidth, editHeight); + + Dimension copyErrorButtonSize = copyErrorButton.getPreferredSize(); + copyErrorButton.setLocation(sizeW - copyErrorButtonSize.width - 5, top); + copyErrorButton.setSize(copyErrorButtonSize.width, Preferences.BUTTON_HEIGHT); }