-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewdialog.cpp
More file actions
167 lines (150 loc) · 6.89 KB
/
newdialog.cpp
File metadata and controls
167 lines (150 loc) · 6.89 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
#include "newdialog.h"
#include "ui_newdialog.h"
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QItemSelectionModel>
#include <QRect>
#include <QObjectList>
#include <QFileDialog>
#include <aide.h>
NewDialog::NewDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewDialog)
{
ui->setupUi(this);
connect(ui->CancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->CreateButton, SIGNAL(clicked()), this, SLOT(create()));
connect(this,SIGNAL(newFileCreated(QString)),(Aide*)parent,SLOT(createFile(QString)));
connect(ui->ProjectTree, SIGNAL(clicked(QModelIndex)), this, SLOT(selectProject()));
connect(ui->FileTree, SIGNAL(clicked(QModelIndex)), this, SLOT(selectFile()));
connect(ui->FileTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this,SLOT(setDescription(QTreeWidgetItem*,QTreeWidgetItem*)));
connect(ui->ProjectTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this,SLOT(setDescription(QTreeWidgetItem*,QTreeWidgetItem*)));
connect(ui->NextButton,SIGNAL(clicked()), this, SLOT(nextPage()));
connect(ui->BackButton,SIGNAL(clicked()), this, SLOT(prevPage()));
connect(ui->BrowseButton,SIGNAL(clicked()),this,SLOT(getDirectory()));
QTreeWidget * tmpTree = ui->ProjectTree;
int itemTopCount = 0;
tmpTree->addTopLevelItem(new QTreeWidgetItem(QStringList("Assembly"),itemTopCount++));
tmpTree->addTopLevelItem(new QTreeWidgetItem(QStringList("C Project"),itemTopCount++));
tmpTree->addTopLevelItem(new QTreeWidgetItem(QStringList("C++ Project"),itemTopCount++));
tmpTree->addTopLevelItem(new QTreeWidgetItem(QStringList("Empty Project"),itemTopCount++));
tmpTree = ui->FileTree;
int filecount = itemTopCount;
QTreeWidgetItem * tmpParent = new QTreeWidgetItem(QStringList("Code"),-1);
tmpParent->addChild(new QTreeWidgetItem(QStringList("Assembly (.asm)"), filecount++));
tmpParent->addChild( new QTreeWidgetItem(QStringList("C Document (.c)"),filecount++));
tmpParent->addChild( new QTreeWidgetItem(QStringList("C++ Document (.cpp)"),filecount++));
tmpTree->addTopLevelItem(tmpParent);
tmpTree->addTopLevelItem(new QTreeWidgetItem(QStringList("Other"),filecount));
ui->ExtensionFrame->hide();
}
NewDialog::~NewDialog()
{
delete ui;
}
void NewDialog::create()
{
QTreeWidgetItem * currentItem = ui->FileTree->currentItem();
if(currentItem->type() == -1)
return;
else
if(currentItem->type() >= ui->ProjectTree->topLevelItemCount())
{
QString ext;
if(currentItem->text(0) == "Other")
{
ext = ui->ExtensionEdit->text();
}
else
{
ext = currentItem->text(0);
}
ext = ext.section("",(ext.indexOf('.')+1),ext.indexOf(')'));
QString filepath = ui->LocationEdit->text();
QString filename = ui->NameEdit->text();
if(!filepath.endsWith('/'))
filepath += '/';
filepath += filename;
filepath += ext;
emit newFileCreated(filepath);
}
close();
}
void NewDialog::getDirectory()
{
QString filepath = QFileDialog::getExistingDirectory(this,"Location to create Project/File",QDir::currentPath());
if(filepath != "")
{
ui->LocationEdit->setText(filepath);
}
}
void NewDialog::open()
{
ui->StackedWidget->setCurrentIndex(0);
this->show();
}
void NewDialog::nextPage()
{
ui->StackedWidget->setCurrentIndex(ui->StackedWidget->currentIndex() > ui->StackedWidget->count() ? (ui->StackedWidget->count() -1) : (ui->StackedWidget->currentIndex() +1));
}
void NewDialog::prevPage()
{
ui->StackedWidget->setCurrentIndex(ui->StackedWidget->currentIndex() > 0 ? (ui->StackedWidget->currentIndex() -1) : 0);
}
void NewDialog::selectProject()
{
QTreeWidgetItem * currentItem = ui->FileTree->currentItem();
if (currentItem)
currentItem->setSelected(false);
ui->ExtensionFrame->hide();
switch(ui->ProjectTree->currentItem()->type())
{
case 0:ui->DescripionLabel->setText("Description:\nCreates a new project with an assembly file as the\n entry to the program.");break;
case 1:ui->DescripionLabel->setText("Description:\nCreates a new project with a C file as the entry to\n the program.");break;
case 2:ui->DescripionLabel->setText("Description:\nCreates a new project with a C++ file as the entry\n to the program.");break;
case 3:ui->DescripionLabel->setText("Description:\nCreates a new empty project.");break;
default: ui->DescripionLabel->setText("Description:");break;
}
}
void NewDialog::selectFile()
{
if(ui->FileTree->currentItem()->type() != -1)
{
if(ui->ProjectTree->currentItem())
ui->ProjectTree->currentItem()->setSelected(false);
ui->ExtensionFrame->hide();
switch(ui->FileTree->currentItem()->type())
{
case 4:ui->DescripionLabel->setText("Description:\nCreates a new Assembly File with the extension .asm");break;
case 5:ui->DescripionLabel->setText("Description:\nCreates a new C File with the extension .c");break;
case 6:ui->DescripionLabel->setText("Description:\nCreates a new C++ File with the extension .cpp");break;
case 7:ui->DescripionLabel->setText("Description:\nCreates a new file with an optional user defined\n extension");ui->ExtensionFrame->show();break;
default: ui->DescripionLabel->setText("Description:");break;
}
}
else
ui->FileTree->currentItem()->setSelected(false);
}
void NewDialog::setDescription(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
if(current)
{
ui->ExtensionFrame->hide();
switch(current->type())
{
case 0:ui->DescripionLabel->setText("Description:\nCreates a new project with an assembly file as the\n entry to the program.");break;
case 1:ui->DescripionLabel->setText("Description:\nCreates a new project with a C file as the entry to\n the program.");break;
case 2:ui->DescripionLabel->setText("Description:\nCreates a new project with a C++ file as the entry\n to the program.");break;
case 3:ui->DescripionLabel->setText("Description:\nCreates a new empty project.");break;
case 4:ui->DescripionLabel->setText("Description:\nCreates a new Assembly File with the extension .asm");break;
case 5:ui->DescripionLabel->setText("Description:\nCreates a new C File with the extension .c");break;
case 6:ui->DescripionLabel->setText("Description:\nCreates a new C++ File with the extension .cpp");break;
case 7:ui->DescripionLabel->setText("Description:\nCreates a new file with an optional user defined\n extension");ui->ExtensionFrame->show();break;
default: ui->DescripionLabel->setText("Description:");break;
}
}
else
{
ui->DescripionLabel->setText("Description:");
}
}