[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_9.0-133-gdadb1e2

Pierre Biava nobody at users.sourceforge.net
Wed Apr 20 20:59:07 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grisbi".

The branch, master has been updated
       via  dadb1e24a9a782adbd5877f88d971331beab4559 (commit)
      from  19b219962b592042d8ece953ef5bd763cfb51d67 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dadb1e24a9a782adbd5877f88d971331beab4559
Author: pbiava <pierre.biava at nerim.net>
Date:   Wed Apr 20 20:48:28 2011 +0200

    added management of drag and drop in the left window of Grisbi
    (cherry picked from commit 7129b74545514c0fd4f06a27a68ff306fbc2ebd4)

-----------------------------------------------------------------------

Changes:
diff --git a/src/navigation.c b/src/navigation.c
index 2340530..cf822e8 100644
--- a/src/navigation.c
+++ b/src/navigation.c
@@ -67,47 +67,57 @@
 
 
 /*START_STATIC*/
-static void create_report_list ( GtkTreeModel * model, GtkTreeIter * reports_iter );
+static void gsb_gui_navigation_create_report_listreport_list ( GtkTreeModel *model );
 static gboolean gsb_gui_navigation_check_key_press ( GtkWidget *tree_view,
                         GdkEventKey *ev,
                         GtkTreeModel *model );
 static void gsb_gui_navigation_clear_pages_list ( void );
-static gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel * tree_model, 
-                        GtkTreePath *path, 
-                        GtkTreeIter *iter, 
+static GtkTreePath *gsb_gui_navigation_get_page_path ( GtkTreeModel *model,
+                        gint type_page );
+static gboolean gsb_gui_navigation_move_ordre ( gint src_ordre,
+                        gint dst_ordre );
+static gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel *model,
+                        GtkTreePath *path,
+                        GtkTreeIter *iter,
                         gpointer data );
-static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel * tree_model, 
-                        GtkTreePath *path, 
-                        GtkTreeIter *iter, 
+static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel *model,
+                        GtkTreePath *path,
+                        GtkTreeIter *iter,
                         gpointer data );
 static gboolean gsb_gui_navigation_select_line ( GtkTreeSelection *selection,
                         GtkTreeModel *model );
+static void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection *selection,
+					    GtkTreeIter * iter, gint page,
+					    gint account_number, gpointer report );
 static void gsb_gui_navigation_set_navigation_pages ( GtkTreeModel *model,
-                        gint type_page );
-static void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection * selection, 
+                        gint type_page,
+                        gint ordre );
+static void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection *selection, 
 					    GtkTreeIter *iter,
-                        gint page, 
+                        gint page,
 					    gint account_number,
                         gpointer report );
-static void gsb_gui_navigation_update_account_iter ( GtkTreeModel * model, 
+static void gsb_gui_navigation_update_account_iter ( GtkTreeModel *model, 
                         GtkTreeIter * account_iter,
                         gint account_number );
-static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel * tree_model, 
-                        GtkTreePath *path, 
-                        GtkTreeIter *iter, 
+static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel *model,
+                        GtkTreePath *path,
+                        GtkTreeIter *iter,
                         gpointer data );
-static void gsb_gui_navigation_update_report_iter ( GtkTreeModel * model, 
+static void gsb_gui_navigation_update_report_iter ( GtkTreeModel *model,
                         GtkTreeIter * report_iter,
                         gint report_number );
-static gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel * tree_model, 
-                        GtkTreePath *path, 
-                        GtkTreeIter *iter, 
+static gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel *model,
+                        GtkTreePath *path,
+                        GtkTreeIter *iter,
                         gpointer data );
-static gboolean navigation_sort_column ( GtkTreeModel * model, 
-                        GtkTreeIter * a, GtkTreeIter * b, 
+static gboolean navigation_sort_column ( GtkTreeModel *model,
+                        GtkTreeIter *a,
+                        GtkTreeIter *b,
                         gpointer user_data );
-static gboolean navigation_tree_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
-                        GtkSelectionData * selection_data );
+static gboolean navigation_tree_drag_data_get ( GtkTreeDragSource *drag_source,
+                        GtkTreePath *path,
+                        GtkSelectionData *selection_data );
 /*END_STATIC*/
 
 
@@ -136,7 +146,7 @@ GtkWidget *reconcile_panel;
  * at the end of the switch, contains the current account number */
 static gint buffer_last_account = -1;
 
-/** contains a g_slist of struct_navigation_page */
+/** contains a g_queue of struct_page */
 static GQueue *pages_list = NULL;
 
 
@@ -171,60 +181,66 @@ GtkWidget *gsb_gui_navigation_create_navigation_pane ( void )
     gtk_tree_view_set_headers_visible ( GTK_TREE_VIEW(navigation_tree_view), FALSE );
     gtk_container_add ( GTK_CONTAINER(sw), navigation_tree_view );
 
-    navigation_model = GTK_TREE_MODEL (gtk_tree_store_new ( NAVIGATION_TOTAL, 
-							    GDK_TYPE_PIXBUF,
-							    G_TYPE_BOOLEAN, G_TYPE_STRING, 
-							    G_TYPE_INT, G_TYPE_INT, 
-							    G_TYPE_INT, G_TYPE_INT,
-							    G_TYPE_INT ));
+    navigation_model = GTK_TREE_MODEL ( gtk_tree_store_new ( NAVIGATION_TOTAL, 
+							    GDK_TYPE_PIXBUF,        /* NAVIGATION_PIX */
+							    G_TYPE_BOOLEAN,         /* NAVIGATION_PIX_VISIBLE */
+                                G_TYPE_STRING,          /* NAVIGATION_TEXT */ 
+							    G_TYPE_INT,             /* NAVIGATION_FONT */
+                                G_TYPE_INT,             /* NAVIGATION_PAGE */
+							    G_TYPE_INT,             /* NAVIGATION_ACCOUNT */
+                                G_TYPE_INT,             /* NAVIGATION_REPORT */
+							    G_TYPE_INT,             /* NAVIGATION_SENSITIVE */
+                                G_TYPE_INT ) );         /* NAVIGATION_ORDRE */
 
     gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE ( navigation_model ),
