Revert the changes made to save Register default layouts as discussed in PR #743

This commit is contained in:
Robert Fewell 2020-06-26 15:28:15 +01:00
parent 2c62ae418b
commit a019bb2f2d
7 changed files with 29 additions and 260 deletions

View File

@ -168,7 +168,6 @@ static GtkActionEntry gnc_sxed_menu_entries [] =
{ "TransactionAction", NULL, N_("_Transaction"), NULL, NULL, NULL },
{ "ViewAction", NULL, N_("_View"), NULL, NULL, NULL },
{ "ActionsAction", NULL, N_("_Actions"), NULL, NULL, NULL },
{ "WindowsAction", NULL, N_("_Windows"), NULL, NULL, NULL },
};
static guint gnc_sxed_menu_n_entries = G_N_ELEMENTS (gnc_sxed_menu_entries);

View File

@ -253,10 +253,6 @@ static void gnc_plugin_page_register_cmd_account_report (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_transaction_report (GtkAction* action,
GncPluginPageRegister* plugin_page);
static void gnc_plugin_page_register_cmd_save_layout (GtkAction *action,
GncPluginPageRegister *plugin_page);
static void gnc_plugin_page_register_cmd_reset_layout (GtkAction *action,
GncPluginPageRegister *plugin_page);
static void gnc_plugin_page_register_cmd_associate_transaction (GtkAction *action,
GncPluginPageRegister *plugin_page);
static void gnc_plugin_page_register_cmd_associate_transaction_open (GtkAction *action,
@ -519,18 +515,6 @@ static GtkActionEntry gnc_plugin_page_register_actions [] =
N_ ("Open a register report for the selected Transaction"),
G_CALLBACK (gnc_plugin_page_register_cmd_transaction_report)
},
/* Windows menu */
{
"WindowsSaveLayoutAction", NULL, "_Use as Default Layout for this Register Group", NULL,
N_("Use the current layout as default for all registers in the group 'Currency account registers'"),
G_CALLBACK (gnc_plugin_page_register_cmd_save_layout)
},
{
"WindowsResetLayoutAction", NULL, "_Reset Default Layout for this Register Group", NULL,
N_("Reset default layout for all registers in the group 'Currency account registers' back to built-in defaults and update page accordingly"),
G_CALLBACK (gnc_plugin_page_register_cmd_reset_layout)
},
};
static guint gnc_plugin_page_register_n_actions = G_N_ELEMENTS (
@ -655,8 +639,6 @@ typedef struct GncPluginPageRegisterPrivate
GtkWidget* widget;
const gchar *page_state_name; /* Used for loading state information */
gint event_handler_id;
gint component_manager_id;
GncGUID key; /* The guid of the Account we're watching */
@ -925,7 +907,6 @@ gnc_plugin_page_register_init (GncPluginPageRegister* plugin_page)
priv->enable_refresh = TRUE;
priv->search_query = NULL;
priv->filter_query = NULL;
priv->page_state_name = NULL;
}
static void
@ -1220,26 +1201,6 @@ gnc_plugin_page_register_ui_update (gpointer various,
}
}
}
// update the register default layouts actions
{
gboolean has_default = FALSE;
const gchar *group = gnc_split_reg_get_register_state_group (priv->gsr);
GtkAction *layout_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), "WindowsSaveLayoutAction");
gchar *tt = g_strdup_printf (gettext ("Use the current layout as default for all registers in the group '%s'"), _(group));
gtk_action_set_tooltip (layout_action, tt);
g_free (tt);
layout_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), "WindowsResetLayoutAction");
tt = g_strdup_printf (gettext ("Reset default layout for all registers in the group '%s' back to built-in defaults and update page accordingly"), _(group));
gtk_action_set_tooltip (layout_action, tt);
g_free (tt);
// if there is no default layout do not enable reset action
if (gnc_split_reg_register_has_user_state (priv->gsr))
has_default = TRUE;
gtk_action_set_sensitive (layout_action, has_default);
}
}
static void
@ -1382,7 +1343,7 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page)
gnc_window = GNC_WINDOW(GNC_PLUGIN_PAGE(page)->window);
gsr = gnc_split_reg_new (priv->ledger,
gnc_window_get_gtk_window (gnc_window),
numRows, priv->read_only, priv->page_state_name);
numRows, priv->read_only);
priv->gsr = (GNCSplitReg *)gsr;
gtk_widget_show (gsr);
@ -1745,9 +1706,6 @@ gnc_plugin_page_register_save_page (GncPluginPage* plugin_page,
g_key_file_set_boolean (key_file, group_name, KEY_DOUBLE_LINE,
reg->use_double_line);
// save the open table layout
gnc_table_save_state (reg->table, group_name);
LEAVE(" ");
}
@ -1885,7 +1843,6 @@ gnc_plugin_page_register_recreate_page (GtkWidget* window,
* sort/filter updates and double line/style changes */
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page);
priv->enable_refresh = FALSE;
priv->page_state_name = group_name;
/* Recreate page in given window */
gnc_plugin_page_set_use_new_window (page, FALSE);
@ -5011,46 +4968,6 @@ gnc_plugin_page_register_cmd_transaction_report (GtkAction* action,
LEAVE (" ");
}
static void
gnc_plugin_page_register_cmd_save_layout (GtkAction *action, GncPluginPageRegister *plugin_page)
{
GNCSplitReg *gsr;
GtkAction *layout_action;
ENTER("(action %p, plugin_page %p)", action, plugin_page);
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE(plugin_page));
gnc_split_reg_save_register_layout_to_user_state (gsr);
layout_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(plugin_page),
"WindowsResetLayoutAction");
gtk_action_set_sensitive (layout_action, TRUE);
LEAVE(" ");
}
static void
gnc_plugin_page_register_cmd_reset_layout (GtkAction *action, GncPluginPageRegister *plugin_page)
{
GNCSplitReg *gsr;
GtkAction *layout_action;
ENTER("(action %p, plugin_page %p)", action, plugin_page);
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE(plugin_page));
gnc_split_reg_reset_register_layout_and_clear_user_state (gsr);
layout_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(plugin_page),
"WindowsResetLayoutAction");
gtk_action_set_sensitive (layout_action, FALSE);
LEAVE(" ");
}
/************************************************************/
/* Auxiliary functions */
/************************************************************/

