[Xfce4-commits] <xfce4-panel:devel> * Fix some issues in the remote add code and add dialog to choose a panel.

Nick Schermer nick at xfce.org
Tue Aug 11 20:22:09 CEST 2009


Updating branch refs/heads/devel
         to f3fe9edec774429c81038534e65a91cfcf673cc8 (commit)
       from 416942fab63f48bcd02947ea7bae4add8f4583b5 (commit)

commit f3fe9edec774429c81038534e65a91cfcf673cc8
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Jun 16 23:06:20 2008 +0200

    * Fix some issues in the remote add code and add dialog to choose a panel.

 Panel-desktop-handler.desktop.in.in |    1 +
 panel/main.c                        |    3 ++
 panel/panel-application.c           |   26 ++++++++++++---
 panel/panel-dialogs.c               |   61 +++++++++++++++++++++++++++++++++++
 panel/panel-dialogs.h               |    4 ++-
 panel/panel-module-factory.c        |   12 +++++++
 panel/panel-module-factory.h        |    3 ++
 7 files changed, 104 insertions(+), 6 deletions(-)

diff --git a/Panel-desktop-handler.desktop.in.in b/Panel-desktop-handler.desktop.in.in
index cfa027d..f37c688 100644
--- a/Panel-desktop-handler.desktop.in.in
+++ b/Panel-desktop-handler.desktop.in.in
@@ -7,6 +7,7 @@ TryExec=xfce4-panel
 Exec=xfce4-panel --add=launcher %F
 Icon=application-x-executable
 Terminal=false
+Hidden=true
 StartupNotify=true
 Type=Application
 MimeType=application/x-desktop;
diff --git a/panel/main.c b/panel/main.c
index d709246..db814c1 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -141,6 +141,9 @@ main (gint argc, gchar **argv)
     }
   else if (opt_add)
     {
+      /* stop any running startup notification */
+      gdk_notify_startup_complete ();
+
       /* send a add new item signal to the running instance */
       result = panel_dbus_client_add_new_item (opt_add, arguments, &error);
 
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 9e91255..b478d7c 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -38,6 +38,7 @@
 #include <panel/panel-module-factory.h>
 #include <panel/panel-preferences-dialog.h>
 #include <panel/panel-item-dialog.h>
+#include <panel/panel-dialogs.h>
 #include <panel/panel-glue.h>
 
 #define PANEL_CONFIG_PATH "xfce4" G_DIR_SEPARATOR_S "panel" G_DIR_SEPARATOR_S "panels.new.xml"
@@ -823,16 +824,31 @@ panel_application_add_new_item (PanelApplication  *application,
                                 gchar            **arguments)
 {
   PanelWindow *window;
+  gint         nth = 0;
 
   panel_return_if_fail (PANEL_IS_APPLICATION (application));
   panel_return_if_fail (plugin_name != NULL);
+  panel_return_if_fail (g_slist_length (application->windows) > 0);
 
-  /* TODO fix this */
-  window = application->windows->data;
+  if (panel_module_factory_has_plugin (application->factory, plugin_name))
+    {
+      /* ask the user what panel to use if there is more then one */
+      if (g_slist_length (application->windows) > 1)
+        if ((nth = panel_dialogs_choose_panel (application->windows)) == -1)
+          return;
+
+      /* get the window */
+      window = g_slist_nth_data (application->windows, nth);
 
-  if (!panel_application_insert_plugin (application, window, gtk_widget_get_screen (GTK_WIDGET (window)),
-                                        plugin_name, NULL, arguments, FROM_DESKTOP_FILE, -1))
-    g_warning (_("The plugin you want to add is not recognized by the panel."), plugin_name);
+      /* add the panel to the end of the choosen window */
+      panel_application_insert_plugin (application, window, gtk_widget_get_screen (GTK_WIDGET (window)),
+                                       plugin_name, NULL, arguments, FROM_DESKTOP_FILE, -1);
+    }
+  else
+    {
+      /* print warning */
+      g_warning (_("The plugin (%s) you want to add is not recognized by the panel."), plugin_name);
+    }
 }
 
 
diff --git a/panel/panel-dialogs.c b/panel/panel-dialogs.c
index 1d90e70..b9f93a7 100644
--- a/panel/panel-dialogs.c
+++ b/panel/panel-dialogs.c
@@ -25,6 +25,7 @@
 
 #include <exo/exo.h>
 #include <libxfce4util/libxfce4util.h>
+#include <libxfce4panel/libxfce4panel.h>
 
 #include <panel/panel-private.h>
 #include <panel/panel-dialogs.h>
@@ -62,3 +63,63 @@ panel_dialogs_show_about (void)
                          "logo-icon-name", PACKAGE_NAME,
                          NULL);
 }
