[grisbi-cvs] grisbi/src categories_onglet.c, 1.190, 1.191 gsb_data_budget.c, 1.45, 1.46 import.c, 1.265, 1.266 imputation_budgetaire.c, 1.153, 1.154

Pierre Biava pbiava at users.sourceforge.net
Thu Mar 19 23:31:40 CET 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3408/src

Modified Files:
	categories_onglet.c gsb_data_budget.c import.c 
	imputation_budgetaire.c 
Log Message:
fix bug 435

Index: categories_onglet.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/categories_onglet.c,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -d -r1.190 -r1.191
--- categories_onglet.c	5 Mar 2009 19:12:28 -0000	1.190
+++ categories_onglet.c	19 Mar 2009 22:31:38 -0000	1.191
@@ -34,6 +34,7 @@
 #include "./gsb_file.h"
 #include "./gsb_file_others.h"
 #include "./main.h"
+#include "./utils_str.h"
 #include "./utils.h"
 #include "./utils_buttons.h"
 #include "./transaction_list.h"
@@ -45,7 +46,7 @@
 /*END_INCLUDE*/
 
 /*START_STATIC*/
-static void appui_sur_ajout_category ( GtkTreeModel * model );
+static void appui_sur_ajout_category ( GtkTreeModel * model, GtkButton *button );
 static gboolean categ_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
 			       GtkSelectionData * selection_data );
 static GtkWidget *creation_barre_outils_categ ( void );
@@ -53,6 +54,7 @@
 static gboolean exporter_categ ( GtkButton * widget, gpointer data );
 static void importer_categ ( void );
 static gboolean popup_category_view_mode_menu ( GtkWidget * button );
+static void selectionne_sub_category ( GtkTreeModel * model );
 /*END_STATIC*/
 
 
@@ -456,29 +458,31 @@
     button = gsb_automem_imagefile_button_new ( etat.display_toolbar,
 					       _("New\ncategory"),
 					       "new-categ.png",
-					       G_CALLBACK( appui_sur_ajout_category ),
+					       G_CALLBACK ( appui_sur_ajout_category ),
 					       categ_tree_model );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Create a new category")));
     gtk_box_pack_start ( GTK_BOX ( hbox2 ), button, FALSE, TRUE, 0 );
+    g_object_set_data ( G_OBJECT (button), "type", GINT_TO_POINTER (1) );
 
     /* New sub category button */
     button = gsb_automem_imagefile_button_new ( etat.display_toolbar,
 					       _("New sub\ncategory"),
 					       "new-sub-categ.png",
-					       G_CALLBACK(appui_sur_ajout_sub_division),
+					       G_CALLBACK (appui_sur_ajout_category),
 					       categ_tree_model );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(categ_tree_model), button, "selection" );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(categ_tree_model), button, "sub-division" );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Create a new sub-category")));
     gtk_box_pack_start ( GTK_BOX ( hbox2 ), button, FALSE, TRUE, 0 );
+    g_object_set_data ( G_OBJECT (button), "type", GINT_TO_POINTER (2) );
 
     /* Import button */
     button = gsb_automem_stock_button_new ( etat.display_toolbar,
 					   GTK_STOCK_OPEN,
 					   _("Import"),
-					   G_CALLBACK(importer_categ),
+					   G_CALLBACK (importer_categ),
 					   NULL );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Import a Grisbi category file (.cgsb)")));
@@ -497,7 +501,7 @@
     /* Delete button */
     button = gsb_automem_stock_button_new ( etat.display_toolbar,
 					   GTK_STOCK_DELETE, _("Delete"),
-					   G_CALLBACK(supprimer_division), arbre_categ );
+					   G_CALLBACK (supprimer_division), arbre_categ );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(categ_tree_model), button, "selection" );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Delete selected category")));
@@ -506,7 +510,7 @@
     /* Properties button */
     button = gsb_automem_stock_button_new ( etat.display_toolbar,
 					   GTK_STOCK_PROPERTIES, _("Properties"),
-					   G_CALLBACK(edit_category), arbre_categ );
+					   G_CALLBACK (edit_category), arbre_categ );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(categ_tree_model), button, "selection" );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Edit selected category")));
@@ -516,7 +520,7 @@
     button = gsb_automem_stock_button_menu_new ( etat.display_toolbar,
 						GTK_STOCK_SELECT_COLOR,
 						_("View"),
-						G_CALLBACK(popup_category_view_mode_menu),
+						G_CALLBACK (popup_category_view_mode_menu),
 						NULL );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Change view mode")));
@@ -764,15 +768,80 @@
  *
  * \param the model for the division
  */
