r20033 - gnucash/trunk/src/gnome - Add "copy budget" command to menu. Works like "open budget" except that a copy of the budget is made with the name "Copy of "+name of old budget.
Phil Longstaff
plongstaff at code.gnucash.org
Thu Jan 6 20:48:17 EST 2011
Author: plongstaff
Date: 2011-01-06 20:48:17 -0500 (Thu, 06 Jan 2011)
New Revision: 20033
Trac: http://svn.gnucash.org/trac/changeset/20033
Modified:
gnucash/trunk/src/gnome/gnc-plugin-budget.c
gnucash/trunk/src/gnome/ui/gnc-plugin-budget-ui.xml
Log:
Add "copy budget" command to menu. Works like "open budget" except that a copy of the budget is made with the name "Copy of "+name of old budget.
This command will allow you to easily create a copy of your 2010 budget and change its name to "2011". I also plan to add UI capabilities to more easily manipulate budget numbers.
Modified: gnucash/trunk/src/gnome/gnc-plugin-budget.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-budget.c 2011-01-05 09:46:59 UTC (rev 20032)
+++ gnucash/trunk/src/gnome/gnc-plugin-budget.c 2011-01-07 01:48:17 UTC (rev 20033)
@@ -50,6 +50,8 @@
GncMainWindowActionData *data);
static void gnc_plugin_budget_cmd_open_budget (GtkAction *action,
GncMainWindowActionData *data);
+static void gnc_plugin_budget_cmd_copy_budget (GtkAction *action,
+ GncMainWindowActionData *data);
static GtkActionEntry gnc_plugin_actions [] =
{
@@ -64,6 +66,12 @@
N_("Open an existing Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_open_budget)
},
+
+ {
+ "CopyBudgetAction", NULL, N_("Copy Budget"), NULL,
+ N_("Copy an existing Budget"),
+ G_CALLBACK (gnc_plugin_budget_cmd_copy_budget)
+ },
};
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
@@ -213,6 +221,51 @@
}
}
+/* If only one budget exists, create a copy of it; otherwise user selects one to copy */
+static void
+gnc_plugin_budget_cmd_copy_budget (GtkAction *action,
+ GncMainWindowActionData *data)
+{
+ guint count;
+ QofBook *book;
+ GncBudget *bgt = NULL;
+ QofCollection *col;
+ g_return_if_fail (data != NULL);
+
+ book = gnc_get_current_book();
+ col = qof_book_get_collection(book, GNC_ID_BUDGET);
+ count = qof_collection_count(col);
+ if (count > 0)
+ {
+ if (count == 1)
+ {
+ bgt = gnc_budget_get_default(book);
+ }
+ else
+ {
+ bgt = gnc_budget_gui_select_budget(book);
+ }
+
+ if (bgt)
+ {
+ GncBudget* copy;
+ gchar* name;
+
+ copy = gnc_budget_clone(bgt);
+ name = g_strdup_printf("Copy of %s", gnc_budget_get_name(bgt));
+ gnc_budget_set_name(copy, name);
+ g_free(name);
+
+ gnc_main_window_open_page(
+ data->window, gnc_plugin_page_budget_new(copy));
+ }
+ }
+ else /* if no budgets exist yet, just open a new budget */
+ {
+ gnc_plugin_budget_cmd_new_budget(action, data);
+ }
+}
+
/************************************************************
* Other Functions *
************************************************************/
Modified: gnucash/trunk/src/gnome/ui/gnc-plugin-budget-ui.xml
===================================================================
--- gnucash/trunk/src/gnome/ui/gnc-plugin-budget-ui.xml 2011-01-05 09:46:59 UTC (rev 20032)
+++ gnucash/trunk/src/gnome/ui/gnc-plugin-budget-ui.xml 2011-01-07 01:48:17 UTC (rev 20033)
@@ -5,6 +5,7 @@
<menu name="ActionsBudget" action="ActionsBudgetAction">
<menuitem name="BudgetNewBudget" action="NewBudgetAction"/>
<menuitem name="BudgetOpenBudget" action="OpenBudgetAction"/>
+ <menuitem name="BudgetCopyBudget" action="CopyBudgetAction"/>
</menu>
</placeholder>
</menu>
More information about the gnucash-changes
mailing list