root/trunk/ConfigureToolsDlg.cpp

Revision 5, 6.9 kB (checked in by qbert, 6 years ago)

Initial ( and last :( ) commit

Line 
1 // ConfigureToolsDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Elephant.h"
6 #include "ConfigureToolsDlg.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CConfigureToolsDlg dialog
16
17
18 CConfigureToolsDlg::CConfigureToolsDlg(CWnd* pParent /*=NULL*/)
19     : CXTResizeDialog(CConfigureToolsDlg::IDD, pParent)
20 {
21     //{{AFX_DATA_INIT(CConfigureToolsDlg)
22     m_csCommand = _T("");
23     m_csName = _T("");
24     m_captureOutput = FALSE;
25     //}}AFX_DATA_INIT
26 }
27
28
29 void CConfigureToolsDlg::DoDataExchange(CDataExchange* pDX)
30 {
31     CXTResizeDialog::DoDataExchange(pDX);
32     //{{AFX_DATA_MAP(CConfigureToolsDlg)
33     DDX_Control(pDX, IDC_BUTTON5, m_close);
34     DDX_Control(pDX, IDC_STATIC2, m_s2);
35     DDX_Control(pDX, IDC_STATIC1, m_s1);
36     DDX_Control(pDX, IDC_LIST2, m_constants);
37     DDX_Control(pDX, IDC_LIST1, m_tools);
38     DDX_Control(pDX, IDC_EDIT7, m_command);
39     DDX_Control(pDX, IDC_EDIT1, m_name);
40     DDX_Control(pDX, IDC_BUTTON6, m_browse);
41     DDX_Control(pDX, IDC_BUTTON2, m_remove);
42     DDX_Control(pDX, IDC_BUTTON1, m_add);
43     DDX_Text(pDX, IDC_EDIT7, m_csCommand);
44     DDX_Text(pDX, IDC_EDIT1, m_csName);
45     DDX_Check(pDX, IDC_CHECK3, m_captureOutput);
46     //}}AFX_DATA_MAP
47 }
48
49
50 BEGIN_MESSAGE_MAP(CConfigureToolsDlg, CXTResizeDialog)
51     //{{AFX_MSG_MAP(CConfigureToolsDlg)
52     ON_WM_SIZE()
53     ON_WM_DESTROY()
54     ON_BN_CLICKED(IDC_BUTTON1, OnAdd)
55     ON_BN_CLICKED(IDC_BUTTON2, OnRemove)
56     ON_BN_CLICKED(IDC_BUTTON6, OnBrowse)
57     ON_NOTIFY(NM_CLICK, IDC_LIST1, OnToolsClick)
58     ON_BN_CLICKED(IDC_BUTTON5, OnClose)
59     //}}AFX_MSG_MAP
60 END_MESSAGE_MAP()
61
62 /////////////////////////////////////////////////////////////////////////////
63 // CConfigureToolsDlg message handlers
64
65 BOOL CConfigureToolsDlg::OnInitDialog()
66 {
67     CXTResizeDialog::OnInitDialog();
68    
69     SetupButton(&m_add);
70     SetupButton(&m_remove);
71     SetupButton(&m_browse);
72     SetupButton(&m_close);
73    
74
75    
76     m_name.SetText("Name of tool.");
77     m_command.SetText("Command : [ example syntax ] C:\\emacs.exe CURRENTFILE");
78
79     m_tools.InsertColumn(0,"Tool Name",LVCFMT_LEFT,180);
80     m_tools.InsertColumn(1,"Output",LVCFMT_LEFT,60);
81     m_tools.InsertColumn(2,"Tool Command",LVCFMT_LEFT,200);
82
83     m_constants.InsertColumn(0,"Constant Name",LVCFMT_LEFT,180);   
84     m_constants.InsertColumn(1,"Current Value",LVCFMT_LEFT,240);
85
86     SetupListCtrl(&m_tools);
87     SetupListCtrl(&m_constants);
88
89
90     SetupTitle(&m_s1);
91     SetupTitle(&m_s2);
92
93     SetResize(IDC_BUTTON6 ,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
94     SetResize(IDC_BUTTON2 ,SZ_TOP_RIGHT,SZ_TOP_RIGHT);
95     SetResize(IDC_EDIT1 ,SZ_TOP_LEFT,SZ_TOP_RIGHT);
96     SetResize(IDC_EDIT7 ,SZ_TOP_LEFT,SZ_TOP_RIGHT);
97     SetResize(IDC_LIST1 ,SZ_TOP_LEFT,SZ_BOTTOM_RIGHT );
98     SetResize(IDC_LIST2 ,SZ_BOTTOM_LEFT,SZ_BOTTOM_RIGHT);
99     SetResize(IDC_BUTTON5,SZ_BOTTOM_RIGHT,SZ_BOTTOM_RIGHT);
100    
101
102     LoadPlacement("CConfigureToolsDlg");
103
104     SetIcon(AfxGetApp()->LoadIcon(IDI_ICON2) ,true);
105
106     InitConstants();
107     InitTools();
108     return TRUE;  // return TRUE unless you set the focus to a control
109                   // EXCEPTION: OCX Property Pages should return FALSE
110 }
111
112 void CConfigureToolsDlg::OnSize(UINT nType, int cx, int cy)
113 {
114     CXTResizeDialog::OnSize(nType, cx, cy);
115     // TODO: Add your message handler code here
116     m_constants.SetColumnWidth(1,cx-180);
117     m_tools.SetColumnWidth(2,cx-240);
118 }
119
120 void CConfigureToolsDlg::OnDestroy()
121 {
122     CXTResizeDialog::OnDestroy();
123    
124     SavePlacement("CConfigureToolsDlg");
125    
126 }
127
128 void CConfigureToolsDlg::OnAdd()
129 {
130     UpdateData();
131     int count = m_tools.GetItemCount();
132    
133    
134     if ( m_csName == "" || m_csName == m_name.GetText().c_str() )
135     {
136         ElephantMessageBox("Could you please enter a name for the tool you wish to add?",this);
137         return;
138     }
139     if ( m_csCommand == "" || m_csCommand == m_command.GetText() .c_str() )
140     {
141         ElephantMessageBox("Could you please enter the command for the tool you wish to add?",this);
142         return;
143     }
144
145
146     m_tools.InsertItem(count,m_csName);
147     m_tools.SetItemText(count,1,m_captureOutput ? "Yes" : "No");
148     m_tools.SetItemText(count,2,m_csCommand);
149
150     CString toolTotal = m_csName + "~";
151     toolTotal += m_captureOutput ? "1" : "0";   
152     toolTotal += "~" + m_csCommand;
153
154     vector<string> vTools;
155     Split(Globals::settings->baseSettings->GetCache("tools"),",",vTools );
156     vTools.push_back(toolTotal.GetBuffer(0) );
157     Globals::settings->baseSettings->SetCache("tools",Join(vTools,"," ) );
158 }
159
160
161 void CConfigureToolsDlg::InitConstants()
162 {
163     m_constants.InsertItem(0,"PROJECTFILES");
164     m_constants.SetItemText(0,1,"Full paths to all files in the project , seperated by spaces.");
165
166     m_constants.InsertItem(1,"PROJECTEXE");
167     m_constants.SetItemText(1,1,"The path to the project executable.");
168
169     m_constants.InsertItem(2,"PROJECTDIR");
170     m_constants.SetItemText(2,1,"The path to the project directory.");
171
172     m_constants.InsertItem(3,"CURRENTFILE");
173     m_constants.SetItemText(3,1,"The path to the current file.");
174
175
176 }
177
178 void CConfigureToolsDlg::InitTools()
179 {
180
181     vector<string> vTools, temp;
182     Split(Globals::settings->baseSettings->GetCache("tools"),",",vTools );
183
184     for ( int i = 0 ; i < vTools.size(); i ++ )
185     {
186         string buf = vTools[i];
187         Split(buf,"~",temp);
188         m_tools.InsertItem(i,temp[0].c_str());
189         m_tools.SetItemText(i,1,temp[1] == "1" ? "Yes" : "No");
190         m_tools.SetItemText(i,2,temp[2].c_str());
191         temp.clear();
192     }
193    
194
195 }
196
197 void CConfigureToolsDlg::OnRemove()
198 {
199     vector<string> currentTools;
200
201     GetSelListCtrlItems(&m_tools,&currentTools,2);
202    
203     string delItem = currentTools[0];
204
205    
206     vector<string> vTools, newTools, temp;
207
208     Split(Globals::settings->baseSettings->GetCache("tools"),",",vTools );
209
210     for ( int i = 0 ; i < vTools.size(); i ++ )
211     {
212         string buf = vTools[i];
213         Split(buf,"~",temp);
214         if ( temp[2] == delItem )
215         {
216             ;           
217         }
218        
219         else newTools.push_back(buf);
220    
221         temp.clear();
222     }
223    
224     Globals::settings->baseSettings->SetCache("tools",Join(newTools,","));
225
226     DeleteAllSelectedItems(&m_tools);
227
228    
229 }
230
231 void CConfigureToolsDlg::OnBrowse()
232 {
233    
234     string file = "";
235     if ( GetFileFromCFileDialog(Globals::lastDir,file, "exe","All files(*.*)|*.*||" ,this) )
236     {
237         m_csCommand = file.c_str();
238        
239     UpdateData(FALSE);
240     }
241    
242    
243    
244    
245 }
246
247
248 void CConfigureToolsDlg::OnToolsClick(NMHDR* pNMHDR, LRESULT* pResult)
249 {
250     vector<string> temp;
251    
252     string name, cmd, output;
253
254     GetSelListCtrlItems(&m_tools,&temp,0);
255
256     if (!temp.size()) return;
257     name = temp[0];
258
259     temp.clear();
260
261     GetSelListCtrlItems(&m_tools,&temp,1);
262     if (!temp.size()) return;
263
264     output = temp[0];
265    
266     temp.clear();
267
268     GetSelListCtrlItems(&m_tools,&temp,2);
269     if (!temp.size()) return;
270    
271     cmd = temp[0];
272    
273     temp.clear();
274
275     {
276    
277         m_csCommand = cmd.c_str();
278
279         m_csName = name.c_str();
280
281         //ElephantMessageBox(output.c_str(),this);
282         m_captureOutput = output == "Yes" ? true : false;
283
284         UpdateData(false);
285
286     }
287
288    
289     *pResult = 0;
290 }
291
292 void CConfigureToolsDlg::OnClose()
293 {
294     EndDialog(0);
295    
296 }
Note: See TracBrowser for help on using the browser.