mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
linux: Disable parent window when showing modal dialogs (#6160)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
@@ -40,7 +40,8 @@ class FileChooserDialog {
|
||||
const std::string& button_label,
|
||||
const base::FilePath& default_path,
|
||||
const Filters& filters)
|
||||
: dialog_scope_(parent_window),
|
||||
: parent_(static_cast<atom::NativeWindowViews*>(parent_window)),
|
||||
dialog_scope_(parent_window),
|
||||
filters_(filters) {
|
||||
const char* confirm_text = GTK_STOCK_OK;
|
||||
|
||||
@@ -58,9 +59,10 @@ class FileChooserDialog {
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
confirm_text, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
if (parent_window) {
|
||||
gfx::NativeWindow window = parent_window->GetNativeWindow();
|
||||
libgtk2ui::SetGtkTransientForAura(dialog_, window);
|
||||
if (parent_) {
|
||||
parent_->SetEnabled(false);
|
||||
libgtk2ui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
}
|
||||
|
||||
if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
||||
@@ -69,8 +71,6 @@ class FileChooserDialog {
|
||||
if (action != GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||
gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(dialog_), TRUE);
|
||||
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
|
||||
if (!default_path.empty()) {
|
||||
if (base::DirectoryExists(default_path)) {
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
||||
@@ -89,6 +89,8 @@ class FileChooserDialog {
|
||||
|
||||
virtual ~FileChooserDialog() {
|
||||
gtk_widget_destroy(dialog_);
|
||||
if (parent_)
|
||||
parent_->SetEnabled(true);
|
||||
}
|
||||
|
||||
void RunAsynchronous() {
|
||||
@@ -143,6 +145,7 @@ class FileChooserDialog {
|
||||
void AddFilters(const Filters& filters);
|
||||
base::FilePath AddExtensionForFilename(const gchar* filename) const;
|
||||
|
||||
atom::NativeWindowViews* parent_;
|
||||
atom::NativeWindow::DialogScope dialog_scope_;
|
||||
|
||||
GtkWidget* dialog_;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
@@ -36,7 +36,8 @@ class GtkMessageBox {
|
||||
const std::string& detail,
|
||||
const gfx::ImageSkia& icon)
|
||||
: dialog_scope_(parent_window),
|
||||
cancel_id_(cancel_id) {
|
||||
cancel_id_(cancel_id),
|
||||
parent_(static_cast<NativeWindowViews*>(parent_window)) {
|
||||
// Create dialog.
|
||||
dialog_ = gtk_message_dialog_new(
|
||||
nullptr, // parent
|
||||
@@ -75,14 +76,17 @@ class GtkMessageBox {
|
||||
}
|
||||
|
||||
// Parent window.
|
||||
if (parent_window) {
|
||||
gfx::NativeWindow window = parent_window->GetNativeWindow();
|
||||
libgtk2ui::SetGtkTransientForAura(dialog_, window);
|
||||
if (parent_) {
|
||||
parent_->SetEnabled(false);
|
||||
libgtk2ui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
~GtkMessageBox() {
|
||||
gtk_widget_destroy(dialog_);
|
||||
if (parent_)
|
||||
parent_->SetEnabled(true);
|
||||
}
|
||||
|
||||
GtkMessageType GetMessageType(MessageBoxType type) {
|
||||
@@ -123,7 +127,6 @@ class GtkMessageBox {
|
||||
}
|
||||
|
||||
int RunSynchronous() {
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
Show();
|
||||
int response = gtk_dialog_run(GTK_DIALOG(dialog_));
|
||||
if (response < 0)
|
||||
@@ -149,6 +152,7 @@ class GtkMessageBox {
|
||||
// The id to return when the dialog is closed without pressing buttons.
|
||||
int cancel_id_;
|
||||
|
||||
NativeWindowViews* parent_;
|
||||
GtkWidget* dialog_;
|
||||
MessageBoxCallback callback_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user