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 #include "Xm/Form.h"
16 #include "Xm/Label.h"
17 #include "Xm/PushB.h"
18 #include "Xm/Separator.h"
19 #include "Xm/Text.h"
20 
21 #include <sys/stat.h>
22 
23 
24 #include "DXStrings.h"
25 #include "lex.h"
26 #include "CreateMacroDialog.h"
27 
28 #include "DXApplication.h"
29 #include "Network.h"
30 #include "QuestionDialogManager.h"
31 #include "ErrorDialogManager.h"
32 #include "TextFile.h"
33 #include "EditorWindow.h"
34 
35 
36 #include "NodeDefinition.h"
37 #include "DictionaryIterator.h"
38 #include "XmUtility.h"
39 
40 boolean CreateMacroDialog::ClassInitialized = FALSE;
41 String CreateMacroDialog::DefaultResources[] =
42 {
43 //    "*nameLabel.labelString:            Name:",
44 //    "*nameLabel.foreground:             SteelBlue",
45 //    "*categoryLabel.labelString:        Category:",
46 //   "*categoryLabel.foreground:         SteelBlue",
47 //  "*descriptionLabel.labelString:     Description:",
48 //  "*descriptionLabel.foreground:      SteelBlue",
49     "*filenameLabel.labelString:  	Filename:",
50     "*filenameLabel.foreground:      	SteelBlue",
51     "*dialogTitle:			Create Macro...",
52 //    "*fsdbutton.labelString:  		...",
53     "*okButton.labelString:             OK",
54 //    "*okButton.width:                   70",
55 //    "*cancelButton.labelString:         Cancel",
56 //    "*cancelButton.width:               70",
57     NULL
58 };
59 
60 
CreateMacroDialog(Widget parent,EditorWindow * e)61 CreateMacroDialog::CreateMacroDialog(Widget parent,
62 				     EditorWindow *e):
63     SetMacroNameDialog("createMacroDialog", parent, e->getNetwork())
64 {
65     this->editor = e;
66     if (NOT CreateMacroDialog::ClassInitialized)
67     {
68         CreateMacroDialog::ClassInitialized = TRUE;
69 	this->installDefaultResources(theApplication->getRootWidget());
70     }
71     this->textFile = new TextFile();
72 }
73 
74 //
75 // Install the default resources for this class.
76 //
installDefaultResources(Widget baseWidget)77 void CreateMacroDialog::installDefaultResources(Widget  baseWidget)
78 {
79     this->setDefaultResources(baseWidget, CreateMacroDialog::DefaultResources);
80     this->SetMacroNameDialog::installDefaultResources( baseWidget);
81 }
82 
~CreateMacroDialog()83 CreateMacroDialog::~CreateMacroDialog()
84 {
85     if (this->textFile)
86        delete this->textFile;
87 }
88 
ConfirmationCancel(void * data)89 void CreateMacroDialog::ConfirmationCancel(void *data)
90 {
91 }
92 
ConfirmationOk(void * data)93 void CreateMacroDialog::ConfirmationOk(void *data)
94 {
95 
96     CreateMacroDialog *cmd = (CreateMacroDialog*)data;
97     cmd->createMacro();
98 
99 }
100 
101 
okCallback(Dialog * d)102 boolean CreateMacroDialog::okCallback(Dialog *d)
103 {
104 
105     /*CreateMacroDialog *cmd = (CreateMacroDialog*)d;*/
106 
107     char *name = SetMacroNameDialog::GetTextWidgetToken(this->macroName);
108 
109     if (!this->verifyMacroName(name, TRUE)) {
110 	return FALSE;
111 	delete name;
112     }
113 
114     char *filename = this->textFile->getText();
115     if (IsBlankString(filename)) {
116 	ModalErrorMessage(this->getRootWidget(), "A file name must be given");
117 	delete name;
118 	XtFree(filename);
119 	return FALSE;
120     }
121 
122     char *newname = Network::FilenameToNetname(filename);
123     XtFree(filename);
124 
125     struct STATSTRUCT buffer;
126 	if(STATFUNC(newname, &buffer) == 0) {
127 
128     	theQuestionDialogManager->modalPost(
129 				this->parent,
130 				"Do you want to overwrite an existing file?",
131 				"Overwrite existing file",
132 				(void *)this,
133 				CreateMacroDialog::ConfirmationOk,
134 				CreateMacroDialog::ConfirmationCancel,
135 				NULL);
136 	delete name;
137         delete newname;
138 
139 	return TRUE;
140     }
141 
142     boolean worked = this->createMacro();
143 
144     delete name;
145     delete newname;
146 
147     return worked;
148 
149 }
150 
151 
152 
createMacro()153 boolean CreateMacroDialog::createMacro()
154 {
155 
156 
157     char *filename = this->textFile->getText();
158     char *name = SetMacroNameDialog::GetTextWidgetToken(this->macroName);
159     char *cat = SetMacroNameDialog::GetTextWidgetToken(this->category);
160     char *desc = XmTextGetString(this->description);
161 
162     boolean worked = this->editor->macroifySelectedNodes(name, cat, desc,
163 								 filename);
164     delete name;
165     delete cat;
166     XtFree(desc);
167     XtFree(filename);
168 
169     return worked;
170 }
171 
172 
setFileName(const char * filename)173 void CreateMacroDialog::setFileName(const char *filename)
174 {
175     XtVaSetValues(this->filename,XmNvalue,filename,NULL);
176 
177     //
178     //  Right justify the text
179     //
180 
181     int len = STRLEN(filename);
182     XmTextShowPosition(this->filename,len);
183     XmTextSetInsertionPosition(this->filename,len);
184 
185 }
186 
187 
188 
createDialog(Widget parent)189 Widget CreateMacroDialog::createDialog(Widget parent)
190 {
191     Arg arg[10];
192     XtSetArg(arg[0], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL);
193     XtSetArg(arg[1], XmNautoUnmanage, False);
194 //    Widget dialog = XmCreateFormDialog(parent, this->name, arg, 2);
195     Widget dialog = this->CreateMainForm(parent, this->name, arg, 2);
196 
197     Widget nameLabel = XtVaCreateManagedWidget(
198 	"nameLabel", xmLabelWidgetClass, dialog,
199         XmNtopAttachment   , XmATTACH_FORM,
200         XmNtopOffset       , 10,
201         XmNleftAttachment  , XmATTACH_FORM,
202         XmNleftOffset      , 5,
203         XmNrightAttachment , XmATTACH_POSITION,
204         XmNrightPosition   , 25,
205         XmNalignment       , XmALIGNMENT_BEGINNING,
206 	NULL);
207 
208     this->macroName = XtVaCreateManagedWidget(
209 	"name", xmTextWidgetClass, dialog,
210         XmNtopAttachment   , XmATTACH_FORM,
211         XmNtopOffset       , 10,
212         XmNleftAttachment  , XmATTACH_POSITION,
213         XmNleftPosition    , 25,
214         XmNrightAttachment , XmATTACH_FORM,
215         XmNrightOffset     , 5,
216         XmNeditMode        , XmSINGLE_LINE_EDIT,
217         XmNeditable        , True,
218 	NULL);
219 
220     Widget categoryLabel = XtVaCreateManagedWidget(
221         "categoryLabel", xmLabelWidgetClass, dialog,
222         XmNtopAttachment   , XmATTACH_WIDGET,
223         XmNtopWidget       , this->macroName,
224         XmNtopOffset       , 10,
225         XmNleftAttachment  , XmATTACH_FORM,
226         XmNleftOffset      , 5,
227         XmNrightAttachment , XmATTACH_POSITION,
228         XmNrightPosition   , 25,
229         XmNalignment       , XmALIGNMENT_BEGINNING,
230 	NULL);
231 
232     this->category = XtVaCreateManagedWidget(
233         "category", xmTextWidgetClass, dialog,
234         XmNtopAttachment   , XmATTACH_WIDGET,
235         XmNtopWidget       , this->macroName,
236         XmNtopOffset       , 10,
237         XmNleftAttachment  , XmATTACH_POSITION,
238         XmNleftPosition    , 25,
239         XmNrightAttachment , XmATTACH_FORM,
240         XmNrightOffset     , 5,
241         XmNeditMode        , XmSINGLE_LINE_EDIT,
242         XmNeditable        , True,
243 	NULL);
244 
245     Widget descriptionLabel = XtVaCreateManagedWidget(
246         "descriptionLabel", xmLabelWidgetClass, dialog,
247         XmNtopAttachment   , XmATTACH_WIDGET,
248         XmNtopWidget       , this->category,
249         XmNtopOffset       , 10,
250         XmNleftAttachment  , XmATTACH_FORM,
251         XmNleftOffset      , 5,
252         XmNrightAttachment , XmATTACH_POSITION,
253         XmNrightPosition   , 25,
254         XmNalignment       , XmALIGNMENT_BEGINNING,
255 	NULL);
256 
257     this->description = XtVaCreateManagedWidget(
258         "description", xmTextWidgetClass, dialog,
259         XmNtopAttachment   , XmATTACH_WIDGET,
260         XmNtopWidget       , this->category,
261         XmNtopOffset       , 10,
262         XmNleftAttachment  , XmATTACH_POSITION,
263         XmNleftPosition    , 25,
264         XmNrightAttachment , XmATTACH_FORM,
265         XmNrightOffset     , 5,
266         XmNeditMode        , XmSINGLE_LINE_EDIT,
267 	NULL);
268 
269 
270     Widget filenameLabel = XtVaCreateManagedWidget(
271         "filenameLabel", xmLabelWidgetClass, dialog,
272         XmNtopAttachment   , XmATTACH_WIDGET,
273         XmNtopWidget       , this->description,
274         XmNtopOffset       , 10,
275         XmNleftAttachment  , XmATTACH_FORM,
276         XmNleftOffset      , 5,
277         XmNrightAttachment , XmATTACH_POSITION,
278         XmNrightPosition   , 25,
279         XmNalignment       , XmALIGNMENT_BEGINNING,
280 	NULL);
281 
282     this->textFile->createTextFile(dialog);
283 
284 
285     XtVaSetValues(this->textFile->getRootWidget(),
286 	XmNtopAttachment   , XmATTACH_WIDGET,
287 	XmNtopWidget	   , this->description,
288 	XmNtopOffset	   , 10,
289 	XmNleftAttachment  , XmATTACH_POSITION,
290 	XmNleftPosition	   , 25,
291 	XmNrightAttachment , XmATTACH_FORM,
292 	XmNrightOffset	   , 5,
293 	NULL);
294 
295 
296     Widget separator = XtVaCreateManagedWidget(
297         "separator", xmSeparatorWidgetClass, dialog,
298         XmNtopAttachment   , XmATTACH_WIDGET,
299         XmNtopWidget       , this->textFile->getRootWidget(),
300         XmNtopOffset       , 10,
301         XmNleftAttachment  , XmATTACH_FORM,
302         XmNleftOffset      , 2,
303         XmNrightAttachment , XmATTACH_FORM,
304         XmNrightOffset     , 2,
305 	NULL);
306 
307     this->ok = XtVaCreateManagedWidget(
308         "okButton", xmPushButtonWidgetClass, dialog,
309         XmNtopAttachment   , XmATTACH_WIDGET,
310         XmNtopWidget       , separator,
311         XmNtopOffset       , 10,
312         XmNleftAttachment  , XmATTACH_FORM,
313         XmNleftOffset      , 5,
314         XmNbottomAttachment, XmATTACH_FORM,
315         XmNbottomOffset    , 5,
316 	NULL);
317 
318     this->cancel = XtVaCreateManagedWidget(
319         "cancelButton", xmPushButtonWidgetClass, dialog,
320         XmNtopAttachment   , XmATTACH_WIDGET,
321         XmNtopWidget       , separator,
322         XmNtopOffset       , 10,
323         XmNrightAttachment , XmATTACH_FORM,
324         XmNrightOffset     , 5,
325         XmNbottomAttachment, XmATTACH_FORM,
326         XmNbottomOffset    , 5,
327 	NULL);
328 
329     this->textFile->enableCallbacks(TRUE);
330 
331     return dialog;
332 }
333 
manage()334 void CreateMacroDialog::manage()
335 {
336     XmTextSetString(this->category, "Macros");
337     XmTextSetString(this->macroName, "");
338     XmTextSetString(this->description, "new macro");
339 
340     this->Dialog::manage();
341 
342     XmProcessTraversal(this->macroName, XmTRAVERSE_CURRENT);
343     XmProcessTraversal(this->macroName, XmTRAVERSE_CURRENT);
344 }
345 
346 
347 
348 
349 
350 
351 
352 
353 
354