forked from QNnovation/ZBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbc_newfolder.cpp
61 lines (50 loc) · 2.18 KB
/
zbc_newfolder.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
#include "zbc_newfolder.h"
#include <QDialogButtonBox>
#include <QDir>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QVBoxLayout>
ZBC_NewFolder::ZBC_NewFolder(QString _curPath, QWidget* pwgt) : QDialog(pwgt)
{
QLabel* plblText = new QLabel("New folder(directory)", this);
QLineEdit* pledName = new QLineEdit(this);
pledName->setPlaceholderText("New Folder");
QDialogButtonBox* pdbbButtons = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel,
this);
QVBoxLayout* pLayout = new QVBoxLayout(this);
pLayout->addWidget(plblText);
pLayout->addWidget(pledName);
pLayout->addWidget(pdbbButtons);
this->setLayout(pLayout);
this->setAttribute(Qt::WA_DeleteOnClose);
this->setFixedSize(this->minimumSizeHint());
connect(pdbbButtons, &QDialogButtonBox::accepted,
[this, _curPath, pledName](){
QString sNewFolder;
if (pledName->text().isEmpty())
sNewFolder = _curPath + "New Folder";
else
sNewFolder = _curPath + pledName->text();
if (!QDir(sNewFolder).exists()){
if(!QDir("").mkdir(sNewFolder)){
QMessageBox errorMsg(QMessageBox::Critical,
QString("ZBC"),
QString("Eror creation of " + sNewFolder),
QMessageBox::Ok);
errorMsg.exec();
}
}
else{
QMessageBox errorMsg(QMessageBox::Critical,
QString("ZBC"),
QString("Directory " + sNewFolder + " exists"),
QMessageBox::Ok);
errorMsg.exec();
}
this->close();
}
);
connect(pdbbButtons, &QDialogButtonBox::rejected, [this](){ this->close(); });
}