[libpeas] [PeasUIPluginManager] Create a dialog to host the configure widget.



commit 47c6e958927a7040c40e4ba9509c59b297b691ab
Author: Steve Frécinaux <code istique net>
Date:   Thu Jul 1 14:02:00 2010 +0200

    [PeasUIPluginManager] Create a dialog to host the configure widget.
    
    With the PeasUIConfigurable API changed to return a widget instead of a
    dialog, we need to create the dialog to host that widget ourselves.
    
    Also we need to ensure plugins don't return a dialog.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621857

 libpeasui/peas-ui-plugin-manager.c                 |   23 ++++++++++++++++---
 .../helloworld/peasdemo-hello-world-plugin.c       |   20 +----------------
 peas-demo/plugins/seedhello/seedhello.js           |   13 +----------
 3 files changed, 21 insertions(+), 35 deletions(-)
---
diff --git a/libpeasui/peas-ui-plugin-manager.c b/libpeasui/peas-ui-plugin-manager.c
index 6ec929c..1533b79 100644
--- a/libpeasui/peas-ui-plugin-manager.c
+++ b/libpeasui/peas-ui-plugin-manager.c
@@ -200,7 +200,9 @@ configure_button_cb (GtkWidget           *button,
   PeasPluginInfo *info;
   PeasExtension *exten;
   GtkWindow *toplevel;
-  GtkWidget *conf_dlg = NULL;
+  GtkWidget *conf_widget = NULL;
+  GtkWidget *conf_dlg;
+  GtkWidget *vbox;
   GtkWindowGroup *wg;
 
   info = plugin_manager_get_selected_plugin (pm);
@@ -211,12 +213,24 @@ configure_button_cb (GtkWidget           *button,
 
   g_debug ("Calling create_configure_widget on %p", exten);
 
-  peas_extension_call (exten, "create_configure_widget", &conf_dlg);
+  peas_extension_call (exten, "create_configure_widget", &conf_widget);
+
   g_object_unref (exten);
-  g_return_if_fail (conf_dlg != NULL);
+  g_return_if_fail (GTK_IS_WIDGET (conf_widget));
+  g_return_if_fail (!GTK_IS_WINDOW (conf_widget));
 
   toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (pm)));
-  gtk_window_set_transient_for (GTK_WINDOW (conf_dlg), toplevel);
+
+  conf_dlg = gtk_dialog_new_with_buttons (peas_plugin_info_get_name (info),
+                                          toplevel,
+                                          GTK_DIALOG_NO_SEPARATOR,
+                                          GTK_STOCK_CLOSE,
+                                          GTK_RESPONSE_CLOSE,
+                                          NULL);
+  g_signal_connect (conf_dlg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+
+  vbox = gtk_dialog_get_content_area (GTK_DIALOG (conf_dlg));
+  gtk_box_pack_start (GTK_BOX (vbox), conf_widget, TRUE, TRUE, 0);
 
   if (gtk_window_has_group (toplevel))
     {
@@ -230,6 +244,7 @@ configure_button_cb (GtkWidget           *button,
 
   gtk_window_group_add_window (wg, GTK_WINDOW (conf_dlg));
 
+  gtk_window_set_transient_for (GTK_WINDOW (conf_dlg), toplevel);
   gtk_window_set_modal (GTK_WINDOW (conf_dlg), TRUE);
   gtk_widget_show_all (conf_dlg);
 }
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 73c1d97..effd081 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -105,30 +105,12 @@ peasdemo_hello_world_plugin_deactivate (PeasActivatable *activatable,
   g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
 }
 
-static void
-on_configure_dialog_response (GtkDialog *dialog,
-                              gint       response_id,
-                              gpointer   user_data)
-{
-  gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
 static GtkWidget *
 peasdemo_hello_world_plugin_create_configure_widget (PeasUIConfigurable  *configurable)
 {
-  GtkWidget *dialog;
-
   g_debug (G_STRFUNC);
 
-  dialog = gtk_message_dialog_new (NULL,
-                                   0,
-                                   GTK_MESSAGE_INFO,
-                                   GTK_BUTTONS_OK,
-                                   "This is a configuration dialog for the HelloWorld plugin.");
-  g_signal_connect (dialog, "response",
-                    G_CALLBACK (on_configure_dialog_response), NULL);
-
-  return dialog;
+  return gtk_label_new ("This is a configuration dialog for the HelloWorld plugin.");
 }
 
 static void
diff --git a/peas-demo/plugins/seedhello/seedhello.js b/peas-demo/plugins/seedhello/seedhello.js
index 95d3705..114309e 100644
--- a/peas-demo/plugins/seedhello/seedhello.js
+++ b/peas-demo/plugins/seedhello/seedhello.js
@@ -23,18 +23,7 @@ activatable_extension = {
 
 configurable_extension = {
   create_configure_widget: function () {
-    var dialog = new Gtk.Dialog({ title: "Seedhello Config Dialog" });
-    var label = new Gtk.Label({ label: "Example of configuration dialog for a Seed plugin" });
-
-    dialog.get_content_area().pack_start(label);
-    dialog.add_button(Gtk.STOCK_OK, 1);
-
-    dialog.signal.response.connect(function (w, response_id) {
-      print("Dialog button clicked");
-      dialog.destroy();
-    });
-
-    return dialog;
+    return new Gtk.Label({ label: "Example of configuration dialog for a Seed plugin" });
   }
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]