2022-04-08 17:22:24 +08:00
|
|
|
#include "newprojectunitdialog.h"
|
|
|
|
#include "ui_newprojectunitdialog.h"
|
|
|
|
#include "../iconsmanager.h"
|
|
|
|
#include "../utils.h"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
NewProjectUnitDialog::NewProjectUnitDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::NewProjectUnitDialog),
|
|
|
|
mSuffix("cpp")
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
onUpdateIcons();
|
|
|
|
connect(pIconsManager,&IconsManager::actionIconsUpdated,
|
|
|
|
this, &NewProjectUnitDialog::onUpdateIcons);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewProjectUnitDialog::~NewProjectUnitDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString NewProjectUnitDialog::folder() const
|
|
|
|
{
|
|
|
|
return ui->txtFolder->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::setFolder(const QString &folderName)
|
|
|
|
{
|
|
|
|
if (folderName!=folder()) {
|
|
|
|
ui->txtFolder->setText(folderName);
|
|
|
|
QDir dir(folder());
|
2022-04-08 18:12:40 +08:00
|
|
|
if (filename().isEmpty() || dir.exists(filename())) {
|
2022-04-08 17:22:24 +08:00
|
|
|
//todo change filename
|
|
|
|
QString newFileName;
|
|
|
|
QString ext;
|
|
|
|
if (filename().isEmpty()) {
|
|
|
|
ext = mSuffix;
|
|
|
|
} else {
|
|
|
|
ext = QFileInfo(filename()).suffix();
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber());
|
|
|
|
if (!ext.isEmpty())
|
|
|
|
newFileName += "." + ext;
|
|
|
|
} while (dir.exists(newFileName));
|
|
|
|
setFilename(newFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:12:40 +08:00
|
|
|
QString NewProjectUnitDialog::filename() const
|
|
|
|
{
|
|
|
|
return ui->txtFilename->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::setFilename(const QString &filename)
|
|
|
|
{
|
|
|
|
ui->txtFilename->setText(filename);
|
|
|
|
}
|
|
|
|
|
2022-04-08 17:22:24 +08:00
|
|
|
void NewProjectUnitDialog::onUpdateIcons()
|
|
|
|
{
|
|
|
|
pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::on_btnBrowse_clicked()
|
|
|
|
{
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(
|
|
|
|
this,
|
|
|
|
tr("Choose directory"),
|
|
|
|
folder()
|
|
|
|
);
|
|
|
|
if (!dir.isEmpty()) {
|
|
|
|
setFolder(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::on_btnOk_clicked()
|
|
|
|
{
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::on_btnCancel_clicked()
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::on_txtFilename_textChanged(const QString &/*arg1*/)
|
|
|
|
{
|
|
|
|
updateBtnOkStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewProjectUnitDialog::updateBtnOkStatus()
|
|
|
|
{
|
|
|
|
ui->btnOk->setEnabled(!ui->txtFilename->text().isEmpty()
|
|
|
|
&& QFileInfo(ui->txtFolder->text()).isDir());
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:12:40 +08:00
|
|
|
const QString &NewProjectUnitDialog::suffix() const
|
2022-04-08 17:22:24 +08:00
|
|
|
{
|
|
|
|
return mSuffix;
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:12:40 +08:00
|
|
|
void NewProjectUnitDialog::setSuffix(const QString &newSuffix)
|
2022-04-08 17:22:24 +08:00
|
|
|
{
|
|
|
|
mSuffix = newSuffix;
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:12:40 +08:00
|
|
|
void NewProjectUnitDialog::closeEvent(QCloseEvent */*event*/)
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
2022-04-08 17:22:24 +08:00
|
|
|
|
|
|
|
void NewProjectUnitDialog::on_txtFolder_textChanged(const QString &/*arg1*/)
|
|
|
|
{
|
|
|
|
updateBtnOkStatus();
|
|
|
|
}
|
|
|
|
|