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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20033 57a11ea4-9604-0410-9ed3-97b8803252fd
pull/1/head
Phil Longstaff 16 years ago
parent c6fa015dad
commit e8d8c4be42

@ -50,6 +50,8 @@ static void gnc_plugin_budget_cmd_new_budget (GtkAction *action,
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 @@ static GtkActionEntry gnc_plugin_actions [] =
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 @@ gnc_plugin_budget_cmd_open_budget (GtkAction *action,
}
}
/* 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 *
************************************************************/

@ -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>

Loading…
Cancel
Save