-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMACRODLG.CPP
More file actions
252 lines (203 loc) · 5.99 KB
/
MACRODLG.CPP
File metadata and controls
252 lines (203 loc) · 5.99 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// MacroDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MacroDlg.h"
#include "afxdialogex.h"
#include "resource.h"
#include <EAF\EAFUtilities.h>
#include <EAF\EAFApp.h>
#include "Scripting.h"
#include "PGSuperScriptingAgentImp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CMacroDlg dialog
IMPLEMENT_DYNAMIC(CMacroDlg, CDialog)
CMacroDlg::CMacroDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD_MACROS, pParent)
{
m_pScriptEngine = nullptr;
}
CMacroDlg::~CMacroDlg()
{
}
void CMacroDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
void CMacroDlg::SetScriptEngine(CPyScriptEngine* pScriptEngine)
{
m_pScriptEngine = pScriptEngine;
}
BEGIN_MESSAGE_MAP(CMacroDlg, CDialog)
ON_BN_CLICKED(IDC_RUN, &CMacroDlg::OnRun)
ON_BN_CLICKED(IDC_DEBUG, &CMacroDlg::OnDebug)
ON_BN_CLICKED(IDC_EDIT, &CMacroDlg::OnEdit)
ON_BN_CLICKED(IDC_CREATE, &CMacroDlg::OnCreate)
ON_BN_CLICKED(IDC_DELETE, &CMacroDlg::OnDelete)
ON_CBN_DBLCLK(IDC_MACROS, &CMacroDlg::OnCbnDblclkMacros)
ON_WM_CLOSE()
ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()
// CMacroDlg message handlers
BOOL CMacroDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
std::vector<CString> vScripts = pScripting->GetScriptNames();
for (const auto& name : vScripts)
{
pCB->AddString(name);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMacroDlg::OnRun()
{
// TODO: Add your control notification handler code here
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
CString strScript;
pCB->GetLBText(pCB->GetCurSel(), strScript);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
strScript = pScripting->GetScriptFile(strScript);
m_pScriptEngine->Run(strScript);
}
void CMacroDlg::OnDebug()
{
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
int curSel = pCB->GetCurSel();
CString strScript;
pCB->GetLBText(curSel, strScript);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
CString strScriptFile = pScripting->GetScriptFile(strScript);
m_pScriptEngine->Debug(strScriptFile);
}
void CMacroDlg::OnEdit()
{
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
int curSel = pCB->GetCurSel();
CString strScript;
pCB->GetLBText(curSel, strScript);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
CString strScriptFile = pScripting->GetScriptFile(strScript);
m_pScriptEngine->Edit(strScriptFile);
}
void CMacroDlg::OnCreate()
{
// TODO: Add your control notification handler code here
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
CString strScript;
pCB->GetWindowText(strScript);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
CString strScriptFile = pScripting->GetScriptFile(strScript);
CFileFind finder;
BOOL bFound = finder.FindFile(strScriptFile);
if (bFound)
{
CString strError;
strError.Format(_T("Could not create script file %s. The file already exists."), strScriptFile);
AfxMessageBox(strError);
return;
}
CFile f;
CFileException e;
if (!f.Open(strScriptFile, CFile::modeCreate | CFile::modeWrite, &e))
{
CString strError;
TCHAR szError[255];
e.GetErrorMessage(szError, 255);
strError.Format(_T("Could not create script file %s (%s)"), strScriptFile, szError);
AfxMessageBox(strError);
}
else
{
CString strBoilerPlate(_T("#Script\r\nimport BridgeLink\r\npgsuper = BridgeLink.GetPGSuper()\r\n#your script goes here"));
f.Write(strBoilerPlate,strBoilerPlate.GetLength());
f.Close();
pCB->AddString(strScript);
m_pScriptEngine->Edit(strScriptFile);
}
}
void CMacroDlg::OnDelete()
{
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_MACROS);
int curSel = pCB->GetCurSel();
CString strScript;
pCB->GetLBText(curSel, strScript);
CComPtr<IBroker> pBroker;
EAFGetBroker(&pBroker);
GET_IFACE2(pBroker, IScripting, pScripting);
CString strScriptFile = pScripting->GetScriptFile(strScript);
CString strMsg;
strMsg.Format(_T("Are you sure you want to delete %s.\nThis action cannot be undone."), strScript);
if (AfxMessageBox(strMsg,MB_YESNOCANCEL) == IDYES)
{
try
{
CFile::Remove(strScriptFile);
pCB->DeleteString(curSel);
}
catch (CFileException* pEx)
{
TCHAR szError[255];
pEx->GetErrorMessage(szError, 255);
CString strMsg;
strMsg.Format(_T("Cannot delete %s (%s)"), strScriptFile, szError);
AfxMessageBox(strMsg);
pEx->Delete();
};
}
}
void CMacroDlg::OnCbnDblclkMacros()
{
OnRun();
}
void CMacroDlg::OnCancel()
{
SaveWindowState();
__super::OnCancel();
}
void CMacroDlg::OnClose()
{
SaveWindowState();
CDialog::OnClose();
}
void CMacroDlg::SaveWindowState()
{
CEAFApp* pApp = EAFGetApp();
// Save the layout of the application window
WINDOWPLACEMENT wp;
wp.length = sizeof wp;
if (GetWindowPlacement(&wp))
{
pApp->WriteWindowPlacement(_T("Window Positions"), _T("Macros"), &wp);
}
}
void CMacroDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// Restore the layout of the application window
if (bShow)
{
WINDOWPLACEMENT wp;
CEAFApp* pApp = EAFGetApp();
if (pApp->ReadWindowPlacement(_T("Window Positions"), _T("Macros"), &wp))
{
SetWindowPos(NULL, wp.rcNormalPosition.left, wp.rcNormalPosition.top, wp.rcNormalPosition.right - wp.rcNormalPosition.left, wp.rcNormalPosition.bottom - wp.rcNormalPosition.top, 0);
}
}
}