-					   NAVIGATION_PAGE, GTK_SORT_ASCENDING );
-    gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE ( navigation_model ),
-				      NAVIGATION_PAGE, navigation_sort_column,
-				      NULL, NULL );
+                        NAVIGATION_ORDRE, GTK_SORT_ASCENDING );
+    gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE ( navigation_model ), 
+                        NAVIGATION_ORDRE, navigation_sort_column,
+                        NULL, NULL );
 
     /* Enable drag & drop */
-    gtk_tree_view_enable_model_drag_source ( GTK_TREE_VIEW(navigation_tree_view),
-					     GDK_BUTTON1_MASK, row_targets, 1,
-					     GDK_ACTION_MOVE | GDK_ACTION_COPY );
-    gtk_tree_view_enable_model_drag_dest ( GTK_TREE_VIEW(navigation_tree_view), row_targets,
-					   1, GDK_ACTION_MOVE | GDK_ACTION_COPY );
-    gtk_tree_view_set_reorderable ( GTK_TREE_VIEW(navigation_tree_view), TRUE );
-    gtk_tree_selection_set_mode ( gtk_tree_view_get_selection ( GTK_TREE_VIEW(navigation_tree_view)),
-				  GTK_SELECTION_SINGLE );
-    gtk_tree_view_set_model ( GTK_TREE_VIEW(navigation_tree_view), 
-			      GTK_TREE_MODEL(navigation_model) );
+    gtk_tree_view_enable_model_drag_source ( GTK_TREE_VIEW ( navigation_tree_view ),
+					    GDK_BUTTON1_MASK,
+                        row_targets, 1,
+					    GDK_ACTION_MOVE | GDK_ACTION_COPY );
+    gtk_tree_view_enable_model_drag_dest ( GTK_TREE_VIEW ( navigation_tree_view ),
+                        row_targets,
+                        1,
+                        GDK_ACTION_MOVE | GDK_ACTION_COPY );
+    gtk_tree_view_set_reorderable ( GTK_TREE_VIEW ( navigation_tree_view ), TRUE );
+    gtk_tree_selection_set_mode ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( navigation_tree_view ) ),
+                        GTK_SELECTION_SINGLE );
+    gtk_tree_view_set_model ( GTK_TREE_VIEW ( navigation_tree_view ), GTK_TREE_MODEL( navigation_model ) );
 
     /* Handle drag & drop */
-    navigation_dst_iface = GTK_TREE_DRAG_DEST_GET_IFACE (navigation_model);
+    navigation_dst_iface = GTK_TREE_DRAG_DEST_GET_IFACE ( navigation_model );
     if ( navigation_dst_iface )
     {
-	navigation_dst_iface -> drag_data_received = &navigation_drag_data_received;
-	navigation_dst_iface -> row_drop_possible = &navigation_row_drop_possible;
+        navigation_dst_iface -> drag_data_received = &navigation_drag_data_received;
+        navigation_dst_iface -> row_drop_possible = &navigation_row_drop_possible;
     }
 
     navigation_src_iface = GTK_TREE_DRAG_SOURCE_GET_IFACE (navigation_model);
     if ( navigation_src_iface )
     {
-	gtk_selection_add_target (navigation_tree_view,
-				  GDK_SELECTION_PRIMARY,
-				  GDK_SELECTION_TYPE_ATOM,
-				  1);
-	navigation_src_iface -> drag_data_get = &navigation_tree_drag_data_get;
+        gtk_selection_add_target (navigation_tree_view,
+                        GDK_SELECTION_PRIMARY,
+                        GDK_SELECTION_TYPE_ATOM,
+                        1);
+        navigation_src_iface -> drag_data_get = &navigation_tree_drag_data_get;
     }
 
     /* check the keyboard before all, if we need to move other things that the navigation
      * tree view (for example, up and down on transactions list) */
     g_signal_connect ( navigation_tree_view,
-		       "key-press-event", 
-		       G_CALLBACK (gsb_gui_navigation_check_key_press),
-		       navigation_model  );
+                        "key-press-event", 
+                        G_CALLBACK ( gsb_gui_navigation_check_key_press ),
+                        navigation_model  );
 
-    g_signal_connect_after (gtk_tree_view_get_selection (GTK_TREE_VIEW (navigation_tree_view)), 
-			    "changed", 
-			    G_CALLBACK (gsb_gui_navigation_select_line),
-			    navigation_model );
+    g_signal_connect_after ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( navigation_tree_view ) ), 
+                        "changed", 
+                        G_CALLBACK ( gsb_gui_navigation_select_line ),
+                        navigation_model );
 
     /* Create column */
     column = gtk_tree_view_column_new ( );
@@ -260,11 +276,11 @@ GtkWidget *gsb_gui_navigation_create_navigation_pane ( void )
         struct_page *page;
 
         page = g_queue_peek_nth ( tmp_queue, i );
-        gsb_gui_navigation_set_navigation_pages ( navigation_model, page -> type_page );
+        gsb_gui_navigation_set_navigation_pages ( navigation_model, page -> type_page, i );
     }
 
     /* Finish tree. */
