Bug 645379 - Problem with Number field when duplicating a transaction

When you duplicate a transaction, the dialog presented has a
GtkSpinbutton for the number field and non-numeric values are being
discarded. The register and transfer dialog have a GtkEntry for this
field so change this dialog to using them also.
This commit is contained in:
Robert Fewell 2020-11-08 11:40:35 +00:00
parent 2290fa7c22
commit 4c2df4c2ad
4 changed files with 371 additions and 293 deletions

View File

@ -81,17 +81,61 @@ parse_num (const char *string, long int *num)
}
static gboolean
gnc_dup_trans_output_cb(GtkSpinButton *spinbutton,
gpointer user_data)
gnc_dup_inc_dec (GtkWidget *widget, const gchar *text, gint inc_dec)
{
gboolean is_number;
long int num;
gchar *txt = gtk_editable_get_chars(GTK_EDITABLE(spinbutton), 0, -1);
is_number = parse_num(txt, &num);
g_free(txt);
if (!is_number)
gtk_entry_set_text(GTK_ENTRY(spinbutton), "");
return !is_number;
if (parse_num (text, &num))
{
gchar *format;
gchar *out;
num = num + inc_dec;
if (num == -1)
num = 0;
if (g_str_has_prefix (text, "0"))
format = g_strdup_printf ("%s%ld%s", "%0", strlen (text), "d");
else
format = g_strdup_printf ("%s", "%ld");
out = g_strdup_printf (format, num);
gtk_entry_set_text (GTK_ENTRY(widget), out);
g_free (format);
g_free (out);
return TRUE;
}
return FALSE;
}
static gboolean
gnc_dup_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
const gchar *text = gtk_entry_get_text (GTK_ENTRY(widget));
if (gnc_strisnum (text))
{
GdkModifierType modifiers = gtk_accelerator_get_default_mod_mask ();
gint increment;
long int num;
if ((event->state & modifiers) == GDK_CONTROL_MASK ||
(event->state & modifiers) == GDK_MOD1_MASK)
return FALSE;
if (event->keyval == GDK_KEY_plus || event->keyval == GDK_KEY_KP_Add)
increment = 1;
else if (event->keyval == GDK_KEY_minus || event->keyval == GDK_KEY_KP_Subtract)
increment = -1;
else
return FALSE;
return gnc_dup_inc_dec (widget, text, increment);
}
else
return FALSE;
}
static void
@ -101,6 +145,7 @@ gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
{
GtkWidget *dialog;
GtkBuilder *builder;
const gchar *tt = _("Use +- keys to increment/decrement number");
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "num_adjustment");
@ -147,31 +192,33 @@ gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
dt_dialog->num_label = GTK_WIDGET(gtk_builder_get_object (builder, "num_label"));
dt_dialog->tnum_label = GTK_WIDGET(gtk_builder_get_object (builder, "tnum_label"));
dt_dialog->num_edit = GTK_WIDGET(gtk_builder_get_object (builder, "num_entry"));
dt_dialog->tnum_edit = GTK_WIDGET(gtk_builder_get_object (builder, "tnum_entry"));
if (num_str)
gtk_entry_set_text (GTK_ENTRY(dt_dialog->num_edit), num_str);
if (tnum_str)
gtk_entry_set_text (GTK_ENTRY(dt_dialog->tnum_edit), tnum_str);
g_signal_connect (dt_dialog->num_edit, "key-press-event",
G_CALLBACK(gnc_dup_key_press_event_cb),
dt_dialog);
g_signal_connect (dt_dialog->tnum_edit, "key-press-event",
G_CALLBACK(gnc_dup_key_press_event_cb),
dt_dialog);
if (gnc_strisnum (num_str))
{
GtkWidget *num_spin, *tnum_spin;
long int num, tnum;
num_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_spin"));
tnum_spin = GTK_WIDGET(gtk_builder_get_object (builder, "tnum_spin"));
dt_dialog->num_edit = num_spin;
dt_dialog->tnum_edit = tnum_spin;
gtk_entry_set_activates_default(GTK_ENTRY(num_spin), TRUE);
g_signal_connect(num_spin, "output",
G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
g_signal_connect(tnum_spin, "output",
G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
if (num_str && parse_num (num_str, &num))
gtk_spin_button_set_value (GTK_SPIN_BUTTON (num_spin), num + 1);
else
gtk_entry_set_text (GTK_ENTRY (num_spin), "");
if (tnum_str && parse_num (tnum_str, &tnum))
gtk_spin_button_set_value (GTK_SPIN_BUTTON (tnum_spin), tnum + 1);
else
gtk_entry_set_text (GTK_ENTRY (tnum_spin), "");
gtk_widget_set_tooltip_text (GTK_WIDGET(dt_dialog->num_edit), tt);
gnc_dup_inc_dec (GTK_WIDGET(dt_dialog->num_edit), num_str, 1);
}
if (gnc_strisnum (tnum_str))
{
gtk_widget_set_tooltip_text (GTK_WIDGET(dt_dialog->tnum_edit), tt);
gnc_dup_inc_dec (GTK_WIDGET(dt_dialog->tnum_edit), tnum_str, 1);
}
/* Transaction Linked Document */
{
dt_dialog->link_label = GTK_WIDGET(gtk_builder_get_object (builder, "link_label"));

View File

@ -559,10 +559,209 @@ If 0, all previous days included</property>
<placeholder/>
</child>
</object>
<object class="GtkAdjustment" id="num_adjustment">
<property name="upper">1000000000</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<object class="GtkDialog" id="duplicate_transaction_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" comments="Duplicate Transaction Dialog">Duplicate Transaction</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox15">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area15">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button76">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button77">
<property name="label" translatable="yes">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="duplicate_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">&lt;b&gt;New Transaction Information&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="duplicate_table">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">6</property>
<property name="margin_end">6</property>
<property name="border_width">6</property>
<property name="row_spacing">3</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkLabel" id="date_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Date</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="num_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">num_entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="date_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="tnum_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Transaction Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">tnum_entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="link_check_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="image_position">top</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Keep Linked Document Entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="num_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tnum_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button76</action-widget>
<action-widget response="-5">button77</action-widget>
</action-widgets>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkEntryBuffer" id="entrybuffer1">
<property name="text" translatable="yes">0</property>
</object>
<object class="GtkDialog" id="sort_by_dialog">
<property name="can_focus">False</property>
@ -906,221 +1105,6 @@ If 0, all previous days included</property>
<placeholder/>
</child>
</object>
<object class="GtkAdjustment" id="tnum_adjustment">
<property name="upper">1000000000</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="duplicate_transaction_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" comments="Duplicate Transaction Dialog">Duplicate Transaction</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox15">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area15">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button76">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button77">
<property name="label" translatable="yes">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="duplicate_table">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">6</property>
<property name="margin_end">6</property>
<property name="border_width">6</property>
<property name="row_spacing">3</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkLabel" id="date_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Date</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="num_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">num_spin</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="num_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="adjustment">num_adjustment</property>
<property name="climb_rate">1</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="date_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="tnum_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Transaction Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">tnum_spin</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="tnum_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="adjustment">tnum_adjustment</property>
<property name="climb_rate">1</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="link_check_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="image_position">top</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Keep Linked Document Entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="duplicate_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">&lt;b&gt;New Transaction Information&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button76</action-widget>
<action-widget response="-5">button77</action-widget>
</action-widgets>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkDialog" id="void_transaction_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>

View File

@ -64,6 +64,21 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="duplicate_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_start">6</property>
<property name="label" translatable="yes">&lt;b&gt;New Transaction Information&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="duplicate_table">
<property name="visible">True</property>
@ -93,28 +108,13 @@
<property name="label" translatable="yes">_Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">num_spin</property>
<property name="mnemonic_widget">num_entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="num_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="adjustment">adjustment1</property>
<property name="climb_rate">1</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="date_hbox">
<property name="visible">True</property>
@ -128,6 +128,68 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="num_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="tnum_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Transaction Number</property>
<property name="use_underline">True</property>
<property name="justify">center</property>
<property name="mnemonic_widget">tnum_entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Keep Linked Document Entry</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tnum_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="link_check_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="image_position">top</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -135,21 +197,6 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="duplicate_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_start">6</property>
<property name="label" translatable="yes">&lt;b&gt;New Transaction Information&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>

View File

@ -571,6 +571,7 @@ gnc_split_register_duplicate_current (SplitRegister* reg)
}
else
{
Account* account;
NumCell* num_cell;
Transaction* new_trans;
int trans_split_index;
@ -587,18 +588,17 @@ gnc_split_register_duplicate_current (SplitRegister* reg)
/* We are on a transaction row. Copy the whole transaction. */
date = info->last_date_entered;
if (gnc_strisnum (gnc_get_num_action (trans, trans_split)))
{
Account* account = gnc_split_register_get_default_account (reg);
if (account)
in_num = xaccAccountGetLastNum (account);
else
in_num = gnc_get_num_action (trans, trans_split);
in_tnum = (reg->use_tran_num_for_num_field
? NULL
: gnc_get_num_action (trans, NULL));
}
account = gnc_split_register_get_default_account (reg);
if (account && gnc_strisnum (gnc_get_num_action (trans, trans_split)))
in_num = xaccAccountGetLastNum (account);
else
in_num = gnc_get_num_action (trans, trans_split);
in_tnum = (reg->use_tran_num_for_num_field
? NULL
: gnc_get_num_action (trans, NULL));
if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg), NULL,
TRUE, &date, in_num, &out_num, in_tnum, &out_tnum,