[Xfce4-commits] <xfce4-panel:devel> Properly handle an empty panel configuration.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:30:12 CEST 2009
Updating branch refs/heads/devel
to 3232ea7a166c178c0cd945da2921ff7f19ef407b (commit)
from 4ce94af69330a0eb4eec9bffe25c161941e48d61 (commit)
commit 3232ea7a166c178c0cd945da2921ff7f19ef407b
Author: Nick Schermer <nick at xfce.org>
Date: Fri Mar 13 23:22:28 2009 +0100
Properly handle an empty panel configuration.
Make sure the dialog works are expected when there are
not windows created. To be secure the panel creates an
empty window when no panels were found.
Fix various warnings and crashed in the properties dialog
when no active window was set.
panel/panel-application.c | 25 +++++++++++-
panel/panel-application.h | 3 +-
panel/panel-preferences-dialog.c | 70 +++++++++++++++++++--------------
panel/panel-preferences-dialog.glade | 15 ++++++-
4 files changed, 77 insertions(+), 36 deletions(-)
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 190f8d5..a36593a 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -172,6 +172,8 @@ panel_application_class_init (PanelApplicationClass *klass)
static void
panel_application_init (PanelApplication *application)
{
+ PanelWindow *window;
+
/* initialize */
application->windows = NULL;
application->dialogs = NULL;
@@ -191,6 +193,13 @@ panel_application_init (PanelApplication *application)
/* start the autosave timeout */
panel_application_save_reschedule (application);
+
+ /* create empty window */
+ if (G_UNLIKELY (application->windows == NULL))
+ {
+ window = panel_application_new_window (application, NULL, TRUE);
+ gtk_widget_show (GTK_WIDGET (window));
+ }
}
@@ -313,7 +322,7 @@ panel_application_load (PanelApplication *application)
for (i = 0; i < n_panels; i++)
{
/* create a new window */
- window = panel_application_new_window (application, NULL);
+ window = panel_application_new_window (application, NULL, FALSE);
/* walk all the plugins on the panel */
g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugins", i);
@@ -1110,13 +1119,16 @@ panel_application_add_new_item (PanelApplication *application,
PanelWindow *
panel_application_new_window (PanelApplication *application,
- GdkScreen *screen)
+ GdkScreen *screen,
+ gboolean reset_properties)
{
GtkWidget *window;
GtkWidget *itembar;
+ gchar *property;
panel_return_val_if_fail (PANEL_IS_APPLICATION (application), NULL);
panel_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), NULL);
+ panel_return_val_if_fail (XFCONF_IS_CHANNEL (application->xfconf), NULL);
/* create panel window */
window = g_object_new (PANEL_TYPE_WINDOW, NULL);
@@ -1134,6 +1146,15 @@ panel_application_new_window (PanelApplication *application,
/* add the window to internal list */
application->windows = g_slist_append (application->windows, window);
+ /* flush the window properties */
+ if (reset_properties)
+ {
+ /* remove the xfconf properties */
+ property = g_strdup_printf ("/panels/panel-%d", g_slist_index (application->windows, window));
+ xfconf_channel_reset_property (application->xfconf, property, TRUE);
+ g_free (property);
+ }
+
/* add the itembar */
itembar = panel_itembar_new ();
exo_binding_new (G_OBJECT (window), "horizontal", G_OBJECT (itembar), "horizontal");
diff --git a/panel/panel-application.h b/panel/panel-application.h
index 0b99553..59cbef6 100644
--- a/panel/panel-application.h
+++ b/panel/panel-application.h
@@ -56,7 +56,8 @@ void panel_application_add_new_item (PanelApplication *applic
gchar **arguments);
PanelWindow *panel_application_new_window (PanelApplication *application,
- GdkScreen *screen);
+ GdkScreen *screen,
+ gboolean reset_properties);
guint panel_application_get_n_windows (PanelApplication *application);
diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c
index 4b33ab9..b8a5f43 100644
--- a/panel/panel-preferences-dialog.c
+++ b/panel/panel-preferences-dialog.c
@@ -171,7 +171,7 @@ panel_preferences_dialog_init (PanelPreferencesDialog *dialog)
/* setup tree selection */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (panel_preferences_dialog_item_selection_changed), dialog);
@@ -204,7 +204,7 @@ panel_preferences_dialog_finalize (GObject *object)
GtkWidget *itembar;
/* disconnect changed signal */
- if (dialog->changed_handler_id != 0)
+ if (dialog->active != NULL && dialog->changed_handler_id != 0)
{
itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
g_signal_handler_disconnect (G_OBJECT (itembar), dialog->changed_handler_id);
@@ -335,7 +335,7 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
panel_return_if_fail (PANEL_IS_PREFERENCES_DIALOG (dialog));
/* disconnect signal we used to monitor changes in the itembar */
- if (dialog->changed_handler_id != 0)
+ if (dialog->active != NULL && dialog->changed_handler_id != 0)
{
itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
g_signal_handler_disconnect (G_OBJECT (itembar), dialog->changed_handler_id);
@@ -345,20 +345,23 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
nth = gtk_combo_box_get_active (combobox);
dialog->active = panel_application_get_window (dialog->application, nth);
+ if (G_LIKELY (dialog->active != NULL))
+ {
+ itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
+ dialog->changed_handler_id =
+ g_signal_connect_swapped (G_OBJECT (itembar), "notify::changed",
+ G_CALLBACK (panel_preferences_dialog_item_store_rebuild),
+ dialog);
- itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
- dialog->changed_handler_id = g_signal_connect_swapped (G_OBJECT (itembar), "notify::changed",
- G_CALLBACK (panel_preferences_dialog_item_store_rebuild),
- dialog);
-
- /* rebind the dialog bindings */
- panel_preferences_dialog_bindings_update (dialog);
+ /* rebind the dialog bindings */
+ panel_preferences_dialog_bindings_update (dialog);
- /* update selection state */
- panel_application_window_select (dialog->application, dialog->active);
+ /* update selection state */
+ panel_application_window_select (dialog->application, dialog->active);
- /* update the items treeview */
- panel_preferences_dialog_item_store_rebuild (dialog);
+ /* update the items treeview */
+ panel_preferences_dialog_item_store_rebuild (dialog);
+ }
}
@@ -366,15 +369,14 @@ panel_preferences_dialog_panel_combobox_changed (GtkComboBox *combobo
static void
panel_preferences_dialog_panel_combobox_rebuild (PanelPreferencesDialog *dialog)
{
- GObject *store, *combo;
+ GObject *store, *combo, *object;
gint n, n_items;
gchar *name;
/* get the combo box and model */
store = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-liststore");
- combo = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-combobox");
-
panel_return_if_fail (GTK_IS_LIST_STORE (store));
+ combo = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-combobox");
panel_return_if_fail (GTK_IS_COMBO_BOX (combo));
/* block signal */
@@ -392,6 +394,15 @@ panel_preferences_dialog_panel_combobox_rebuild (PanelPreferencesDialog *dialog)
g_free (name);
}
+ /* set sensitivity of some widgets */
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "notebook");
+ panel_return_if_fail (GTK_IS_WIDGET (object));
+ gtk_widget_set_sensitive (GTK_WIDGET (object), !!(n_items > 0));
+
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-remove");
+ panel_return_if_fail (GTK_IS_WIDGET (object));
+ gtk_widget_set_sensitive (GTK_WIDGET (object), !!(n_items > 1));
+
/* unblock signal */
g_signal_handlers_unblock_by_func (combo, panel_preferences_dialog_panel_combobox_changed, dialog);
}
@@ -408,7 +419,7 @@ panel_preferences_dialog_panel_add (GtkWidget *widget,
/* create new window */
window = panel_application_new_window (dialog->application,
- gtk_widget_get_screen (widget));
+ gtk_widget_get_screen (widget), TRUE);
/* block autohide */
panel_window_freeze_autohide (window);
@@ -416,20 +427,14 @@ panel_preferences_dialog_panel_add (GtkWidget *widget,
/* rebuild the selector */
panel_preferences_dialog_panel_combobox_rebuild (dialog);
- /* set the sensitivity of the remove button */
- object = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-remove");
- panel_return_if_fail (GTK_IS_WIDGET (object));
- gtk_widget_set_sensitive (GTK_WIDGET (object),
- panel_application_get_n_windows (dialog->application) > 1);
+ /* show window */
+ gtk_widget_show (GTK_WIDGET (window));
/* select new panel (new window is appended) */
object = gtk_builder_get_object (GTK_BUILDER (dialog), "panel-combobox");
panel_return_if_fail (GTK_IS_WIDGET (object));
active = panel_application_get_n_windows (dialog->application) - 1;
gtk_combo_box_set_active (GTK_COMBO_BOX (object), active);
-
- /* show window */
- gtk_widget_show (GTK_WIDGET (window));
}
@@ -453,9 +458,7 @@ panel_preferences_dialog_panel_remove (GtkWidget *widget,
/* destroy the panel */
gtk_widget_destroy (GTK_WIDGET (dialog->active));
-
- /* set the sensitivity of the remove button */
- gtk_widget_set_sensitive (widget, panel_application_get_n_windows (dialog->application) > 1);
+ dialog->active = NULL;
/* rebuild the selector */
panel_preferences_dialog_panel_combobox_rebuild (dialog);
@@ -787,6 +790,7 @@ panel_preferences_dialog_show (PanelWindow *active)
static PanelPreferencesDialog *dialog = NULL;
gint idx = 0;
GObject *window, *combo;
+ GdkScreen *screen;
panel_return_if_fail (active == NULL || PANEL_IS_WINDOW (active));
@@ -803,10 +807,16 @@ panel_preferences_dialog_show (PanelWindow *active)
else
active = panel_application_get_window (dialog->application, idx);
+ /* get the active screen */
+ if (active != NULL)
+ screen = gtk_widget_get_screen (GTK_WIDGET (active));
+ else
+ screen = gdk_screen_get_default ();
+
/* show the dialog on the same screen as the panel */
window = gtk_builder_get_object (GTK_BUILDER (dialog), "dialog");
panel_return_if_fail (GTK_IS_WIDGET (window));
- gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (GTK_WIDGET (active)));
+ gtk_window_set_screen (GTK_WINDOW (window), screen);
gtk_window_present (GTK_WINDOW (window));
/* select the active window in the dialog */
diff --git a/panel/panel-preferences-dialog.glade b/panel/panel-preferences-dialog.glade
index eb227f0..eab25f4 100644
--- a/panel/panel-preferences-dialog.glade
+++ b/panel/panel-preferences-dialog.glade
@@ -79,6 +79,7 @@
<child>
<object class="GtkButton" id="panel-remove">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Remove the currently selected panel</property>
@@ -101,8 +102,9 @@
</packing>
</child>
<child>
- <object class="GtkNotebook" id="notebook1">
+ <object class="GtkNotebook" id="notebook">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<child>
<object class="GtkVBox" id="vbox2">
@@ -490,6 +492,7 @@
<object class="GtkTreeView" id="item-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="model">item-liststore</property>
<property name="headers_visible">False</property>
<property name="rules_hint">True</property>
<property name="enable_search">False</property>
@@ -507,6 +510,7 @@
<child>
<object class="GtkButton" id="item-up">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Move currently selected item up by one row</property>
@@ -525,6 +529,7 @@
<child>
<object class="GtkButton" id="item-down">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Move currently selected item down by one row</property>
@@ -543,6 +548,7 @@
<child>
<object class="GtkButton" id="item-add">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Add new item to this panel</property>
@@ -561,6 +567,7 @@
<child>
<object class="GtkButton" id="item-remove">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Remove currently selected item</property>
@@ -579,6 +586,7 @@
<child>
<object class="GtkButton" id="item-properties">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Edit the currently selected item</property>
@@ -597,6 +605,7 @@
<child>
<object class="GtkButton" id="item-about">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text">Show about information of the currently selected item</property>
@@ -721,9 +730,9 @@
</object>
<object class="GtkSizeGroup" id="sizegroup1">
<widgets>
- <widget name="label10"/>
- <widget name="label9"/>
<widget name="label7"/>
+ <widget name="label9"/>
+ <widget name="label10"/>
</widgets>
</object>
</interface>
More information about the Xfce4-commits
mailing list