-    gtk_tree_view_expand_all ( GTK_TREE_VIEW(navigation_tree_view) );
+/*     gtk_tree_view_expand_all ( GTK_TREE_VIEW(navigation_tree_view) );  */
     gtk_box_pack_start ( GTK_BOX(vbox), sw, TRUE, TRUE, 0 );
 
     /* Create calendar (hidden for now). */
@@ -421,38 +437,39 @@ gint gsb_gui_navigation_get_current_report ( void )
  * \param model		Tree model to insert items into.
  * \param account_iter	Parent iter.
  */
-void gsb_gui_navigation_create_account_list ( GtkTreeModel * model )
+void gsb_gui_navigation_create_account_list ( GtkTreeModel *model )
 {
     GSList *list_tmp;
     GtkTreeIter parent, child;
-    GtkTreePath * path;
+    GtkTreePath *path;
 
-    gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(navigation_model), &parent );
+    path = gsb_gui_navigation_get_page_path ( model, GSB_HOME_PAGE );
+    gtk_tree_model_get_iter ( GTK_TREE_MODEL( model ), &parent, path );
 
     /* Remove childs if any. */
     while ( gtk_tree_model_iter_children ( model, &child, &parent ) )
     {
-	gtk_tree_store_remove ( GTK_TREE_STORE(model), &child );
+        gtk_tree_store_remove ( GTK_TREE_STORE ( model ), &child );
     }
 
     /* Fill in with accounts. */
     list_tmp = gsb_data_account_get_list_accounts ();
     while ( list_tmp )
     {
-	gint i = gsb_data_account_get_no_account ( list_tmp -> data );
+        gint i = gsb_data_account_get_no_account ( list_tmp -> data );
 
-	if ( etat.show_closed_accounts || 
-	     ! gsb_data_account_get_closed_account ( i ) )
-	{
-	    gsb_gui_navigation_add_account ( i, FALSE );
-	}
+        if ( etat.show_closed_accounts || 
+             ! gsb_data_account_get_closed_account ( i ) )
+        {
+            gsb_gui_navigation_add_account ( i, FALSE );
+        }
 
-	list_tmp = list_tmp -> next;
+        list_tmp = list_tmp -> next;
     }
 
     /* Expand stuff */
-    path = gtk_tree_model_get_path ( GTK_TREE_MODEL(navigation_model), &parent );
-    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW(navigation_tree_view), path );
+    path = gtk_tree_model_get_path ( GTK_TREE_MODEL ( model ), &parent );
+    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW ( navigation_tree_view ), path );
     gtk_tree_path_free ( path );
 }
 
@@ -464,33 +481,42 @@ void gsb_gui_navigation_create_account_list ( GtkTreeModel * model )
  * \param model		Tree model to insert items into.
  * \param reports_iter	Parent iter.
  */
-void create_report_list ( GtkTreeModel * model, GtkTreeIter * reports_iter )
+void gsb_gui_navigation_create_report_list ( GtkTreeModel *model )
 {
     GSList *tmp_list;
-    GtkTreeIter iter;
+    GtkTreeIter parent, child;
+    GtkTreePath *path;
+
+    path = gsb_gui_navigation_get_page_path ( model, GSB_REPORTS_PAGE );
+    gtk_tree_model_get_iter ( GTK_TREE_MODEL( model ), &parent, path );
+
+    /* Remove childs if any. */
+    while ( gtk_tree_model_iter_children ( model, &child, &parent ) )
+    {
+        gtk_tree_store_remove ( GTK_TREE_STORE ( model ), &child );
+    }
 
     /* Fill in with reports */
-    
     tmp_list = gsb_data_report_get_report_list ();
 
     while ( tmp_list )
     {
-	gint report_number;
+        gint report_number;
+
+        report_number = gsb_data_report_get_report_number ( tmp_list -> data );
 
-	report_number = gsb_data_report_get_report_number (tmp_list -> data);
-
-	gtk_tree_store_append(GTK_TREE_STORE(model), &iter, reports_iter);
-	gtk_tree_store_set(GTK_TREE_STORE(model), &iter, 
-			   NAVIGATION_PIX_VISIBLE, FALSE, 
-			   NAVIGATION_TEXT, gsb_data_report_get_report_name (report_number),
-			   NAVIGATION_FONT, 400,
-			   NAVIGATION_PAGE, GSB_REPORTS_PAGE,
-			   NAVIGATION_ACCOUNT, -1,
-			   NAVIGATION_SENSITIVE, 1,
-			   NAVIGATION_REPORT, report_number,
-			   -1 );
+        gtk_tree_store_append ( GTK_TREE_STORE ( model ), &child, &parent);
+        gtk_tree_store_set(GTK_TREE_STORE(model), &child, 
+                        NAVIGATION_PIX_VISIBLE, FALSE, 
+                        NAVIGATION_TEXT, gsb_data_report_get_report_name ( report_number ),
+                        NAVIGATION_FONT, 400,
+                        NAVIGATION_PAGE, GSB_REPORTS_PAGE,
+                        NAVIGATION_ACCOUNT, -1,
+                        NAVIGATION_SENSITIVE, 1,
+                        NAVIGATION_REPORT, report_number,
+                        -1 );
 	
-	tmp_list = tmp_list -> next;
+        tmp_list = tmp_list -> next;
     }
 }
 
@@ -502,53 +528,49 @@ void create_report_list ( GtkTreeModel * model, GtkTreeIter * reports_iter )
  *
  *
  */
