Observe window and only use it when it is open

This commit is contained in:
Kevin Sawicki 2016-12-20 15:52:58 -08:00
parent bb012c3db2
commit 87f09131aa

View file

@ -5,6 +5,7 @@
#include "atom/browser/ui/message_box.h" #include "atom/browser/ui/message_box.h"
#include "atom/browser/browser.h" #include "atom/browser/browser.h"
#include "atom/browser/native_window_observer.h"
#include "atom/browser/native_window_views.h" #include "atom/browser/native_window_views.h"
#include "atom/browser/unresponsive_suppressor.h" #include "atom/browser/unresponsive_suppressor.h"
#include "base/callback.h" #include "base/callback.h"
@ -25,7 +26,7 @@ namespace atom {
namespace { namespace {
class GtkMessageBox { class GtkMessageBox : public NativeWindowObserver {
public: public:
GtkMessageBox(NativeWindow* parent_window, GtkMessageBox(NativeWindow* parent_window,
MessageBoxType type, MessageBoxType type,
@ -77,6 +78,7 @@ class GtkMessageBox {
// Parent window. // Parent window.
if (parent_) { if (parent_) {
parent_->AddObserver(this);
parent_->SetEnabled(false); parent_->SetEnabled(false);
libgtk2ui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow()); libgtk2ui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE); gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
@ -85,8 +87,10 @@ class GtkMessageBox {
~GtkMessageBox() { ~GtkMessageBox() {
gtk_widget_destroy(dialog_); gtk_widget_destroy(dialog_);
if (parent_) if (parent_) {
parent_->RemoveObserver(this);
parent_->SetEnabled(true); parent_->SetEnabled(true);
}
} }
GtkMessageType GetMessageType(MessageBoxType type) { GtkMessageType GetMessageType(MessageBoxType type) {
@ -144,6 +148,11 @@ class GtkMessageBox {
Show(); Show();
} }
void OnWindowClosed() {
parent_->RemoveObserver(this);
parent_ = nullptr;
}
CHROMEGTK_CALLBACK_1(GtkMessageBox, void, OnResponseDialog, int); CHROMEGTK_CALLBACK_1(GtkMessageBox, void, OnResponseDialog, int);
private: private: