summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-08-20 05:48:07 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-08-20 05:48:07 -0700
commit972669d6363c163ed6d3b737cbd6b1bd534f3d7b (patch)
treea95115c2231bd7ce81480a9e3dd107d8cc4c6cab /info.c
parent38f92f780ac3a9345bcb34d297ade0eadbd903ea (diff)
downloadsubsurface-972669d6363c163ed6d3b737cbd6b1bd534f3d7b.tar.gz
Rework dive selection logic
This completely changes how we keep track of selected dives: instead of having an array listing the selection ("selectiontracker") or trusting the gtk selection information, just save the information about whether a dive is selected in the dive itself. That makes it trivial to keep track of the state of selection across group collapse/expand events, or when changing the tree view model. It also ends up simplifying the code and logic in other ways. HOWEVER, it does currently (re-)introduce an annoying oddity with gtk: if you collapse a dive trip that has individual selections, gtk will forget those selections ("out of sight, out of mind"), and when you do *new* selections, the old hidden ones remain. So there's some games required to make gtk do sane things. We may need to either explicitly drop selections when collapsing trips, or make sure the group entry gets selected when collapsing a group that has selections in it. Or something. There may be other issues introduced by this too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/info.c b/info.c
index adc6c5902..468f35772 100644
--- a/info.c
+++ b/info.c
@@ -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(-1);
}
static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
@@ -489,15 +489,14 @@ void update_equipment_data(struct dive *dive, struct dive *master)
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(int index)
{
- int success, i;
+ int success;
GtkWidget *dialog, *vbox;
struct dive_info info;
struct dive *master;
- if (!nr)
- return 0;
dialog = gtk_dialog_new_with_buttons("Dive Info",
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -506,34 +505,31 @@ 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 = get_dive(index);
+ if (!master)
+ master = current_dive;
+ dive_info_widget(vbox, master, &info, index < 0);
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 (index < 0) {
+ int i;
+ struct dive *dive;
+
+ for (i = 0; (dive = get_dive(i)) != NULL; i++) {
+ 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! */
@@ -553,7 +549,7 @@ int edit_dive_info(struct dive *dive)
if (!dive)
return 0;
idx = dive->number;
- return edit_multi_dive_info(1, &idx);
+ return edit_multi_dive_info(idx);
}
static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)