From cbd0c8a0cb782887a0868edfd8c8c234c2c8e32e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 17 Jul 2007 18:39:08 +0200 Subject: ask before overwriting files --- src/flpsed.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/flpsed.cxx b/src/flpsed.cxx index b5b0f60..363aa3f 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,15 @@ int check_save(void) { return (r == 2) ? 1 : 0; } +static int +confirm_overwrite(const char *f) { + struct stat sb; + if (stat(f, &sb) == 0) { + return fl_choice("The file exists.\n", "Cancel", "Overwrite", NULL); + } else { + return 1; + } +} char filename[256] = ""; @@ -161,7 +171,7 @@ void export_pdf_cb() { pid_t pid; file = fl_file_chooser("Open File?", "*.pdf", filename); - if(file != NULL) { + if(file != NULL && confirm_overwrite(file)) { args[0] = "ps2pdf"; args[1] = "-"; args[2] = file; @@ -215,7 +225,7 @@ void quit_cb() { void save_cb() { char *file = fl_file_chooser("Open File?", "*.ps", filename); - if (file != NULL) { + if (file != NULL && confirm_overwrite(file)) { psed_p->save(file); } } -- cgit v1.2.3