[Patch] Enhance account renumbering dialog with 'Begin At' entry to increment from

Darryl Rees dardie at gmail.com
Fri Jun 6 09:10:34 EDT 2008


I've attached the patch as an attachment, I just round-trip cut-and-pasted
between gmail and the patch file (using gedit) - not the same :-(
I guess I should use a real email client - sorry.

Darryl Rees

On Fri, Jun 6, 2008 at 7:58 PM, Darryl Rees <dardie at gmail.com> wrote:

> On Thu, Jun 5, 2008 at 8:15 PM, Derek Atkins <warlord at mit.edu> wrote:
>
>> "Darryl Rees" <dardie at gmail.com> writes:
>>
>> > By way of illustration, I wanted to do something like the following:
>> > A000            Assets
>> >     A100        Fixed Assets
>> >         A110    Buildings
>> >         A120    Furniture and Fittings
>> >         A130    Other Fixed Asset
>> >     A200        Current Assets
>> >         A210    Petty Cash
>> >         A230    Bank Account
>>
>> Why do you want to skip A220?
>>
>
> Sorry - typo.
>
>
>> > Hope the patch is useful. If accepted I will submit a documentation
>> patch to
>> > reflect change in the dialog. I haven't seriously coded since last
>> millenium
>> > so any constructive advice welcome :-(
>>
>> Thanks.  Could you re-submit with glade-2.
>> Also, you might want to run it through the glade-cleanup script.
>>
>> Thanks!
>>
>> > Darryl Rees
>>
>> -derek
>>
>
> Thanks for the feedback Derek. As suggested I redid with glade-2 and
> glade-fixup, new patch below:
>
>
> Index: src/gnome-utils/dialog-account.c
> ===================================================================
> --- src/gnome-utils/dialog-account.c    (revision 17190)
> +++ src/gnome-utils/dialog-account.c    (working copy)
> @@ -119,9 +119,11 @@
>  {
>    GtkWidget *dialog;
>    GtkWidget *prefix;
> +  GtkWidget *beginat;
>    GtkWidget *interval;
>    GtkWidget *example1;
>    GtkWidget *example2;
> +  GtkWidget *example3;
>
>    Account *parent;
>    gint num_children;
> @@ -138,6 +140,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_beginat_changed_cb (GtkEditable *editable,
> RenumberDialog *data);
>  void gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
> RenumberDialog *data);
>  void gnc_account_renumber_response_cb (GtkDialog *dialog, gint response,
> RenumberDialog *data);
>
> @@ -1744,23 +1747,32 @@
>  gnc_account_renumber_update_examples (RenumberDialog *data)
>  {
>    gchar *str;
> -  gchar *prefix;
> -  gint interval, num_digits;
> +  gchar *prefix, *beginat;
> +  gint interval, beginint, num_digits;
>
>    prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
> +  beginat = gtk_editable_get_chars(GTK_EDITABLE(data->beginat), 0, -1);
> +  beginint = strtol(beginat, NULL, 10);
>    interval =
> gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
> -  num_digits = log10(data->num_children * interval) + 1;
> +  num_digits = MAX(strlen(beginat), log10(data->num_children * interval) +
> 1);
> +  if (num_digits > 12)
> +    num_digits = 12; /* Prevent insanity */
>
> -  str = g_strdup_printf("%s-%0*d", prefix, num_digits, interval);
> +  str = g_strdup_printf("%s%0*d", prefix, num_digits, beginint);
>    gtk_label_set_text(GTK_LABEL(data->example1), str);
>    g_free(str);
>
> -  str = g_strdup_printf("%s-%0*d", prefix, num_digits,
> -            interval * data->num_children);
> +  str = g_strdup_printf("%s%0*d", prefix, num_digits, beginint +
> interval);
>    gtk_label_set_text(GTK_LABEL(data->example2), str);
>    g_free(str);
>
> +  str = g_strdup_printf("%s%0*d", prefix, num_digits,
> +            beginint + interval * data->num_children);
> +  gtk_label_set_text(GTK_LABEL(data->example3), str);
> +  g_free(str);
> +
>    g_free(prefix);
> +  g_free(beginat);
>  }
>
>  void
> @@ -1771,6 +1783,13 @@
>  }
>
>  void
> +gnc_account_renumber_beginat_changed_cb (GtkEditable *editable,
> +                     RenumberDialog *data)
> +{
> +  gnc_account_renumber_update_examples(data);
> +}
> +
> +void
>  gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
>                      RenumberDialog *data)
>  {
> @@ -1784,25 +1803,31 @@
>  {
>    GList *children, *tmp;
>    gchar *str;
> -  gchar *prefix;
> -  gint interval, num_digits, i;
> +  gchar *prefix, *beginat;
> +  gint beginint, interval, num_digits, i;
>
>    if (response == GTK_RESPONSE_OK) {
>      gtk_widget_hide(data->dialog);
>      children = gnc_account_get_children(data->parent);
>      prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
> +    beginat = gtk_editable_get_chars(GTK_EDITABLE(data->beginat), 0, -1);
> +    beginint = strtol(beginat, NULL, 10);
>      interval =
>        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
> -    num_digits = log10(data->num_children * interval) + 1;
> +    num_digits = MAX(strlen(beginat), log10(data->num_children * interval)
> + 1);
> +    if (num_digits > 12)
> +      num_digits = 12; /* Prevent insanity */
>
>      gnc_set_busy_cursor (NULL, TRUE);
> -    for (tmp = children, i = 1; tmp; tmp = g_list_next(tmp), i += 1) {
> -      str = g_strdup_printf("%s-%0*d", prefix, num_digits, interval * i);
> +    for (tmp = children, i = 0; tmp; tmp = g_list_next(tmp), i += 1) {
> +      str = g_strdup_printf("%s%0*d", prefix, num_digits, beginint +
> interval * i);
>        xaccAccountSetCode(tmp->data, str);
>        g_free(str);
>      }
>      gnc_unset_busy_cursor (NULL);
>      g_list_free(children);
> +    g_free(prefix);
> +    g_free(beginat);
>    }
>
>    gtk_widget_destroy(data->dialog);
> @@ -1827,19 +1852,23 @@
>    g_object_set_data_full(G_OBJECT(data->dialog), "xml", xml,
> g_object_unref);
>
>    widget = glade_xml_get_widget (xml, "header_label");
> -  string = g_strdup_printf(_( "Renumber the immediate sub-accounts of %s?
> "
> -                  "This will replace the account code field of "
> +  string = g_strdup_printf(_( "Renumber the immediate sub-accounts of %s.
> "
> +                  "ie. replace the account code field of "
>                    "each child account with a newly generated code."),
>                 xaccAccountGetFullName(account));
>    gtk_label_set_text(GTK_LABEL(widget), string);
>    g_free(string);
>
>    data->prefix = glade_xml_get_widget (xml, "prefix_entry");
> +  data->beginat = glade_xml_get_widget (xml, "beginat_entry");
>    data->interval = glade_xml_get_widget (xml, "interval_spin");
>    data->example1 = glade_xml_get_widget (xml, "example1_label");
>    data->example2 = glade_xml_get_widget (xml, "example2_label");
> +  data->example3 = glade_xml_get_widget (xml, "example3_label");
>
> -  gtk_entry_set_text(GTK_ENTRY(data->prefix),
> xaccAccountGetCode(account));
> +  string = g_strdup_printf("%s-", xaccAccountGetCode(account));
> +  gtk_entry_set_text(GTK_ENTRY(data->prefix), string);
> +  g_free(string);
>    gnc_account_renumber_update_examples(data);
>
>    glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func,
> Index: src/gnome/glade/account.glade
> ===================================================================
> --- src/gnome/glade/account.glade    (revision 17190)
> +++ src/gnome/glade/account.glade    (working copy)
> @@ -3530,7 +3530,7 @@
>        <child>
>      <widget class="GtkTable" id="table12">
>        <property name="visible">True</property>
> -      <property name="n_rows">5</property>
> +      <property name="n_rows">8</property>
>        <property name="n_columns">2</property>
>        <property name="homogeneous">False</property>
>        <property name="row_spacing">6</property>
> @@ -3635,8 +3635,8 @@
>          <packing>
>            <property name="left_attach">0</property>
>            <property name="right_attach">1</property>
> -          <property name="top_attach">3</property>
> -          <property name="bottom_attach">4</property>
> +          <property name="top_attach">4</property>
> +          <property name="bottom_attach">5</property>
>            <property name="x_options">fill</property>
>            <property name="y_options"></property>
>          </packing>
> @@ -3663,14 +3663,98 @@
>          <packing>
>            <property name="left_attach">1</property>
>            <property name="right_attach">2</property>
> -          <property name="top_attach">3</property>
> -          <property name="bottom_attach">4</property>
> +          <property name="top_attach">4</property>
> +          <property name="bottom_attach">5</property>
>            <property name="x_options">fill</property>
>            <property name="y_options"></property>
>          </packing>
>        </child>
>
>        <child>
> +        <widget class="GtkLabel" id="label8477442">
> +          <property name="visible">True</property>
> +          <property name="label" translatable="yes">...</property>
> +          <property name="use_underline">False</property>
> +          <property name="use_markup">False</property>
> +          <property name="justify">GTK_JUSTIFY_LEFT</property>
> +          <property name="wrap">False</property>
> +          <property name="selectable">False</property>
> +          <property name="xalign">0</property>
> +          <property name="yalign">0.5</property>
> +          <property name="xpad">0</property>
> +          <property name="ypad">0</property>
> +          <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
> +          <property name="width_chars">-1</property>
> +          <property name="single_line_mode">False</property>
> +          <property name="angle">0</property>
> +        </widget>
> +        <packing>
> +          <property name="left_attach">1</property>
> +          <property name="right_attach">2</property>
> +          <property name="top_attach">6</property>
> +          <property name="bottom_attach">7</property>
> +          <property name="x_options">fill</property>
> +          <property name="y_options"></property>
> +        </packing>
> +      </child>
> +
> +      <child>
> +        <widget class="GtkLabel" id="example2_label">
> +          <property name="visible">True</property>
> +          <property name="label" translatable="yes"></property>
> +          <property name="use_underline">False</property>
> +          <property name="use_markup">False</property>
> +          <property name="justify">GTK_JUSTIFY_LEFT</property>
> +          <property name="wrap">False</property>
> +          <property name="selectable">False</property>
> +          <property name="xalign">0</property>
> +          <property name="yalign">0.5</property>
> +          <property name="xpad">0</property>
> +          <property name="ypad">0</property>
> +          <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
> +          <property name="width_chars">-1</property>
> +          <property name="single_line_mode">False</property>
> +          <property name="angle">0</property>
> +        </widget>
> +        <packing>
> +          <property name="left_attach">1</property>
> +          <property name="right_attach">2</property>
> +          <property name="top_attach">5</property>
> +          <property name="bottom_attach">6</property>
> +          <property name="x_options">fill</property>
> +          <property name="y_options"></property>
> +        </packing>
> +      </child>
> +
> +      <child>
> +        <widget class="GtkLabel" id="example3_label">
> +          <property name="visible">True</property>
> +          <property name="label" translatable="yes"></property>
> +          <property name="use_underline">False</property>
> +          <property name="use_markup">False</property>
> +          <property name="justify">GTK_JUSTIFY_LEFT</property>
> +          <property name="wrap">False</property>
> +          <property name="selectable">False</property>
> +          <property name="xalign">0</property>
> +          <property name="yalign">0.5</property>
> +          <property name="xpad">0</property>
> +          <property name="ypad">0</property>
> +          <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
> +          <property name="width_chars">-1</property>
> +          <property name="single_line_mode">False</property>
> +          <property name="angle">0</property>
> +        </widget>
> +        <packing>
> +          <property name="left_attach">1</property>
> +          <property name="right_attach">2</property>
> +          <property name="top_attach">7</property>
> +          <property name="bottom_attach">8</property>
> +          <property name="x_options">fill</property>
> +          <property name="y_options"></property>
> +        </packing>
> +      </child>
> +
> +      <child>
>          <widget class="GtkLabel" id="label8477438">
>            <property name="visible">True</property>
>            <property name="label" translatable="yes">Interval:</property>
> @@ -3691,8 +3775,8 @@
>          <packing>
>            <property name="left_attach">0</property>
>            <property name="right_attach">1</property>
> -          <property name="top_attach">2</property>
> -          <property name="bottom_attach">3</property>
> +          <property name="top_attach">3</property>
> +          <property name="bottom_attach">4</property>
>            <property name="x_options">fill</property>
>            <property name="y_options"></property>
>          </packing>
> @@ -3714,16 +3798,16 @@
>          <packing>
>            <property name="left_attach">1</property>
>            <property name="right_attach">2</property>
> -          <property name="top_attach">2</property>
> -          <property name="bottom_attach">3</property>
> +          <property name="top_attach">3</property>
> +          <property name="bottom_attach">4</property>
>            <property name="y_options"></property>
>          </packing>
>        </child>
>
>        <child>
> -        <widget class="GtkLabel" id="example2_label">
> +        <widget class="GtkLabel" id="label8477444">
>            <property name="visible">True</property>
> -          <property name="label" translatable="yes"></property>
> +          <property name="label" translatable="yes">Begin at:</property>
>            <property name="use_underline">False</property>
>            <property name="use_markup">False</property>
>            <property name="justify">GTK_JUSTIFY_LEFT</property>
> @@ -3739,11 +3823,33 @@
>            <property name="angle">0</property>
>          </widget>
>          <packing>
> +          <property name="left_attach">0</property>
> +          <property name="right_attach">1</property>
> +          <property name="top_attach">2</property>
> +          <property name="bottom_attach">3</property>
> +          <property name="x_options">fill</property>
> +          <property name="y_options"></property>
> +        </packing>
> +      </child>
> +
> +      <child>
> +        <widget class="GtkEntry" id="beginat_entry">
> +          <property name="visible">True</property>
> +          <property name="can_focus">True</property>
> +          <property name="editable">True</property>
> +          <property name="visibility">True</property>
> +          <property name="max_length">12</property>
> +          <property name="text" translatable="yes">00</property>
> +          <property name="has_frame">True</property>
> +          <property name="invisible_char">*</property>
> +          <property name="activates_default">False</property>
> +          <signal name="changed"
> handler="gnc_account_renumber_prefix_changed_cb"
> last_modification_time="Sat, 18 Mar 2006 21:52:12 GMT"/>
> +        </widget>
> +        <packing>
>            <property name="left_attach">1</property>
>            <property name="right_attach">2</property>
> -          <property name="top_attach">4</property>
> -          <property name="bottom_attach">5</property>
> -          <property name="x_options">fill</property>
> +          <property name="top_attach">2</property>
> +          <property name="bottom_attach">3</property>
>            <property name="y_options"></property>
>          </packing>
>        </child>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: renumber2.patch
Type: text/x-diff
Size: 13495 bytes
Desc: not available
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20080606/393b0101/attachment-0001.bin 


More information about the gnucash-devel mailing list