/** * Update the clickable list of closed accounts and target * accounts to move a transaction, in menu. * * \param * \return FALSE * */ gboolean gsb_menu_update_accounts_in_menus ( void ) { GSList *list_tmp; GtkActionGroup * action_group; if ( move_to_account_merge_id != -1 ) gtk_ui_manager_remove_ui ( ui_manager, move_to_account_merge_id ); move_to_account_merge_id = gtk_ui_manager_new_merge_id ( ui_manager ); action_group = gtk_action_group_new ( "Group3" ); /* create the closed accounts and accounts in the menu to move a transaction */ list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint i; i = gsb_data_account_get_no_account ( list_tmp -> data ); if ( !gsb_data_account_get_closed_account ( i ) ) { gchar *tmp_name; gchar *account_name; GtkAction *action; tmp_name = g_strdup_printf ( "MoveToAccount%d", i ); account_name = gsb_data_account_get_name ( i ); if ( !account_name ) account_name = _("Unnamed account"); action = gtk_action_new ( tmp_name, account_name, "", "" ); if ( gsb_gui_navigation_get_current_account () == i ) gtk_action_set_sensitive ( action, FALSE ); gtk_action_group_add_action ( action_group, action ); g_signal_connect ( action, "activate", G_CALLBACK ( move_selected_operation_to_account_nb ), GINT_TO_POINTER ( i ) ); gtk_ui_manager_add_ui ( ui_manager, move_to_account_merge_id, "/menubar/EditMenu/MoveToAnotherAccount/", tmp_name, tmp_name, GTK_UI_MANAGER_MENUITEM, FALSE ); g_free ( tmp_name ); } list_tmp = list_tmp -> next; } gtk_ui_manager_insert_action_group ( ui_manager, action_group, 2 ); gtk_ui_manager_ensure_update ( ui_manager ); return FALSE; }
/** * create a combobox containing the list of the accounts * * \param func Function to call when a line is selected (type : gboolean func ( GtkWidget *button, gpointer data ) * \param data data to send to the function * \param include_closed If set to TRUE, include the closed accounts * * \return a new GtkCombobox containing the list of the accounts */ GtkWidget *gsb_account_create_combo_list ( GCallback func, gpointer data, gboolean include_closed ) { GSList *list_tmp; GtkListStore *store; GtkCellRenderer *renderer; GtkWidget *combobox; combobox = gtk_combo_box_new (); store = gtk_list_store_new ( 2, G_TYPE_STRING, G_TYPE_INT ); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GtkTreeIter iter; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); if ( account_number >= 0 && ( !gsb_data_account_get_closed_account (account_number) || include_closed ) ) { gtk_list_store_append ( GTK_LIST_STORE (store), &iter ); gtk_list_store_set ( store, &iter, 0, gsb_data_account_get_name (account_number), 1, account_number, -1 ); } list_tmp = list_tmp -> next; } gtk_combo_box_set_model ( GTK_COMBO_BOX (combobox), GTK_TREE_MODEL (store)); /* by default, this is blank, so set the first */ gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox), 0 ); if ( func ) g_signal_connect ( G_OBJECT (combobox), "changed", G_CALLBACK(func), data ); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); return combobox; }
/** * Create a menu with the list of accounts. This list is * clickable and activates func if specified. * used for now to add a submenu item in a main menu * * \param func Function to call when a line is selected * \param activate_currrent If set to TRUE, does not mark as * unsensitive current account * \param include_closed If set to TRUE, include the closed accounts * * \return A newly created menu */ GtkWidget *gsb_account_create_menu_list ( GCallback func, gboolean activate_currrent, gboolean include_closed ) { GtkWidget *menu; GtkWidget *item; GSList *list_tmp; menu = gtk_menu_new (); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint i; i = gsb_data_account_get_no_account ( list_tmp -> data ); if ( i >= 0 && ( !gsb_data_account_get_closed_account (i) || include_closed ) ) { item = gtk_menu_item_new_with_label ( gsb_data_account_get_name (i)); g_object_set_data ( G_OBJECT ( item ), "account_number", GINT_TO_POINTER (i)); if ( func ) g_signal_connect ( G_OBJECT ( item ), "activate", G_CALLBACK(func), NULL ); gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), item ); if ( !activate_currrent && gsb_gui_navigation_get_current_account () == i) { gtk_widget_set_sensitive ( item, FALSE ); } gtk_widget_show ( item ); } list_tmp = list_tmp -> next; } return ( menu ); }
/** * update the list of accounts in a combo_box filled * by gsb_account_create_combo_list * * \param combo_box * \param include_closed * * \return FALSE * */ gboolean gsb_account_update_combo_list ( GtkWidget *combo_box, gboolean include_closed ) { GSList *list_tmp; GtkListStore *store; if (!combo_box) return FALSE; store = GTK_LIST_STORE (gtk_combo_box_get_model ( GTK_COMBO_BOX (combo_box))); gtk_list_store_clear (store); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GtkTreeIter iter; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); if ( account_number >= 0 && ( !gsb_data_account_get_closed_account (account_number) || include_closed ) ) { gtk_list_store_append ( GTK_LIST_STORE (store), &iter ); gtk_list_store_set ( store, &iter, 0, gsb_data_account_get_name (account_number), 1, account_number, -1 ); } list_tmp = list_tmp -> next; } return FALSE; }