[Xfce4-commits] <xfce4-panel:devel> Make the add button work in the items dialog.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:34:43 CEST 2009
Updating branch refs/heads/devel
to 9b67c9b5a23ffdb2a86281d7023273ece21dedf3 (commit)
from 45596e125955e9688f24bd4494e06d59b0a5982c (commit)
commit 9b67c9b5a23ffdb2a86281d7023273ece21dedf3
Author: Nick Schermer <nick at xfce.org>
Date: Sun Jun 7 00:23:19 2009 +0200
Make the add button work in the items dialog.
panel/panel-application.c | 35 +++++++++++++-----
panel/panel-application.h | 2 +-
panel/panel-dbus-service.c | 3 +-
panel/panel-dialogs.c | 20 +++-------
panel/panel-item-dialog.c | 74 +++++++++++++++++++++++++-------------
panel/panel-item-dialog.h | 5 ++-
panel/panel-preferences-dialog.c | 50 +++++++++++++++++---------
panel/panel-preferences-dialog.h | 2 +
panel/panel-window.c | 19 +++++++++-
9 files changed, 140 insertions(+), 70 deletions(-)
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 5589bce..74feec8 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -459,6 +459,7 @@ panel_application_plugin_provider_signal (XfcePanelPluginProvider *provide
gint unique_id;
gchar *name;
gboolean expand;
+ gint nth;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
@@ -512,8 +513,12 @@ panel_application_plugin_provider_signal (XfcePanelPluginProvider *provide
break;
case PROVIDER_SIGNAL_ADD_NEW_ITEMS:
+ /* select active window */
+ nth = panel_application_get_window_index (application, window);
+ panel_application_window_select (application, nth);
+
/* open the items dialog */
- panel_item_dialog_show (window);
+ panel_item_dialog_show (gtk_widget_get_screen (GTK_WIDGET (window)));
break;
case PROVIDER_SIGNAL_PANEL_PREFERENCES:
@@ -1109,6 +1114,8 @@ panel_application_add_new_item (PanelApplication *application,
{
PanelWindow *window;
gint nth = 0;
+ GSList *li;
+ gboolean active;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (plugin_name != NULL);
@@ -1116,10 +1123,20 @@ panel_application_add_new_item (PanelApplication *application,
if (panel_module_factory_has_module (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)) == -1)
- return;
+ /* look for an active panel or ask the user */
+ if (LIST_HAS_TWO_OR_MORE_ENTRIES (application->windows))
+ {
+ for (li = application->windows, nth = 0; li != NULL; li = li->next, nth++)
+ {
+ g_object_get (G_OBJECT (li->data), "active", &active, NULL);
+ if (active)
+ break;
+ }
+
+ if (li == NULL
+ && (nth = panel_dialogs_choose_panel (application)) == -1)
+ return;
+ }
/* get the window */
window = g_slist_nth_data (application->windows, nth);
@@ -1244,16 +1261,16 @@ panel_application_get_window (PanelApplication *application,
void
panel_application_window_select (PanelApplication *application,
- PanelWindow *window)
+ gint nth)
{
GSList *li;
+ gint n;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
- panel_return_if_fail (window == NULL || PANEL_IS_WINDOW (window));
/* update state for all windows */
- for (li = application->windows; li != NULL; li = li->next)
- g_object_set (G_OBJECT (li->data), "active", li->data == window, NULL);
+ for (li = application->windows, n = 0; li != NULL; li = li->next, n++)
+ g_object_set (G_OBJECT (li->data), "active", !!(n == nth), NULL);
}
diff --git a/panel/panel-application.h b/panel/panel-application.h
index ae64642..f1b840a 100644
--- a/panel/panel-application.h
+++ b/panel/panel-application.h
@@ -68,7 +68,7 @@ PanelWindow *panel_application_get_window (PanelApplication *applic
guint idx);
void panel_application_window_select (PanelApplication *application,
- PanelWindow *window);
+ gint nth);
void panel_application_windows_sensitive (PanelApplication *application,
gboolean sensitive);
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 62e7d92..9d35209 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -235,7 +235,8 @@ panel_dbus_service_display_items_dialog (PanelDBusService *service,
/* show the items dialog */
application = panel_application_get ();
- panel_item_dialog_show (panel_application_get_window (application, active));
+ panel_application_window_select (application, (gint) active);
+ panel_item_dialog_show (NULL);
g_object_unref (G_OBJECT (application));
return TRUE;
diff --git a/panel/panel-dialogs.c b/panel/panel-dialogs.c
index 43bc2c6..d1e275e 100644
--- a/panel/panel-dialogs.c
+++ b/panel/panel-dialogs.c
@@ -68,23 +68,14 @@ static void
panel_dialogs_choose_panel_combo_changed (GtkComboBox *combo,
PanelApplication *application)
{
- PanelWindow *window = NULL;
- gint active;
+ gint active;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (GTK_IS_COMBO_BOX (combo));
- /* get the selected item */
+ /* select active panel */
active = gtk_combo_box_get_active (combo);
-
- if (G_LIKELY (active != -1))
- {
- /* get the window */
- window = panel_application_get_window (application, active);
-
- /* select the window */
- panel_application_window_select (application, window);
- }
+ panel_application_window_select (application, active);
}
@@ -135,7 +126,8 @@ panel_dialogs_choose_panel (PanelApplication *application)
}
/* select first panel */
- g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (panel_dialogs_choose_panel_combo_changed), application);
+ g_signal_connect (G_OBJECT (combo), "changed",
+ G_CALLBACK (panel_dialogs_choose_panel_combo_changed), application);
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
/* run the dialog */
@@ -146,7 +138,7 @@ panel_dialogs_choose_panel (PanelApplication *application)
gtk_widget_destroy (dialog);
/* remove the panel selection */
- panel_application_window_select (application, NULL);
+ panel_application_window_select (application, -1);
return response;
}
diff --git a/panel/panel-item-dialog.c b/panel/panel-item-dialog.c
index 46bc4b9..88a50b0 100644
--- a/panel/panel-item-dialog.c
+++ b/panel/panel-item-dialog.c
@@ -36,6 +36,7 @@
#include <panel/panel-item-dialog.h>
#include <panel/panel-module.h>
#include <panel/panel-module-factory.h>
+#include <panel/panel-preferences-dialog.h>
@@ -76,6 +77,7 @@ struct _PanelItemDialog
/* list store */
GtkListStore *store;
+ GtkTreeView *treeview;
};
enum
@@ -97,6 +99,10 @@ G_DEFINE_TYPE (PanelItemDialog, panel_item_dialog, XFCE_TYPE_TITLED_DIALOG);
+static PanelItemDialog *dialog_singleton = NULL;
+
+
+
static void
panel_item_dialog_class_init (PanelItemDialogClass *klass)
{
@@ -201,6 +207,7 @@ panel_item_dialog_init (PanelItemDialog *dialog)
/* treeview */
treeview = gtk_tree_view_new_with_model (filter);
+ dialog->treeview = GTK_TREE_VIEW (treeview);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
@@ -268,31 +275,42 @@ panel_item_dialog_finalize (GObject *object)
static void
-panel_item_dialog_response (GtkDialog *dialog,
+panel_item_dialog_response (GtkDialog *gtk_dialog,
gint response_id)
{
- GError *error = NULL;
- GdkScreen *screen;
+ GError *error = NULL;
+ PanelItemDialog *dialog = PANEL_ITEM_DIALOG (gtk_dialog);
+ GdkScreen *screen;
+ PanelModule *module;
+
+ panel_return_if_fail (PANEL_IS_ITEM_DIALOG (dialog));
+ panel_return_if_fail (GTK_IS_TREE_VIEW (dialog->treeview));
+ panel_return_if_fail (PANEL_IS_APPLICATION (dialog->application));
if (response_id == GTK_RESPONSE_HELP)
{
- /* get the dialog screen */
- screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
-
- /* open the help url */
- if (exo_url_show_on_screen (ITEMS_HELP_URL, NULL, screen, &error) == FALSE)
+ /* open the help url on this screen */
+ screen = gtk_widget_get_screen (GTK_WIDGET (gtk_dialog));
+ if (!exo_url_show_on_screen (ITEMS_HELP_URL, NULL, screen, &error))
{
- /* show error */
+ /* show error and cleanup */
g_warning ("Failed to open help: %s", error->message);
-
- /* cleanup */
g_error_free (error);
}
}
+ else if (response_id == GTK_RESPONSE_OK)
+ {
+ module = panel_item_dialog_get_selected_module (dialog->treeview);
+ if (G_LIKELY (module != NULL))
+ panel_application_add_new_item (dialog->application,
+ panel_module_get_name (module), NULL);
+ }
else
{
- /* destroy the dialog */
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ if (!panel_preferences_dialog_visible ())
+ panel_application_window_select (dialog->application, -1);
+
+ gtk_widget_destroy (GTK_WIDGET (gtk_dialog));
}
}
@@ -696,27 +714,33 @@ panel_item_dialog_text_renderer (GtkTreeViewColumn *column,
void
-panel_item_dialog_show (PanelWindow *active)
+panel_item_dialog_show (GdkScreen *screen)
{
- static PanelItemDialog *dialog = NULL;
+ panel_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
- if (G_LIKELY (dialog == NULL))
+ if (G_LIKELY (dialog_singleton == NULL))
{
/* create new dialog singleton */
- dialog = g_object_new (PANEL_TYPE_ITEM_DIALOG, NULL);
- g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer) &dialog);
+ dialog_singleton = g_object_new (PANEL_TYPE_ITEM_DIALOG, NULL);
+ g_object_add_weak_pointer (G_OBJECT (dialog_singleton), (gpointer) &dialog_singleton);
}
- if (G_UNLIKELY (active == NULL))
- active = panel_application_get_window (dialog->application, 0);
-
/* show the dialog on the same screen as the panel */
- gtk_window_set_screen (GTK_WINDOW (dialog),
- gtk_widget_get_screen (GTK_WIDGET (active)));
+ if (G_UNLIKELY (screen == NULL))
+ screen = gdk_screen_get_default ();
+ gtk_window_set_screen (GTK_WINDOW (dialog_singleton), screen);
/* show the dialog */
- gtk_widget_show (GTK_WIDGET (dialog));
+ gtk_widget_show (GTK_WIDGET (dialog_singleton));
/* focus the window */
- gtk_window_present (GTK_WINDOW (dialog));
+ gtk_window_present (GTK_WINDOW (dialog_singleton));
+}
+
+
+
+gboolean
+panel_item_dialog_visible (void)
+{
+ return !!(dialog_singleton != NULL);
}
diff --git a/panel/panel-item-dialog.h b/panel/panel-item-dialog.h
index 975708a..7833df6 100644
--- a/panel/panel-item-dialog.h
+++ b/panel/panel-item-dialog.h
@@ -21,7 +21,6 @@
#define __PANEL_ITEM_DIALOG_H__
#include <gtk/gtk.h>
-#include <panel/panel-window.h>
G_BEGIN_DECLS
@@ -37,7 +36,9 @@ typedef struct _PanelItemDialog PanelItemDialog;
GType panel_item_dialog_get_type (void) G_GNUC_CONST;
-void panel_item_dialog_show (PanelWindow *active);
+void panel_item_dialog_show (GdkScreen *screen);
+
+gboolean panel_item_dialog_visible (void);
G_END_DECLS
diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c
index b5303a7..3fa0e48 100644
--- a/panel/panel-preferences-dialog.c
+++ b/panel/panel-preferences-dialog.c
@@ -103,6 +103,10 @@ G_DEFINE_TYPE (PanelPreferencesDialog, panel_preferences_dialog, GTK_TYPE_BUILDE
+static PanelPreferencesDialog *dialog_singleton = NULL;
+
+
+
static void
panel_preferences_dialog_class_init (PanelPreferencesDialogClass *klass)
{
@@ -213,7 +217,8 @@ panel_preferences_dialog_finalize (GObject *object)
panel_application_windows_autohide (dialog->application, FALSE);
/* deselect all windows */
- panel_application_window_select (dialog->application, NULL);
+ if (!panel_item_dialog_visible ())
+ panel_application_window_select (dialog->application, -1);
/* release the application */
g_object_unref (G_OBJECT (dialog->application));
@@ -329,6 +334,7 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
{
gint nth;
GtkWidget *itembar;
+ GObject *object;
panel_return_if_fail (GTK_IS_COMBO_BOX (combobox));
panel_return_if_fail (PANEL_IS_PREFERENCES_DIALOG (dialog));
@@ -343,6 +349,7 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
/* set the selected window */
nth = gtk_combo_box_get_active (combobox);
dialog->active = panel_application_get_window (dialog->application, nth);
+ panel_application_window_select (dialog->application, nth);
if (G_LIKELY (dialog->active != NULL))
{
@@ -355,12 +362,14 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
/* rebind the dialog bindings */
panel_preferences_dialog_bindings_update (dialog);
- /* update selection state */
- panel_application_window_select (dialog->application, dialog->active);
-
/* update the items treeview */
panel_preferences_dialog_item_store_rebuild (dialog);
}
+
+ /* sensitivity of the add button in item tab */
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "item-add");
+ panel_return_if_fail (GTK_IS_WIDGET (object));
+ gtk_widget_set_sensitive (GTK_WIDGET (object), !!(dialog->active != NULL));
}
@@ -452,7 +461,7 @@ panel_preferences_dialog_panel_remove (GtkWidget *widget,
/* destroy the window */
if (xfce_dialog_confirm (dialog, GTK_STOCK_REMOVE, NULL,
- "Are you sure you want to remove panel %d?", nth + 1))
+ _("Are you sure you want to remove panel %d?"), nth + 1))
{
/* release the bindings */
panel_preferences_dialog_bindings_unbind (dialog);
@@ -678,7 +687,7 @@ panel_preferences_dialog_item_add (GtkWidget *button,
panel_return_if_fail (PANEL_IS_PREFERENCES_DIALOG (dialog));
/* show the items dialog */
- panel_item_dialog_show (dialog->active);
+ panel_item_dialog_show (gtk_widget_get_screen (button));
}
@@ -788,25 +797,24 @@ panel_preferences_dialog_item_selection_changed (GtkTreeSelection *selecti
void
panel_preferences_dialog_show (PanelWindow *active)
{
- static PanelPreferencesDialog *dialog = NULL;
- gint idx = 0;
- GObject *window, *combo;
- GdkScreen *screen;
+ gint idx = 0;
+ GObject *window, *combo;
+ GdkScreen *screen;
panel_return_if_fail (active == NULL || PANEL_IS_WINDOW (active));
- if (G_LIKELY (dialog == NULL))
+ if (G_LIKELY (dialog_singleton == NULL))
{
/* create new dialog singleton */
- dialog = g_object_new (PANEL_TYPE_PREFERENCES_DIALOG, NULL);
- g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer) &dialog);
+ dialog_singleton = g_object_new (PANEL_TYPE_PREFERENCES_DIALOG, NULL);
+ g_object_add_weak_pointer (G_OBJECT (dialog_singleton), (gpointer) &dialog_singleton);
}
/* get the active window index */
if (G_LIKELY (active))
- idx = panel_application_get_window_index (dialog->application, active);
+ idx = panel_application_get_window_index (dialog_singleton->application, active);
else
- active = panel_application_get_window (dialog->application, idx);
+ active = panel_application_get_window (dialog_singleton->application, idx);
/* get the active screen */
if (active != NULL)
@@ -815,13 +823,21 @@ panel_preferences_dialog_show (PanelWindow *active)
screen = gdk_screen_get_default ();
/* show the dialog on the same screen as the panel */
- window = gtk_builder_get_object (GTK_BUILDER (dialog), "dialog");
+ window = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "dialog");
panel_return_if_fail (GTK_IS_WIDGET (window));
gtk_window_set_screen (GTK_WINDOW (window), screen);
gtk_window_present (GTK_WINDOW (window));
/* select the active window in the dialog */
- combo = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-combobox");
+ combo = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "panel-combobox");
panel_return_if_fail (GTK_IS_WIDGET (combo));
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), idx);
}
+
+
+
+gboolean
+panel_preferences_dialog_visible (void)
+{
+ return !!(dialog_singleton != NULL);
+}
diff --git a/panel/panel-preferences-dialog.h b/panel/panel-preferences-dialog.h
index 2c50c46..427f78e 100644
--- a/panel/panel-preferences-dialog.h
+++ b/panel/panel-preferences-dialog.h
@@ -40,6 +40,8 @@ GType panel_preferences_dialog_get_type (void) G_GNUC_CONST;
void panel_preferences_dialog_show (PanelWindow *active);
+gboolean panel_preferences_dialog_visible (void);
+
G_END_DECLS
#endif /* !__PANEL_PREFERENCES_DIALOG_H__ */
diff --git a/panel/panel-window.c b/panel/panel-window.c
index 5d13d1d..9452129 100644
--- a/panel/panel-window.c
+++ b/panel/panel-window.c
@@ -1824,6 +1824,23 @@ panel_window_menu_deactivate (GtkMenu *menu,
static void
+panel_window_menu_add_items (PanelWindow *window)
+{
+ gint nth;
+ PanelApplication *application;
+
+ panel_return_if_fail (PANEL_IS_WINDOW (window));
+
+ application = panel_application_get ();
+ nth = panel_application_get_window_index (application, window);
+ panel_application_window_select (application, nth);
+ g_object_unref (G_OBJECT (application));
+ panel_item_dialog_show (gtk_widget_get_screen (GTK_WIDGET (window)));
+}
+
+
+
+static void
panel_window_menu_popup (PanelWindow *window,
guint32 event_time)
{
@@ -1858,7 +1875,7 @@ panel_window_menu_popup (PanelWindow *window,
/* add new items */
item = gtk_image_menu_item_new_with_mnemonic (_("Add _New Items..."));
g_signal_connect_swapped (G_OBJECT (item), "activate",
- G_CALLBACK (panel_item_dialog_show), window);
+ G_CALLBACK (panel_window_menu_add_items), window);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
More information about the Xfce4-commits
mailing list