From d45c0b87b38c266d1231d059e216afd4c2fc91df Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 15 Mar 2022 20:17:47 +0800 Subject: [PATCH] - fix: "ok" button should be disabled when no template selected in new project dialog - enhancement: auto add parentheis when complete function like MARCOs --- NEWS.md | 2 ++ RedPandaIDE/RedPandaIDE.pro | 1 + RedPandaIDE/editor.cpp | 11 +++++++++-- RedPandaIDE/project.cpp | 2 +- RedPandaIDE/projecttemplate.cpp | 10 ++++++---- RedPandaIDE/projecttemplates.qrc | 6 ++++++ .../resources}/templates/Empty.ico | Bin .../resources/templates/Empty.template | 6 +++--- RedPandaIDE/widgets/newprojectdialog.cpp | 16 +++++++++++++++- RedPandaIDE/widgets/newprojectdialog.h | 4 ++++ linux/templates/empty.ico | Bin 4286 -> 0 bytes linux/templates/empty.template | 17 ----------------- 12 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 RedPandaIDE/projecttemplates.qrc rename {windows => RedPandaIDE/resources}/templates/Empty.ico (100%) rename windows/templates/5-Empty.template => RedPandaIDE/resources/templates/Empty.template (81%) delete mode 100644 linux/templates/empty.ico delete mode 100644 linux/templates/empty.template 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 b41b95cff98de368e922083427797994ba9ea523..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmchaFKpXD6vnUWq{0PFV{6$m77Yb$3M^}3s9~U?K|9INFfgDbQa}R@O*57;!_dIM zNCUmS-^DMzoMI>Lq+a#mjBHQhD-$nZUzFjO9mZBVby`EjK*G`B-E2-w`{5p-# ztP6gg=X-283Gd@WYo2IEvlV*wI*k&@WCvhH0yr= z`LL$e;eyTBWB!wmoBfh_mBN9w@pV3*6YhF^IH<_n zI!wQPk5}!Dv-PZqZi5d`m9{+Kbik$ZpFKI{zm8GtP`5c78XLG!=dM15&$zAZONblV zZ;FY;;S@d`DIs2+-G;|f&i^TV`nA+y*0rC*? z3GolOczF?G9sq6iqV-#O?i0Rv`jolP~IO^I)e4bBsn5DEw z$=H1}SVPAsZm4}+t#c2Zk1rU4pUWE&PHVv&#)-U}3%3UNehKk?n{n90ju`OPZuJM$i{}?uXq5p1tzVlx>(bl#w7vc9&9X4xnCizXsS=s5_ zruo8-MyZ@ZxdV#az1iq%EADsKk(m3wuqJ22mr@RWG?q7Fl-Ya9{c+ImkFBfYkKSoM zo?m}7=2GNB_0z6?@npW=JeqHJqVMRZy-8-$k33g0`ye)Q_4sRc^;h)ErO5Bu$Cp3P N4=-P2%^xBU{{StjsdxYY 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