View File

@ -330,8 +330,7 @@ GtkWidget*
gnc_split_reg_new( GNCLedgerDisplay *ld,
GtkWindow *parent,
gint numberOfLines,
gboolean read_only,
const gchar *group_name )
gboolean read_only )
{
GNCSplitReg *gsrToRet;
@ -346,8 +345,6 @@ gnc_split_reg_new( GNCLedgerDisplay *ld,
gsrToRet->ledger = ld;
gsrToRet->window = GTK_WIDGET(parent);
gsrToRet->page_state_name = group_name;
gnc_split_reg_init2( gsrToRet );
LEAVE("%p", gsrToRet);
@ -367,7 +364,6 @@ gnc_split_reg_init( GNCSplitReg *gsr )
gsr->height = -1;
gsr->numRows = 10;
gsr->read_only = FALSE;
gsr->page_state_name = NULL;
}
static void
@ -411,56 +407,12 @@ gsr_setup_table( GNCSplitReg *gsr )
LEAVE(" ");
}
const gchar *
gnc_split_reg_get_register_state_group (GNCSplitReg *gsr)
{
SplitRegister *split_reg = gnc_ledger_display_get_split_register (gsr->ledger);
switch (gnc_split_register_get_register_group (split_reg))
{
case REG_TYPE_GROUP_CURRENCY:
{
return N_("Currency account registers");
break;
}
case REG_TYPE_GROUP_APAR:
{
return N_("Business account registers");
break;
}
case REG_TYPE_GROUP_JOURNAL:
{
return N_("Journal registers");
break;
}
case REG_TYPE_GROUP_STOCK:
{
return N_("Stock account registers");
break;
}
case REG_TYPE_GROUP_PORTFOLIO:
{
return N_("Portfolio registers");
break;
}
default:
{
return N_("Register group Unknown");
break;
}
}
}
static void
gsr_drop_register_width_state (GNCSplitReg *gsr, GKeyFile* state_file, const gchar *state_section)
gsr_move_sort_and_filter_to_state_file (GNCSplitReg *gsr, GKeyFile* state_file, const gchar *state_section)
{
GNCLedgerDisplayType ledger_type;
GNCLedgerDisplay* ld;
gboolean sort_reversed = FALSE;
gchar* sort_text = NULL;
gchar* filter_text = NULL;
// Look for any old kvp entries and add them to .gcm file
ledger_type = gnc_ledger_display_type (gsr->ledger);
@ -500,31 +452,6 @@ gsr_drop_register_width_state (GNCSplitReg *gsr, GKeyFile* state_file, const gch
xaccAccountSetSortReversed (leader, FALSE);
}
}
sort_reversed = g_key_file_get_boolean (state_file, state_section,
KEY_PAGE_SORT_REV, NULL);
sort_text = g_key_file_get_string (state_file, state_section,
KEY_PAGE_SORT, NULL);
filter_text = g_key_file_get_string (state_file, state_section,
KEY_PAGE_FILTER, NULL);
// drop the register state widths
gnc_state_drop_sections_for (state_section);
if (filter_text)
g_key_file_set_string (state_file, state_section, KEY_PAGE_FILTER,
filter_text);
if (sort_text)
g_key_file_set_string (state_file, state_section, KEY_PAGE_SORT, sort_text);
if (sort_reversed)
g_key_file_set_boolean (state_file, state_section, KEY_PAGE_SORT_REV,
sort_reversed);
g_free (filter_text);
g_free (sort_text);
}
static
@ -539,9 +466,6 @@ gsr_create_table( GNCSplitReg *gsr )
gchar guidstr[GUID_ENCODING_LENGTH+1];
GKeyFile* state_file = gnc_state_get_current();
gchar *register_state_section;
const gchar *default_state_section;
const gchar *group;
gboolean has_date_width = FALSE;
guid_to_string_buff (guid, guidstr);
@ -550,23 +474,7 @@ gsr_create_table( GNCSplitReg *gsr )
ENTER("gsr=%p", gsr);
sr = gnc_ledger_display_get_split_register (gsr->ledger);
default_state_section = gnc_split_reg_get_register_state_group (gsr);
// see if register group has the date_width key, old format pre 4.0
has_date_width = g_key_file_has_key (state_file, register_state_section, "date_width", NULL);
// if this is from a page recreate and no register state use those settings,
// register state width information is dropped at the end of function.
if (gsr->page_state_name && !has_date_width)
group = gsr->page_state_name;
else
{
// if no default state, use register state if available
if (gnc_split_reg_register_has_user_state (gsr))
group = default_state_section;
else
group = register_state_section;
}
gnc_ledger_display_set_user_data( gsr->ledger, (gpointer)gsr );
gnc_ledger_display_set_handlers( gsr->ledger,
gnc_split_reg_ld_destroy,
@ -574,7 +482,7 @@ gsr_create_table( GNCSplitReg *gsr )
/* FIXME: We'd really rather pass this down... */
sr = gnc_ledger_display_get_split_register( gsr->ledger );
register_widget = gnucash_register_new( sr->table, group );
register_widget = gnucash_register_new( sr->table, register_state_section );
gsr->reg = GNUCASH_REGISTER( register_widget );
gtk_box_pack_start (GTK_BOX (gsr), GTK_WIDGET(gsr->reg), TRUE, TRUE, 0);
@ -594,15 +502,8 @@ gsr_create_table( GNCSplitReg *gsr )
g_signal_connect (gsr->reg, "show_popup_menu",
G_CALLBACK(gsr_emit_show_popup_menu), gsr);
// if no default state and register has state, copy it.
if (has_date_width) // we have old register state section
{
if (!gnc_split_reg_register_has_user_state (gsr))
gnc_table_save_state (sr->table, default_state_section);
gsr_move_sort_and_filter_to_state_file (gsr, state_file, register_state_section);
// drop the register width state information
gsr_drop_register_width_state (gsr, state_file, register_state_section);
}
g_free (register_state_section);
LEAVE(" ");
}
@ -884,11 +785,30 @@ static void
gnc_split_reg_ld_destroy( GNCLedgerDisplay *ledger )
{
GNCSplitReg *gsr = gnc_ledger_display_get_user_data( ledger );
Account * account = gnc_ledger_display_leader(ledger);
const GncGUID * guid = xaccAccountGetGUID(account);
gchar guidstr[GUID_ENCODING_LENGTH+1];
gchar *state_section;
guid_to_string_buff(guid, guidstr);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", guidstr, NULL);
if (gsr)
{
SplitRegister *reg;
reg = gnc_ledger_display_get_split_register (ledger);
if (reg && reg->table)
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);
/*
* Don't destroy the window here any more. The register no longer
* owns it.
*/
gnc_ledger_display_set_user_data (ledger, NULL);
g_object_unref (gsr);
}
@ -1890,44 +1810,6 @@ gnc_split_reg_set_sheet_focus (GNCSplitReg *gsr, gboolean has_focus)
gnucash_sheet_set_has_focus (sheet, has_focus);
}
/* Save user state layout information to the register group that
* this register belongs to so it can be used as the default
* user layout
*/
void
gnc_split_reg_save_register_layout_to_user_state (GNCSplitReg *gsr)
{
SplitRegister *split_reg = gnc_ledger_display_get_split_register (gsr->ledger);
const gchar *group = gnc_split_reg_get_register_state_group (gsr);
gnc_table_save_state (split_reg->table, group);
}
/* Removes the user state layout information for the register group
* that this register belongs to and also resets the current layout to
* the built-in defaults
*/
void
gnc_split_reg_reset_register_layout_and_clear_user_state (GNCSplitReg *gsr)
{
GnucashRegister *reg = gsr->reg;
const gchar *group = gnc_split_reg_get_register_state_group (gsr);
gnucash_register_reset_sheet_layout (reg);
gnc_state_drop_sections_for (group);
}
/* Checks to see if there is user state layout information for the
* register group that this register belongs to.
*/
gboolean
gnc_split_reg_register_has_user_state (GNCSplitReg *gsr)
{
GKeyFile *state_file = gnc_state_get_current ();
const gchar *group = gnc_split_reg_get_register_state_group (gsr);
return g_key_file_has_group (state_file, group);
}
void
gnc_split_reg_balancing_entry(GNCSplitReg *gsr, Account *account,
time64 statement_date, gnc_numeric balancing_amount)

