Skip to content

Commit 0c45335

Browse files
committedApr 4, 2016
Merge branch 'fix-annoying-popup'
2 parents 84fdb0c + 8d7ee63 commit 0c45335

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed
 

‎app/src/cc/arduino/contributions/ContributionsSelfCheck.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@
3636
import cc.arduino.view.NotificationPopup;
3737
import processing.app.Base;
3838
import processing.app.BaseNoGui;
39+
import processing.app.Editor;
3940
import processing.app.I18n;
4041

4142
import javax.swing.*;
4243
import javax.swing.event.HyperlinkListener;
44+
45+
import java.awt.event.WindowEvent;
46+
import java.awt.event.WindowFocusListener;
4347
import java.util.TimerTask;
4448

4549
import static processing.app.I18n.tr;
@@ -95,8 +99,30 @@ public void run() {
9599
}
96100

97101
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.begin();
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.begin();
120+
for (Editor e : base.getEditors())
121+
e.removeWindowFocusListener(this);
122+
}
123+
};
124+
for (Editor e : base.getEditors())
125+
e.addWindowFocusListener(wfl);
100126
});
101127
}
102128

‎app/src/cc/arduino/view/NotificationPopup.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import java.awt.event.MouseEvent;
4343
import java.awt.event.WindowAdapter;
4444
import java.awt.event.WindowEvent;
45+
import java.util.Timer;
46+
import java.util.TimerTask;
4547

4648
import javax.swing.ImageIcon;
4749
import javax.swing.JButton;
@@ -52,16 +54,18 @@
5254
import javax.swing.border.LineBorder;
5355
import javax.swing.event.HyperlinkListener;
5456

57+
import cc.arduino.Constants;
5558
import processing.app.Theme;
5659

5760
public class NotificationPopup extends JDialog {
5861

62+
private Timer autoCloseTimer = new Timer(false);
63+
5964
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
6065
String message) {
6166
super(parent, false);
6267
setLayout(new FlowLayout());
6368
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
64-
setAlwaysOnTop(true);
6569
setUndecorated(true);
6670
setResizable(false);
6771

@@ -131,6 +135,17 @@ private void updateLocation(Frame parent) {
131135
}
132136

133137
public void close() {
138+
autoCloseTimer.cancel();
134139
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
135140
}
141+
142+
public void begin() {
143+
autoCloseTimer.schedule(new TimerTask() {
144+
@Override
145+
public void run() {
146+
close();
147+
}
148+
}, Constants.NOTIFICATION_POPUP_AUTOCLOSE_DELAY);
149+
setVisible(true);
150+
}
136151
}

‎arduino-core/src/cc/arduino/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Constants {
4444
public static final String LIBRARY_DEVELOPMENT_FLAG_FILE = ".development";
4545

4646
public static final long BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD = 60000;
47-
public static final int NOTIFICATION_POPUP_AUTOCLOSE_DELAY = 10000;
47+
public static final long NOTIFICATION_POPUP_AUTOCLOSE_DELAY = 10000;
4848

4949
public static final String PROXY_TYPE_NONE = "none";
5050
public static final String PROXY_TYPE_AUTO = "auto";

‎build/shared/revisions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARDUINO 1.6.9
33
[ide]
44
* Catch and report errors during parsing contributed index files
55
* Fixed IDE version color on about dialog box. Thanks @ivanebernal
6+
* The "always-on-top update notification" popup is now less intrusive.
67

78
[core]
89
* sam: Allow 3rd party boards that depend on SAM core to use their own

0 commit comments

Comments
 (0)
Please sign in to comment.