[PATCH] info.c: Make sure we only edit when there is dive selection
Dirk Hohndel
dirk at hohndel.org
Tue Oct 23 08:11:17 PDT 2012
"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:
> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>
> 1) info.c: always check for "amount_selected > 0" before calling
> edit_multi_dive_info().
>
> 2) populate_popup_cb() should only add the "Edit" and "Delete"
> items if there are dives are selected
>
> 3) in info_menu_delete_cb() we clear the selection, therefore
> we need to set "amount_selected" to 0.
>
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
> info.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/info.c b/info.c
> index 8380135..54da8a5 100644
> --- a/info.c
> +++ b/info.c
> @@ -226,13 +226,15 @@ static int delete_dive_info(struct dive *dive)
>
> static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
> {
> - edit_multi_dive_info(NULL);
> + if (amount_selected)
> + edit_multi_dive_info(NULL);
> }
>
> static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
> {
> /* this needs to delete all the selected dives as well, I guess? */
> delete_dive_info(current_dive);
> + amount_selected = 0;
That reminds me... the ability to delete a dive from that context menu
is... strange, really strange. This was implemented back before we had a
context menu for the divelist. I'd much rather get rid of the ability to
delete from there...
> }
>
> static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
> @@ -253,8 +255,10 @@ static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, vo
>
> static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
> {
> - add_menu_item(menu, _("Delete"), GTK_STOCK_DELETE, info_menu_delete_cb);
> - add_menu_item(menu, _("Edit"), GTK_STOCK_EDIT, info_menu_edit_cb);
> + if (amount_selected) {
> + add_menu_item(menu, _("Delete"), GTK_STOCK_DELETE, info_menu_delete_cb);
> + add_menu_item(menu, _("Edit"), GTK_STOCK_EDIT, info_menu_edit_cb);
> + }
Which I guess means in this hunk remove the info_menu_delete_cb
> }
>
> static GtkEntry *text_value(GtkWidget *box, const char *label)
> @@ -769,7 +773,7 @@ int edit_multi_dive_info(struct dive *single_dive)
>
> int edit_dive_info(struct dive *dive)
> {
> - if (!dive)
> + if (!dive || !amount_selected)
> return 0;
> return edit_multi_dive_info(dive);
> }
> --
The rest of the patch looks good
/D
More information about the subsurface
mailing list