X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=info.c;h=d9379ac68b200976f08c9afada59bd87f88bb736;hb=9d46581913ce33664e333a4d6eaf7f4e26e20b1c;hp=adc6c590239d6837416f9f05038c10aac862dc1d;hpb=bc53bbb10b3aaa22503c2d2b7024d1ac170a5733;p=ext%2Fsubsurface.git diff --git a/info.c b/info.c index adc6c59..d9379ac 100644 --- a/info.c +++ b/info.c @@ -1,7 +1,7 @@ /* info.c */ -/* creates the UI for the info frame - +/* creates the UI for the info frame - * controlled through the following interfaces: - * + * * void show_dive_info(struct dive *dive) * * called from gtk-ui: @@ -166,7 +166,7 @@ static int delete_dive_info(struct dive *dive) static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data) { - edit_multi_dive_info(amount_selected, selectiontracker); + edit_multi_dive_info(NULL); } static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data) @@ -482,22 +482,22 @@ void update_equipment_data(struct dive *dive, struct dive *master) if ( ! cylinders_equal(remember_cyl, master->cylinder) && (no_cylinders(dive->cylinder) || cylinders_equal(dive->cylinder, remember_cyl))) - memcpy(dive->cylinder, master->cylinder, CYL_BYTES); + copy_cylinders(master->cylinder, dive->cylinder); if (! weightsystems_equal(remember_ws, master->weightsystem) && (no_weightsystems(dive->weightsystem) || weightsystems_equal(dive->weightsystem, remember_ws))) memcpy(dive->weightsystem, master->weightsystem, WS_BYTES); } -int edit_multi_dive_info(int nr, int *indices) +/* A negative index means "all selected" */ +int edit_multi_dive_info(struct dive *single_dive) { - int success, i; + int success; GtkWidget *dialog, *vbox; struct dive_info info; struct dive *master; + gboolean multi; - if (!nr) - return 0; dialog = gtk_dialog_new_with_buttons("Dive Info", GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -506,34 +506,46 @@ int edit_multi_dive_info(int nr, int *indices) NULL); vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - /* SCARY STUFF - IS THIS THE BEST WAY TO DO THIS??? - * - * current_dive is one of our selected dives - and that is - * the one that is used to pre-fill the edit widget. Its - * data is used as the starting point for all selected dives - * I think it would be better to somehow collect and combine - * info from all the selected dives */ - master = current_dive; - dive_info_widget(vbox, master, &info, (nr > 1)); + master = single_dive; + if (!master) + master = current_dive; + + /* See if we should use multi dive mode */ + multi = FALSE; + if (!single_dive) { + int i; + struct dive *dive; + + for_each_dive(i, dive) { + if (dive != master && dive->selected) { + multi = TRUE; + break; + } + } + } + + dive_info_widget(vbox, master, &info, multi); show_dive_equipment(master, W_IDX_SECONDARY); save_equipment_data(master); gtk_widget_show_all(dialog); success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; if (success) { - /* Update the other non-current dives first */ - for (i = 0; i < nr; i++) { - int idx = indices[i]; - struct dive *dive = get_dive(idx); - - if (!dive || dive == master) - continue; - /* copy all "info" fields */ - save_dive_info_changes(dive, master, &info); - /* copy the cylinders / weightsystems */ - update_equipment_data(dive, master); - /* this is extremely inefficient... it loops through all - dives to find the right one - but we KNOW the index already */ - flush_divelist(dive); + /* Update the non-current selected dives first */ + if (!single_dive) { + int i; + struct dive *dive; + + for_each_dive(i, dive) { + if (dive == master || !dive->selected) + continue; + /* copy all "info" fields */ + save_dive_info_changes(dive, master, &info); + /* copy the cylinders / weightsystems */ + update_equipment_data(dive, master); + /* this is extremely inefficient... it loops through all + dives to find the right one - but we KNOW the index already */ + flush_divelist(dive); + } } /* Update the master dive last! */ @@ -548,12 +560,9 @@ int edit_multi_dive_info(int nr, int *indices) int edit_dive_info(struct dive *dive) { - int idx; - if (!dive) return 0; - idx = dive->number; - return edit_multi_dive_info(1, &idx); + return edit_multi_dive_info(dive); } static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)