Change the spacing in files gnc-plugin-budget.*

This commit is contained in:
Robert Fewell
2019-12-11 14:45:28 +00:00
parent eb7810788b
commit 1320b79dc7
2 changed files with 74 additions and 87 deletions

View File

@@ -60,19 +60,19 @@ static GtkActionEntry gnc_plugin_actions [] =
{
"NewBudgetAction", NULL, N_("New Budget"), NULL,
N_("Create a new Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_new_budget)
G_CALLBACK(gnc_plugin_budget_cmd_new_budget)
},
{
"OpenBudgetAction", NULL, N_("Open Budget"), NULL,
N_("Open an existing Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_open_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)
G_CALLBACK(gnc_plugin_budget_cmd_copy_budget)
},
};
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
@@ -83,7 +83,7 @@ typedef struct GncPluginBudgetPrivate
} GncPluginBudgetPrivate;
#define GNC_PLUGIN_BUDGET_GET_PRIVATE(o) \
((GncPluginBudgetPrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_PLUGIN_BUDGET))
((GncPluginBudgetPrivate*)g_type_instance_get_private ((GTypeInstance*)o, GNC_TYPE_PLUGIN_BUDGET))
static GObjectClass *parent_class = NULL;
@@ -98,12 +98,13 @@ GncPlugin * gnc_plugin_budget_new (void)
plugin = g_object_new (GNC_TYPE_PLUGIN_BUDGET, NULL);
LEAVE(" ");
return GNC_PLUGIN (plugin);
return GNC_PLUGIN(plugin);
}
static void
gnc_plugin_budget_main_window_page_changed (GncMainWindow *window,
GncPluginPage *plugin_page, gpointer user_data)
GncPluginPage *plugin_page,
gpointer user_data)
{
// We continue only if the plugin_page is a valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
@@ -116,9 +117,9 @@ gnc_plugin_budget_main_window_page_changed (GncMainWindow *window,
// The page changed signal is emitted multiple times so we need
// to use an idle_add to change the focus to the tree view
g_idle_remove_by_data (GNC_PLUGIN_PAGE_BUDGET (plugin_page));
g_idle_remove_by_data (GNC_PLUGIN_PAGE_BUDGET(plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_budget_focus,
GNC_PLUGIN_PAGE_BUDGET (plugin_page));
GNC_PLUGIN_PAGE_BUDGET(plugin_page));
}
}
@@ -127,8 +128,8 @@ G_DEFINE_TYPE_WITH_PRIVATE(GncPluginBudget, gnc_plugin_budget, GNC_TYPE_PLUGIN)
static void
gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS(klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS(klass);
ENTER (" ");
parent_class = g_type_class_peek_parent (klass);
@@ -147,14 +148,14 @@ gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
}
static void
gnc_plugin_budget_init(GncPluginBudget *plugin)
gnc_plugin_budget_init (GncPluginBudget *plugin)
{
}
static void
gnc_plugin_budget_finalize(GObject *object)
gnc_plugin_budget_finalize (GObject *object)
{
g_return_if_fail(GNC_IS_PLUGIN_BUDGET (object));
g_return_if_fail (GNC_IS_PLUGIN_BUDGET(object));
ENTER(" ");
(parent_class->finalize)(object);
@@ -168,12 +169,12 @@ gnc_plugin_budget_finalize(GObject *object)
*
*/
static void gnc_plugin_budget_add_to_window (GncPlugin *plugin,
GncMainWindow *mainwindow,
GQuark type)
GncMainWindow *mainwindow,
GQuark type)
{
g_signal_connect(mainwindow, "page_changed",
G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
plugin);
g_signal_connect (mainwindow, "page_changed",
G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
plugin);
}
/************************************************************
@@ -183,95 +184,84 @@ static void gnc_plugin_budget_add_to_window (GncPlugin *plugin,
/* Make a new budget; put it in a page; open the page. */
static void
gnc_plugin_budget_cmd_new_budget (GtkAction *action,
GncMainWindowActionData *data)
GncMainWindowActionData *user_data)
{
GncBudget *budget;
GncPluginPage *page;
g_return_if_fail (data != NULL);
g_return_if_fail (user_data != NULL);
budget = gnc_budget_new(gnc_get_current_book());
page = gnc_plugin_page_budget_new(budget);
gnc_main_window_open_page (data->window, page);
budget = gnc_budget_new (gnc_get_current_book());
page = gnc_plugin_page_budget_new (budget);
gnc_main_window_open_page (user_data->window, page);
}
/* If only one budget exists, open it; otherwise user selects one to open */
static void
gnc_plugin_budget_cmd_open_budget (GtkAction *action,
GncMainWindowActionData *data)
GncMainWindowActionData *user_data)
{
guint count;
QofBook *book;
GncBudget *bgt = NULL;
QofCollection *col;
g_return_if_fail (data != NULL);
g_return_if_fail (user_data != NULL);
book = gnc_get_current_book();
col = qof_book_get_collection(book, GNC_ID_BUDGET);
count = qof_collection_count(col);
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);
}
bgt = gnc_budget_get_default (book);
else
{
bgt = gnc_budget_gui_select_budget(GTK_WINDOW(data->window), book);
}
bgt = gnc_budget_gui_select_budget (GTK_WINDOW(user_data->window), book);
if (bgt) gnc_main_window_open_page(
data->window, gnc_plugin_page_budget_new(bgt));
if (bgt)
gnc_main_window_open_page (user_data->window,
gnc_plugin_page_budget_new (bgt));
}
else /* if no budgets exist yet, just open a new budget */
{
gnc_plugin_budget_cmd_new_budget(action, data);
}
gnc_plugin_budget_cmd_new_budget (action, user_data);
}
/* 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)
GncMainWindowActionData *user_data)
{
guint count;
QofBook *book;
GncBudget *bgt = NULL;
QofCollection *col;
g_return_if_fail (data != NULL);
g_return_if_fail (user_data != NULL);
book = gnc_get_current_book();
col = qof_book_get_collection(book, GNC_ID_BUDGET);
count = qof_collection_count(col);
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(GTK_WINDOW(data->window), book);
}
bgt = gnc_budget_gui_select_budget (GTK_WINDOW(user_data->window), 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);
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));
gnc_main_window_open_page (user_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);
}
gnc_plugin_budget_cmd_new_budget (action, user_data);
}
/************************************************************
@@ -279,14 +269,14 @@ gnc_plugin_budget_cmd_copy_budget (GtkAction *action,
************************************************************/
static void
row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *column,
gpointer data)
row_activated_cb (GtkTreeView *tv, GtkTreePath *path,
GtkTreeViewColumn *column, gpointer user_data)
{
gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_OK);
gtk_dialog_response (GTK_DIALOG(user_data), GTK_RESPONSE_OK);
}
GncBudget *
gnc_budget_gui_select_budget(GtkWindow *parent, QofBook *book)
gnc_budget_gui_select_budget (GtkWindow *parent, QofBook *book)
{
GncBudget *bgt;
GtkDialog *dlg;
@@ -297,44 +287,41 @@ gnc_budget_gui_select_budget(GtkWindow *parent, QofBook *book)
gint response;
gboolean ok;
dlg = GTK_DIALOG(gtk_dialog_new_with_buttons(
dlg = GTK_DIALOG(gtk_dialog_new_with_buttons (
_("Select a Budget"), parent, GTK_DIALOG_MODAL,
_("_OK"), GTK_RESPONSE_OK,
_("_Cancel"), GTK_RESPONSE_CANCEL, NULL));
tv = GTK_TREE_VIEW(gtk_tree_view_new());
sel = gtk_tree_view_get_selection(tv);
gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE);
g_signal_connect(tv, "row-activated", G_CALLBACK(row_activated_cb), dlg);
tm = gnc_tree_model_budget_new(book);
gnc_tree_view_budget_set_model(tv, tm);
g_object_unref(tm);
gtk_container_add(GTK_CONTAINER (gtk_dialog_get_content_area (dlg)), GTK_WIDGET(tv));
gtk_widget_show_all(GTK_WIDGET(dlg));
tv = GTK_TREE_VIEW(gtk_tree_view_new ());
sel = gtk_tree_view_get_selection (tv);
gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
g_signal_connect (tv, "row-activated", G_CALLBACK(row_activated_cb), dlg);
tm = gnc_tree_model_budget_new (book);
gnc_tree_view_budget_set_model (tv, tm);
g_object_unref (tm);
gtk_container_add (GTK_CONTAINER(gtk_dialog_get_content_area (dlg)), GTK_WIDGET(tv));
gtk_widget_show_all (GTK_WIDGET(dlg));
// Preselect the default budget
bgt = gnc_budget_get_default(book);
if (bgt && gnc_tree_model_budget_get_iter_for_budget(tm, &iter, bgt))
{
gtk_tree_view_set_cursor(tv, gtk_tree_model_get_path(tm, &iter), NULL,
FALSE);
}
bgt = gnc_budget_get_default (book);
if (bgt && gnc_tree_model_budget_get_iter_for_budget (tm, &iter, bgt))
gtk_tree_view_set_cursor (tv, gtk_tree_model_get_path (tm, &iter), NULL, FALSE);
bgt = NULL;
response = gtk_dialog_run(dlg);
response = gtk_dialog_run (dlg);
switch (response)
{
case GTK_RESPONSE_OK:
ok = gtk_tree_selection_get_selected(sel, &tm, &iter);
ok = gtk_tree_selection_get_selected (sel, &tm, &iter);
if (ok)
{
bgt = gnc_tree_model_budget_get_budget(tm, &iter);
}
bgt = gnc_tree_model_budget_get_budget (tm, &iter);
break;
default:
break;
}
gtk_widget_destroy(GTK_WIDGET(dlg));
gtk_widget_destroy (GTK_WIDGET(dlg));
return bgt;
}

View File

@@ -55,11 +55,11 @@ typedef struct
} GncPluginBudgetClass;
/* function prototypes */
GType gnc_plugin_budget_get_type(void);
GncPlugin *gnc_plugin_budget_new(void);
GType gnc_plugin_budget_get_type (void);
GncPlugin *gnc_plugin_budget_new (void);
/* Launch the budget list dialog.*/
GncBudget * gnc_budget_gui_select_budget(GtkWindow *parent, QofBook *book);
GncBudget * gnc_budget_gui_select_budget (GtkWindow *parent, QofBook *book);
G_END_DECLS