Add - and + button after number entry
These should make it easier to work with numbers. * src/eom-new-item-dialog.c (change): New function. Callback for the `+' and `-' buttons, either adds or subtracts one from the quantity field. (eom_new_item_dialog_init): Add `+' and `-' buttons after quantity entry.
This commit is contained in:
parent
5849e3d2e4
commit
7727a458fb
1 changed files with 41 additions and 0 deletions
|
@ -10,6 +10,7 @@ enum {
|
|||
EOM_NEW_PROP_MID = 1
|
||||
};
|
||||
|
||||
static void change(GtkButton*,GtkEntry*);
|
||||
static void eom_new_item_dialog_class_init(EomNewItemDialogClass*);
|
||||
static void eom_new_item_dialog_init(EomNewItemDialog*);
|
||||
static void finalize(GObject*);
|
||||
|
@ -37,6 +38,33 @@ eom_new_item_dialog_new(void)
|
|||
return g_object_new(EOM_TYPE_NEW_ITEM_DIALOG, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
change(GtkButton *button, GtkEntry *entry)
|
||||
{
|
||||
gchar action, *txt;
|
||||
int current_value;
|
||||
int delta;
|
||||
|
||||
action = gtk_button_get_label(button)[0];
|
||||
current_value = atoi(gtk_entry_get_text(entry));
|
||||
|
||||
switch (action) {
|
||||
case '-':
|
||||
delta = -1;
|
||||
break;
|
||||
case '+':
|
||||
delta = +1;
|
||||
break;
|
||||
default:
|
||||
delta = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
txt = g_strdup_printf("%d", current_value + delta);
|
||||
gtk_entry_set_text(entry, txt);
|
||||
g_free(txt);
|
||||
}
|
||||
|
||||
static void
|
||||
eom_new_item_dialog_class_init(EomNewItemDialogClass *klass)
|
||||
{
|
||||
|
@ -59,6 +87,7 @@ eom_new_item_dialog_init(EomNewItemDialog *dialog)
|
|||
{
|
||||
GtkWidget *content_area;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *pbutton, *mbutton;
|
||||
|
||||
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||
|
||||
|
@ -75,6 +104,18 @@ eom_new_item_dialog_init(EomNewItemDialog *dialog)
|
|||
hildon_entry_set_text(HILDON_ENTRY(dialog->qty_entry), "0");
|
||||
gtk_box_pack_start(GTK_BOX(hbox), dialog->qty_entry, TRUE, TRUE, 0);
|
||||
|
||||
mbutton = hildon_gtk_button_new(HILDON_SIZE_AUTO);
|
||||
gtk_button_set_label(GTK_BUTTON(mbutton), "-");
|
||||
g_signal_connect_after(mbutton, "clicked", G_CALLBACK(change),
|
||||
dialog->qty_entry);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), mbutton, FALSE, FALSE, 0);
|
||||
|
||||
pbutton = hildon_gtk_button_new(HILDON_SIZE_AUTO);
|
||||
gtk_button_set_label(GTK_BUTTON(pbutton), "+");
|
||||
g_signal_connect_after(pbutton, "clicked", G_CALLBACK(change),
|
||||
dialog->qty_entry);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), pbutton, FALSE, FALSE, 0);
|
||||
|
||||
gtk_window_set_title(GTK_WINDOW(dialog), "New item");
|
||||
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
|
||||
GTK_STOCK_OK,
|
||||
|
|
Loading…
Reference in a new issue