-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectexplorer.cpp
More file actions
174 lines (155 loc) · 5.22 KB
/
projectexplorer.cpp
File metadata and controls
174 lines (155 loc) · 5.22 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
#include "projectexplorer.h"
#include "ui_projectexplorer.h"
#include <QTreeWidgetItem>
#include <QDir>
#include <QFileInfo>
#include <aide.h>
ProjectExplorer::ProjectExplorer(QWidget *parent) :
QDockWidget(parent), ui(new Ui::ProjectExplorer),mCurrentProject(0), mFilterIcon(":/images/images/Open.png")
{
ui->setupUi(this);
setGeometry(0,0,260,1080);
setStyleSheet(
"QDockWidget::title{ position: absolute; padding-left: 3px;text-align: center; background-color: blue; border: 2px solid black; }"
"QDockWidget { color: yellow; font bold 20px; border: 2px solid black; }"
); // set the dock widget title style
setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); // Set this dock widget for only left and ride sides
mProjectMenu = new QMenu("ProjectMenu",ui->TreeWidget);
QAction * new_file = mProjectMenu->addAction("Add New File");
QAction * add_file = mProjectMenu->addAction("Add Existing File");
connect(ui->TreeWidget,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(openContextMenu(QPoint)));
}
FileInfo ProjectExplorer::addFile(QString filepath, QString type)
{
QFileInfo info(filepath);
FileInfo fileinfo;
fileinfo.mRelativePath = fileinfo.mPath = info.absolutePath();
fileinfo.mDir = info.dir().dirName();
fileinfo.mFilename = info.completeBaseName() + '.' + info.completeSuffix();
fileinfo.mType = type;
QString project_path = ((Aide*)this->parent())->getProject(mCurrentProject)->filePath();
fileinfo.mRelativePath.remove(/*project_path*/ "/home/christopher/Qt_Projects/AIDE-build-Desktop-Debug");
int filters = ui->TreeWidget->topLevelItemCount();
QTreeWidgetItem * child;
bool TYPEFOUND = false;
int found_at = 0;
QTreeWidgetItem * parent = 0;
for (int index = 0; index < filters; index ++)
{
QTreeWidgetItem * item = ui->TreeWidget->topLevelItem(index);
if(item)
{
if(type == item->text(0))
{
TYPEFOUND = true;
found_at = index;
parent = item;
}
}
}
if(TYPEFOUND)
{
int items = parent->childCount();
bool NOTINSERTED = true;
int i = 0;
child = new QTreeWidgetItem(found_at);
child->setText(0,fileinfo.mFilename);
if(items > 0)
{
while(NOTINSERTED)
{
if(fileinfo.mFilename.compare(parent->child(i)->text(0)) >= 0)
{
parent->insertChild(i,child);
NOTINSERTED = false;
}
else
{
i ++;
if(i == items)
{
parent->insertChild(i,child);
NOTINSERTED = false;
}
}
}
}
else
{
parent->insertChild(0,child);
}
}
else
{
QTreeWidgetItem * parent = new QTreeWidgetItem(ui->TreeWidget->topLevelItemCount());
parent->setText(0,fileinfo.mType);
parent->setIcon(0,mFilterIcon);
ui->TreeWidget->addTopLevelItem(parent);
child = new QTreeWidgetItem(0);
child->setText(0,fileinfo.mFilename);
parent->insertChild(0,child);
}
QString iconpath = getIcon(fileinfo);
QPixmap icon(QDir::currentPath()+iconpath);
child->setIcon(0,icon);
return fileinfo;
}
void ProjectExplorer::addFilter(QString filter)
{
QTreeWidgetItem * treewidgetitem = new QTreeWidgetItem(ui->TreeWidget->topLevelItemCount()-1);
treewidgetitem->setText(0,filter);
treewidgetitem->setIcon(0,mFilterIcon);
ui->TreeWidget->addTopLevelItem(treewidgetitem);
}
void ProjectExplorer::addProject(QString name)
{
ui->ProjectSelector->addItem(name);
mCurrentProject = ui->ProjectSelector->count()-1;
ui->ProjectSelector->setCurrentIndex(mCurrentProject);
}
void ProjectExplorer::createEmptyProject()
{
QTreeWidgetItem * codeptr = new QTreeWidgetItem(0);
QTreeWidgetItem * otherptr = new QTreeWidgetItem(1);
codeptr->setText(0,"Code");
otherptr->setText(0,"Other");
codeptr->setIcon(0,mFilterIcon);
otherptr->setIcon(0,mFilterIcon);
ui->TreeWidget->addTopLevelItem(codeptr);
ui->TreeWidget->addTopLevelItem(otherptr);
}
void ProjectExplorer::fillTreeWidget(ProjectFile *project)
{
QStringList & filters = project->Filters();
foreach(QString filter, filters)
{
addFilter(filter);
}
QList<FileInfo *> & files = project->Files();
foreach(FileInfo * file, files)
{
addFile((file->mPath+file->mFilename),file->mType);
}
}
QString ProjectExplorer::getIcon(FileInfo fileinfo)
{
QString extension = fileinfo.mFilename.remove(0,fileinfo.mFilename.lastIndexOf(".")+1);
extension = extension.toLower();
extension += ".png";
return ("/images/files/" + extension);
}
void ProjectExplorer::openContextMenu(QPoint pos)
{
mProjectMenu->popup(ui->TreeWidget->mapToGlobal(pos));
}
void ProjectExplorer::openProject(ProjectFile * project_file)
{
}
void ProjectExplorer::setCurrentProject(int index)
{
}
ProjectExplorer::~ProjectExplorer()
{
delete ui;
delete mProjectMenu;
}