1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11
12
13
14
15
16 #include "Network.h"
17 #include "SaveCFGDialog.h"
18 #include "ControlPanel.h"
19 #include "Application.h"
20 #include "ErrorDialogManager.h"
21 #include "DXStrings.h"
22
23
24 boolean SaveCFGDialog::ClassInitialized = FALSE;
25
26 String SaveCFGDialog::DefaultResources[] =
27 {
28 "*dialogTitle: Save Configuration...",
29 "*dirMask: *.cfg",
30 NULL
31 };
32
saveFile(const char * string)33 void SaveCFGDialog::saveFile(const char *string)
34 {
35 boolean result;
36 char *op;
37
38 result = this->network->saveCfgFile(string);
39 op = "writing";
40
41 if(NOT result)
42 ErrorMessage("Error while %s configuration file %s", op, string);
43
44 }
45
SaveCFGDialog(Widget parent,Network * net)46 SaveCFGDialog::SaveCFGDialog(Widget parent, Network *net) :
47 SaveFileDialog("saveCFGDialog", parent, ".cfg")
48 {
49 this->network= net;
50 this->hasCommentButton = FALSE;
51
52 if (NOT SaveCFGDialog::ClassInitialized)
53 {
54 SaveCFGDialog::ClassInitialized = TRUE;
55 this->installDefaultResources(theApplication->getRootWidget());
56 }
57 }
58
59 //
60 // Install the default resources for this class.
61 //
installDefaultResources(Widget baseWidget)62 void SaveCFGDialog::installDefaultResources(Widget baseWidget)
63 {
64 this->setDefaultResources(baseWidget, SaveCFGDialog::DefaultResources);
65 this->SaveFileDialog::installDefaultResources( baseWidget);
66 }
67 // FIXME: There is a chunk of code here which belongs in Network. It actually
68 // sits in Network::FilenameToCfgname but it's ifdef-ed out. Remove this one
69 // and enable that one.
getDefaultFileName()70 char *SaveCFGDialog::getDefaultFileName()
71 {
72 const char *netname = this->network->getFileName();
73 char *file = new char[STRLEN(netname) + 1];
74 strcpy (file, netname);
75
76 //
77 // Remove the .net extension if present
78 //
79 #define NetExtension ".net"
80 const char *netext = strrstr(file, NetExtension);
81 int netExtLen = STRLEN(NetExtension);
82 if ((netext) && (STRLEN(netext) == netExtLen)) {
83 int filelen = STRLEN(file);
84 file[filelen-netExtLen] = '\0';
85 }
86
87 return Network::FilenameToCfgname(file);
88 }
89
90