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 #include "ConfirmedQCommand.h"
15 #include "MBApplication.h"
16 #include "MBMainWindow.h"
17 #include "QuitCommand.h"
18
19 #include <Xm/Xm.h>
20 #include <Xm/FileSB.h>
21 #include <Xm/SelectioB.h>
22
ConfirmedQCommand(const char * name,CommandScope * scope,boolean active,MBMainWindow * mbmw,MBApplication * app)23 ConfirmedQCommand::ConfirmedQCommand(const char* name,
24 CommandScope* scope,
25 boolean active,
26 MBMainWindow *mbmw,
27 MBApplication *app) :
28 OptionalPreActionCommand(name, scope, active,
29 "Save Confirmation",
30 "Do you want to save the file?")
31 {
32 this->application = app;
33 this->mbmw = mbmw;
34
35 //
36 // We create this later, because creation uses a virtual Application
37 // method. If this class gets instanced in the Application's constructor
38 // (typical) then the wrong virtual method will get called.
39 //
40 this->command = NULL;
41
42 }
43
doPreAction()44 void ConfirmedQCommand::doPreAction()
45 {
46 char *fname = mbmw->getFilename();
47
48 if(fname)
49 {
50 if(this->mbmw->saveMB(fname))
51 this->doIt(NULL);
52 }
53 else
54 this->mbmw->PostSaveAsDialog(this->mbmw, this);
55
56 }
57
doIt(CommandInterface * ci)58 boolean ConfirmedQCommand::doIt(CommandInterface *ci)
59 {
60 if (!this->command) {
61
62 //
63 // We can use a static buffer since there is only one application.
64 //
65 static char *dialogQuestion = NULL;
66 if (!dialogQuestion) {
67 dialogQuestion = new char[256];
68 sprintf(dialogQuestion,"Do you really want to quit %s?",
69 theApplication->getInformalName());
70 }
71
72 CommandScope *scope = (CommandScope*)this->scopeList.getElement(1);
73 this->command =
74 new QuitCommand
75 (this->application,
76 "quit",
77 scope,
78 TRUE,
79 "Quit",
80 dialogQuestion);
81 }
82
83 this->command->execute(ci);
84 return TRUE;
85 }
86
needsConfirmation()87 boolean ConfirmedQCommand::needsConfirmation()
88 {
89 return this->application->isDirty();
90 }
91
92