forked from n00b87/RCBasic-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcbasic_edit_projectSettings_dialog.cpp
executable file
·303 lines (238 loc) · 9.69 KB
/
rcbasic_edit_projectSettings_dialog.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include "rcbasic_edit_projectSettings_dialog.h"
#include "rcbasic_edit_fileProperties_dialog.h"
rcbasic_edit_projectSettings_dialog::rcbasic_edit_projectSettings_dialog( wxWindow* parent )
:
rc_projectSettings_dialog( parent )
{
parent_frame = (rcbasic_edit_frame*)parent;
current_project = parent_frame->getActiveProject();
projectSettings_flag = PROJECT_SETTINGS_CANCEL;
if(!current_project)
{
Close();
}
new_project = new rcbasic_project();
new_project->copyFromProject(current_project);
m_projectName_textCtrl->SetValue(new_project->getName());
wxFileName ms_fname = new_project->getMainSource();
wxFileName ms_fname_rel = ms_fname;
ms_fname_rel.MakeRelativeTo(new_project->getLocation());
wxFileName ms_fname_abs = ms_fname;
ms_fname_abs.MakeAbsolute();
//m_mainSource_textCtrl->SetValue(ms_fname.GetFullPath());
//m_projectLocation_textCtrl->SetValue(new_project->getLocation());
m_author_textCtrl->SetValue(new_project->getAuthor());
m_website_textCtrl->SetValue(new_project->getWebsite());
m_description_textCtrl->SetValue(new_project->getDescription());
//wxListBox * m_files_listBox;
//wxCheckListBox m_mainSource_checkList;
//rcbasic_project project;
std::vector<rcbasic_project_node*> nodes = new_project->getSourceFiles();
wxString cwd = wxGetCwd();
wxSetWorkingDirectory(new_project->getLocation());
int ms_index = 0;
for(int i = 0; i < nodes.size(); i++)
{
if(!nodes[i])
continue;
wxFileName tmp = nodes[i]->getPath();
switch(nodes[i]->getLocationStoreType())
{
case STORE_LOCATION_RELATIVE:
tmp.MakeRelativeTo(new_project->getLocation());
break;
case STORE_LOCATION_ABSOLUTE:
tmp.MakeAbsolute();
break;
}
m_files_listBox->AppendAndEnsureVisible(tmp.GetFullPath());
m_mainSource_listBox->AppendAndEnsureVisible(tmp.GetFullPath());
}
for(int i = 0; i < m_mainSource_listBox->GetCount(); i++)
{
if(m_mainSource_listBox->GetString(i).compare(ms_fname_rel.GetFullPath()) == 0 || m_mainSource_listBox->GetString(i).compare(ms_fname_abs.GetFullPath()) == 0)
{
//wxPuts(_("FOIND: ")+ m_mainSource_listBox->GetString(i));
m_mainSource_listBox->SetSelection(i);
m_mainSource_textCtrl->SetValue(m_mainSource_listBox->GetString(i));
break;
}
}
wxSetWorkingDirectory(cwd);
}
void rcbasic_edit_projectSettings_dialog::onCancelButtonClick( wxCommandEvent& event )
{
// TODO: Implement onCancelButtonClick
new_project->setPointersNull();
if(new_project)
delete new_project;
//wxPuts(_("THE END"));
Close();
}
void rcbasic_edit_projectSettings_dialog::onOKButtonClick( wxCommandEvent& event )
{
// TODO: Implement onOKButtonClick
wxString project_name = m_projectName_textCtrl->GetValue();
wxString mainSource = m_mainSource_textCtrl->GetValue();
wxString author = m_author_textCtrl->GetValue();
wxString website = m_website_textCtrl->GetValue();
wxString description = m_description_textCtrl->GetValue();
wxString cwd = wxGetCwd();
wxSetWorkingDirectory(new_project->getLocation());
wxFileName mainSource_fname(mainSource);
if(!mainSource_fname.Exists())
{
wxMessageBox(_("Main Source cannot be set. Cannot find [") + mainSource + _("]"));
wxSetWorkingDirectory(cwd);
return;
}
//wxPuts(_("--------------"));
for(int i = 0; i < new_project->getSourceFiles().size(); i++)
{
rcbasic_project_node* node = new_project->getSourceFiles()[i];
node->setAsTemp(false);
}
//wxPrintf(_("SOURCE SIZE: %d\n\n"), new_project->getSourceFiles().size());
wxSetWorkingDirectory(cwd);
new_project->setName(project_name);
new_project->setMainSource(mainSource_fname.GetFullPath());
new_project->setAuthor(author);
new_project->setWebsite(website);
new_project->setDescription(description);
int i = parent_frame->getProjectFromRoot(new_project->getRootNode());
if(i >= 0 && current_project != NULL)
{
current_project->setPointersNull();
delete current_project;
current_project = NULL;
parent_frame->setOpenProject(i, new_project);
}
projectSettings_flag = PROJECT_SETTINGS_OK;
Close();
}
void rcbasic_edit_projectSettings_dialog::onFileSelection( wxCommandEvent& event )
{
// TODO: Implement onFileSelection
//NOTE: Probably won't be doing anything with this event but I am too lazy to remove it
}
void rcbasic_edit_projectSettings_dialog::onAddFilesButtonClick( wxCommandEvent& event )
{
// TODO: Implement onAddFilesButtonClick
if(!new_project)
return;
wxArrayString sourceFiles = parent_frame->openMultiFileDialog( _("Open RCBasic Source file"), _("RCBasic Source files (*.bas)|*.bas"), wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_MULTIPLE);
for(int i = 0; i < sourceFiles.size(); i++)
{
wxFileName fname(sourceFiles[i]);
if(!fname.Exists())
continue;
fname.MakeRelativeTo(new_project->getLocation());
if(new_project->addSourceFile(fname.GetFullPath(), STORE_LOCATION_RELATIVE, false))
{
m_files_listBox->AppendAndEnsureVisible(fname.GetFullPath());
m_mainSource_listBox->AppendAndEnsureVisible(fname.GetFullPath());
}
}
}
void rcbasic_edit_projectSettings_dialog::onRemoveSelectedButtonClick( wxCommandEvent& event )
{
// TODO: Implement onRemoveSelectedButtonClick
//wxListBox m_files_listBox;
int selected_item = m_files_listBox->GetSelection();
//wxPrintf(_("i = %d\n"), i);
if(selected_item < 0)
return;
//wxFileName main_source = project->getMainSource();
//main_source.MakeRelativeTo(project->getLocation());
if(m_files_listBox->GetString(selected_item).compare(m_mainSource_textCtrl->GetValue())==0)
{
wxMessageBox(_("Cannot remove \"") + m_mainSource_textCtrl->GetValue() + _("\" while it is set as main source."));
return;
}
//wxListBox m_files_listbox;
std::vector<rcbasic_project_node*> nodes = new_project->getSourceFiles();
for(int i = 0; i < new_project->getSourceFiles().size(); i++)
{
rcbasic_project_node* node = nodes[i];
wxFileName fname_rel = node->getPath();
wxFileName fname_abs = node->getPath();
fname_rel.MakeRelativeTo(new_project->getLocation());
fname_abs.MakeAbsolute();
if(fname_rel.GetFullPath().compare(m_files_listBox->GetString(selected_item))==0 ||
fname_abs.GetFullPath().compare(m_files_listBox->GetString(selected_item))==0)
{
new_project->removeSourceFile(node->getPath().GetFullPath());
//node->setAsAddFile(false);
//wxPrintf(_("SET NODE to remove: [%d] ")+ m_files_listBox->GetString(selected_item) +_("\n"), node->getAddRemoveFlag());
//removed_files.push_back(node);
//break;
}
}
//removed_files.push_back(m_files_listBox->GetString(selected_item));
m_files_listBox->Delete(selected_item);
m_mainSource_listBox->Delete(selected_item);
}
void rcbasic_edit_projectSettings_dialog::onFilePropertiesButtonClick( wxCommandEvent& event )
{
openProperties();
}
void rcbasic_edit_projectSettings_dialog::openProperties()
{
// TODO: Implement onFilePropertiesButtonClick
if(m_files_listBox->GetSelection()<0)
return;
int selected_item = m_files_listBox->GetSelection();
rcbasic_project_node* f_node;
for(int i = 0; i < new_project->getSourceFiles().size(); i++)
{
f_node = new_project->getSourceFiles()[i];
wxFileName fname(f_node->getPath().GetFullPath());
if(f_node->getLocationStoreType()==STORE_LOCATION_RELATIVE)
fname.MakeRelativeTo(new_project->getLocation());
else
fname.MakeAbsolute();
//wxPuts(_("Compare1: ") + fname.GetFullPath() );
//wxPuts(_("Compare2: ") + m_files_listBox->GetString(selected_item));
if(fname.GetFullPath().compare(m_files_listBox->GetString(selected_item))==0)
break;
f_node = NULL;
}
if(!f_node)
{
//wxPuts(_("Could not find file node"));
return;
}
rcbasic_edit_fileProperties_dialog fp_dialog(this, f_node);
fp_dialog.ShowModal();
wxFileName node_fname = f_node->getPath();
if(f_node->getLocationStoreType()==STORE_LOCATION_RELATIVE)
node_fname.MakeRelativeTo(new_project->getLocation());
else
node_fname.MakeAbsolute();
m_files_listBox->SetString(selected_item, node_fname.GetFullPath());
m_mainSource_listBox->SetString(selected_item, node_fname.GetFullPath());
wxFileName node_fname_rel = node_fname;
node_fname_rel.MakeRelativeTo(new_project->getLocation());
wxFileName node_fname_abs = node_fname;
node_fname_abs.MakeAbsolute();
if(node_fname.GetFullPath().compare(m_mainSource_textCtrl->GetValue())==0 ||
node_fname_rel.GetFullPath().compare(m_mainSource_textCtrl->GetValue())==0 ||
node_fname_abs.GetFullPath().compare(m_mainSource_textCtrl->GetValue())==0)
{
m_mainSource_textCtrl->SetValue(node_fname.GetFullPath());
}
}
void rcbasic_edit_projectSettings_dialog::onMainSourceListBoxSelection( wxCommandEvent& event )
{
// TODO: Implement onMainSourceListBoxSelection
//wxListBox m_mainSource_listBox;
int selected_item = event.GetSelection();
if(selected_item < 0)
return;
m_mainSource_textCtrl->SetValue(m_mainSource_listBox->GetString(selected_item));
}
void rcbasic_edit_projectSettings_dialog::onFileDoubleClick( wxCommandEvent& event )
{
// TODO: Implement onFileDoubleClick
openProperties();
}