-void appui_sur_ajout_category ( GtkTreeModel * model )
+void appui_sur_ajout_category ( GtkTreeModel * model, GtkButton *button )
 {
-    metatree_new_division ( model );
+    gint type;
+
+    type = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT (button), "type" ) );
+    if ( type == 1 )
+        metatree_new_division ( model );
+    else
+    {
+        appui_sur_ajout_sub_division ( model );
+        selectionne_sub_category ( model );
+    }
     sortie_edit_category = FALSE;
     edit_category ( GTK_TREE_VIEW ( arbre_categ ) );
     if ( sortie_edit_category )
         supprimer_division ( GTK_TREE_VIEW ( arbre_categ ) );
     sortie_edit_category = FALSE;
 }
+
+
+/**
+ * function to expand category and select new sub-category.
+ *
+ * \param the model for the division
+ */
+void selectionne_sub_category ( GtkTreeModel * model )
+{
+    GtkTreeSelection * selection;
+    GtkTreeIter parent;
+    GtkTreeIter iter;
+    gchar * name;
+    gint category_number = -1, sub_category_number = -1;
+    gint i = 0,j = 0;
+
+    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (arbre_categ) );
+    if ( selection && gtk_tree_selection_get_selected (
+                        selection, &model, &parent ) )
+    {
+	gtk_tree_model_get ( model, &parent,
+                        META_TREE_NO_DIV_COLUMN, &category_number,
+                        META_TREE_NO_SUB_DIV_COLUMN, &sub_category_number,
+                        -1 );
+    }
+
+    if ( !selection || category_number <= 0 )
+        return;
+
+    if ( sub_category_number > 0 )
+        return;
+
+    name =  my_strdup (_("New sub-category"));
+    sub_category_number = gsb_data_category_get_sub_category_number_by_name ( 
+                        category_number, name, FALSE );
+    j = gtk_tree_model_iter_n_children ( model, &parent );
+    for (i = 0; i < j; i++ )
+    {
+        gint numero;
+
+        gtk_tree_model_iter_nth_child ( model, &iter, &parent, i );
+        gtk_tree_model_get ( model, &iter,
+                        META_TREE_NO_SUB_DIV_COLUMN, &numero,
+                        -1 );
+        if ( numero == sub_category_number )
+            break;
+    }
+    GtkTreePath * path = gtk_tree_model_get_path ( model, &iter );
+    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW (arbre_categ), path );
+    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (arbre_categ) );
+    gtk_tree_selection_select_path ( selection, path );
+    gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (arbre_categ), path,
+                        NULL, TRUE, 0.5, 0.5 );
+    gtk_tree_path_free ( path );
+    g_free ( name );
+}
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */

Index: gsb_data_budget.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_budget.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- gsb_data_budget.c	5 Mar 2009 19:12:29 -0000	1.45
+++ gsb_data_budget.c	19 Mar 2009 22:31:38 -0000	1.46
@@ -1527,14 +1527,14 @@
 				2 );
 
 	/* we don't mind if tab_char exists and others, all the checks will be done in ...get_number_by_name */
-	budget_number = gsb_data_budget_get_number_by_name ( tab_char[0],
+	budget_number = gsb_data_budget_get_number_by_name ( g_strstrip (tab_char[0]),
 							     TRUE,
 							     gsb_data_transaction_get_amount (transaction_number).mantissa <0 );
 	gsb_data_transaction_set_budgetary_number ( transaction_number,
 						    budget_number );
 	gsb_data_transaction_set_sub_budgetary_number ( transaction_number,
 							gsb_data_budget_get_sub_budget_number_by_name ( budget_number,
-													tab_char[1],
+													g_strstrip (tab_char[1]),
 													TRUE ));
     }
     else

Index: import.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/import.c,v
retrieving revision 1.265
retrieving revision 1.266
diff -u -d -r1.265 -r1.266
--- import.c	17 Mar 2009 22:05:33 -0000	1.265
+++ import.c	19 Mar 2009 22:31:38 -0000	1.266
@@ -2,6 +2,7 @@
 /*                                                                            */
 /*     Copyright (C)	2000-2008 Cédric Auger (cedric at grisbi.org)	          */
 /*			2004-2008 Benjamin Drieu (bdrieu at april.org)	                      */
+/*          2008-2009 Pierre Biava (pierre at pierre.biava.name)                 */
 /* 			http://www.grisbi.org				                              */
 /*                                                                            */
 /*  This program is free software; you can redistribute it and/or modify      */

Index: imputation_budgetaire.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/imputation_budgetaire.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- imputation_budgetaire.c	5 Mar 2009 19:12:30 -0000	1.153
+++ imputation_budgetaire.c	19 Mar 2009 22:31:38 -0000	1.154
@@ -41,6 +41,7 @@
 #include "./gsb_form_widget.h"
 #include "./gtk_combofix.h"
 #include "./main.h"
+#include "./utils_str.h"
 #include "./utils.h"
 #include "./utils_buttons.h"
 #include "./transaction_list.h"
@@ -54,7 +55,7 @@
 /*END_INCLUDE*/
 
 /*START_STATIC*/
