diff --git a/NEWS.md b/NEWS.md index 5ff6f0af..1d5a67c8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,6 +23,8 @@ Red Panda C++ Version 1.0.0 - fix: error when insert text in column mode - fix: error when delete contents in column mode on lines that has wide-chars - fix: error when create folder in files view + - fix: "ok" button should be disabled when no template selected in new project dialog + - enhancement: auto add parentheis when complete function like MARCOs Red Panda C++ Version 0.14.5 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index c7bb5a63..a78d51d0 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -430,6 +430,7 @@ RESOURCES += \ codes.qrc \ defaultconfigs.qrc \ icons.qrc \ + projecttemplates.qrc \ translations.qrc RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index a9f4f372..5d75c88f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -319,7 +319,8 @@ bool Editor::saveAs(const QString &name, bool fromProject){ if (mInProject && pMainWindow->project() && !fromProject) { int unitIndex = pMainWindow->project()->indexInUnits(mFilename); if (unitIndex>=0) { - pMainWindow->project()->saveUnitAs(unitIndex,newName,false); + pMainWindow->project()->units()[unitIndex]->setEditor(nullptr); + mInProject = false; } } @@ -338,6 +339,9 @@ bool Editor::saveAs(const QString &name, bool fromProject){ exception.reason()); return false; } + if (pMainWindow->project() && !fromProject) { + pMainWindow->project()->associateEditor(this); + } pMainWindow->fileSystemWatcher()->addPath(mFilename); switch(getFileType(mFilename)) { case FileType::CppSource: @@ -3020,7 +3024,10 @@ void Editor::completionInsert(bool appendFunc) if (appendFunc) { if (statement->kind == StatementKind::skFunction || statement->kind == StatementKind::skConstructor - || statement->kind == StatementKind::skDestructor) { + || statement->kind == StatementKind::skDestructor + || + (statement->kind == StatementKind::skPreprocessor + && !statement->args.isEmpty())) { if ((p.Char >= lineText().length()) // it's the last char on line || (lineText().at(p.Char-1) != '(')) { // it don't have '(' after it if (statement->fullName!="std::endl") diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 2016532a..ac296fe3 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -696,7 +696,7 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b // Copy icon to project directory if (!mOptions.icon.isEmpty()) { - QString originIcon = QDir(pSettings->dirs().templateDir()).absoluteFilePath(mOptions.icon); + QString originIcon = QFileInfo(aTemplate->fileName()).absoluteDir().absoluteFilePath(mOptions.icon); if (fileExists(originIcon)) { QString destIcon = changeFileExt(mFilename,ICON_EXT); QFile::copy(originIcon,destIcon); diff --git a/RedPandaIDE/projecttemplate.cpp b/RedPandaIDE/projecttemplate.cpp index 88e53105..78582aec 100644 --- a/RedPandaIDE/projecttemplate.cpp +++ b/RedPandaIDE/projecttemplate.cpp @@ -81,10 +81,12 @@ void ProjectTemplate::readTemplateFile(const QString &fileName) { if (mIni) mIni=nullptr; - if (QFile(fileName).exists()) { + QFile file(fileName); + if (file.open(QFile::ReadOnly)) { mFileName = fileName; mIni = std::make_shared(); - if (mIni->LoadFile(mFileName.toLocal8Bit()) != SI_OK) { + QByteArray data = file.readAll(); + if (mIni->LoadData(data.toStdString()) != SI_OK) { QMessageBox::critical(pMainWindow, tr("Read failed."), tr("Can't read template file '%1'.").arg(fileName), @@ -93,8 +95,8 @@ void ProjectTemplate::readTemplateFile(const QString &fileName) } } else { QMessageBox::critical(pMainWindow, - tr("Template not exist"), - tr("Template file '%1' doesn't exist.").arg(fileName), + tr("Can't Open Template"), + tr("Can't open template file '%1' for read.").arg(fileName), QMessageBox::Ok); return; } diff --git a/RedPandaIDE/projecttemplates.qrc b/RedPandaIDE/projecttemplates.qrc new file mode 100644 index 00000000..7462ed20 --- /dev/null +++ b/RedPandaIDE/projecttemplates.qrc @@ -0,0 +1,6 @@ + + + resources/templates/empty.template + resources/templates/empty.ico + + diff --git a/windows/templates/Empty.ico b/RedPandaIDE/resources/templates/Empty.ico similarity index 100% rename from windows/templates/Empty.ico rename to RedPandaIDE/resources/templates/Empty.ico diff --git a/windows/templates/5-Empty.template b/RedPandaIDE/resources/templates/Empty.template similarity index 81% rename from windows/templates/5-Empty.template rename to RedPandaIDE/resources/templates/Empty.template index 7ff67157..5f83aa53 100644 --- a/windows/templates/5-Empty.template +++ b/RedPandaIDE/resources/templates/Empty.template @@ -2,15 +2,15 @@ ver=2 Name=Empty Project Name[zh_CN]=空项目 -Icon=Empty.ico +Icon=empty.ico Description=An empty project Description[zh_CN]=一个空项目 Category=Basic Category[zh_CN]=基础 [Unit0] -CName= -CppName= +CName=main.c +CppName=main.cpp [Project] UnitCount=1 diff --git a/RedPandaIDE/widgets/newprojectdialog.cpp b/RedPandaIDE/widgets/newprojectdialog.cpp index eb9441da..18767736 100644 --- a/RedPandaIDE/widgets/newprojectdialog.cpp +++ b/RedPandaIDE/widgets/newprojectdialog.cpp @@ -60,6 +60,7 @@ NewProjectDialog::NewProjectDialog(QWidget *parent) : &QLineEdit::textChanged, this, &NewProjectDialog::updateProjectLocation); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } NewProjectDialog::~NewProjectDialog() @@ -117,6 +118,7 @@ void NewProjectDialog::addTemplate(const QString &filename) void NewProjectDialog::readTemplateDir() { + addTemplate(":/templates/empty.template"); QString templateExt("."); templateExt += TEMPLATE_EXT; QDir dir(pSettings->dirs().templateDir()); @@ -165,7 +167,7 @@ void NewProjectDialog::updateView() QString tabText = mTemplatesTabBar->tabText(index); if (category == tabText) { QListWidgetItem * item; - QString iconFilename = QDir(pSettings->dirs().templateDir()).absoluteFilePath(t->icon()); + QString iconFilename = QFileInfo(t->fileName()).absoluteDir().absoluteFilePath(t->icon()); QIcon icon=QIcon(iconFilename); if (icon.isNull()) { //todo : use an default icon @@ -257,3 +259,15 @@ void NewProjectDialog::updateIcons() pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER); } + +void NewProjectDialog::on_btnOk_clicked() +{ + accept(); +} + + +void NewProjectDialog::on_btnCancel_clicked() +{ + reject(); +} + diff --git a/RedPandaIDE/widgets/newprojectdialog.h b/RedPandaIDE/widgets/newprojectdialog.h index 1e4ef016..801a3d3e 100644 --- a/RedPandaIDE/widgets/newprojectdialog.h +++ b/RedPandaIDE/widgets/newprojectdialog.h @@ -49,6 +49,10 @@ private slots: void on_btnBrowse_clicked(); void updateIcons(); + void on_btnOk_clicked(); + + void on_btnCancel_clicked(); + private: void addTemplate(const QString& filename); void readTemplateDir(); diff --git a/linux/templates/empty.ico b/linux/templates/empty.ico deleted file mode 100644 index b41b95cf..00000000 Binary files a/linux/templates/empty.ico and /dev/null differ diff --git a/linux/templates/empty.template b/linux/templates/empty.template deleted file mode 100644 index c7073c2e..00000000 --- a/linux/templates/empty.template +++ /dev/null @@ -1,17 +0,0 @@ -[Template] -ver=2 -Name=Empty Project -Name[zh_CN]=空项目 -Icon=empty.ico -Description=An empty project -Description[zh_CN]=空项目 -Category=Basic -Category[zh_CN]=基础 - -[Unit0] -CName= -CppName= - -[Project] -UnitCount=1 -Type=1