mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-12 18:46:16 +00:00
Turn tag checkboxes code into a simple loop
This makes the code much cleaner and also reuses the strings in the dtag_names array. This means the tag names are all lower case everywhere, but that seems like an acceptable trade-off. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Suggested-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
593a0a7a60
commit
0a64844abd
1 changed files with 16 additions and 76 deletions
86
info.c
86
info.c
|
@ -799,11 +799,11 @@ static gboolean base_data_cb(GtkWidget *w, GdkEvent *event, gpointer _data)
|
||||||
|
|
||||||
void divetag_toggle_cb(GtkWidget *widget, gpointer data)
|
void divetag_toggle_cb(GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
int DT = GPOINTER_TO_INT (data);
|
int togglebit = GPOINTER_TO_INT (data);
|
||||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
|
||||||
edit_dive.dive_tags |= DT;
|
edit_dive.dive_tags |= togglebit;
|
||||||
else
|
else
|
||||||
edit_dive.dive_tags &= ~DT;
|
edit_dive.dive_tags &= ~togglebit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_info *info, gboolean multi)
|
static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_info *info, gboolean multi)
|
||||||
|
@ -816,6 +816,7 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
|
||||||
char airtemp[10];
|
char airtemp[10];
|
||||||
const char *unit;
|
const char *unit;
|
||||||
double value;
|
double value;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (multi) {
|
if (multi) {
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
|
@ -889,79 +890,18 @@ static void dive_info_widget(GtkWidget *obox, struct dive *dive, struct dive_inf
|
||||||
framebox = gtk_vbox_new(FALSE, 3);
|
framebox = gtk_vbox_new(FALSE, 3);
|
||||||
gtk_container_add(GTK_CONTAINER(frame), framebox);
|
gtk_container_add(GTK_CONTAINER(frame), framebox);
|
||||||
|
|
||||||
|
/* check boxes for the (currently fixed) list of tags;
|
||||||
|
* let's do 5 per row */
|
||||||
|
for (i = 0; i < DTAG_NR; i++) {
|
||||||
|
if (i % 5 == 0) {
|
||||||
sbox = gtk_hbox_new(FALSE, 6);
|
sbox = gtk_hbox_new(FALSE, 6);
|
||||||
gtk_box_pack_start(GTK_BOX(framebox), sbox, TRUE, FALSE, 3);
|
gtk_box_pack_start(GTK_BOX(framebox), sbox, TRUE, FALSE, 3);
|
||||||
/* 1st line */
|
}
|
||||||
button = gtk_check_button_new_with_label(_("Boat"));
|
button = gtk_check_button_new_with_label(_(dtag_names[i]));
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_BOAT);
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & (1 << i));
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_BOAT));
|
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER(1 << i));
|
||||||
|
}
|
||||||
button = gtk_check_button_new_with_label(_("Shore"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_SHORE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_SHORE));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Pool"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_POOL);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_POOL));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Lake"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_LAKE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_LAKE));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("River"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_RIVER);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_RIVER));
|
|
||||||
|
|
||||||
sbox = gtk_hbox_new(FALSE, 6);
|
|
||||||
gtk_box_pack_start(GTK_BOX(framebox), sbox, TRUE, FALSE, 3);
|
|
||||||
/* 2nd line */
|
|
||||||
button = gtk_check_button_new_with_label(_("Drift"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_DRIFT);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_DRIFT));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Deep"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_DEEP);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_DEEP));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Cavern"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_CAVERN);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_CAVERN));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Ice"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_ICE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_ICE));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Wreck"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_WRECK);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_WRECK));
|
|
||||||
|
|
||||||
sbox = gtk_hbox_new(FALSE, 6);
|
|
||||||
gtk_box_pack_start(GTK_BOX(framebox), sbox, TRUE, FALSE, 3);
|
|
||||||
/* 3rd line */
|
|
||||||
button = gtk_check_button_new_with_label(_("Cave"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_CAVE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_CAVE));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Night"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_NIGHT);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_NIGHT));
|
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(_("Freshwater"));
|
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dive->dive_tags & DTAG_FRESH);
|
|
||||||
gtk_box_pack_start(GTK_BOX(sbox), button, FALSE, FALSE, 6);
|
|
||||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(divetag_toggle_cb), GINT_TO_POINTER (DTAG_FRESH));
|
|
||||||
|
|
||||||
/* only show notes if editing a single dive */
|
/* only show notes if editing a single dive */
|
||||||
if (multi) {
|
if (multi) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue