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 <defines.h>
11 
12 
13 
14 #include <Xm/Xm.h>
15 #include <Xm/FileSB.h>
16 #include <Xm/SelectioB.h>
17 
18 #include "ConfirmedQuitCommand.h"
19 #include "DXApplication.h"
20 #include "DXWindow.h"
21 #include "Network.h"
22 #include "QuitCommand.h"
23 
ConfirmedQuitCommand(const char * name,CommandScope * scope,boolean active,DXApplication * app)24 ConfirmedQuitCommand::ConfirmedQuitCommand(const char*   name,
25                          CommandScope* scope,
26                          boolean       active,
27 			 DXApplication *app) :
28     OptionalPreActionCommand(name, scope, active,
29                              "Save Confirmation",
30                              "Do you want to save the program?")
31 {
32     this->application = app;
33 
34     //
35     // We create this later, because creation uses a virtual Application
36     // method.  If this class gets instanced in the Application's constructor
37     // (typical) then the wrong virtual method will get called.
38     //
39     this->command = NULL;
40 }
~ConfirmedQuitCommand()41 ConfirmedQuitCommand::~ConfirmedQuitCommand()
42 {
43     if (this->command)
44 	delete this->command;
45 
46 }
47 
doPreAction()48 void   ConfirmedQuitCommand::doPreAction()
49 {
50     Network *net = theDXApplication->network;
51     const char    *fname = net->getFileName();
52 
53     if(fname)
54     {
55         if(net->saveNetwork(fname))
56             this->doIt(NULL);
57     }
58     else
59         net->postSaveAsDialog(theDXApplication->getAnchor()->getRootWidget(),
60 					this);
61 }
62 
doIt(CommandInterface * ci)63 boolean ConfirmedQuitCommand::doIt(CommandInterface *ci)
64 {
65     //
66     // If the application doesn't allow confirmation, then don't do it.
67     // (Yes, another, possibly better, way to do this would be to have
68     //  DXApplication allocate an (non-existent yet) UnconfirmedQuitCommand
69     // instead of a ConfirmedQuitCommand)
70     //
71     if (!theDXApplication->appAllowsConfirmedQuit()) {
72 	theDXApplication->shutdownApplication();
73 	return TRUE;
74     }
75 
76 
77     //
78     // We can use a static buffer since there is only one application.
79     //
80     if (!this->command) {
81 
82 	static char *dialogQuestion = NULL;
83 	if (!dialogQuestion) {
84 	    dialogQuestion = new char[256];
85 	    sprintf(dialogQuestion,"Do you really want to quit %s?",
86 				theApplication->getInformalName());
87 	}
88 
89 	CommandScope *scope = (CommandScope*)this->scopeList.getElement(1);
90 	this->command =
91 	    new QuitCommand
92 		(this->application,
93 		 "quit",
94 		 scope,
95 		 TRUE,
96 		 "Quit",
97 		 dialogQuestion);
98     }
99 
100     this->command->execute(ci);
101 
102     return TRUE;
103 }
104 
needsConfirmation()105 boolean ConfirmedQuitCommand::needsConfirmation()
106 {
107     DXApplication *ap = this->application;
108 
109     return ap->network->saveToFileRequired();
110 }
111 
112