-gboolean navigation_sort_column ( GtkTreeModel * model, 
-                        GtkTreeIter * a, GtkTreeIter * b, 
+gboolean navigation_sort_column ( GtkTreeModel *model, 
+                        GtkTreeIter *a,
+                        GtkTreeIter *b, 
                         gpointer user_data )
 {
-    gint page_a, page_b, account_a, account_b, report_a, report_b;
+    gint ordre_a, page_a, account_a, report_a;
+    gint ordre_b, page_b, account_b, report_b;
 
     if ( ! model )
-	return FALSE;
+        return FALSE;
 
     gtk_tree_model_get ( model, a, 
-			 NAVIGATION_PAGE, &page_a,
-			 NAVIGATION_ACCOUNT, &account_a,
-			 NAVIGATION_REPORT, &report_a,
-			 -1 );
+                        NAVIGATION_PAGE, &page_a,
+                        NAVIGATION_ACCOUNT, &account_a,
+                        NAVIGATION_REPORT, &report_a,
+                        NAVIGATION_ORDRE, &ordre_a,
+                        -1 );
 
     gtk_tree_model_get ( model, b, 
-			 NAVIGATION_PAGE, &page_b,
-			 NAVIGATION_ACCOUNT, &account_b,
-			 NAVIGATION_REPORT, &report_b,
-			 -1 );
+                        NAVIGATION_PAGE, &page_b,
+                        NAVIGATION_ACCOUNT, &account_b,
+                        NAVIGATION_REPORT, &report_b,
+                        NAVIGATION_ORDRE, &ordre_b,
+                        -1 );
+
+    if ( ordre_a < ordre_b )
+        return - 1;
+    if ( ordre_a > ordre_b )
+        return 1;
 
     if ( page_a == GSB_ACCOUNT_PAGE && page_b == GSB_ACCOUNT_PAGE )
     {
-	return gsb_data_account_compare_position (account_a, account_b);
+        return gsb_data_account_compare_position (account_a, account_b);
     }
     else if ( page_a == GSB_REPORTS_PAGE && page_b == GSB_REPORTS_PAGE )
     {
-	return gsb_data_report_compare_position (report_a, report_b);
+        return gsb_data_report_compare_position (report_a, report_b);
     }
     else
-    {
-	if ( page_a == page_b )
-	{
-	    return 0;
-	}
-	if ( page_a < page_b )
-	{
-	    return -1;
-	}
-	return 1;
-    }
+        return 0;
 }
 
 
-
-
-
 /**
  * Iterator that iterates over the navigation pane model and update
  * iter of account that is equal to `data'.
@@ -561,7 +583,7 @@ gboolean navigation_sort_column ( GtkTreeModel * model,
  *
  * \return TRUE if this iter matches.
  */
-static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel * tree_model, 
+static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel *tree_model, 
                         GtkTreePath *path, 
                         GtkTreeIter *iter, 
                         gpointer data )
@@ -595,7 +617,7 @@ static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel * tree
  *
  * \return TRUE if this iter matches.
  */
-static gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel * tree_model, 
+static gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel *tree_model, 
                         GtkTreePath *path, 
                         GtkTreeIter *iter, 
                         gpointer data )
@@ -638,7 +660,7 @@ void gsb_gui_navigation_update_report ( gint report_number )
  * \param report_iter	Iter to update.
  * \param data		Number of report as a reference.
  */
-void gsb_gui_navigation_update_report_iter ( GtkTreeModel * model, 
+void gsb_gui_navigation_update_report_iter ( GtkTreeModel *model, 
                         GtkTreeIter * report_iter,
                         gint report_number )
 {
@@ -665,7 +687,7 @@ void gsb_gui_navigation_update_report_iter ( GtkTreeModel * model,
  *
  * \return TRUE if this iter matches.
  */
-static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel * tree_model, 
+static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel *tree_model, 
                         GtkTreePath *path, 
                         GtkTreeIter *iter, 
                         gpointer data )
@@ -695,19 +717,17 @@ static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel * tree_
 void gsb_gui_navigation_add_report ( gint report_number )
 {
     GtkTreeIter parent, iter;
-    GtkTreeSelection * selection;
-    GtkTreePath * path;
+    GtkTreeSelection *selection;
+    GtkTreePath *path;
 
-    path = gtk_tree_path_new ();
-    gtk_tree_path_prepend_index ( path, GSB_REPORTS_PAGE - 1 );
-    gtk_tree_model_get_iter ( GTK_TREE_MODEL(navigation_model), &parent, path );
-    gtk_tree_store_append ( GTK_TREE_STORE(navigation_model), &iter, &parent );
-    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW(navigation_tree_view), path );
+    path = gsb_gui_navigation_get_page_path ( navigation_model, GSB_REPORTS_PAGE );
+    gtk_tree_model_get_iter ( GTK_TREE_MODEL( navigation_model ), &parent, path );
+    gtk_tree_store_append ( GTK_TREE_STORE ( navigation_model ), &iter, &parent );
+    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW ( navigation_tree_view ), path );
 
-    gsb_gui_navigation_update_report_iter ( GTK_TREE_MODEL(navigation_model), &iter, 
-					    report_number );    
+    gsb_gui_navigation_update_report_iter ( GTK_TREE_MODEL ( navigation_model ), &iter,  report_number );    
 
-    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(navigation_tree_view) );
+    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( navigation_tree_view ) );
     gtk_tree_selection_select_iter ( selection, &iter );
 }
 
@@ -748,24 +768,24 @@ void gsb_gui_navigation_update_account ( gint account_number )
  * \param account_iter	Iter to update.
  * \param data		Number of account as a reference.
  */
