Add the ugliest 'delete dive' model ever

This interface works the same way the "edit dive" menu item does: it's a
text entry meny item on the dive text entries (ie buddy/divemaster/notes
sections).  Except you pick the "Delete" entry rather than the "Edit"
entry.

It kind of works, but it really is a pretty horrible interface.  I'll
need to add a top-level dive menu entry for just deleting all selected
dives instead.  And it would be good to be able to get a drop-down menu
from the divelist instead of having to do it from the dive text entries,
which is just insane.

But that requires gtk work.  I'm not quite ready to get back into that.
Thus the "exact same insane interface as the explicit 'Edit' mode".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2012-04-02 19:19:01 -07:00
parent 3a7d577ff1
commit 1cbe2444cc
3 changed files with 66 additions and 3 deletions

1
dive.h
View file

@ -299,6 +299,7 @@ extern time_t utc_mktime(struct tm *tm);
extern struct dive *alloc_dive(void);
extern void record_dive(struct dive *dive);
extern void delete_dive(struct dive *dive);
extern struct sample *prepare_sample(struct dive **divep);
extern void finish_sample(struct dive *dive);

45
info.c
View file

@ -100,19 +100,58 @@ void show_dive_info(struct dive *dive)
dive && dive->notes ? dive->notes : "", -1);
}
static int delete_dive_info(struct dive *dive)
{
int success;
GtkWidget *dialog;
if (!dive)
return 0;
dialog = gtk_dialog_new_with_buttons("Delete Dive",
GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
gtk_widget_show_all(dialog);
success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
if (success) {
delete_dive(dive);
mark_divelist_changed(TRUE);
dive_list_update_dives();
}
gtk_widget_destroy(dialog);
return success;
}
static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
{
edit_dive_info(current_dive);
}
static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
{
GtkWidget *item = gtk_menu_item_new_with_label("Edit");
g_signal_connect(item, "activate", G_CALLBACK(info_menu_edit_cb), NULL);
delete_dive_info(current_dive);
}
static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuItem *, gpointer))
{
GtkWidget *item = gtk_menu_item_new_with_label(label);
g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
gtk_widget_show(item); /* Yes, really */
gtk_menu_prepend(menu, item);
}
static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
{
add_menu_item(menu, "Delete", info_menu_delete_cb);
add_menu_item(menu, "Edit", info_menu_edit_cb);
}
static GtkEntry *text_value(GtkWidget *box, const char *label)
{
GtkWidget *widget;

View file

@ -39,6 +39,29 @@ void record_dive(struct dive *dive)
dive_table.nr = nr+1;
}
/*
* Remove a dive from the dive_table array
*/
void delete_dive(struct dive *dive)
{
int nr = dive_table.nr, i;
struct dive **dives = dive_table.dives;
/*
* Stupid. We know the dive table is sorted by date,
* we could do a binary lookup. Sue me.
*/
for (i = 0; i < nr; i++) {
struct dive *d = dives[i];
if (d != dive)
continue;
memmove(dives+i, dives+i+1, sizeof(struct dive *)*(nr-i-1));
dives[nr] = NULL;
dive_table.nr = nr-1;
break;
}
}
static void start_match(const char *type, const char *name, char *buffer)
{
if (verbose > 2)