mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23430 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
71a50a8bb4
commit
d3b7d454b5
@ -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
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 @@ 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);
|
||||
|
||||
@ -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) );
|
||||
@ -689,16 +692,15 @@ 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;
|
||||
@ -706,13 +708,14 @@ gnc_split_reg_ld_destroy( GNCLedgerDisplay *ledger )
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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 @@ 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;
|
||||
@ -249,22 +253,21 @@ 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);
|
||||
|
||||
/* 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.
|
||||
if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2)
|
||||
state_key = g_strconcat (STATE_SECTION_PREFIX, "00000000000000000000000000000001", NULL);
|
||||
else if (ledger_type == LD2_SUBACCOUNT)
|
||||
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);
|
||||
|
||||
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 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_section = g_strdup (STATE_SECTION_GEN_LEDGER);
|
||||
else if (ledger_type == LD2_SUBACCOUNT)
|
||||
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), " w/subaccounts", NULL);
|
||||
else
|
||||
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);
|
||||
gtk_widget_show (hbox);
|
||||
@ -290,21 +293,30 @@ gsr2_create_table (GNCSplitReg2 *gsr)
|
||||
|
||||
gnc_ledger_display2_set_split_view_register (gsr->ledger, view);
|
||||
|
||||
/* Restore the sort depth from saved state */
|
||||
/* Restore the sort order from saved state */
|
||||
// FIXME currently not implemented
|
||||
/* 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. */
|
||||
|
||||
sort_string = NULL;
|
||||
/* 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 */
|
||||
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 @@ 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);
|
||||
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
@ -749,6 +751,7 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
|
||||
if (ld)
|
||||
return ld;
|
||||
|
||||
display_subaccounts = TRUE;
|
||||
break;
|
||||
|
||||
case LD2_GL:
|
||||
@ -759,6 +762,7 @@ gnc_ledger_display2_internal (Account *lead_account, Query *q,
|
||||
PWARN ("general ledger with no query");
|
||||
}
|
||||
|
||||
is_gl = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
@ -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 @@ static QofLogModule log_module = GNC_MOD_REGISTER;
|
||||
/** 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 @@ gnc_table_save_state (Table *table, gchar * state_key)
|
||||
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 @@ table_destroy_cb (Table *table)
|
||||
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 @@ gnc_table_init_gui (GtkWidget *widget, gchar * state_key)
|
||||
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 @@ gnc_table_init_gui (GtkWidget *widget, gchar * state_key)
|
||||
|
||||
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 @@ gnc_table_init_gui (GtkWidget *widget, gchar * state_key)
|
||||
|
||||
/* 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);
|
||||
|
Loading…
Reference in New Issue
Block a user