-void gsb_gui_navigation_update_account_iter ( GtkTreeModel * model, 
-                        GtkTreeIter * account_iter,
+void gsb_gui_navigation_update_account_iter ( GtkTreeModel *model, 
+                        GtkTreeIter *account_iter,
                         gint account_number )
 {
     GdkPixbuf * pixbuf = NULL;
 
     pixbuf = gsb_data_account_get_account_icon_pixbuf ( account_number );
 
-    gtk_tree_store_set(GTK_TREE_STORE(model), account_iter, 
-		       NAVIGATION_PIX, pixbuf,
-		       NAVIGATION_PIX_VISIBLE, TRUE, 
-		       NAVIGATION_TEXT, gsb_data_account_get_name ( account_number ), 
-		       NAVIGATION_FONT, 400,
-		       NAVIGATION_PAGE, GSB_ACCOUNT_PAGE,
-		       NAVIGATION_ACCOUNT, account_number,
-		       NAVIGATION_SENSITIVE, !gsb_data_account_get_closed_account ( account_number ),
-		       NAVIGATION_REPORT, -1,
-		       -1 );
+    gtk_tree_store_set ( GTK_TREE_STORE ( model ), account_iter, 
+                        NAVIGATION_PIX, pixbuf,
+                        NAVIGATION_PIX_VISIBLE, TRUE, 
+                        NAVIGATION_TEXT, gsb_data_account_get_name ( account_number ), 
+                        NAVIGATION_FONT, 400,
+                        NAVIGATION_PAGE, GSB_ACCOUNT_PAGE,
+                        NAVIGATION_ACCOUNT, account_number,
+                        NAVIGATION_SENSITIVE, !gsb_data_account_get_closed_account ( account_number ),
+                        NAVIGATION_REPORT, -1,
+                        -1 );
 }
 
 
@@ -782,7 +802,7 @@ void gsb_gui_navigation_update_account_iter ( GtkTreeModel * model,
  *
  * \return TRUE if this iter matches.
  */
-static gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel * tree_model, 
+static gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel *tree_model, 
                         GtkTreePath *path, 
                         GtkTreeIter *iter, 
                         gpointer data )
@@ -814,18 +834,20 @@ void gsb_gui_navigation_add_account ( gint account_number,
                         gboolean switch_to_account )
 {
     GtkTreeIter parent, iter;
+    GtkTreePath *path;
 
-    gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(navigation_model), &parent );
-    gtk_tree_store_append ( GTK_TREE_STORE(navigation_model), &iter, &parent );
+    path = gsb_gui_navigation_get_page_path ( navigation_model, GSB_HOME_PAGE );
+    gtk_tree_model_get_iter ( GTK_TREE_MODEL( navigation_model ), &parent, path );
+    gtk_tree_store_append ( GTK_TREE_STORE ( navigation_model ), &iter, &parent );
 
-    gsb_gui_navigation_update_account_iter ( GTK_TREE_MODEL(navigation_model), &iter, account_number );    
+    gsb_gui_navigation_update_account_iter ( GTK_TREE_MODEL ( navigation_model ), &iter, account_number );    
 
-    if (switch_to_account)
+    if ( switch_to_account )
     {
-	GtkTreeSelection * selection;
+        GtkTreeSelection * selection;
 
-	selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(navigation_tree_view) );
-	gtk_tree_selection_select_iter ( selection, &iter );
+        selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( navigation_tree_view ) );
+        gtk_tree_selection_select_iter ( selection, &iter );
     }
 }
 
@@ -1192,7 +1214,7 @@ gboolean gsb_gui_navigation_select_line ( GtkTreeSelection *selection,
  * Set the selection of the navigation list depending on desired
  * page and/or account or report.
  *
- * \param page		Page to switch to.
+ * \param page		        Page to switch to.
  * \param account_number	If page is GSB_ACCOUNT_PAGE, switch to given
  *			account.
  * \param report	If page is GSB_REPORTS, switch to given
@@ -1200,27 +1222,28 @@ gboolean gsb_gui_navigation_select_line ( GtkTreeSelection *selection,
  * 
  * \return		TRUE on success.
  */
-gboolean gsb_gui_navigation_set_selection ( gint page, gint account_number, gpointer report )
+gboolean gsb_gui_navigation_set_selection ( gint page,
+                        gint account_number,
+                        gpointer report )
 {
     GtkTreeIter iter;
-    GtkTreeSelection * selection;
+    GtkTreeSelection *selection;
 
-    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(navigation_tree_view) );
+    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( navigation_tree_view ) );
     g_return_val_if_fail ( selection, FALSE );
 
-    /* if we select an account, open the expander if necessary,
-     * we assume the accounts are still in first place */
-    if (page == GSB_ACCOUNT_PAGE)
+    /* if we select an account, open the expander if necessary */
+    if ( page == GSB_ACCOUNT_PAGE )
     {
-	GtkTreePath *path = gtk_tree_path_new_first ();
-	gtk_tree_view_expand_row ( GTK_TREE_VIEW (navigation_tree_view),
-				   path, TRUE );
-	gtk_tree_path_free (path);
+        GtkTreePath *path;
+
+        path = gsb_gui_navigation_get_page_path ( navigation_model, GSB_HOME_PAGE );
+        gtk_tree_view_expand_row ( GTK_TREE_VIEW ( navigation_tree_view ), path, TRUE );
+        gtk_tree_path_free (path);
     }
 
     gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(navigation_model), &iter );
-    gsb_gui_navigation_set_selection_branch ( selection, &iter, page, account_number, 
-					      report );
+    gsb_gui_navigation_set_selection_branch ( selection, &iter, page, account_number, report );
 
     return TRUE;
 }