+
+
+
+gint
+panel_dialogs_choose_panel (GSList *windows)
+{
+  GtkWidget *dialog;
+  GtkWidget *vbox;
+  GtkWidget *label;
+  GtkWidget *combo;
+  gint       i, response = -1;
+  gchar     *name;
+  GSList    *li;
+
+  panel_return_val_if_fail (GTK_IS_WINDOW (windows->data), -1);
+
+  /* setup the dialog */
+  dialog = gtk_dialog_new_with_buttons (_("Add New Item"), GTK_WINDOW (windows->data),
+                                        GTK_DIALOG_NO_SEPARATOR,
+                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                        GTK_STOCK_ADD, GTK_RESPONSE_OK, NULL);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_ADD);
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+
+  /* create widgets */
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
+  gtk_widget_show (vbox);
+
+  label = gtk_label_new (_("Please choose a panel for the new plugin:"));
+  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+  gtk_widget_show (label);
+
+  combo = gtk_combo_box_new_text ();
+  gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
+  gtk_widget_show (combo);
+
+  /* insert the panels */
+  for (li = windows, i = 1; li != NULL; li = li->next, i++)
+    {
+      /* add panel name to the combo box */
+      name = g_strdup_printf (_("Panel %d"), i);
+      gtk_combo_box_append_text (GTK_COMBO_BOX (combo), name);
+      g_free (name);
+    }
+
+  /* select first panel */
+  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+
+  /* run the dialog */
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+    response = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+
+  /* destroy the dialog */
+  gtk_widget_destroy (dialog);
+
+  return response;
+}
diff --git a/panel/panel-dialogs.h b/panel/panel-dialogs.h
index 0c320f8..722de42 100644
--- a/panel/panel-dialogs.h
+++ b/panel/panel-dialogs.h
@@ -22,7 +22,9 @@
 
 G_BEGIN_DECLS
 
-void panel_dialogs_show_about (void);
+void panel_dialogs_show_about   (void);
+
+gint panel_dialogs_choose_panel (GSList *windows);
 
 G_END_DECLS
 
diff --git a/panel/panel-module-factory.c b/panel/panel-module-factory.c
index 96ba071..5c25697 100644
--- a/panel/panel-module-factory.c
+++ b/panel/panel-module-factory.c
@@ -342,6 +342,18 @@ panel_module_factory_get_modules (PanelModuleFactory *factory)
 
 
 
+gboolean
+panel_module_factory_has_plugin (PanelModuleFactory *factory,
+                                 const gchar        *name)
+{
+  panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), FALSE);
+  panel_return_val_if_fail (name != NULL, FALSE);
+
+  return !!(g_hash_table_lookup (factory->modules, name) != NULL);
+}
+
+
+
 XfcePanelPluginProvider *
 panel_module_factory_create_plugin (PanelModuleFactory  *factory,
                                     GdkScreen           *screen,
diff --git a/panel/panel-module-factory.h b/panel/panel-module-factory.h
index 5613a60..14f537a 100644
--- a/panel/panel-module-factory.h
+++ b/panel/panel-module-factory.h
@@ -47,6 +47,9 @@ void                     panel_module_factory_emit_unique_changed (PanelModule
 
 GList                   *panel_module_factory_get_modules         (PanelModuleFactory  *factory);
 
+gboolean                 panel_module_factory_has_plugin          (PanelModuleFactory  *factory,
+                                                                   const gchar         *name);
+
 XfcePanelPluginProvider *panel_module_factory_create_plugin       (PanelModuleFactory  *factory,
                                                                    GdkScreen           *screen,
                                                                    const gchar         *name,



More information about the Xfce4-commits mailing list