From d17e6ecc2613ac0aad82a8ac7d006ca77303d2e8 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 31 Jul 2002 03:59:08 +0000 Subject: [PATCH] optional confirmation of file overwrite --- Common/Context.h | 1 + Common/DefaultOptions.h | 2 ++ Common/Options.cpp | 10 +++++++++- Common/Options.h | 1 + Fltk/Callbacks.cpp | 27 ++++++++++++++++++++++++--- Fltk/GUI.cpp | 26 +++++++++++++++++--------- 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Common/Context.h b/Common/Context.h index ff804ba155..afd1bb815b 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -57,6 +57,7 @@ public : char *error_filename; // the name of the error file int session_save, options_save; // save session/option file on exit + int confirm_overwrite; // confirm overwrite when file->save as char *display; // forced display host:0.0 under X11 int terminal; // show we print to the terminal console? char *editor; // text editor command (with included '%s') diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 3f873d58ae..29fafd24ed 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -405,6 +405,8 @@ StringXNumber GeneralOptions_Number[] = { "Fourth clip plane 5 equation coefficient ('D' in equation 'AX+BY+CZ+D=0')" }, { F|O, "ColorScheme", opt_general_color_scheme , 0. , "Default color scheme (0, 1 or 2)" }, + { F|S, "ConfirmOverwrite" , opt_general_confirm_overwrite, 1. , + "Ask confirmation before overwriting files?" }, { F|O, "DefaultPlugins" , opt_general_default_plugins , 1. , "Load default plugins on startup" }, diff --git a/Common/Options.cpp b/Common/Options.cpp index b91aec231f..8bb15aae75 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.82 2002-06-15 21:25:27 geuzaine Exp $ +// $Id: Options.cpp,v 1.83 2002-07-31 03:59:08 geuzaine Exp $ // // Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle // @@ -986,6 +986,14 @@ double opt_general_options_save(OPT_ARGS_NUM){ #endif return CTX.options_save; } +double opt_general_confirm_overwrite(OPT_ARGS_NUM){ + if(action & GMSH_SET) CTX.confirm_overwrite = (int)val; +#ifdef _FLTK + if(WID && (action & GMSH_GUI)) + WID->gen_butt[14]->value(CTX.confirm_overwrite); +#endif + return CTX.confirm_overwrite; +} double opt_general_rotation0(OPT_ARGS_NUM){ if(action & GMSH_SET) CTX.r[0] = val; return CTX.r[0]; diff --git a/Common/Options.h b/Common/Options.h index e4e36e2f31..6a4efc86df 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -220,6 +220,7 @@ double opt_general_color_scheme(OPT_ARGS_NUM); double opt_general_verbosity(OPT_ARGS_NUM); double opt_general_terminal(OPT_ARGS_NUM); double opt_general_tooltips(OPT_ARGS_NUM); +double opt_general_confirm_overwrite(OPT_ARGS_NUM); double opt_general_orthographic(OPT_ARGS_NUM); double opt_general_fast_redraw(OPT_ARGS_NUM); double opt_general_axes(OPT_ARGS_NUM); diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 9e68ddaed5..6525c810eb 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.133 2002-07-12 17:20:24 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.134 2002-07-31 03:59:08 geuzaine Exp $ // // Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle // @@ -414,6 +414,9 @@ typedef struct{ void (*func)(char *name) ; } patXfunc; +#include <sys/types.h> +#include <sys/stat.h> + void file_save_as_cb(CALLBACK_ARGS) { int i, nbformats; static int patindex=0; @@ -452,13 +455,30 @@ void file_save_as_cb(CALLBACK_ARGS) { } } + test: + if(file_chooser(0,"Save file as", pat, patindex)){ + + char *name = file_chooser_get_name(1); + + if(CTX.confirm_overwrite){ + struct stat buf; + if(!stat(name, &buf)) + if(fl_ask("%s already exists.\nDo you want to replace it?", name)) + goto save; + else + goto test; + } + + save: i = file_chooser_get_filter(); if(i>=0 && i<nbformats) - formats[i].func(file_chooser_get_name(1)); + formats[i].func(name); else // handle any additional automatic fltk filter - _save_auto(file_chooser_get_name(1)); + _save_auto(name); + } + patindex = file_chooser_get_filter(); } @@ -577,6 +597,7 @@ void opt_general_ok_cb(CALLBACK_ARGS){ opt_general_orthographic(0, GMSH_SET, WID->gen_butt[10]->value()); opt_general_moving_light(0, GMSH_SET, WID->gen_butt[12]->value()); opt_general_tooltips(0, GMSH_SET, WID->gen_butt[13]->value()); + opt_general_confirm_overwrite(0, GMSH_SET, WID->gen_butt[14]->value()); opt_general_shine(0, GMSH_SET, WID->gen_value[1]->value()); opt_general_light00(0, GMSH_SET, WID->gen_value[2]->value()); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index 9a844d8845..849cd3c07a 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -1,4 +1,4 @@ -// $Id: GUI.cpp,v 1.184 2002-07-03 23:54:10 geuzaine Exp $ +// $Id: GUI.cpp,v 1.185 2002-07-31 03:59:08 geuzaine Exp $ // // Copyright (C) 1997 - 2002 C. Geuzaine, J.-F. Remacle // @@ -1103,7 +1103,7 @@ void GUI::create_general_options_window(){ } int width = 25*CTX.fontsize; - int height = 5*WB+11*BH ; + int height = 5*WB+12*BH ; int BW = width-4*WB; gen_window = new Fl_Window(width,height); @@ -1125,6 +1125,7 @@ void GUI::create_general_options_window(){ gen_butt[i]->down_box(TOGGLE_BOX); gen_butt[i]->selection_color(TOGGLE_COLOR); } + gen_butt[13] = new Fl_Check_Button(2*WB, 2*WB+8*BH, BW, BH, "Show tooltips"); gen_butt[13]->type(FL_TOGGLE_BUTTON); gen_butt[13]->down_box(TOGGLE_BOX); @@ -1142,16 +1143,23 @@ void GUI::create_general_options_window(){ gen_butt[i]->down_box(TOGGLE_BOX); gen_butt[i]->selection_color(TOGGLE_COLOR); } - gen_value[5] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Message verbosity"); + + gen_butt[14] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW, BH, "Ask confirmation before overwriting a file"); + gen_butt[14]->type(FL_TOGGLE_BUTTON); + gen_butt[14]->down_box(TOGGLE_BOX); + gen_butt[14]->selection_color(TOGGLE_COLOR); + + + gen_value[5] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Message verbosity"); gen_value[5]->minimum(0); gen_value[5]->maximum(10); gen_value[5]->step(1); gen_value[5]->align(FL_ALIGN_RIGHT); - gen_input[0] = new Fl_Input(2*WB, 2*WB+5*BH, IW, BH, "Default file name"); - gen_input[1] = new Fl_Input(2*WB, 2*WB+6*BH, IW, BH, "Temporary file"); - gen_input[2] = new Fl_Input(2*WB, 2*WB+7*BH, IW, BH, "Error file"); - gen_input[3] = new Fl_Input(2*WB, 2*WB+8*BH, IW, BH, "Option file"); - gen_input[4] = new Fl_Input(2*WB, 2*WB+9*BH, IW, BH, "Text editor command"); + gen_input[0] = new Fl_Input(2*WB, 2*WB+6*BH, IW, BH, "Default file name"); + gen_input[1] = new Fl_Input(2*WB, 2*WB+7*BH, IW, BH, "Temporary file"); + gen_input[2] = new Fl_Input(2*WB, 2*WB+8*BH, IW, BH, "Error file"); + gen_input[3] = new Fl_Input(2*WB, 2*WB+9*BH, IW, BH, "Option file"); + gen_input[4] = new Fl_Input(2*WB, 2*WB+10*BH, IW, BH, "Text editor command"); for(i=0 ; i<5 ; i++){ gen_input[i]->align(FL_ALIGN_RIGHT); } @@ -2442,7 +2450,7 @@ void GUI::create_view_options_window(int num){ static Fl_Menu_Item menu_pointtype[] = { {"Color dot", 0, 0, 0}, - {"3D Sphere", 0, 0, 0}, + {"3D sphere", 0, 0, 0}, {0} }; view_choice[5] = new Fl_Choice(2*WB, 2*WB+ 2*BH, IW, BH, "Point type"); -- GitLab