View File

@ -88,8 +88,6 @@ struct _GNCSplitReg
/** The actual gnucash register widget. **/
GnucashRegister *reg;
const gchar *page_state_name; /* Used for loading open state information */
gint numRows;
guint sort_type;
@ -184,13 +182,11 @@ GType gnc_split_reg_get_type(void);
* @param parent The containing window.
* @param numberOfLines The initial number of lines for the register.
* @param read_only If the contained register should be setup read-only.
* @param group_name The group name of the page state section for this page
**/
GtkWidget* gnc_split_reg_new( GNCLedgerDisplay *ld,
GtkWindow *parent,
gint numberOfLines,
gboolean read_only,
const gchar *group_name );
gboolean read_only );
/**
* Returns the GnucashRegister in effect for this GNCSplitReg.
@ -268,14 +264,6 @@ gboolean gnc_split_reg_clear_filter_for_split (GNCSplitReg *gsr, Split *split);
void gnc_split_reg_focus_on_sheet (GNCSplitReg *gsr);
void gnc_split_reg_set_sheet_focus (GNCSplitReg *gsr, gboolean has_focus);
/**
* Save/Reset/Has functions used for the user default register layouts.
**/
void gnc_split_reg_save_register_layout_to_user_state (GNCSplitReg *gsr);
void gnc_split_reg_reset_register_layout_and_clear_user_state (GNCSplitReg *gsr);
gboolean gnc_split_reg_register_has_user_state (GNCSplitReg *gsr);
const gchar *gnc_split_reg_get_register_state_group (GNCSplitReg *gsr);
/*
* Create a transaction entry with given amount and date. One account is
* specified, the other is undefined i.e. it defaults to orphan account.

View File

@ -66,13 +66,6 @@
<menuitem name="ReportsAcctTransReport" action="ReportsAcctTransReportAction"/>
</placeholder>
</menu>
<menu name="Windows" action="WindowsAction">
<placeholder name="WindowsLayoutPlaceholder">
<menuitem name="WindowsSaveLayout" action="WindowsSaveLayoutAction"/>
<menuitem name="WindowsResetLayout" action="WindowsResetLayoutAction"/>
</placeholder>
</menu>
</menubar>
<toolbar name="DefaultToolbar">

View File

@ -32,14 +32,6 @@
<menuitem name="BlankTransaction" action="BlankTransactionAction"/>
</placeholder>
</menu>
<menu name="Windows" action="WindowsAction">
<placeholder name="WindowsLayoutPlaceholder">
<menuitem name="WindowsSaveLayout" action="WindowsSaveLayoutAction"/>
<menuitem name="WindowsResetLayout" action="WindowsResetLayoutAction"/>
</placeholder>
</menu>
</menubar>
<toolbar name="DefaultToolbar">

View File

@ -5,8 +5,6 @@
<menu name="Windows" action="WindowsAction">
<menuitem name="WindowNew" action="WindowNewAction"/>
<menuitem name="WindowMovePage" action="WindowMovePageAction"/>
<separator name="ViewSep5"/>
<placeholder name="WindowsLayoutPlaceholder"/>
<separator name="ViewSep4"/>
<menuitem name="Window0" action="Window0Action"/>
<menuitem name="Window1" action="Window1Action"/>