mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add 'Save As' entry to context menu shown when right clicking on a dive
Something which is nice especially when asked on the list to share an interesting dive is the possibility to save just some dives into a file. This commit adds to the context menu shown with right-click the 'Save As' entry. This entry allows to save selected dives. [Dirk Hohndel: clean up white space, commit message and remove unused variables] Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
60f9c338e9
commit
20d3b5f714
3 changed files with 56 additions and 12 deletions
1
dive.h
1
dive.h
|
@ -515,6 +515,7 @@ extern void show_yearly_stats(void);
|
||||||
|
|
||||||
extern void update_dive(struct dive *new_dive);
|
extern void update_dive(struct dive *new_dive);
|
||||||
extern void save_dives(const char *filename);
|
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 timestamp_t utc_mktime(struct tm *tm);
|
||||||
extern void utc_mkdate(timestamp_t, struct tm *tm);
|
extern void utc_mkdate(timestamp_t, struct tm *tm);
|
||||||
|
|
29
divelist.c
29
divelist.c
|
@ -1621,6 +1621,31 @@ gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data)
|
||||||
return FALSE;
|
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)
|
static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
|
||||||
{
|
{
|
||||||
gtk_tree_view_expand_all(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);
|
deletelabel = _(deleteplurallabel);
|
||||||
editlabel = _(editplurallabel);
|
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);
|
menuitem = gtk_menu_item_new_with_label(deletelabel);
|
||||||
g_signal_connect(menuitem, "activate", G_CALLBACK(delete_selected_dives_cb), 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);
|
||||||
|
|
14
save-xml.c
14
save-xml.c
|
@ -535,6 +535,11 @@ static void save_device_info(FILE *f)
|
||||||
#define VERSION 2
|
#define VERSION 2
|
||||||
|
|
||||||
void save_dives(const char *filename)
|
void save_dives(const char *filename)
|
||||||
|
{
|
||||||
|
save_dives_logic(filename, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_dives_logic(const char *filename, const gboolean select_only)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
|
@ -561,6 +566,14 @@ void save_dives(const char *filename)
|
||||||
|
|
||||||
/* save the dives */
|
/* save the dives */
|
||||||
for_each_dive(i, dive) {
|
for_each_dive(i, dive) {
|
||||||
|
|
||||||
|
if (select_only) {
|
||||||
|
|
||||||
|
if(!dive->selected)
|
||||||
|
continue;
|
||||||
|
save_dive(f, dive);
|
||||||
|
|
||||||
|
} else {
|
||||||
trip = dive->divetrip;
|
trip = dive->divetrip;
|
||||||
|
|
||||||
/* Bare dive without a trip? */
|
/* Bare dive without a trip? */
|
||||||
|
@ -577,6 +590,7 @@ void save_dives(const char *filename)
|
||||||
trip->index = 1;
|
trip->index = 1;
|
||||||
save_trip(f, trip);
|
save_trip(f, trip);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fprintf(f, "</dives>\n</divelog>\n");
|
fprintf(f, "</dives>\n</divelog>\n");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue