|
36 | 36 | import cc.arduino.view.NotificationPopup;
|
37 | 37 | import processing.app.Base;
|
38 | 38 | import processing.app.BaseNoGui;
|
| 39 | +import processing.app.Editor; |
39 | 40 | import processing.app.I18n;
|
40 | 41 |
|
41 | 42 | import javax.swing.*;
|
42 | 43 | import javax.swing.event.HyperlinkListener;
|
| 44 | + |
| 45 | +import java.awt.event.WindowEvent; |
| 46 | +import java.awt.event.WindowFocusListener; |
43 | 47 | import java.util.TimerTask;
|
44 | 48 |
|
45 | 49 | import static processing.app.I18n.tr;
|
@@ -95,8 +99,30 @@ public void run() {
|
95 | 99 | }
|
96 | 100 |
|
97 | 101 | SwingUtilities.invokeLater(() -> {
|
98 |
| - notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text); |
99 |
| - notificationPopup.setVisible(true); |
| 102 | + Editor ed = base.getActiveEditor(); |
| 103 | + notificationPopup = new NotificationPopup(ed, hyperlinkListener, text); |
| 104 | + if (ed.isFocused()) { |
| 105 | + notificationPopup.setVisible(true); |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + // If the IDE is not focused wait until it is focused again to |
| 110 | + // display the notification, this avoids the annoying side effect |
| 111 | + // to "steal" the focus from another application. |
| 112 | + WindowFocusListener wfl = new WindowFocusListener() { |
| 113 | + @Override |
| 114 | + public void windowLostFocus(WindowEvent evt) { |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void windowGainedFocus(WindowEvent evt) { |
| 119 | + notificationPopup.setVisible(true); |
| 120 | + for (Editor e : base.getEditors()) |
| 121 | + e.removeWindowFocusListener(this); |
| 122 | + } |
| 123 | + }; |
| 124 | + for (Editor e : base.getEditors()) |
| 125 | + e.addWindowFocusListener(wfl); |
100 | 126 | });
|
101 | 127 | }
|
102 | 128 |
|
|
0 commit comments