mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added the functionality to delete selected (multiple) dives
Moved portion of the code from delete_dive_cb() to a function called delete_single_dive(), that directly accepts a GtkTreeIter pointer. Added the function delete_selected_dives_cb(), which is called when calling "Delete dives" from the combo box for the selected dives. The above function iterates trought the selection calling delete_selected_foreach(), which on its own calls delete_single_dive(). The "for-each" API in this case looks much prettier C code wise, however we do potentially create an extra jump and also do not have anything but the redirection: delete_selected_foreach() -> delete_single_dive() Probably slighly slower than using gtk_tree_selection_get_selected_rows(), performance wise, but less C code. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
6458057599
commit
4d9abf6e8e
1 changed files with 42 additions and 10 deletions
52
divelist.c
52
divelist.c
|
@ -1842,19 +1842,15 @@ void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath)
|
||||||
mark_divelist_changed(TRUE);
|
mark_divelist_changed(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this gets called with path pointing to a dive, either in the top level
|
/* delete a dive by passing a tree iterator */
|
||||||
* or as part of a trip */
|
static void delete_single_dive(GtkTreeIter *iter)
|
||||||
static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
|
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
int i, idx;
|
||||||
int idx, i;
|
|
||||||
struct dive *dive, *pdive, *ndive;
|
struct dive *dive, *pdive, *ndive;
|
||||||
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
|
|
||||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
|
|
||||||
|
|
||||||
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
|
gtk_tree_model_get(MODEL(dive_list), iter, DIVE_INDEX, &idx, -1);
|
||||||
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
|
|
||||||
dive = get_dive(idx);
|
dive = get_dive(idx);
|
||||||
|
|
||||||
if (dive->divetrip) {
|
if (dive->divetrip) {
|
||||||
/* we could be displaying the list model, in which case we can't find out
|
/* we could be displaying the list model, in which case we can't find out
|
||||||
* if this is part of a trip and the only dive in that trip from the model,
|
* if this is part of a trip and the only dive in that trip from the model,
|
||||||
|
@ -1879,6 +1875,42 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
|
||||||
if (dive->selected)
|
if (dive->selected)
|
||||||
amount_selected--;
|
amount_selected--;
|
||||||
free(dive);
|
free(dive);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* much simpler to use compared to gtk_tree_selection_get_selected_rows() */
|
||||||
|
static void delete_selected_foreach(GtkTreeModel *model, GtkTreePath *path,
|
||||||
|
GtkTreeIter *iter, gpointer userdata)
|
||||||
|
{
|
||||||
|
delete_single_dive(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* called when multiple dives are selected and one of these is right-clicked for delete */
|
||||||
|
static void delete_selected_dives_cb(GtkWidget *menuitem, GtkTreePath *path)
|
||||||
|
{
|
||||||
|
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
|
||||||
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
|
||||||
|
gtk_tree_selection_selected_foreach(selection, delete_selected_foreach, NULL);
|
||||||
|
|
||||||
|
dive_list_update_dives();
|
||||||
|
mark_divelist_changed(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this gets called with path pointing to a dive, either in the top level
|
||||||
|
* or as part of a trip */
|
||||||
|
static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
int i, idx;
|
||||||
|
struct dive *dive;
|
||||||
|
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
|
||||||
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
|
||||||
|
|
||||||
|
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
|
||||||
|
delete_single_dive(&iter);
|
||||||
|
|
||||||
|
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
|
||||||
|
dive = get_dive(idx);
|
||||||
|
|
||||||
/* now make sure the correct dive list is displayed, the same
|
/* now make sure the correct dive list is displayed, the same
|
||||||
* dives stay selected and if necessary their trips are
|
* dives stay selected and if necessary their trips are
|
||||||
* expanded. If no selected dives are left then fill_dive_list()
|
* expanded. If no selected dives are left then fill_dive_list()
|
||||||
|
@ -1955,7 +1987,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
|
||||||
editlabel[strlen(editlabel) - 1] = '\0';
|
editlabel[strlen(editlabel) - 1] = '\0';
|
||||||
}
|
}
|
||||||
menuitem = gtk_menu_item_new_with_label(deletelabel);
|
menuitem = gtk_menu_item_new_with_label(deletelabel);
|
||||||
g_signal_connect(menuitem, "activate", G_CALLBACK(NULL), path);
|
g_signal_connect(menuitem, "activate", G_CALLBACK(delete_selected_dives_cb), path);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||||
|
|
||||||
menuitem = gtk_menu_item_new_with_label(editlabel);
|
menuitem = gtk_menu_item_new_with_label(editlabel);
|
||||||
|
|
Loading…
Add table
Reference in a new issue