-static void appui_sur_ajout_imputation ( GtkTreeModel * model );
+static void appui_sur_ajout_imputation ( GtkTreeModel * model, GtkButton *button );
 static gboolean budgetary_line_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
 					GtkSelectionData * selection_data );
 static GtkWidget *creation_barre_outils_ib ( void );
@@ -62,6 +63,7 @@
 static void exporter_ib ( void );
 static void importer_ib ( void );
 static gboolean popup_budgetary_line_view_mode_menu ( GtkWidget * button );
+static void selectionne_sub_budgetary ( GtkTreeModel * model );
 /*END_STATIC*/
 
 
@@ -494,18 +496,20 @@
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Create a new budgetary line")));
     gtk_box_pack_start ( GTK_BOX ( hbox2 ), button, FALSE, TRUE, 0 );
+    g_object_set_data ( G_OBJECT (button), "type", GINT_TO_POINTER (1) );
 
     /* New sub budgetary line button */
     button = gsb_automem_imagefile_button_new ( etat.display_toolbar,
 					       _("New sub\nbudgetary line"),
 					       "new-sub-ib.png",
-					       G_CALLBACK(appui_sur_ajout_sub_division),
+					       G_CALLBACK(appui_sur_ajout_imputation),
 					       budgetary_line_tree_model );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(budgetary_line_tree_model), button, "selection" );
     metatree_register_widget_as_linked ( GTK_TREE_MODEL(budgetary_line_tree_model), button, "sub-division" );
     gtk_widget_set_tooltip_text ( GTK_WIDGET (button),
 				  SPACIFY(_("Create a new sub-budgetary line")));
     gtk_box_pack_start ( GTK_BOX ( hbox2 ), button, FALSE, TRUE, 0 );
+    g_object_set_data ( G_OBJECT (button), "type", GINT_TO_POINTER (2) );
 
     /* Import button */
     button = gsb_automem_stock_button_new ( etat.display_toolbar,
@@ -799,15 +803,81 @@
  *
  * \param the model for the division
  */
-void appui_sur_ajout_imputation ( GtkTreeModel * model )
+void appui_sur_ajout_imputation ( GtkTreeModel * model, GtkButton *button )
 {
-    metatree_new_division ( model );
+    gint type;
+
+    type = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT (button), "type" ) );
+    if ( type == 1 )
+        metatree_new_division ( model );
+    else
+    {
+        appui_sur_ajout_sub_division ( model );
+        selectionne_sub_budgetary ( model );
+    }
     sortie_edit_budgetary_line = FALSE;
     edit_budgetary_line ( GTK_TREE_VIEW ( budgetary_line_tree ) );
     if ( sortie_edit_budgetary_line )
         supprimer_division ( GTK_TREE_VIEW ( budgetary_line_tree ) );
     sortie_edit_budgetary_line = FALSE;
 }
+
+
+/**
+ * function to expand budgetary and select new sub-budgetary.
+ *
+ * \param the model for the division
+ */
+void selectionne_sub_budgetary ( GtkTreeModel * model )
+{
+    GtkTreeSelection * selection;
+    GtkTreeIter parent;
+    GtkTreeIter iter;
+    gchar * name;
+    gint budget_number = -1, sub_budget_number = -1;
+    gint i = 0,j = 0;
+
+    selection = gtk_tree_view_get_selection ( 
+                        GTK_TREE_VIEW (budgetary_line_tree) );
+    if ( selection && gtk_tree_selection_get_selected (
+                        selection, &model, &parent ) )
+    {
+	gtk_tree_model_get ( model, &parent,
+                        META_TREE_NO_DIV_COLUMN, &budget_number,
+                        META_TREE_NO_SUB_DIV_COLUMN, &sub_budget_number,
+                        -1 );
+    }
+
+    if ( !selection || budget_number <= 0 )
+        return;
+
+    if ( sub_budget_number > 0 )
+        return;
+
+    name =  my_strdup (_("New sub-budget"));
+    sub_budget_number = gsb_data_budget_get_sub_budget_number_by_name ( 
+                        budget_number, name, FALSE );
+    j = gtk_tree_model_iter_n_children ( model, &parent );
+    for (i = 0; i < j; i++ )
+    {
+        gint numero;
+
+        gtk_tree_model_iter_nth_child ( model, &iter, &parent, i );
+        gtk_tree_model_get ( model, &iter,
+                        META_TREE_NO_SUB_DIV_COLUMN, &numero,
+                        -1 );
+        if ( numero == sub_budget_number )
+            break;
+    }
+    GtkTreePath * path = gtk_tree_model_get_path ( model, &iter );
+    gtk_tree_view_expand_to_path ( GTK_TREE_VIEW (budgetary_line_tree), path );
+    selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (budgetary_line_tree) );
+    gtk_tree_selection_select_path ( selection, path );
+    gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (budgetary_line_tree), path,
+                        NULL, TRUE, 0.5, 0.5 );
+    gtk_tree_path_free ( path );
+    g_free ( name );
+}
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */



More information about the cvs mailing list