@@ -1240,9 +1263,11 @@ gboolean gsb_gui_navigation_set_selection ( gint page, gint account_number, gpoi
  * 
  * \return		TRUE on success.
  */
-void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection * selection, 
-					    GtkTreeIter * iter, gint page, 
-					    gint account_number, gpointer report )
+void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection *selection, 
+					    GtkTreeIter *iter,
+                        gint page, 
+					    gint account_number,
+                        gpointer report )
 {
     do 
     {
@@ -1442,8 +1467,9 @@ gboolean gsb_gui_navigation_check_key_press ( GtkWidget *tree_view,
  *
  * \return FALSE, to allow future processing by the callback chain.
  */
-gboolean navigation_tree_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
-                        GtkSelectionData * selection_data )
+gboolean navigation_tree_drag_data_get ( GtkTreeDragSource *drag_source,
+                        GtkTreePath *path,
+                        GtkSelectionData *selection_data )
 {
     gchar *tmpstr = gtk_tree_path_to_string (path);
     gchar *tmpstr2 = g_strdup_printf ( "Orig path : %s", tmpstr);
@@ -1466,9 +1492,9 @@ gboolean navigation_tree_drag_data_get ( GtkTreeDragSource * drag_source, GtkTre
  *  
  *
  */
-gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
-                        GtkTreePath * dest_path,
-                        GtkSelectionData * selection_data )
+gboolean navigation_drag_data_received ( GtkTreeDragDest *drag_dest,
+                        GtkTreePath *dest_path,
+                        GtkSelectionData *selection_data )
 {
     gchar *tmpstr = gtk_tree_path_to_string (dest_path);
     gchar *tmpstr2 = g_strdup_printf ( "Dest path : %s", tmpstr);
@@ -1478,48 +1504,54 @@ gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
 
     if ( dest_path && selection_data )
     {
-	GtkTreeModel * model;
-	GtkTreeIter iter;
-	GtkTreePath * orig_path;
-	gint src_report, dst_report = -1;
-	gint src_account, dst_account = -1;
-
-	gtk_tree_get_row_drag_data (selection_data, &model, &orig_path);
-
-	if ( gtk_tree_model_get_iter ( GTK_TREE_MODEL(model), &iter, dest_path ) ) 
-	    gtk_tree_model_get (model , &iter, 
-				NAVIGATION_REPORT, &dst_report, 
-				NAVIGATION_ACCOUNT, &dst_account,
-				-1 );
-
-	if ( gtk_tree_model_get_iter ( GTK_TREE_MODEL(model), &iter, orig_path ) )
-	    gtk_tree_model_get ( model, &iter, 
-				 NAVIGATION_REPORT, &src_report, 
-				 NAVIGATION_ACCOUNT, &src_account,
-				 -1 );
-
-	/* at this stage, src_account or src_report contains the account/report we move
-	 * and dst_account/dst_report the account/report destination we want to move before,
-	 * or dst_account/dst_report can be -1 to set at the end of the list */
-	if (src_account != -1)
-	    /* we moved an account */
-	    gsb_data_account_move_account (src_account, dst_account);
-	if (src_report != -1 )
-	    /* we moved a report */
-	    gsb_data_report_move_report (src_report, dst_report);
-
-	/* update the tree view */
-	gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE(model),
-					       NAVIGATION_PAGE, GTK_SORT_ASCENDING );
-	gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE(model), 
-					  NAVIGATION_PAGE, navigation_sort_column,
-					  NULL, NULL );
-
-	/* update the order of accounts in first page */
-	mise_a_jour_liste_comptes_accueil = TRUE;
-
-	if ( etat.modification_fichier == 0 )
-        modification_fichier ( TRUE );
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+        GtkTreePath *orig_path;
+        gint src_report, dst_report = -1;
+        gint src_account, dst_account = -1;
+        gint src_ordre, dst_ordre = -1;
+
+        gtk_tree_get_row_drag_data (selection_data, &model, &orig_path);
+
+        if ( gtk_tree_model_get_iter ( GTK_TREE_MODEL(model), &iter, dest_path ) ) 
+            gtk_tree_model_get (model , &iter, 
+                        NAVIGATION_REPORT, &dst_report, 
+                        NAVIGATION_ACCOUNT, &dst_account,
+                        NAVIGATION_ORDRE, &dst_ordre,
+                        -1 );
+
+        if ( gtk_tree_model_get_iter ( GTK_TREE_MODEL(model), &iter, orig_path ) )
+            gtk_tree_model_get ( model, &iter, 
+                        NAVIGATION_REPORT, &src_report, 
+                        NAVIGATION_ACCOUNT, &src_account,
+                        NAVIGATION_ORDRE, &src_ordre,
+                        -1 );
+
+        /* at this stage, src_account or src_report contains the account/report we move
+         * and dst_account/dst_report the account/report destination we want to move before,
+         * or dst_account/dst_report can be -1 to set at the end of the list */
+        if ( src_account != -1 )
+            /* we moved an account */
+            gsb_data_account_move_account ( src_account, dst_account );
+        if ( src_report != -1 )
+            /* we moved a report */
+            gsb_data_report_move_report ( src_report, dst_report );
+        if ( src_ordre != -1 )
+            /* we moved a page */
+            gsb_gui_navigation_move_ordre ( src_ordre, dst_ordre );
+
+        /* update the tree view */
+        gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE ( model ),
+                        NAVIGATION_ORDRE, GTK_SORT_ASCENDING );
+        gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE ( model ), 
+                        NAVIGATION_ORDRE, navigation_sort_column,
+                        NULL, NULL );
+
+        /* update the order of accounts in first page */
+        mise_a_jour_liste_comptes_accueil = TRUE;
+
+        if ( etat.modification_fichier == 0 )
+            modification_fichier ( TRUE );
     }
     return FALSE;
 }
