mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-25 10:20:18 -06:00
Bug 798053 - Accounts renumeration (renumbering)
In the renumbering sub accounts dialog, the examples displayed have leading zeros but when pressing 'OK' they are dropped. This has been fixed and an additional spin button added to specify the number of digits the generated code will have.
This commit is contained in:
parent
d195a87079
commit
b41e626076
@ -128,6 +128,7 @@ typedef struct _RenumberDialog
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *prefix;
|
||||
GtkWidget *interval;
|
||||
GtkWidget *digits;
|
||||
GtkWidget *example1;
|
||||
GtkWidget *example2;
|
||||
|
||||
@ -147,6 +148,7 @@ static void gnc_account_window_set_name (AccountWindow *aw);
|
||||
|
||||
void gnc_account_renumber_prefix_changed_cb (GtkEditable *editable, RenumberDialog *data);
|
||||
void gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton, RenumberDialog *data);
|
||||
void gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton, RenumberDialog *data);
|
||||
void gnc_account_renumber_response_cb (GtkDialog *dialog, gint response, RenumberDialog *data);
|
||||
|
||||
void gnc_account_window_destroy_cb (GtkWidget *object, gpointer data);
|
||||
@ -2043,16 +2045,34 @@ gnc_account_renumber_update_examples (RenumberDialog *data)
|
||||
{
|
||||
gchar *str;
|
||||
gchar *prefix;
|
||||
gint interval;
|
||||
gint interval;
|
||||
gint digits;
|
||||
unsigned int num_digits = 1;
|
||||
|
||||
g_return_if_fail (data->num_children > 0);
|
||||
|
||||
prefix = gtk_editable_get_chars (GTK_EDITABLE(data->prefix), 0, -1);
|
||||
interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
|
||||
digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
|
||||
|
||||
if (interval <= 0)
|
||||
interval = 10;
|
||||
|
||||
num_digits = (unsigned int)log10((double)(data->num_children * interval)) + 1;
|
||||
|
||||
if (digits <= num_digits)
|
||||
{
|
||||
g_signal_handlers_block_by_func (GTK_SPIN_BUTTON(data->digits),
|
||||
(gpointer)gnc_account_renumber_digits_changed_cb,
|
||||
data);
|
||||
gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->digits), num_digits);
|
||||
g_signal_handlers_unblock_by_func (GTK_SPIN_BUTTON(data->digits),
|
||||
(gpointer)gnc_account_renumber_digits_changed_cb,
|
||||
data);
|
||||
}
|
||||
else
|
||||
num_digits = digits;
|
||||
|
||||
if (strlen (prefix))
|
||||
str = g_strdup_printf ("%s-%0*d", prefix, num_digits, interval);
|
||||
else
|
||||
@ -2088,20 +2108,28 @@ gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
|
||||
gnc_account_renumber_update_examples (data);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton,
|
||||
RenumberDialog *data)
|
||||
{
|
||||
gnc_account_renumber_update_examples (data);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
gint response,
|
||||
RenumberDialog *data)
|
||||
{
|
||||
GList *children = NULL, *tmp;
|
||||
gchar *prefix;
|
||||
gint interval;
|
||||
unsigned int num_digits, i;
|
||||
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
{
|
||||
GList *children = gnc_account_get_children_sorted (data->parent);
|
||||
GList *tmp;
|
||||
gchar *prefix;
|
||||
gint interval;
|
||||
unsigned int num_digits, i;
|
||||
|
||||
gtk_widget_hide (data->dialog);
|
||||
children = gnc_account_get_children_sorted (data->parent);
|
||||
|
||||
if (children == NULL)
|
||||
{
|
||||
PWARN("Can't renumber children of an account with no children!");
|
||||
@ -2110,14 +2138,10 @@ gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
}
|
||||
prefix = gtk_editable_get_chars (GTK_EDITABLE(data->prefix), 0, -1);
|
||||
interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
|
||||
|
||||
if (interval <= 0)
|
||||
interval = 10;
|
||||
|
||||
num_digits = (unsigned int)log10 ((double)(data->num_children * interval) + 1);
|
||||
num_digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
|
||||
|
||||
gnc_set_busy_cursor (NULL, TRUE);
|
||||
for (tmp = children, i = 1; tmp; tmp = g_list_next(tmp), i += 1)
|
||||
for (tmp = children, i = 1; tmp; tmp = g_list_next (tmp), i += 1)
|
||||
{
|
||||
gchar *str;
|
||||
if (strlen (prefix))
|
||||
@ -2125,13 +2149,14 @@ gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
num_digits, interval * i);
|
||||
else
|
||||
str = g_strdup_printf ("%0*d", num_digits, interval * i);
|
||||
|
||||
xaccAccountSetCode (tmp->data, str);
|
||||
g_free (str);
|
||||
}
|
||||
gnc_unset_busy_cursor (NULL);
|
||||
g_free (prefix);
|
||||
g_list_free (children);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (data->dialog);
|
||||
g_free (data);
|
||||
}
|
||||
@ -2148,12 +2173,14 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
|
||||
* should be disabled if the account has no children.
|
||||
*/
|
||||
g_return_if_fail (gnc_account_n_children (account) > 0);
|
||||
|
||||
data = g_new (RenumberDialog, 1);
|
||||
data->parent = account;
|
||||
data->num_children = gnc_account_n_children (account);
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gnc_builder_add_from_file (builder, "dialog-account.glade", "interval_adjustment");
|
||||
gnc_builder_add_from_file (builder, "dialog-account.glade", "digit_spin_adjustment");
|
||||
gnc_builder_add_from_file (builder, "dialog-account.glade", "account_renumber_dialog");
|
||||
data->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_renumber_dialog"));
|
||||
gtk_window_set_transient_for (GTK_WINDOW(data->dialog), GTK_WINDOW(window));
|
||||
@ -2163,9 +2190,7 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
|
||||
|
||||
widget = GTK_WIDGET(gtk_builder_get_object (builder, "header_label"));
|
||||
fullname = gnc_account_get_full_name (account);
|
||||
string = g_strdup_printf (_( "Renumber the immediate sub-accounts of %s? "
|
||||
"This will replace the account code field of "
|
||||
"each child account with a newly generated code."),
|
||||
string = g_strdup_printf (_("Renumber the immediate sub-accounts of '%s'?"),
|
||||
fullname);
|
||||
gtk_label_set_text (GTK_LABEL(widget), string);
|
||||
g_free (string);
|
||||
@ -2173,6 +2198,7 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
|
||||
|
||||
data->prefix = GTK_WIDGET(gtk_builder_get_object (builder, "prefix_entry"));
|
||||
data->interval = GTK_WIDGET(gtk_builder_get_object (builder, "interval_spin"));
|
||||
data->digits = GTK_WIDGET(gtk_builder_get_object (builder, "digit_spin"));
|
||||
data->example1 = GTK_WIDGET(gtk_builder_get_object (builder, "example1_label"));
|
||||
data->example2 = GTK_WIDGET(gtk_builder_get_object (builder, "example2_label"));
|
||||
|
||||
|
@ -1050,6 +1050,13 @@
|
||||
<class name="gnc-class-account"/>
|
||||
</style>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="digit_spin_adjustment">
|
||||
<property name="lower">1</property>
|
||||
<property name="upper">100</property>
|
||||
<property name="value">3</property>
|
||||
<property name="step-increment">1</property>
|
||||
<property name="page-increment">10</property>
|
||||
</object>
|
||||
<object class="GtkListStore" id="fraction_liststore">
|
||||
<columns>
|
||||
<!-- column-name Fractions -->
|
||||
@ -1901,7 +1908,7 @@
|
||||
<property name="border-width">6</property>
|
||||
<property name="title" translatable="yes">Renumber sub-accounts</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default-width">400</property>
|
||||
<property name="default-width">450</property>
|
||||
<property name="type-hint">dialog</property>
|
||||
<signal name="response" handler="gnc_account_renumber_response_cb" swapped="no"/>
|
||||
<child internal-child="vbox">
|
||||
@ -1954,7 +1961,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<!-- n-columns=2 n-rows=6 -->
|
||||
<object class="GtkGrid" id="grid400">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
@ -1969,15 +1976,17 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="header_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label">Renumber the immediate sub-accounts of xxx.</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@ -1993,7 +2002,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">1</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -2007,7 +2016,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -2019,7 +2028,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -2033,7 +2042,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -2080,7 +2089,48 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSpinButton" id="digit_spin">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="adjustment">digit_spin_adjustment</property>
|
||||
<signal name="value-changed" handler="gnc_account_renumber_digits_changed_cb" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Number of Digits</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label401">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin-top">3</property>
|
||||
<property name="margin-bottom">3</property>
|
||||
<property name="label" translatable="yes">This will replace the account code field of each child account with a newly generated code</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
Reference in New Issue
Block a user