diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-11 15:39:46 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-11 15:49:50 -0700 |
commit | 9d960c1845ef069a76e58520dfe6f9042b4eb42e (patch) | |
tree | b17e82339d3f2b28e415581bdd6c7c5eacc9462d /main.c | |
parent | c96e2d1767f5c6379b2d7a780ccabc6039cf60bf (diff) | |
download | subsurface-9d960c1845ef069a76e58520dfe6f9042b4eb42e.tar.gz |
Add a 'Renumber' menu choice
If you want to re-number your dives - either because they didn't have
any numbering at all, or because you forgot about other dives - you now
can.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -325,12 +325,51 @@ static void unit_dialog(GtkWidget *w, gpointer data) gtk_widget_destroy(dialog); } +static void renumber_dives(int nr) +{ + int i; + + for (i = 0; i < dive_table.nr; i++) { + struct dive *dive = dive_table.dives[i]; + dive->number = nr + i; + } +} + +static void renumber_dialog(GtkWidget *w, gpointer data) +{ + int result; + GtkWidget *dialog, *frame, *button; + + dialog = gtk_dialog_new_with_buttons("Renumber", + GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + + frame = gtk_frame_new("New starting number"); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), frame); + + button = gtk_spin_button_new_with_range(1, 50000, 1); + gtk_container_add(GTK_CONTAINER(frame), button); + + gtk_widget_show_all(dialog); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_ACCEPT) { + int nr = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button)); + renumber_dives(nr); + repaint_dive(); + } + gtk_widget_destroy(dialog); +} + static GtkActionEntry menu_items[] = { { "FileMenuAction", GTK_STOCK_FILE, "Log", NULL, NULL, NULL}, { "OpenFile", GTK_STOCK_OPEN, NULL, "<control>O", NULL, G_CALLBACK(file_open) }, { "SaveFile", GTK_STOCK_SAVE, NULL, "<control>S", NULL, G_CALLBACK(file_save) }, + { "Units", NULL, "Units", NULL, NULL, G_CALLBACK(unit_dialog) }, + { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) }, { "Quit", GTK_STOCK_QUIT, NULL, "<control>Q", NULL, G_CALLBACK(quit) }, - { "Units", NULL, "Units", NULL, NULL, G_CALLBACK(unit_dialog) }, }; static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); @@ -342,6 +381,7 @@ static const gchar* ui_string = " \ <menuitem name=\"Save\" action=\"SaveFile\" /> \ <separator name=\"Separator1\"/> \ <menuitem name=\"Units\" action=\"Units\" /> \ + <menuitem name=\"Renumber\" action=\"Renumber\" /> \ <separator name=\"Separator2\"/> \ <menuitem name=\"Quit\" action=\"Quit\" /> \ </menu> \ |