-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaide.cpp
More file actions
320 lines (284 loc) · 9.72 KB
/
aide.cpp
File metadata and controls
320 lines (284 loc) · 9.72 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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include "aide.h"
#include "ui_aide.h"
#include <QDebug>
#include <QDir>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QFile>
#include <QFileDialog>
typedef QPair<QString, QStringList > Pair;
Aide::Aide(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::Aide), mProjectExplorer(new ProjectExplorer(this)),mEditor(new Editor(this)),
mBuildSystemPath("./data/bin/BuildSystem.exe")
{
// Load UI and configure embedded widgets
ui->setupUi(this);
mNewDialog = new NewDialog(this);
mBuildSystemProcess = new QProcess(this);
addDockWidget(Qt::LeftDockWidgetArea,mProjectExplorer,Qt::Vertical);
setCentralWidget(mEditor);
loadKnownFileTypes(); //load the known file types file Data/Startup/
Connections();
// For testing Save Project
ProjectFile * project = new ProjectFile("test.aid","/home/christopher/Desktop/AIDE/",this);
project->addFilter("Code");
project->addFilter("Other");
FileInfo * fileinfo = new FileInfo;
fileinfo->mPath = "FilePath";
fileinfo->mType = "Code";
fileinfo->mFilename = "file.code";
fileinfo->mBreakpoints.append(25);
fileinfo->mBreakpoints.append(26);
fileinfo->mBreakpoints.append(29);
fileinfo->mBreakpoints.append(231);
fileinfo->mBreakpoints.append(250);
fileinfo->mBreakpoints.append(252);
fileinfo->mDir = "AIDE";
fileinfo->mRelativePath = "/AIDE";
project->addFile(fileinfo);
addNewProject(project->name(),project->filePath(),project);
}
bool Aide::addNewProject(QString name, QString filepath, ProjectFile *newProject)
{
if(newProject) // If newProject is not NULL
{
mOpenProjects.append(newProject); // add it to open project list
mProjectExplorer->addProject(name);
mProjectExplorer->fillTreeWidget(newProject);
}
else
{
ProjectFile * ptr = new ProjectFile(name, filepath,this);
mProjectExplorer->addProject(name);
mProjectExplorer->createEmptyProject();
mOpenProjects.append(ptr); // add it to open project list
}
return newProject;
}
bool Aide::addFileToProject(int project_index, FileInfo *file)
{
int count = mOpenProjects.count();
if(project_index >= 0 && project_index < count)
{
ProjectFile * project = mOpenProjects.at(project_index);
project->addFile(file);
return true;
}
return false;
}
void Aide::Connections()
{
connect(ui->ActionExit,SIGNAL(triggered()),this,SLOT(close()));
connect(ui->ActionNew,SIGNAL(triggered()),mNewDialog, SLOT(open()));
connect(ui->ActionBuild_and_Run, SIGNAL(triggered()), this, SLOT(setRun()));
connect(ui->ActionBuild_and_Debug, SIGNAL(triggered()), this, SLOT(setDebug()));
connect(ui->ActionClean, SIGNAL(triggered()), this, SLOT(setClean()));
connect(ui->ActionReBuild, SIGNAL(triggered()), this, SLOT(setReBuild()));
QAction * new_file = mProjectExplorer->conextMenu()->actions()[0];
QAction * existing_file = mProjectExplorer->conextMenu()->actions()[1];
connect(existing_file,SIGNAL(triggered()),this,SLOT(createExisting()));
connect(new_file,SIGNAL(triggered()),mNewDialog,SLOT(open()));
connect(ui->ActionProject,SIGNAL(triggered()),this,SLOT(saveProject()));
}
void Aide::createExisting()
{
QString file = QFileDialog::getOpenFileName(this,"Add Existing File to Project",QDir::currentPath());
if(file != "")
{
createFile(file);
}
}
void Aide::createFile(QString filepath)
{
qDebug() << "Creating file at:" << filepath;
//type = getFiletype(filepath);
FileInfo * file_info = new FileInfo;
QString filter = getFilter(QString(filepath));
FileInfo info = mProjectExplorer->addFile(filepath, filter);
file_info->mDir = info.mDir;
file_info->mFilename = info.mFilename;
file_info->mPath = info.mPath;
file_info->mType = info.mType;
ProjectFile * current_project = mOpenProjects.at(mProjectExplorer->currentProject());
current_project->addFile(file_info);
}
void Aide::createProject(QString projectPath)
{
// int current_project = mProjectExplorer
}
QString Aide::getFilter(QString filepath)
{
QString exit_str;
bool FOUND = false;
QString ext = filepath.remove(0,filepath.lastIndexOf('.')+1);
foreach (Pair filter, mKnownFileTypes) //Pair is a typdef see top of file
{
foreach (QString type, filter.second)
{
if(type == ext)
{
exit_str = filter.first;
FOUND = true;
break;
}
}
if(FOUND)
break;
}
return exit_str;
}
ProjectFile * Aide::getProject(int project_index)
{
return mOpenProjects.at(project_index);
}
void Aide::writeKnownFileTypes()
{
QFile output(QDir::currentPath() + "/data/startup/known_types.conf");
QString data;
QXmlStreamWriter writer(&data);
writer.setAutoFormatting(true);
writer.setAutoFormattingIndent(true);
writer.writeStartDocument();
writer.writeStartElement("known_types.conf");
writer.writeAttribute("Purpose", "Define known filters and file types");
foreach (Pair filter, mKnownFileTypes) //Pair is a typdef see top of file
{
writer.writeStartElement("Filter");
writer.writeTextElement("Name",filter.first);
foreach (QString type, filter.second)
{
writer.writeTextElement("Type",type);
}
writer.writeEndElement();
}
writer.writeEndDocument();
output.open(QIODevice::WriteOnly);
output.write(data.toAscii());
output.flush();
output.close();
}
void Aide::loadKnownFileTypes()
{
QFile input(QDir::currentPath() + "/data/startup/known_types.conf");
input.open(QIODevice::ReadOnly);
QString file(input.readAll());
input.close();
QXmlStreamReader reader(file);
QXmlStreamReader::TokenType token;
QPair<QString,QStringList> current;
QString Filter;
QString Type;
QString Name;
QString * current_string;
while(!reader.atEnd())
{
token = reader.readNext();
switch(token)
{
case QXmlStreamReader::StartElement:
{
if(reader.name().toString() == "Name")
{
current.first = reader.text().toString();
current_string = ¤t.first;
}
else if( reader.name() == "Type")
{
current_string = &Name;
}
else
{
current_string = 0;
}
break;
}
case QXmlStreamReader::Characters:
{
Name = reader.name().toString();
if(current_string)
if(!reader.text().toString().contains('\n'))
{
if(current_string == ¤t.first)
*current_string = reader.text().toString();
else
current.second.append(reader.text().toString());
}
break;
}
case QXmlStreamReader::EndElement:
{
if(reader.name().toString() == "Filter")
{
mKnownFileTypes.append(QPair<QString,QStringList>(current));
current.second.clear();
}
break;
}
default: break;
}
}
}
void Aide::saveProject()
{
int current_project = mProjectExplorer->currentProject(); //Get the current project count
if(mOpenProjects.count() > current_project) //If the project is valid
{
ProjectFile * project = mOpenProjects.at(current_project); //Get the project file pointer
project->saveProject(); //Save its current state
}
}
void Aide::setDebug()
{
ProjectFile * project = mOpenProjects.at(mProjectExplorer->currentProject());
mBuildSystemArgs << "Build" << "Debug" << project->filePath();
startBuildSystem();
}
void Aide::setRun()
{
mBuildSystemArgs << "Run";
startBuildSystem();
}
void Aide::setClean()
{
mBuildSystemArgs << "Clean";
startBuildSystem();
}
void Aide::setReBuild()
{
mBuildSystemArgs << "Rebuild";
startBuildSystem();
}
void Aide::startBuildSystem()
{
// these args will be filled with:
// file_path (default 1st string)
// build_mode (defined 2nd string)
// run_mode (defined 3rd string)
// project_file (defined 3rd string)
// I can write a function to check these guys later ^^ (files)
mBuildSystemProcess->start(mBuildSystemPath,mBuildSystemArgs);
mBuildSystemProcess->setProcessChannelMode(QProcess::MergedChannels);
connect(mBuildSystemProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readBytes()));
}
//BUILDSYSTEM talks on 0/1
//QDEBUG talks on 2
void Aide::readBytes()
{
QString strin = mBuildSystemProcess->readAllStandardOutput();
qDebug() << strin;
}
Aide::~Aide()
{
// writeKnowFileTypes();
delete ui;
delete mEditor;
delete mProjectExplorer;
int length = mOpenProjects.length();
ProjectFile * ptr = 0;
for(int index = 0; index < length; index++)
{
ptr = mOpenProjects.at(index);
delete ptr;
}
}