forked from ff6347/mpolauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPOLnchEyeballObserver.cpp
237 lines (171 loc) · 5.58 KB
/
MPOLnchEyeballObserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//========================================================================================
//
// $File: //depot/indesign_6.0/highprofile/source/sdksamples/wlistboxcomposite/MPOLnchEyeballObserver.cpp $
//
// Owner: Adobe Developer Technologies
//
// $Author: pmbuilder $
//
// $DateTime: 2008/08/19 04:03:07 $
//
// $Revision: #1 $
//
// $Change: 643572 $
//
// Copyright 1997-2008 Adobe Systems Incorporated. All rights reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
// with the terms of the Adobe license agreement accompanying it. If you have received
// this file from a source other than Adobe, then your use, modification, or
// distribution of it requires the prior written permission of Adobe.
//
//========================================================================================
#include "VCPlugInHeaders.h"
// Implementation includes
#include "widgetid.h"
// Interface includes
#include "ISubject.h"
#include "ITriStateControlData.h"
#include "IControlView.h"
#include "ITreeViewController.h"
#include "IWidgetParent.h"
#include "IPanelControlData.h"
#include "ITextControlData.h"
// Implem includes
#include "CAlert.h"
#include "CObserver.h"
#include "MPOLnchID.h"
// Implem includes
#include "K2Vector.tpp" // For NodeIDList to compile
#include "MPOLnchNodeID.h"
// Scripting includes
#include "IScriptRunner.h"
#include "IScriptUtils.h"
// file handling
#include "FileUtils.h"
#include "StreamUtil.h"
#include "IPMStream.h"
#include "MPOLnchHelper.h"
/**
Observes the "eyeball" widget.
@ingroup wlistboxcomposite
*/
class MPOLnchEyeballObserver : public CObserver
{
public:
/**
Constructor for WLBListBoxObserver class.
@param interface ptr from boss object on which this interface is aggregated.
*/
MPOLnchEyeballObserver(IPMUnknown *boss);
/**
Destructor for MPOLnchEyeballObserver class -
performs cleanup
*/
~MPOLnchEyeballObserver();
/**
AutoAttach is only called for registered observers
of widgets. This method is called by the application
core when the widget is shown.
*/
virtual void AutoAttach();
/**
AutoDetach is only called for registered observers
of widgets. Called when widget hidden.
*/
virtual void AutoDetach();
/**
Update when there's been a change on the eyeball widget.
@param theChange this is specified by the agent of change; it can be the class ID of the agent,
or it may be some specialised message ID.
@param theSubject this provides a reference to the object which has changed; in this case, the button
widget boss object that is being observed.
@param protocol the protocol along which the change occurred.
@param changedBy this can be used to provide additional information about the change or a reference
to the boss object that caused the change.
*/
virtual void Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy);
};
CREATE_PMINTERFACE(MPOLnchEyeballObserver, kMPOLnchEyeballObserverImpl)
MPOLnchEyeballObserver::MPOLnchEyeballObserver(IPMUnknown* boss)
: CObserver(boss)
{
}
MPOLnchEyeballObserver::~MPOLnchEyeballObserver()
{
}
void MPOLnchEyeballObserver::AutoAttach()
{
InterfacePtr<ISubject> subject(this, UseDefaultIID());
if (subject != nil)
{
subject->AttachObserver(this, IID_ITRISTATECONTROLDATA);
}
}
void MPOLnchEyeballObserver::AutoDetach()
{
InterfacePtr<ISubject> subject(this, UseDefaultIID());
if (subject != nil)
{
subject->DetachObserver(this,IID_ITRISTATECONTROLDATA);
}
}
void MPOLnchEyeballObserver::Update
(
const ClassID& theChange,
ISubject* theSubject,
const PMIID &protocol,
void* changedBy
)
{
if(theChange == kTrueStateMessage) {
// Then the button has been activated.
do {
InterfacePtr<ITriStateControlData> data(this, IID_ITRISTATECONTROLDATA);
// now look for the parent of the widget
InterfacePtr<IWidgetParent> widgetParent(this, IID_IWIDGETPARENT);
if(widgetParent == nil){
CAlert::InformationAlert("widgetParent is nil");
break;
}
//found it
// Query the parent for the panel
InterfacePtr<IPanelControlData> panelData((IPanelControlData*)widgetParent->QueryParentFor(IID_IPANELCONTROLDATA));
if(panelData == nil) {
CAlert::InformationAlert("panelData is nil");
break;
}
// found it
// look for the TextWidget that holds the name
IControlView* nameView = panelData->FindWidget(kMPOLnchTextWidgetID);
InterfacePtr<ITextControlData> textControlData( nameView, UseDefaultIID() );
if( (textControlData== nil)) {
break;
CAlert::InformationAlert("textControlData is nil");
}
// Thats great. found it
// get the name of the node. The associated PMString
PMString nodeName(textControlData->GetString());
MPOLnchHelper helper;
IDFile scriptFile = helper.GetScriptFilesFolder();
PMString fn(nodeName);
PMString ext(".jsx");
FileUtils::AppendPath(&scriptFile, fn + ext);
if (FileUtils::DoesFileExist(scriptFile)) {
// for debug
//FileUtils::OpenFile(scriptFile);
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));
bool filestatus=scriptRunner->CanHandleFile(scriptFile);
RunScriptParams scriptParams(scriptRunner);
scriptParams.SetShowErrorAlert(kTrue);
scriptParams.SetInvokeDebugger(kFalse);
if(filestatus==1)
{
scriptRunner->RunFile(scriptFile,scriptParams);
}// close filestatus
}else {
CAlert::InformationAlert(helper.MissingScrptFileStr(nodeName));
}
} while(0);
}
}