This commit is contained in:
Gergely Polonkai 2014-08-11 23:46:22 +02:00
parent 085f2225ea
commit bb38df71a7

View File

@ -60,7 +60,8 @@ G_DEFINE_QUARK(ag_window_error_quark, ag_window_error);
G_DEFINE_TYPE_WITH_PRIVATE(AgWindow, ag_window, GTK_TYPE_APPLICATION_WINDOW); G_DEFINE_TYPE_WITH_PRIVATE(AgWindow, ag_window, GTK_TYPE_APPLICATION_WINDOW);
static void ag_window_recalculate_chart(AgWindow *window); static void ag_window_recalculate_chart(AgWindow *window,
gboolean set_everything);
static void static void
ag_window_gear_menu_action(GSimpleAction *action, ag_window_gear_menu_action(GSimpleAction *action,
@ -107,6 +108,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog)
gboolean ret = TRUE; gboolean ret = TRUE;
if (priv->chart) { if (priv->chart) {
ag_window_recalculate_chart(window, TRUE);
save_data = ag_chart_get_db_save(priv->chart, db_id); save_data = ag_chart_get_db_save(priv->chart, db_id);
if ( if (
@ -196,7 +198,7 @@ ag_window_export(AgWindow *window, GError **err)
gint response; gint response;
AgWindowPrivate *priv = ag_window_get_instance_private(window); AgWindowPrivate *priv = ag_window_get_instance_private(window);
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, FALSE);
// We should never enter here, but who knows... // We should never enter here, but who knows...
if (priv->chart == NULL) { if (priv->chart == NULL) {
@ -272,7 +274,7 @@ ag_window_save_action(GSimpleAction *action,
gint old_id; gint old_id;
AgDbSave *save_data; AgDbSave *save_data;
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, TRUE);
if (!ag_window_can_close(window, FALSE)) { if (!ag_window_can_close(window, FALSE)) {
old_id = (priv->saved_data) ? priv->saved_data->db_id : -1; old_id = (priv->saved_data) ? priv->saved_data->db_id : -1;
@ -300,7 +302,7 @@ ag_window_export_action(GSimpleAction *action,
AgWindow *window = AG_WINDOW(user_data); AgWindow *window = AG_WINDOW(user_data);
GError *err = NULL; GError *err = NULL;
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, TRUE);
ag_window_export(window, &err); ag_window_export(window, &err);
if (err) { if (err) {
@ -321,7 +323,7 @@ ag_window_export_svg(AgWindow *window, GError **err)
gint response; gint response;
AgWindowPrivate *priv = ag_window_get_instance_private(window); AgWindowPrivate *priv = ag_window_get_instance_private(window);
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, TRUE);
// We should never enter here, but who knows... // We should never enter here, but who knows...
if (priv->chart == NULL) { if (priv->chart == NULL) {
@ -840,7 +842,7 @@ ag_window_chart_changed(AgChart *chart, AgWindow *window)
} }
static void static void
ag_window_recalculate_chart(AgWindow *window) ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
{ {
AgDbSave *edit_data, AgDbSave *edit_data,
*chart_data; *chart_data;
@ -938,7 +940,7 @@ ag_window_recalculate_chart(AgWindow *window)
: NULL : NULL
; ;
if (ag_db_save_identical(edit_data, chart_data, TRUE)) { if (ag_db_save_identical(edit_data, chart_data, !set_everything)) {
g_debug("No redrawing needed"); g_debug("No redrawing needed");
ag_db_save_data_free(edit_data); ag_db_save_data_free(edit_data);
@ -982,6 +984,13 @@ ag_window_recalculate_chart(AgWindow *window)
); );
} }
if (set_everything) {
ag_chart_set_name(priv->chart, edit_data->name);
ag_chart_set_country(priv->chart, edit_data->country);
ag_chart_set_city(priv->chart, edit_data->city);
ag_chart_set_note(priv->chart, edit_data->note);
}
ag_db_save_data_free(edit_data); ag_db_save_data_free(edit_data);
} }
@ -1022,12 +1031,12 @@ ag_window_tab_changed_cb(GtkStack *stack, GParamSpec *pspec, AgWindow *window)
GTK_STACK(priv->new_back_stack), GTK_STACK(priv->new_back_stack),
"back" "back"
); );
}
// Note that priv->current_tab is actually the previously selected tab, not // Note that priv->current_tab is actually the previously selected tab,
// the real active one! // not the real active one!
if (priv->current_tab == priv->tab_edit) { if (priv->current_tab == priv->tab_edit) {
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, FALSE);
}
} }
priv->current_tab = active_tab; priv->current_tab = active_tab;
@ -1079,6 +1088,8 @@ ag_window_back_action(GSimpleAction *action,
AgWindow *window = AG_WINDOW(user_data); AgWindow *window = AG_WINDOW(user_data);
AgWindowPrivate *priv = ag_window_get_instance_private(window); AgWindowPrivate *priv = ag_window_get_instance_private(window);
g_debug("Back button pressed");
if (ag_window_can_close(window, TRUE)) { if (ag_window_can_close(window, TRUE)) {
g_clear_object(&(priv->chart)); g_clear_object(&(priv->chart));
ag_db_save_data_free(priv->saved_data); ag_db_save_data_free(priv->saved_data);
@ -1292,6 +1303,8 @@ ag_window_list_item_activated_cb(GdMainView *view,
return; return;
} }
g_debug("Loading chart with ID %d", row_id);
if ((priv->saved_data = ag_db_get_chart_data_by_id( if ((priv->saved_data = ag_db_get_chart_data_by_id(
db, db,
row_id, row_id,
@ -1306,8 +1319,7 @@ ag_window_list_item_activated_cb(GdMainView *view,
} }
if (priv->chart) { if (priv->chart) {
g_object_unref(priv->chart); g_clear_object(&(priv->chart));
priv->chart = NULL;
} }
if ((priv->chart = ag_chart_new_from_db_save( if ((priv->chart = ag_chart_new_from_db_save(