From 4826901b42a59f7a956d4d3e04f848c2ecd62db3 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 21 Dec 2000 14:53:10 +0000 Subject: [PATCH] Corrected bug in SaveAs (if file already exists) --- Unix/CbFile.cpp | 24 ++++++++---------------- Unix/CbFile.h | 6 +++--- Unix/Register.cpp | 5 ++--- Unix/Widgets.cpp | 3 ++- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Unix/CbFile.cpp b/Unix/CbFile.cpp index 103a5026c0..8561bf29ce 100644 --- a/Unix/CbFile.cpp +++ b/Unix/CbFile.cpp @@ -1,4 +1,4 @@ -/* $Id: CbFile.cpp,v 1.15 2000-12-21 08:02:06 geuzaine Exp $ */ +/* $Id: CbFile.cpp,v 1.16 2000-12-21 14:53:10 geuzaine Exp $ */ #include <unistd.h> @@ -25,8 +25,6 @@ extern XContext_T XCTX; extern Widgets_T WID; extern Mesh M; -static int WARNING_OVERRIDE = 0; - /* ------------------------------------------------------------------------ */ /* C r e a t e I m a g e */ /* ------------------------------------------------------------------------ */ @@ -36,11 +34,10 @@ void SaveToDisk (char *FileName, Widget warning, FILE *fp ; static char KeepFileName[256]; - if(!WARNING_OVERRIDE){ + if(FileName){ fp = fopen(FileName,"r"); if(fp) { XtManageChild(warning); - WARNING_OVERRIDE = 1; strcpy(KeepFileName,FileName); fclose(fp); return; @@ -51,8 +48,6 @@ void SaveToDisk (char *FileName, Widget warning, } function(KeepFileName, CTX.print.format); - - WARNING_OVERRIDE = 0; } void CreateFile (char *name, int format) { @@ -112,7 +107,6 @@ void CreateFile (char *name, int format) { case FORMAT_XPM : if(!(fp = fopen(name,"wb"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } Window_Dump(XCTX.display, XCTX.scrnum, XtWindow(WID.G.glw), fp); @@ -124,7 +118,6 @@ void CreateFile (char *name, int format) { case FORMAT_JPEG : if(!(fp = fopen(name,"wb"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } Replot(); @@ -139,7 +132,6 @@ void CreateFile (char *name, int format) { // have to replot for filling again buffer ... if(!(fp = fopen(name,"wb"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } Replot(); @@ -153,7 +145,6 @@ void CreateFile (char *name, int format) { case FORMAT_PPM : if(!(fp = fopen(name,"wb"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } Replot(); @@ -171,7 +162,6 @@ void CreateFile (char *name, int format) { case 0 : // Bitmap EPS if(!(fp = fopen(name,"w"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } if(!(tmp = fopen(tmpFileName,"w"))){ @@ -192,7 +182,6 @@ void CreateFile (char *name, int format) { default : // Vector EPS if(!(fp = fopen(name,"w"))) { Msg(WARNING, "Unable to Open File '%s'", name); - WARNING_OVERRIDE = 0; return; } CTX.print.gl_fonts = 0; @@ -234,10 +223,14 @@ void CreateFile (char *name, int format) { void FileCb(Widget w, XtPointer client_data, XtPointer call_data){ char *c; XmString xms; - - if((long int)client_data == FILE_SAVE_MESH){ + + switch ((long int)client_data) { + case FILE_SAVE_MESH : Print_Mesh(&M, NULL, CTX.mesh.format); return; + case FILE_SAVE_AS_OVERWRITE : + SaveToDisk(NULL, WID.ED.saveAsDialog, CreateFile); + return; } XtVaGetValues(w, XmNtextString, &xms, NULL); @@ -247,7 +240,6 @@ void FileCb(Widget w, XtPointer client_data, XtPointer call_data){ switch ((long int)client_data) { case FILE_LOAD_GEOM : OpenProblem(c); Init(); Draw(); break; case FILE_LOAD_POST : MergeProblem(c); ColorBarRedraw(); Init(); Draw(); break; - case FILE_CANCEL : WARNING_OVERRIDE = 0; break; case FILE_SAVE_AS : SaveToDisk(c, WID.ED.saveAsDialog, CreateFile); break; case FILE_SAVE_OPTIONS_AS : Print_Context(c); break; default : diff --git a/Unix/CbFile.h b/Unix/CbFile.h index 0a410237cb..ad634dbaa9 100644 --- a/Unix/CbFile.h +++ b/Unix/CbFile.h @@ -1,4 +1,4 @@ -/* $Id: CbFile.h,v 1.6 2000-12-20 12:17:13 geuzaine Exp $ */ +/* $Id: CbFile.h,v 1.7 2000-12-21 14:53:10 geuzaine Exp $ */ #ifndef _CB_FILE_H_ #define _CB_FILE_H_ @@ -6,7 +6,7 @@ #define FILE_LOAD_POST 302 #define FILE_SAVE_MESH 303 #define FILE_SAVE_AS 304 -#define FILE_SAVE_OPTIONS_AS 305 -#define FILE_CANCEL 306 +#define FILE_SAVE_AS_OVERWRITE 305 +#define FILE_SAVE_OPTIONS_AS 306 #endif diff --git a/Unix/Register.cpp b/Unix/Register.cpp index df30134ee8..f823d3ff19 100644 --- a/Unix/Register.cpp +++ b/Unix/Register.cpp @@ -1,4 +1,4 @@ -/* $Id: Register.cpp,v 1.16 2000-12-21 08:02:06 geuzaine Exp $ */ +/* $Id: Register.cpp,v 1.17 2000-12-21 14:53:10 geuzaine Exp $ */ #include "Gmsh.h" #include "GmshUI.h" @@ -121,8 +121,7 @@ void RegisterCallbacks_C(Widgets_T *w){ void RegisterCallbacks_ED(Widgets_T *w){ - register_ok_cb (w->ED.saveAsDialog, FileCb, FILE_SAVE_AS); - register_cancel_cb (w->ED.saveAsDialog, FileCb, FILE_CANCEL); + register_ok_cb (w->ED.saveAsDialog, FileCb, FILE_SAVE_AS_OVERWRITE); } diff --git a/Unix/Widgets.cpp b/Unix/Widgets.cpp index 5824ece389..8715b120d5 100644 --- a/Unix/Widgets.cpp +++ b/Unix/Widgets.cpp @@ -1,4 +1,4 @@ -/* $Id: Widgets.cpp,v 1.22 2000-12-21 08:02:06 geuzaine Exp $ */ +/* $Id: Widgets.cpp,v 1.23 2000-12-21 14:53:10 geuzaine Exp $ */ #include "Gmsh.h" #include "GmshUI.h" @@ -562,6 +562,7 @@ void CreateWidgets_ED(Widgets_T *w){ i=0 ; XtSetArg(arg[i], XmNdialogTitle, XmStringCreateSimple("Warning")); i++; XtSetArg(arg[i], XmNmessageString, XmStringCreateSimple("File exists")); i++; + XtSetArg(arg[i], XmNautoUnmanage, True); i++; w->ED.saveAsDialog = XmCreateWarningDialog(w->M.shell, "EDsaveAsDialog", arg, i); tmp = XmMessageBoxGetChild(w->ED.saveAsDialog, XmDIALOG_HELP_BUTTON); -- GitLab