/** * This function is called when the main window is deleted. * It proposes to save the file if necessary. */ static gboolean main_window_delete_event (GtkWidget *window, gpointer data) { /* need to save the config before gsb_file_close */ gsb_file_config_save_config(); if (!gsb_file_close ()) return TRUE; return FALSE; }
/** * called by file -> last files -> click on the name * * \param item * \param file_number_ptr the number of file in a pointer format * * \return FALSE * */ gboolean gsb_file_open_direct_menu ( GtkMenuItem *item, gint *file_number_ptr ) { /* continue only if can close the current file */ if ( !gsb_file_close() ) return FALSE; nom_fichier_comptes = my_strdup (tab_noms_derniers_fichiers_ouverts[GPOINTER_TO_INT (file_number_ptr)]); gsb_file_open_file (nom_fichier_comptes); return FALSE; }
/** * Called by menu file -> new, * close the last file and open a new one * in fact just an assistant launcher, but need to check if the previous file is closed * * \param none * * \return FALSE * */ gboolean gsb_file_new ( void ) { /* continue only if closing the file is ok */ if ( !gsb_file_close () ) return FALSE; /* set up all the default variables */ init_variables (); gsb_assistant_file_run (FALSE, FALSE); return FALSE; }
/** * called by file -> open * open a new file * * \param * * \return FALSE * */ gboolean gsb_file_open_menu ( void ) { GtkWidget *selection_fichier; GtkFileFilter * filter; selection_fichier = gtk_file_chooser_dialog_new ( _("Open an accounts file"), GTK_WINDOW ( run.window ), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( selection_fichier ), gsb_file_get_last_path () ); gtk_window_set_position ( GTK_WINDOW ( selection_fichier ), GTK_WIN_POS_CENTER_ON_PARENT ); filter = gtk_file_filter_new (); gtk_file_filter_set_name ( filter, _("Grisbi files (*.gsb)") ); gtk_file_filter_add_pattern ( filter, "*.gsb" ); gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( selection_fichier ), filter ); gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( selection_fichier ), filter ); filter = gtk_file_filter_new (); gtk_file_filter_set_name ( filter, _("All files") ); gtk_file_filter_add_pattern ( filter, "*" ); gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( selection_fichier ), filter ); switch ( gtk_dialog_run ( GTK_DIALOG (selection_fichier))) { case GTK_RESPONSE_OK: if ( gsb_file_close() ) { gtk_widget_hide ( selection_fichier ); nom_fichier_comptes = file_selection_get_filename ( GTK_FILE_CHOOSER ( selection_fichier ) ); gsb_file_update_last_path ( file_selection_get_last_directory ( GTK_FILE_CHOOSER ( selection_fichier), TRUE ) ); gsb_file_open_file (nom_fichier_comptes); } break; default: break; } gsb_file_update_last_path (file_selection_get_last_directory (GTK_FILE_CHOOSER (selection_fichier), TRUE)); gtk_widget_destroy ( selection_fichier ); return FALSE; }
/** that function delete the current account selected in the account properties * \param none * \return FALSE FALSE * */ gboolean gsb_account_delete ( void ) { gint deleted_account; gint page_number; GSList *list_tmp; gchar* tmpstr; deleted_account = gsb_gui_navigation_get_current_account (); tmpstr = g_strdup_printf (_("Delete account \"%s\"?"), gsb_data_account_get_name ( deleted_account ) ) ; if ( !question_yes_no_hint ( tmpstr, _("This will irreversibly remove this account and all operations " "that were previously contained. There is no undo for this. " "Usually it's a better way to close an account."), GTK_RESPONSE_NO )) { g_free ( tmpstr ); return FALSE; } g_free ( tmpstr ); /* if the last account, close the file */ if ( gsb_data_account_get_accounts_amount () == 1 ) { gsb_file_set_modified ( FALSE ); gsb_file_close (); return FALSE; } /* delete the schedules transactions on that account */ list_tmp = gsb_data_scheduled_get_scheduled_list (); while (list_tmp) { gint scheduled_number; scheduled_number = gsb_data_scheduled_get_scheduled_number ( list_tmp -> data ); if ( gsb_data_scheduled_get_account_number (scheduled_number) == deleted_account ) gsb_data_scheduled_remove_scheduled (scheduled_number); list_tmp = list_tmp -> next; } /* remove all the transactions of that account */ list_tmp = gsb_data_transaction_get_complete_transactions_list (); while (list_tmp) { gint transaction_number; transaction_number = gsb_data_transaction_get_transaction_number ( list_tmp -> data ); /* better to go to the next transaction now */ list_tmp = list_tmp -> next; if (gsb_data_transaction_get_account_number (transaction_number) == deleted_account) { gint contra_transaction_number; /* we are on a transaction on the deleted account, we delete that transaction, * but if it's a transfer, modify the contra-transaction to set transfer to deleted account */ contra_transaction_number = gsb_data_transaction_get_contra_transaction_number ( transaction_number); if (contra_transaction_number > 0) /* it's a transfer, modify the contra-transaction */ gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number, -1); /* now can remove the transaction */ gsb_data_transaction_remove_transaction_without_check ( transaction_number ); } } /* delete the payment_number */ list_tmp = gsb_data_account_get_sort_list ( deleted_account ); while (list_tmp) { gpointer ptr; gint payment_number; ptr = list_tmp -> data; payment_number = GPOINTER_TO_INT ( ptr ); gsb_data_payment_remove ( payment_number ); list_tmp = list_tmp -> next; } /* delete the account */ gsb_data_account_delete ( deleted_account ); /* check gsb_gui_navigation_get_current_account () and gsb_gui_navigation_get_current_account ()_onglet and put them * on the first account if they are on the deleted account */ if ( gsb_gui_navigation_get_current_account () == deleted_account ) { GtkWidget *notebook_general; /* update the transaction list */ notebook_general = gsb_gui_get_general_notebook ( ); page_number = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( notebook_general ) ); navigation_change_account ( gsb_data_account_first_number () ); gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), page_number ); } /* update the buttons lists */ gsb_menu_update_accounts_in_menus(); /* Replace trees contents. */ categories_fill_list (); budgetary_lines_fill_list (); payees_fill_list (); /* update the categories in lists */ transaction_list_update_element (ELEMENT_CATEGORY); /* update the name of accounts in form */ gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT), FALSE ); gsb_scheduler_list_fill_list (gsb_scheduler_list_get_tree_view ()); mise_a_jour_liste_echeances_manuelles_accueil = 1; mise_a_jour_liste_comptes_accueil = 1; mise_a_jour_soldes_minimaux = 1; mise_a_jour_fin_comptes_passifs = 1; /* Update navigation pane. */ gsb_gui_navigation_remove_account ( deleted_account ); gsb_file_set_modified ( TRUE ); return FALSE; }