@@ -1530,49 +1562,50 @@ gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
  *
  *
  */
-gboolean navigation_row_drop_possible ( GtkTreeDragDest * drag_dest, 
-                        GtkTreePath * dest_path,
-                        GtkSelectionData * selection_data )
+gboolean navigation_row_drop_possible ( GtkTreeDragDest *drag_dest, 
+                        GtkTreePath *dest_path,
+                        GtkSelectionData *selection_data )
 {
     if ( dest_path && selection_data )
     {
-	GtkTreePath * orig_path;
-	GtkTreeModel * model;
-	gint src_report, dst_report = -1;
-	gint src_account, dst_account = -1, dst_page = -1;
-	GtkTreeIter iter;
-
-	gtk_tree_get_row_drag_data ( selection_data, &model, &orig_path );
-
-	if ( gtk_tree_model_get_iter ( model, &iter, orig_path ) )
-	    gtk_tree_model_get ( model, &iter, 
-				 NAVIGATION_REPORT, &src_report, 
-				 NAVIGATION_ACCOUNT, &src_account,
-				 -1 );
-
-	if ( gtk_tree_model_get_iter ( model, &iter, dest_path ) )
-	    gtk_tree_model_get ( model, &iter, 
-				 NAVIGATION_REPORT, &dst_report, 
-				 NAVIGATION_ACCOUNT, &dst_account,
-				 NAVIGATION_PAGE, &dst_page,
-				 -1 );
-	
-	/* We handle an account */
-	if ( src_account >= 0 && dst_account >= 0 )
-	{
-	    gchar* tmpstr =  g_strdup_printf ("> Possible (account, src : %d, dst : %d)", src_account, dst_account);
-	    notice_debug ( tmpstr );
-	    g_free ( tmpstr );
-	    return TRUE;
-	}
-	/* We handle a report */
-	else if ( src_report > 0 && dst_report > 0 )
-	{
-	    gchar* tmpstr = g_strdup_printf  ("> Possible (report, src : %d, dst : %d)", src_report, dst_report);
-	    notice_debug ( tmpstr );
-	    g_free ( tmpstr );
-	    return TRUE;
-	}
+        GtkTreePath *orig_path;
+        GtkTreeModel *model;
+        gint src_report, dst_report = -1;
+        gint src_account, dst_account = -1;
+        gint src_ordre, dst_ordre = -1;
+        GtkTreeIter iter;
+
+        gtk_tree_get_row_drag_data ( selection_data, &model, &orig_path );
+
+        if ( gtk_tree_model_get_iter ( model, &iter, orig_path ) )
+            gtk_tree_model_get ( model, &iter, 
+                        NAVIGATION_REPORT, &src_report, 
+                        NAVIGATION_ACCOUNT, &src_account,
+                        NAVIGATION_ORDRE, &src_ordre,
+                        -1 );
+
+        if ( gtk_tree_model_get_iter ( model, &iter, dest_path ) )
+            gtk_tree_model_get ( model, &iter, 
+                        NAVIGATION_REPORT, &dst_report, 
+                        NAVIGATION_ACCOUNT, &dst_account,
+                        NAVIGATION_ORDRE, &dst_ordre,
+                        -1 );
+
+        /* We handle an account */
+        if ( src_account >= 0 && dst_account >= 0 )
+        {
+            return TRUE;
+        }
+        /* We handle a report */
+        else if ( src_report > 0 && dst_report > 0 )
+        {
+            return TRUE;
+        }
+        else if ( src_ordre >= 0 && dst_ordre >= 0 )
+        {
+            return TRUE;
+        }
+
     }
 
     return FALSE;
@@ -1604,6 +1637,54 @@ GtkWidget *gsb_gui_navigation_get_tree_view ( void )
 
 
 /**
+ * change the position of an item in the list of pages
+ *
+ * \param src_ordre     the position of item we want to move
+ * \param dest_ordre	the position before we want to move, or -1 to set at the end of list
+ *
+ * \return FALSE
+ * */
+gboolean gsb_gui_navigation_move_ordre ( gint src_ordre,
+                        gint dst_ordre )
+{
+    GQueue *tmp_queue;
+    GList *dst_list;
+    gint i;
+    struct_page *page;
+
+    tmp_queue = pages_list;
+    for ( i = 0 ; i < tmp_queue -> length ; i++ )
+    {
+        page = g_queue_peek_nth ( tmp_queue, i );
+        if ( page -> ordre == src_ordre )
+            break;
+    }
+
+    g_queue_pop_nth ( pages_list, i );
+
+    dst_list = g_queue_peek_nth_link ( pages_list, dst_ordre );
+    if ( dst_list )
+        g_queue_insert_before ( pages_list, dst_list, page );
+    else
+        g_queue_push_tail ( tmp_queue, page );
+
+    /* on reconstruit le modèle */
+    gtk_tree_store_clear ( GTK_TREE_STORE ( navigation_model ) );
+
+    tmp_queue = pages_list;
+
+    for ( i = 0 ; i < tmp_queue -> length ; i++ )
+    {
+        page = g_queue_peek_nth ( tmp_queue, i );
+        page -> ordre = i;
+        gsb_gui_navigation_set_navigation_pages ( navigation_model, page -> type_page, i );
+    }
+
+    return FALSE;
+}
+
+
+/**
  *
  *
  *
@@ -1714,46 +1795,48 @@ GQueue *gsb_gui_navigation_get_pages_list ( void )
  *
  *
  */
-void gsb_gui_navigation_set_navigation_pages ( GtkTreeModel *model, gint type_page )
+void gsb_gui_navigation_set_navigation_pages ( GtkTreeModel *model,
+                        gint type_page,
+                        gint ordre )
 {
     GdkPixbuf *pixbuf;
     GtkTreeIter iter;
-    gchar *title;
-	gchar* tmpstr;
+    gchar *title = NULL;
+    gchar *tmp_str = NULL;
 
     switch ( type_page )
     {
         case GSB_HOME_PAGE :
-            tmpstr = g_build_filename ( gsb_dirs_get_pixmaps_dir ( ), "ac_home.png", NULL );
+            tmp_str = g_build_filename ( gsb_dirs_get_pixmaps_dir ( ), "ac_home.png", NULL );
             title = g_strdup ( _("Accounts") );
         break;
         case GSB_SCHEDULER_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "scheduler.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "scheduler.png", NULL );
             title = g_strdup ( _("Scheduler") );
         break;
         case GSB_PAYEES_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "payees.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "payees.png", NULL );
             title = g_strdup ( _("Payees") );
         break;
         case GSB_SIMULATOR_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "ac_liability.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "ac_liability.png", NULL );
             title = g_strdup ( _("Credits simulator") );
         break;
         case GSB_CATEGORIES_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "categories.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "categories.png", NULL );
             title = g_strdup ( _("Categories") );
         break;
         case GSB_BUDGETARY_LINES_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "budgetary_lines.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "budgetary_lines.png", NULL );
             title = g_strdup ( _("Budgetary lines") );
         break;
         case GSB_REPORTS_PAGE :
-            tmpstr = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "reports.png", NULL );
+            tmp_str = g_build_filename( gsb_dirs_get_pixmaps_dir ( ), "reports.png", NULL );
             title = g_strdup ( _("Reports") );
         break;
     }
 
-    pixbuf = gdk_pixbuf_new_from_file ( tmpstr , NULL );
+    pixbuf = gdk_pixbuf_new_from_file ( tmp_str , NULL );
     gtk_tree_store_append ( GTK_TREE_STORE ( model ), &iter, NULL );
     gtk_tree_store_set( GTK_TREE_STORE ( navigation_model ), &iter,
                         NAVIGATION_PIX, pixbuf,
@@ -1764,21 +1847,52 @@ void gsb_gui_navigation_set_navigation_pages ( GtkTreeModel *model, gint type_pa
                         NAVIGATION_ACCOUNT, -1,
                         NAVIGATION_REPORT, -1,
                         NAVIGATION_SENSITIVE, 1,
+                        NAVIGATION_ORDRE, ordre,
                         -1);
 
-    g_free ( tmpstr );
+    g_free ( tmp_str );
     g_free ( title );
 
     switch ( type_page )
     {
-        case GSB_HOME_PAGE :    /* Account list */
+        case GSB_HOME_PAGE :
             gsb_gui_navigation_create_account_list ( GTK_TREE_MODEL( model ) );
         break;
         case GSB_REPORTS_PAGE :
-            create_report_list ( GTK_TREE_MODEL( model), &iter );
-        break; 
+            gsb_gui_navigation_create_report_list ( GTK_TREE_MODEL( model) );
+        break;
+    }
+
+}
+
+
+/**
+ * renvoie le path d'un item de la vue navigation
+ *
+ *
+ */
+GtkTreePath *gsb_gui_navigation_get_page_path ( GtkTreeModel *model, gint type_page )
+{
+    GtkTreeIter iter;
+
+    if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+    {
+        do
+        {
+            gint tmp_type_page;
+            GtkTreePath *path = NULL;
+
+            gtk_tree_model_get ( GTK_TREE_MODEL( model ), &iter,  NAVIGATION_PAGE, &tmp_type_page, -1 );
+            if ( tmp_type_page == type_page)
+            {
+                path = gtk_tree_model_get_path ( GTK_TREE_MODEL ( model ), &iter );
+                return path;
+            }
+        }
+        while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
     }
 
+    return NULL;
 }
 
 
diff --git a/src/navigation.h b/src/navigation.h
index e9f5db5..e518863 100644
--- a/src/navigation.h
+++ b/src/navigation.h
@@ -13,6 +13,7 @@ enum navigation_cols {
     NAVIGATION_ACCOUNT,
     NAVIGATION_REPORT,
     NAVIGATION_SENSITIVE,
+    NAVIGATION_ORDRE,        /* ordre des pages dans le modèle */
     NAVIGATION_TOTAL,
 };
 
@@ -60,12 +61,12 @@ void gsb_gui_navigation_update_report ( gint report_number ) ;
 void gsb_navigation_update_account_label ( gint account_number );
 void gsb_navigation_update_statement_label ( gint account_number );
 gboolean navigation_change_account ( gint *no_account );
-gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
-                        GtkTreePath * dest_path,
-                        GtkSelectionData * selection_data );
-gboolean navigation_row_drop_possible ( GtkTreeDragDest * drag_dest, 
-                        GtkTreePath * dest_path,
-                        GtkSelectionData * selection_data );
+gboolean navigation_drag_data_received ( GtkTreeDragDest *drag_dest,
+                        GtkTreePath *dest_path,
+                        GtkSelectionData *selection_data );
+gboolean navigation_row_drop_possible ( GtkTreeDragDest *drag_dest, 
+                        GtkTreePath *dest_path,
+                        GtkSelectionData *selection_data );
 /* END_DECLARATION */
 
 #endif


hooks/post-receive
-- 
grisbi


More information about the cvs mailing list