Skip to content

Commit

Permalink
Bug 710905 - Column withs, visibility, order and sort order not saved…
Browse files Browse the repository at this point in the history
… and restored

This commit restores the functionality for register and register2.
As before saved state from 2.4 won't be migrated

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23430 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
gjanssens committed Nov 24, 2013
1 parent 71a50a8 commit d3b7d45
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 106 deletions.
50 changes: 0 additions & 50 deletions src/gnome-utils/gnc-tree-model-split-reg.c
Expand Up @@ -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
{
Expand Down Expand Up @@ -999,54 +997,6 @@ gnc_tree_model_split_reg_get_sub_account (GncTreeModelSplitReg *model)
}


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)
{
Expand Down
3 changes: 0 additions & 3 deletions src/gnome-utils/gnc-tree-model-split-reg.h
Expand Up @@ -217,9 +217,6 @@ void gnc_tree_model_split_reg_destroy (GncTreeModelSplitReg *model);
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);

Expand Down
23 changes: 13 additions & 10 deletions src/gnome/gnc-split-reg.c
Expand Up @@ -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 );

Expand Down Expand Up @@ -386,13 +388,13 @@ gsr_create_table( GNCSplitReg *gsr )
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);

Expand All @@ -405,7 +407,8 @@ gsr_create_table( GNCSplitReg *gsr )
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) );
Expand Down Expand Up @@ -689,30 +692,30 @@ static void
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;

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);
}

Expand Down
53 changes: 34 additions & 19 deletions src/gnome/gnc-split-reg2.c
Expand Up @@ -29,6 +29,7 @@
#include "config.h"

#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>

#include "gnc-split-reg2.h"
Expand All @@ -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;

Expand Down Expand Up @@ -234,7 +237,8 @@ gsr2_create_table (GNCSplitReg2 *gsr)
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;
Expand All @@ -249,21 +253,20 @@ gsr2_create_table (GNCSplitReg2 *gsr)
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);

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));
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);

// Create a hbox for treeview and scrollbar.
hbox = gtk_hbox_new (FALSE, 0);
Expand All @@ -290,21 +293,30 @@ gsr2_create_table (GNCSplitReg2 *gsr)

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 */
/* Restore the sort order from saved state */
// FIXME currently not implemented
view->sort_depth = g_key_file_get_integer (state_file, state_section, "sort_depth", NULL);

sort_string = NULL;
/* Restore the sort order from saved state */
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));

Expand Down Expand Up @@ -792,6 +804,7 @@ gnc_split_reg2_sort_changed_cb (GtkTreeSortable *sortable, gpointer user_data)
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);
Expand Down Expand Up @@ -821,7 +834,9 @@ gnc_split_reg2_sort_changed_cb (GtkTreeSortable *sortable, gpointer user_data)

/* 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);

Expand Down
17 changes: 8 additions & 9 deletions src/register/ledger-core/gnc-ledger-display2.c
Expand Up @@ -700,6 +700,8 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
gint limit;
const char *class;
GList *splits;
gboolean display_subaccounts = FALSE;
gboolean is_gl = FALSE;

switch (ld_type)
{
Expand Down Expand Up @@ -749,6 +751,7 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
if (ld)
return ld;

display_subaccounts = TRUE;
break;

case LD2_GL:
Expand All @@ -759,6 +762,7 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
PWARN ("general ledger with no query");
}

is_gl = TRUE;
break;

default:
Expand Down Expand Up @@ -799,23 +803,18 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
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);

//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);
gnc_tree_model_split_reg_set_display (ld->model, display_subaccounts, is_gl);

// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/register/register-core/table-allgui.h
Expand Up @@ -166,7 +166,7 @@ Table * gnc_table_new (TableLayout *layout,
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);


Expand Down Expand Up @@ -303,7 +303,7 @@ gboolean gnc_table_find_close_valid_cell (Table *table,
/** 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);

Expand Down

0 comments on commit d3b7d45

Please sign in to comment.