From 3aaaef2cc114154f8f2c4fda068ea4fb245afa91 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 13 Jun 2012 15:36:47 -0700 Subject: [PATCH] Add support for displaying alerts --- Atom-Linux/atom.cpp | 1 + Atom-Linux/native_handler.cpp | 46 +++++++++++++++++++++++++++++++++++ Atom-Linux/native_handler.h | 4 +++ 3 files changed, 51 insertions(+) diff --git a/Atom-Linux/atom.cpp b/Atom-Linux/atom.cpp index e6938bf76..4fbd532c6 100644 --- a/Atom-Linux/atom.cpp +++ b/Atom-Linux/atom.cpp @@ -88,6 +88,7 @@ int main(int argc, char *argv[]) { // Create the handler. g_handler = new ClientHandler(); g_handler->SetMainHwnd(vbox); + g_handler->SetWindow(window); // Create the browser view. CefWindowInfo window_info; diff --git a/Atom-Linux/native_handler.cpp b/Atom-Linux/native_handler.cpp index f0c918da7..8293a6c97 100644 --- a/Atom-Linux/native_handler.cpp +++ b/Atom-Linux/native_handler.cpp @@ -291,6 +291,50 @@ void NativeHandler::Remove(const CefString& name, CefRefPtr object, DeleteContents(pathArgument); } +void NativeHandler::Alert(const CefString& name, CefRefPtr object, + const CefV8ValueList& arguments, CefRefPtr& retval, + CefString& exception) { + CefRefPtr buttonNamesAndCallbacks; + if (arguments.size() < 3) + buttonNamesAndCallbacks = CefV8Value::CreateArray(); + else + buttonNamesAndCallbacks = arguments[2]; + + GtkWidget *dialog; + dialog = gtk_dialog_new_with_buttons("atom", GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, NULL); + for (int i = 0; i < buttonNamesAndCallbacks->GetArrayLength(); i++) { + string title = + buttonNamesAndCallbacks->GetValue(i)->GetValue(0)->GetStringValue().ToString(); + gtk_dialog_add_button(GTK_DIALOG(dialog), title.c_str(), i); + } + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + + string dialogMessage(arguments[0]->GetStringValue().ToString()); + dialogMessage.append("\n"); + dialogMessage.append("\n"); + dialogMessage.append(arguments[1]->GetStringValue().ToString()); + GtkWidget *label; + label = gtk_label_new(dialogMessage.c_str()); + + GtkWidget *contentArea; + contentArea = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_container_add(GTK_CONTAINER(contentArea), label); + + gtk_widget_show_all(dialog); + int result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result >= 0) { + CefRefPtr callback = buttonNamesAndCallbacks->GetValue( + result)->GetValue(1); + CefV8ValueList args; + CefRefPtr e; + callback->ExecuteFunction(callback, args, retval, e, true); + if (e) + exception = e->GetMessage(); + } + gtk_widget_destroy(dialog); +} + bool NativeHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) { @@ -326,6 +370,8 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr object, Move(name, object, arguments, retval, exception); else if (name == "remove") Remove(name, object, arguments, retval, exception); + else if (name == "alert") + Alert(name, object, arguments, retval, exception); else cout << "Unhandled -> " + name.ToString() << " : " << arguments[0]->GetStringValue().ToString() << endl; diff --git a/Atom-Linux/native_handler.h b/Atom-Linux/native_handler.h index 8b8b8b3fd..45e2cc3a1 100644 --- a/Atom-Linux/native_handler.h +++ b/Atom-Linux/native_handler.h @@ -82,6 +82,10 @@ private: void Remove(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception); + + void Alert(const CefString& name, CefRefPtr object, + const CefV8ValueList& arguments, CefRefPtr& retval, + CefString& exception); }; #endif