diff options
author | Ďoďo <dodo.sk@gmail.com> | 2013-04-09 17:54:36 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-04-09 10:31:36 -0700 |
commit | ed3f67bc33fbd9aac819687317d3066c22799f83 (patch) | |
tree | 0ca44c39b68f5e2681ebfd915e86105b8a4a0900 /divelist-gtk.c | |
parent | 68545465ba971952e4c66606e44786d9337f97ad (diff) | |
download | subsurface-ed3f67bc33fbd9aac819687317d3066c22799f83.tar.gz |
Add dive tags and support invalid dives
This started out as a way to keep dives in the dive list but being able to
mark them as 'invalid' so they wouldn't be visible (with an option to
disable that feature).
Now it supports an (at this point, fixed) set of tags that can be assigned
to a dive with 'invalid' being just one of them (but one that is special
as it gets some additional support for hiding such dive and marking dives
as (in)valid from the divelist).
[Dirk Hohndel: merged with the latest code and minor changes for coding
style and consistency. Ensure divelist is marked as
modified when changing 'invalid' tag]
Signed-Off-By: Jozef Ivanecký (dodo.sk@gmail.com)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist-gtk.c')
-rw-r--r-- | divelist-gtk.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/divelist-gtk.c b/divelist-gtk.c index dc441881c..c8ad1a6ca 100644 --- a/divelist-gtk.c +++ b/divelist-gtk.c @@ -715,7 +715,10 @@ static void fill_dive_list(void) i = dive_table.nr; while (--i >= 0) { struct dive *dive = get_dive(i); - dive_trip_t *trip = dive->divetrip; + dive_trip_t *trip; + if ((dive->dive_tags & DTYPE_INVALID) && !prefs.display_invalid_dives) + continue; + trip = dive->divetrip; if (!trip) { parent_ptr = NULL; @@ -1061,6 +1064,42 @@ static void save_as_cb(GtkWidget *menuitem, struct dive *dive) } } +static void invalid_dives_cb(GtkWidget *menuitem, GtkTreePath *path) +{ + int i; + int changed = 0; + struct dive *dive; + + if (!amount_selected) + return; + /* walk the dive list in chronological order */ + for_each_dive(i, dive) { + dive = get_dive(i); + if (!dive) + continue; + if (!dive->selected) + continue; + /* now swap the invalid tag if just 1 dive was selected + * otherwise set all to invalid */ + if(amount_selected == 1) { + if (dive->dive_tags & DTYPE_INVALID) + dive->dive_tags &= ~DTYPE_INVALID; + else + dive->dive_tags |= DTYPE_INVALID; + changed = 1; + } else { + if (! dive->dive_tags & DTYPE_INVALID) { + dive->dive_tags |= DTYPE_INVALID; + changed = 1; + } + } + } + if (changed) { + dive_list_update_dives(); + mark_divelist_changed(TRUE); + } +} + static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view) { gtk_tree_view_expand_all(tree_view); @@ -1626,7 +1665,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } else { dive = get_dive(idx); - /* if we right click on selected dive(s), edit or delete those */ + /* if we right click on selected dive(s), edit, delete or tag them as invalid */ if (dive->selected) { if (amount_selected == 1) { deletelabel = _(deletesinglelabel); @@ -1642,6 +1681,17 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int g_signal_connect(menuitem, "activate", G_CALLBACK(save_as_cb), dive); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + if (amount_selected == 1) { + if (dive->dive_tags & DTYPE_INVALID) + menuitem = gtk_menu_item_new_with_label(_("Mark valid")); + else + menuitem = gtk_menu_item_new_with_label(_("Mark invalid")); + } else { + menuitem = gtk_menu_item_new_with_label(_("Mark invalid")); + } + g_signal_connect(menuitem, "activate", G_CALLBACK(invalid_dives_cb), path); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_menu_item_new_with_label(deletelabel); g_signal_connect(menuitem, "activate", G_CALLBACK(delete_selected_dives_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |