r23430 - gnucash/trunk/src - Bug 710905 - Column withs, visibility, order and sort order not saved and restored
Geert Janssens
gjanssens at code.gnucash.org
Sun Nov 24 11:28:13 EST 2013
Author: gjanssens
Date: 2013-11-24 11:28:12 -0500 (Sun, 24 Nov 2013)
New Revision: 23430
Trac: http://svn.gnucash.org/trac/changeset/23430
Modified:
gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c
gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.h
gnucash/trunk/src/gnome/gnc-split-reg.c
gnucash/trunk/src/gnome/gnc-split-reg2.c
gnucash/trunk/src/register/ledger-core/gnc-ledger-display2.c
gnucash/trunk/src/register/register-core/table-allgui.h
gnucash/trunk/src/register/register-gnome/table-gnome.c
Log:
Bug 710905 - Column withs, visibility, order and sort order not saved and restored
This commit restores the functionality for register and register2.
As before saved state from 2.4 won't be migrated
Modified: gnucash/trunk/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.c 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/gnome/gnc-split-reg.c 2013-11-24 16:28:12 UTC (rev 23430)
@@ -59,6 +59,8 @@
// static QofLogModule log_module = GNC_MOD_SX;
static QofLogModule log_module = GNC_MOD_GUI;
+#define STATE_SECTION_REG_PREFIX "Register"
+
/***** PROTOTYPES ***************************************************/
void gnc_split_reg_raise( GNCSplitReg *gsr );
@@ -386,13 +388,13 @@
GtkWidget *register_widget;
SplitRegister *sr;
- gchar *prefs_key;
+ gchar *state_section;
const GncGUID * guid;
Account * account;
account = gnc_ledger_display_leader(gsr->ledger);
guid = xaccAccountGetGUID(account);
- prefs_key = (gchar*)guid_to_string (guid);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), NULL);
ENTER("gsr=%p", gsr);
@@ -405,7 +407,8 @@
sr = gnc_ledger_display_get_split_register( gsr->ledger );
register_widget = gnucash_register_new( sr->table );
gsr->reg = GNUCASH_REGISTER( register_widget );
- gnc_table_init_gui( GTK_WIDGET(gsr->reg), prefs_key );
+ gnc_table_init_gui( GTK_WIDGET(gsr->reg), state_section);
+ g_free (state_section);
gtk_box_pack_start (GTK_BOX (gsr), GTK_WIDGET(gsr->reg), TRUE, TRUE, 0);
gnucash_sheet_set_window (gnucash_register_get_sheet (gsr->reg), gsr->window);
gtk_widget_show ( GTK_WIDGET(gsr->reg) );
@@ -689,16 +692,15 @@
gnc_split_reg_ld_destroy( GNCLedgerDisplay *ledger )
{
GNCSplitReg *gsr = gnc_ledger_display_get_user_data( ledger );
-
- gchar *state_key;
+
+ gchar *state_section;
const GncGUID * guid;
Account * account;
-
+
account = gnc_ledger_display_leader(ledger);
guid = xaccAccountGetGUID(account);
- state_key = (gchar*)guid_to_string (guid);
-
-
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ",(gchar*)guid_to_string (guid), NULL);
+
if (gsr)
{
SplitRegister *reg;
@@ -706,13 +708,14 @@
reg = gnc_ledger_display_get_split_register (ledger);
if (reg && reg->table)
- gnc_table_save_state (reg->table, state_key);
+ gnc_table_save_state (reg->table, state_section);
/*
* Don't destroy the window here any more. The register no longer
* owns it.
*/
}
+ g_free (state_section);
gnc_ledger_display_set_user_data (ledger, NULL);
}
Modified: gnucash/trunk/src/gnome/gnc-split-reg2.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg2.c 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/gnome/gnc-split-reg2.c 2013-11-24 16:28:12 UTC (rev 23430)
@@ -29,6 +29,7 @@
#include "config.h"
#include <gtk/gtk.h>
+#include <glib.h>
#include <glib/gi18n.h>
#include "gnc-split-reg2.h"
@@ -37,10 +38,12 @@
#include "gnc-ledger-display2.h"
#include "gnc-euro.h"
+#include "gnc-state.h"
#include "gnome-utils/gnc-warnings.h"
#include "dialog-utils.h"
-#define STATE_SECTION_PREFIX "window/pages/register2/"
+#define STATE_SECTION_REG_PREFIX "Register"
+#define STATE_SECTION_GEN_LEDGER "General Ledger"
static QofLogModule log_module = GNC_MOD_GUI;
@@ -234,7 +237,8 @@
GtkWidget *hbox;
gdouble num_of_trans;
- gchar *state_key;
+ gchar *state_section;
+ GKeyFile *state_file = gnc_state_get_current();
const GncGUID * guid;
Account * account;
const gchar *sort_string;
@@ -249,22 +253,21 @@
gnc_split_reg2_ld_destroy,
gnc_split_reg2_get_parent);
- ledger_type = gnc_ledger_display2_type (gsr->ledger);
model = gnc_ledger_display2_get_split_model_register (gsr->ledger);
+ view = gnc_tree_view_split_reg_new_with_model (model);
+ g_object_unref (G_OBJECT (model));
- /* Used for saving different register column widths under separate keys */
- // We need to give the General Ledger a Key other than all zeros which the search register gets.
+ /* State_section is used to store per register state: column widths, sort order,... */
+ ledger_type = gnc_ledger_display2_type (gsr->ledger);
if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2)
- state_key = g_strconcat (STATE_SECTION_PREFIX, "00000000000000000000000000000001", NULL);
+ state_section = g_strdup (STATE_SECTION_GEN_LEDGER);
else if (ledger_type == LD2_SUBACCOUNT)
- state_key = g_strconcat (STATE_SECTION_PREFIX, (gchar*)guid_to_string (guid), "_sub", NULL);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), " w/subaccounts", NULL);
else
- state_key = g_strconcat (STATE_SECTION_PREFIX, (gchar*)guid_to_string (guid), NULL);
+ state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), NULL);
+ g_object_set (G_OBJECT (view), "state-section", state_section,
+ "show-column-menu", FALSE, NULL);
- gnc_tree_model_split_reg_set_display (model, ((ledger_type == LD2_SUBACCOUNT)?TRUE:FALSE), ((ledger_type == LD2_GL)?TRUE:FALSE));
- view = gnc_tree_view_split_reg_new_with_model (model);
- g_object_unref (G_OBJECT (model));
-
// Create a hbox for treeview and scrollbar.
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox);
@@ -290,21 +293,30 @@
gnc_ledger_display2_set_split_view_register (gsr->ledger, view);
+ /* Setting the view's state-section above already restores most
+ * of the saved state automatically. There are a few register specific
+ * settings though that will be restored here. */
+
/* Restore the sort depth from saved state */
+ view->sort_depth = g_key_file_get_integer (state_file, state_section, "sort_depth", NULL);
+
/* Restore the sort order from saved state */
- // FIXME currently not implemented
-
- sort_string = NULL;
+ sort_string = g_key_file_get_string (state_file, state_section, "sort_order", NULL);
if (g_strcmp0 ("descending", sort_string) == 0)
view->sort_direction = -1;
else
view->sort_direction = 1;
/* Restore the sort column from saved state */
- view->sort_col = model->sort_col;
+ view->sort_col = g_key_file_get_integer (state_file, state_section, "sort_col", NULL);
+ if (view->sort_col == 0)
+ view->sort_col = 1;
- g_object_set (G_OBJECT (view), "state-section", state_key,
- "show-column-menu", FALSE, NULL);
+ /* Synchronize model state with view state
+ * (needed to properly set up the internal query) */
+ model->sort_col = view->sort_col;
+ model->sort_depth = view->sort_depth;
+ model->sort_direction = view->sort_direction;
gnc_tree_view_configure_columns (GNC_TREE_VIEW (view));
@@ -792,6 +804,7 @@
gint sortcol;
gint sort_depth;
const gchar *state_section;
+ GKeyFile *state_file = gnc_state_get_current();
gtk_tree_sortable_get_sort_column_id (sortable, &sortcol, &type);
ENTER("sortcol is %d", sortcol);
@@ -821,7 +834,9 @@
/* Save the sort depth state */
state_section = gnc_tree_view_get_state_section (GNC_TREE_VIEW (view));
- // FIXME currently not implemented
+ g_key_file_set_integer (state_file, state_section, "sort_depth", view->sort_depth);
+ g_key_file_set_integer (state_file, state_section, "sort_col", view->sort_col);
+ /* NOTE sort_column is handled directly by the treeview */
LEAVE("v_sort_col %d, v_sort_direction is %d v_sort_depth is %d", view->sort_col, view->sort_direction, view->sort_depth);
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c 2013-11-24 16:28:12 UTC (rev 23430)
@@ -46,8 +46,6 @@
#define TREE_MODEL_SPLIT_REG_CM_CLASS "tree-model-split-reg"
-#define STATE_SECTION_PREFIX "window/pages/register2/"
-
/* Signal codes */
enum
{
@@ -1000,54 +998,6 @@
void
-gnc_tree_model_split_reg_default_query (GncTreeModelSplitReg *model, Account *default_account, Query *query)
-{
- gchar *state_key;
- const GncGUID * guid;
- const gchar *sort_string;
- gint depth, col;
-
- guid = xaccAccountGetGUID (default_account);
-
- /* Used for saving different register column widths under seperate keys */
- // We need to give the General Ledger a Key other than all zeros which the search register gets.
- if (model->priv->display_gl == TRUE && model->type == GENERAL_LEDGER2)
- state_key = g_strconcat (STATE_SECTION_PREFIX, "00000000000000000000000000000001", NULL);
- else if (model->priv->display_subacc == TRUE)
- state_key = g_strconcat (STATE_SECTION_PREFIX, (gchar*)guid_to_string (guid), "_sub", NULL);
- else
- state_key = g_strconcat (STATE_SECTION_PREFIX, (gchar*)guid_to_string (guid), NULL);
-
-
- /* Restore the sort column from saved state */
- // FIXME currently not implemented
- col = 0;
- if (col == 0)
- model->sort_col = 1;
- else
- model->sort_col = col;
-
- /* Restore the sort depth from saved state */
- // FIXME currently not implemented
- depth = 0;
- if (depth == 0)
- model->sort_depth = 1;
- else
- model->sort_depth = depth;
-
- /* Restore the sort order from saved state */
- // FIXME currently not implemented
- sort_string = NULL;
- if (g_strcmp0 ("descending", sort_string) == 0)
- model->sort_direction = -1;
- else
- model->sort_direction = 1;
-
- gnc_tree_model_split_reg_update_query (model, query);
-}
-
-
-void
gnc_tree_model_split_reg_update_query (GncTreeModelSplitReg *model, Query *query)
{
GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard;
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.h 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.h 2013-11-24 16:28:12 UTC (rev 23430)
@@ -217,9 +217,6 @@
void gnc_tree_model_split_reg_set_data (GncTreeModelSplitReg *model, gpointer user_data,
SRGetParentCallback2 get_parent);
-/** Sets the default query for the register. */
-void gnc_tree_model_split_reg_default_query (GncTreeModelSplitReg *model, Account *default_account, Query *query);
-
/** Update the query for the register. */
void gnc_tree_model_split_reg_update_query (GncTreeModelSplitReg *model, Query *query);
Modified: gnucash/trunk/src/register/ledger-core/gnc-ledger-display2.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/gnc-ledger-display2.c 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/register/ledger-core/gnc-ledger-display2.c 2013-11-24 16:28:12 UTC (rev 23430)
@@ -700,6 +700,8 @@
gint limit;
const char *class;
GList *splits;
+ gboolean display_subaccounts = FALSE;
+ gboolean is_gl = FALSE;
switch (ld_type)
{
@@ -749,6 +751,7 @@
if (ld)
return ld;
+ display_subaccounts = TRUE;
break;
case LD2_GL:
@@ -759,6 +762,7 @@
PWARN ("general ledger with no query");
}
+ is_gl = TRUE;
break;
default:
@@ -799,23 +803,18 @@
ld->model = gnc_tree_model_split_reg_new (reg_type, style, use_double_line, is_template);
gnc_tree_model_split_reg_set_data (ld->model, ld, gnc_ledger_display2_parent);
+ gnc_tree_model_split_reg_set_display (ld->model, display_subaccounts, is_gl);
-//FIXME We should get the load filter and sort here so we run query once on load....
-
- gnc_tree_model_split_reg_set_display (ld->model, ((ld_type == LD2_SUBACCOUNT)?TRUE:FALSE), ((ld_type == LD2_GL)?TRUE:FALSE));
-
- gnc_tree_model_split_reg_default_query (ld->model, lead_account, ld->query);
-
// This sets up a call back to reload after changes
g_signal_connect (G_OBJECT (ld->model), "refresh_trans",
G_CALLBACK (gnc_ledger_display2_refresh_cb), ld );
- splits = qof_query_run (ld->query);
-
//FIXME Not Needed ? gnc_ledger_display2_set_watches (ld, splits);
// gnc_ledger_display2_set_watches (ld, splits);
- gnc_ledger_display2_refresh_internal (ld, splits);
+ // Populate the model with an empty split
+ // An empty model could cause our gui callbacks to crash
+ gnc_ledger_display2_refresh_internal (ld, NULL);
return ld;
}
Modified: gnucash/trunk/src/register/register-core/table-allgui.h
===================================================================
--- gnucash/trunk/src/register/register-core/table-allgui.h 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/register/register-core/table-allgui.h 2013-11-24 16:28:12 UTC (rev 23430)
@@ -166,7 +166,7 @@
TableControl *control);
void gnc_virtual_location_init (VirtualLocation *vloc);
-void gnc_table_save_state (Table *table, gchar *state_key);
+void gnc_table_save_state (Table *table, gchar *state_section);
void gnc_table_destroy (Table *table);
@@ -303,7 +303,7 @@
/** UI-specific functions *******************************/
/* Initialize the GUI from a table */
-void gnc_table_init_gui (GtkWidget *widget, gchar * state_key);
+void gnc_table_init_gui (GtkWidget *widget, gchar * state_section);
void gnc_table_realize_gui (Table *table);
Modified: gnucash/trunk/src/register/register-gnome/table-gnome.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/table-gnome.c 2013-11-22 21:07:51 UTC (rev 23429)
+++ gnucash/trunk/src/register/register-gnome/table-gnome.c 2013-11-24 16:28:12 UTC (rev 23430)
@@ -50,6 +50,7 @@
#include "table-gnome.h"
#include "gnc-prefs.h"
#include "gnc-engine.h"
+#include "gnc-state.h"
#include "gnc-ledger-display.h"
@@ -64,12 +65,13 @@
/** Implementation *****************************************************/
void
-gnc_table_save_state (Table *table, gchar * state_key)
+gnc_table_save_state (Table *table, gchar * state_section)
{
GnucashSheet *sheet;
GNCHeaderWidths widths;
GList *node;
gchar *key;
+ GKeyFile *state_file = gnc_state_get_current();
if (!table)
return;
@@ -93,16 +95,16 @@
int width;
width = gnc_header_widths_get_width (widths, cell->cell_name);
- if (width <= 0)
- continue;
- if (cell->expandable)
- continue;
-
/* Remember whether the column is visible */
key = g_strdup_printf("%s_width", cell->cell_name);
- // FIXME the actual state saving is currently not implemented
- g_free(key);
+ if ((width > 0) && (!cell->expandable))
+ {
+ g_key_file_set_integer (state_file, state_section, key, width);
+ }
+ else if (g_key_file_has_key (state_file, state_section, key, NULL))
+ g_key_file_remove_key (state_file, state_section, key, NULL);
+ g_free (key);
}
gnc_header_widths_destroy (widths);
@@ -152,7 +154,7 @@
to pass NULL as second parameter. */
void
-gnc_table_init_gui (GtkWidget *widget, gchar * state_key)
+gnc_table_init_gui (GtkWidget *widget, gchar * state_section)
{
GNCHeaderWidths widths;
GnucashSheet *sheet;
@@ -161,12 +163,13 @@
GList *node;
gchar *key;
guint value;
+ GKeyFile *state_file = gnc_state_get_current();
// Stuff for per-register settings load.
g_return_if_fail (widget != NULL);
g_return_if_fail (GNUCASH_IS_REGISTER (widget));
- PINFO("state_key=%s",state_key);
+ PINFO("state_section=%s",state_section);
ENTER("widget=%p, data=%p", widget, "");
@@ -185,7 +188,7 @@
widths = gnc_header_widths_new ();
- if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
+ if (state_section && gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
{
node = gnc_table_layout_get_cells (table->layout);
for (; node; node = node->next)
@@ -197,8 +200,7 @@
/* Remember whether the column is visible */
key = g_strdup_printf("%s_width", cell->cell_name);
- // FIXME the actual state loading is currently not implemented
- value = 0;
+ value = g_key_file_get_integer (state_file, state_section, key, NULL);
if (value != 0)
gnc_header_widths_set_width (widths, cell->cell_name, value);
g_free(key);
More information about the gnucash-changes
mailing list