diff options
-rw-r--r-- | dive.h | 1 | ||||
-rw-r--r-- | divelist.c | 29 | ||||
-rw-r--r-- | save-xml.c | 36 |
3 files changed, 55 insertions, 11 deletions
@@ -515,6 +515,7 @@ extern void show_yearly_stats(void); extern void update_dive(struct dive *new_dive); extern void save_dives(const char *filename); +extern void save_dives_logic(const char *filename, gboolean select_only); extern timestamp_t utc_mktime(struct tm *tm); extern void utc_mkdate(timestamp_t, struct tm *tm); diff --git a/divelist.c b/divelist.c index d8c760db9..f7ed6e14d 100644 --- a/divelist.c +++ b/divelist.c @@ -1621,6 +1621,31 @@ gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data) return FALSE; } +static void save_as_cb(GtkWidget *menuitem, struct dive *dive) +{ + GtkWidget *dialog; + char *filename = NULL; + + dialog = gtk_file_chooser_dialog_new(_("Save File As"), + GTK_WINDOW(main_window), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + } + gtk_widget_destroy(dialog); + + if (filename){ + set_filename(filename, TRUE); + save_dives_logic(filename, TRUE); + g_free(filename); + } +} + static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view) { gtk_tree_view_expand_all(tree_view); @@ -2409,6 +2434,10 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int deletelabel = _(deleteplurallabel); editlabel = _(editplurallabel); } + menuitem = gtk_menu_item_new_with_label(_("Save as")); + g_signal_connect(menuitem, "activate", G_CALLBACK(save_as_cb), dive); + 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); diff --git a/save-xml.c b/save-xml.c index 6e33cd5e6..b95a38028 100644 --- a/save-xml.c +++ b/save-xml.c @@ -536,6 +536,11 @@ static void save_device_info(FILE *f) void save_dives(const char *filename) { + save_dives_logic(filename, FALSE); +} + +void save_dives_logic(const char *filename, const gboolean select_only) +{ int i; struct dive *dive; dive_trip_t *trip; @@ -561,21 +566,30 @@ void save_dives(const char *filename) /* save the dives */ for_each_dive(i, dive) { - trip = dive->divetrip; - /* Bare dive without a trip? */ - if (!trip) { + if (select_only) { + + if(!dive->selected) + continue; save_dive(f, dive); - continue; - } - /* Have we already seen this trip (and thus saved this dive?) */ - if (trip->index) - continue; + } else { + trip = dive->divetrip; + + /* Bare dive without a trip? */ + if (!trip) { + save_dive(f, dive); + continue; + } - /* We haven't seen this trip before - save it and all dives */ - trip->index = 1; - save_trip(f, trip); + /* Have we already seen this trip (and thus saved this dive?) */ + if (trip->index) + continue; + + /* We haven't seen this trip before - save it and all dives */ + trip->index = 1; + save_trip(f, trip); + } } fprintf(f, "</dives>\n</divelog>\n"); fclose(f); |