[Xfce4-commits] <xfce4-panel:master> Allow reordering plugins in preferences with dnd.

Nick Schermer noreply at xfce.org
Mon Dec 13 21:52:01 CET 2010


Updating branch refs/heads/master
         to d16c50765b4d14c40a9864ec0271595090bbc27f (commit)
       from c0a856164936e7a7f8a7dcd3ee35f4eacd9e6338 (commit)

commit d16c50765b4d14c40a9864ec0271595090bbc27f
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Dec 13 19:56:32 2010 +0100

    Allow reordering plugins in preferences with dnd.

 panel/panel-item-dialog.c        |    1 -
 panel/panel-preferences-dialog.c |   52 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/panel/panel-item-dialog.c b/panel/panel-item-dialog.c
index fa48e13..f6293e1 100644
--- a/panel/panel-item-dialog.c
+++ b/panel/panel-item-dialog.c
@@ -232,7 +232,6 @@ panel_item_dialog_init (PanelItemDialog *dialog)
   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);
   gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (treeview), panel_item_dialog_separator_func, NULL, NULL);
   g_signal_connect_swapped (G_OBJECT (treeview), "start-interactive-search", G_CALLBACK (gtk_widget_grab_focus), entry);
diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c
index ac5e606..69c57b9 100644
--- a/panel/panel-preferences-dialog.c
+++ b/panel/panel-preferences-dialog.c
@@ -80,6 +80,10 @@ static void                     panel_preferences_dialog_item_properties
                                                                                  PanelPreferencesDialog *dialog);
 static void                     panel_preferences_dialog_item_about             (GtkWidget              *button,
                                                                                  PanelPreferencesDialog *dialog);
+static void                     panel_preferences_dialog_item_row_changed       (GtkTreeModel           *model,
+                                                                                 GtkTreePath            *path,
+                                                                                 GtkTreeIter            *iter,
+                                                                                 PanelPreferencesDialog *dialog);
 static void                     panel_preferences_dialog_item_selection_changed (GtkTreeSelection       *selection,
                                                                                  PanelPreferencesDialog *dialog);
 
@@ -222,6 +226,10 @@ panel_preferences_dialog_init (PanelPreferencesDialog *dialog)
   gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (dialog->store));
   gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), ITEM_COLUMN_TOOLTIP);
 
+  gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
+  g_signal_connect (G_OBJECT (dialog->store), "row-changed",
+      G_CALLBACK (panel_preferences_dialog_item_row_changed), dialog);
+
   /* setup tree selection */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
   gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
@@ -882,6 +890,9 @@ panel_preferences_dialog_item_store_rebuild (GtkWidget              *itembar,
 
   gtk_list_store_clear (dialog->store);
 
+  g_signal_handlers_block_by_func (G_OBJECT (dialog->store),
+      G_CALLBACK (panel_preferences_dialog_item_row_changed), dialog);
+
   /* add items to the store */
   items = gtk_container_get_children (GTK_CONTAINER (itembar));
   for (li = items, i = 0; li != NULL; li = li->next, i++)
@@ -929,6 +940,9 @@ panel_preferences_dialog_item_store_rebuild (GtkWidget              *itembar,
     }
 
   g_list_free (items);
+
+  g_signal_handlers_unblock_by_func (G_OBJECT (dialog->store),
+      G_CALLBACK (panel_preferences_dialog_item_row_changed), dialog);
 }
 
 
@@ -1090,6 +1104,44 @@ panel_preferences_dialog_item_about (GtkWidget              *button,
 
 
 static void
+panel_preferences_dialog_item_row_changed (GtkTreeModel           *model,
+                                           GtkTreePath            *path,
+                                           GtkTreeIter            *iter,
+                                           PanelPreferencesDialog *dialog)
+{
+  XfcePanelPluginProvider *provider = NULL;
+  gint                     position;
+  GtkWidget               *itembar;
+  gint                     store_position;
+
+  panel_return_if_fail (PANEL_IS_PREFERENCES_DIALOG (dialog));
+  panel_return_if_fail (GTK_TREE_MODEL (dialog->store) == model);
+  panel_return_if_fail (PANEL_IS_WINDOW (dialog->active));
+
+  /* get the changed row */
+  gtk_tree_model_get (model, iter, ITEM_COLUMN_PROVIDER, &provider, -1);
+  panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
+  store_position = gtk_tree_path_get_indices (path)[0];
+
+  /* actual position on the panel */
+  itembar = gtk_bin_get_child (GTK_BIN (dialog->active));
+  position = panel_itembar_get_child_index (PANEL_ITEMBAR (itembar),
+                                            GTK_WIDGET (provider));
+
+  /* correct position in the list */
+  if (position < store_position)
+    store_position--;
+
+  /* move the item on the panel */
+  if (position != store_position)
+    panel_itembar_reorder_child (PANEL_ITEMBAR (itembar),
+                                 GTK_WIDGET (provider),
+                                 store_position);
+}
+
+
+
+static void
 panel_preferences_dialog_item_selection_changed (GtkTreeSelection       *selection,
                                                  PanelPreferencesDialog *dialog)
 {



More information about the Xfce4-commits mailing list