From 6016065b5875c17b1fd35fcba1ca3838f6495a58 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 8 Oct 2023 19:58:04 +0800 Subject: [PATCH] - enhancement: When creating project, warn user if the project folder is not empty. --- Contributors.md | 4 +- NEWS.md | 2 + RedPandaIDE/mainwindow.cpp | 16 +- RedPandaIDE/project.cpp | 39 +-- RedPandaIDE/projecttemplate.cpp | 2 +- RedPandaIDE/projecttemplate.h | 1 + .../resources/templates/empty.template | 4 - RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 12 + RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 287 ++++++++++-------- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 12 + 10 files changed, 224 insertions(+), 155 deletions(-) diff --git a/Contributors.md b/Contributors.md index c08fe391..009baa06 100644 --- a/Contributors.md +++ b/Contributors.md @@ -35,8 +35,8 @@ author: С ### Sea Lite -author: +author: PerryDing ### Ochre_Butter -author: +author: PerryDing diff --git a/NEWS.md b/NEWS.md index c324e44f..3b8bc546 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ Red Panda C++ Version 2.25 - change: Use freetype as the fontengine in windows ( from cyano.CN ) - fix: Custom compile options is not used when retrieve macros defined by the compiler. - fix: Processing for #if/#elif/#else is not correct. + - Change: Empty project template won't auto create main.c/main.cpp + - enhancement: When creating project, warn user if the project folder is not empty. Red Panda C++ Version 2.24 diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 4d11aed0..67b95e5d 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -7036,7 +7036,20 @@ void MainWindow::on_actionNew_Project_triggered() // if cbDefault.Checked then // devData.DefCpp := rbCpp.Checked; - + QDir projectDir = QDir(location); + if (!projectDir.isEmpty()) { + if (QMessageBox::question( + nullptr, + tr("Folder Not Empty"), + tr("The project folder is not empty, existing files may be overwritten.") + + "

" + +tr("Do you want to proceed?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No + ) == QMessageBox::No) { + return; + } + } s = includeTrailingPathDelimiter(location) + dialog.getProjectName() + "." + DEV_PROJECT_EXT; @@ -7060,6 +7073,7 @@ void MainWindow::on_actionNew_Project_triggered() tr("New project fail"), tr("Can't assign project template"), QMessageBox::Ok); + return; } mProject->saveAll(); updateProjectView(); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 3fa5190c..cdf273fd 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -92,13 +92,13 @@ std::shared_ptr Project::create( ini.SetValue("Project","filename", toByteArray(extractRelativePath(project->directory(), project->mFilename))); ini.SetValue("Project","name", toByteArray(project->mName)); - ini.SaveFile(project->mFilename.toLocal8Bit()); project->mParser->setEnabled(false); if (!project->assignTemplate(pTemplate,useCpp)) return std::shared_ptr(); resetCppParser(project->mParser, project->mOptions.compilerSet); project->mModified = true; + ini.SaveFile(project->mFilename.toLocal8Bit()); return project; } @@ -934,8 +934,9 @@ void Project::setCompilerSet(int compilerSetIndex) bool Project::assignTemplate(const std::shared_ptr aTemplate, bool useCpp) { if (!aTemplate) { - return true; + return false; } + mModel.beginUpdate(); mRootNode = makeProjectNode(); rebuildNodes(); @@ -974,10 +975,12 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b PProjectUnit unit; if (!templateUnit->Target.isEmpty()) target = templateUnit->Target; - QFile::copy( - cleanPath(dir.absoluteFilePath(templateUnit->Source)), - includeTrailingPathDelimiter(this->directory())+target); unit = newUnit(mRootNode, target); + if (templateUnit->overwrite || !fileExists(unit->fileName()) ) { + QFile::copy( + cleanPath(dir.absoluteFilePath(templateUnit->Source)), + includeTrailingPathDelimiter(this->directory())+target); + } FileType fileType=getFileType(unit->fileName()); if ( fileType==FileType::GAS @@ -1006,20 +1009,22 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b this, true); - QString s2 = cleanPath(dir.absoluteFilePath(s)); - if (fileExists(s2) && !s.isEmpty()) { - try { - editor->loadFile(s2); - } catch(FileError& e) { - QMessageBox::critical(nullptr, - tr("Error Load File"), - e.reason()); + if (templateUnit->overwrite || !fileExists(unit->fileName()) ) { + QString s2 = cleanPath(dir.absoluteFilePath(s)); + if (fileExists(s2) && !s.isEmpty()) { + try { + editor->loadFile(s2); + } catch(FileError& e) { + QMessageBox::critical(nullptr, + tr("Error Load File"), + e.reason()); + } + } else { + s.replace("#13#10","\r\n"); + editor->insertString(s,false); } - } else { - s.replace("#13#10","\r\n"); - editor->insertString(s,false); + editor->save(true,false); } - editor->save(true,false); editor->activate(); } } diff --git a/RedPandaIDE/projecttemplate.cpp b/RedPandaIDE/projecttemplate.cpp index 62acf0e3..4b9bdb3a 100644 --- a/RedPandaIDE/projecttemplate.cpp +++ b/RedPandaIDE/projecttemplate.cpp @@ -57,7 +57,7 @@ PTemplateUnit ProjectTemplate::unit(int index) if (unit->CppName.isEmpty()) unit->CppName = unit->CName; unit->Target = fromByteArray(mIni->GetValue(toByteArray(section), "Target", "")); - + unit->overwrite = mIni->GetBoolValue(toByteArray(section), "Overwrite", true); return unit; } diff --git a/RedPandaIDE/projecttemplate.h b/RedPandaIDE/projecttemplate.h index 69690ef8..75ad3efe 100644 --- a/RedPandaIDE/projecttemplate.h +++ b/RedPandaIDE/projecttemplate.h @@ -28,6 +28,7 @@ struct TemplateUnit { QString CppText; QString Source; QString Target; + bool overwrite; }; using PTemplateUnit = std::shared_ptr; diff --git a/RedPandaIDE/resources/templates/empty.template b/RedPandaIDE/resources/templates/empty.template index 5f83aa53..1029a68c 100644 --- a/RedPandaIDE/resources/templates/empty.template +++ b/RedPandaIDE/resources/templates/empty.template @@ -8,10 +8,6 @@ Description[zh_CN]=一个空项目 Category=Basic Category[zh_CN]=基础 -[Unit0] -CName=main.c -CppName=main.cpp - [Project] UnitCount=1 Type=1 diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 456901d3..9aec2cf7 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -5375,6 +5375,18 @@ Ignore spaces + + Folder Not Empty + + + + The project folder is not empty, existing files may be overwritten. + + + + Do you want to proceed? + + MemoryModel diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index b3cbcaf8..c74207a1 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -4453,7 +4453,7 @@ Are you really want to continue? - + Issues 编译器 @@ -4886,7 +4886,7 @@ Are you really want to continue? - + New Problem Set 新建试题集 @@ -4908,7 +4908,7 @@ Are you really want to continue? - + Save Problem Set 保存试题集 @@ -4916,7 +4916,7 @@ Are you really want to continue? - + Load Problem Set 载入试题集 @@ -5047,14 +5047,14 @@ Are you really want to continue? - + Import FPS Problem Set 导入FPS试题集 - + Export FPS Problem Set 导出FPS试题集 @@ -5710,7 +5710,7 @@ Are you really want to continue? - + Rename Symbol 重命名符号 @@ -5731,13 +5731,13 @@ Are you really want to continue? - + Export As RTF 导出为RTF - + Export As HTML 导出为HTML @@ -6295,22 +6295,22 @@ Are you really want to continue? 全部复制 - + Go to Line 跳转到行 - + Line - + Template Exists 模板已存在 - + Template %1 already exists. Do you want to overwrite? 模板%1已存在。是否覆盖? @@ -6336,7 +6336,7 @@ Are you really want to continue? - + Problem Set %1 试题集%1 @@ -6406,15 +6406,15 @@ Are you really want to continue? - - + + Bookmark Description 书签描述 - - + + Description: 描述: @@ -6636,7 +6636,7 @@ Are you really want to continue? - + Delete 删除 @@ -6731,12 +6731,27 @@ Are you really want to continue? 保存设置失败 - + + Folder Not Empty + 文件夹非空 + + + + The project folder is not empty, existing files may be overwritten. + 项目文件夹不是空的,已有的文件可能会被覆盖。 + + + + Do you want to proceed? + 您确定要继续吗? + + + Watchpoint variable name 被监控的变量 - + Stop execution when the following variable is modified (it must be visible from the currect scope): 当下面的变量被修改时暂停执行(该变量必须可以从当前程序处访问): @@ -6745,17 +6760,17 @@ Are you really want to continue? 中止 - + FPS Problem Set Files (*.fps;*.xml) FPS试题集文件(*.fps;*.xml) - + FPS Problem Set Files (*.fps) FPS试题集文件(*.fps) - + Export Error 导出时出错 @@ -6817,7 +6832,7 @@ Are you really want to continue? - + Do you want to save it? 需要保存吗? @@ -6829,15 +6844,15 @@ Are you really want to continue? - - + + New Project File? 新建项目文件? - - + + Do you want to add the new file to the project? 您是否要将新建的文件加入项目? @@ -6846,7 +6861,7 @@ Are you really want to continue? - + Save Error 保存失败 @@ -6930,33 +6945,33 @@ Are you really want to continue? 创建文件夹'%1'失败。 - + Save new project as - + Folder %1 is not empty. 文件夹%1不是空的。 - + Do you really want to delete it? 你真的要删除它吗? - + Change working folder 改变工作文件夹 - + File '%1' is not in the current working folder. File '%1' is not in the current working folder 文件'%1'不在当前工作文件夹中。 - + Do you want to change working folder to '%1'? 是否将工作文件夹改设为'%1'? @@ -6965,28 +6980,28 @@ Are you really want to continue? 正在删除试题... - + Can't Commit 无法提交 - + Git needs user info to commit. Git需要用信息进行提交。 - + Choose Input Data File 选择输入数据文件 - - + + All files (*.*) 所有文件 (*.*) - + Choose Expected Output Data File Choose Expected Input Data File 选择期望输出文件 @@ -6998,59 +7013,59 @@ Are you really want to continue? - + Choose Working Folder 选择工作文件夹 - - + + Header Exists 头文件已存在 - - + + Header file "%1" already exists! 头文件"%1"已存在! - + Source Exists 源文件已存在! - + Source file "%1" already exists! 源文件"%1"已存在! - + Can't commit! 无法提交! - + The following files are in conflicting: 下列文件处于冲突状态,请解决后重新添加和提交: - + Commit Message 提交信息 - + Commit Message: 提交信息: - + Commit Failed 提交失败 - + Commit message shouldn't be empty! 提交信息不能为空! @@ -7059,22 +7074,22 @@ Are you really want to continue? 小熊猫Dev-C++项目文件 (*.dev) - + New project fail 新建项目失败 - + Can't assign project template 无法使用模板创建项目 - + Remove file 删除文件 - + Remove the file from disk? 同时从硬盘上删除文件? @@ -7083,27 +7098,27 @@ Are you really want to continue? 无标题 - + New Project File Name 新的项目文件名 - + File Name: 文件名: - + File Already Exists! 文件已存在! - + File '%1' already exists! 文件'%1'已经存在! - + Add to project 添加到项目 @@ -7169,78 +7184,78 @@ Are you really want to continue? 请查看“工具输出”面板中的详细信息。 - + Red Panda C++ project file (*.dev) 小熊猫C++项目文件(*.dev) - + Rename Error 重命名出错 - + Symbol '%1' is defined in system header. 符号'%1'在系统头文件中定义,无法修改。 - + New Name 新名称 - - - - + + + + Replace Error 替换出错 - + Can't open file '%1' for replace! 无法打开文件'%1'进行替换! - + Contents has changed since last search! 内容和上次查找时不一致。 - + Rich Text Format Files (*.rtf) RTF格式文件 (*.rtf) - + HTML Files (*.html) HTML文件 (*.html) - + The current problem set is not empty. 当前的试题集不是空的。 - + Problem %1 试题%1 - - + + Problem Set Files (*.pbs) 试题集文件 (*.pbs) - - + + Load Error 载入失败 - + Problem Case %1 试题案例%1 @@ -7258,7 +7273,7 @@ Are you really want to continue? - + Error 错误 @@ -7332,7 +7347,7 @@ Are you really want to continue? - + Confirm Convertion 确认转换 @@ -7362,7 +7377,7 @@ Are you really want to continue? - + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? @@ -7835,105 +7850,117 @@ Are you really want to continue? 无法保存文件'%1'. - + Folder Not Empty + 文件夹非空 + + + The project folder is not empty, existing files may be overwritten. + 项目文件夹不是空的,已有的文件可能会被覆盖。 + + + Do you want to proceed? + 您确定要继续吗? + + + Error Load File 载入文件错误 - - + + Error 错误 - + Can't create folder %1 无法创建文件夹%1 - + Warning 警告 - - + + Can't save file %1 无法保存文件%1 - + File Exists 文件已存在 - + File '%1' is already in the project 文件'%1'已在项目中 - + Project Updated 项目已升级 - + Your project was succesfully updated to a newer file format! 已成功将项目升级到新的格式 - + If something has gone wrong, we kept a backup-file: '%1'... 旧项目文件备份在'%1'。 - + Headers 头文件 - + Sources 源文件 - + Others 其他文件 - + Settings need update 设置需要更新 - + The compiler settings format of Red Panda C++ has changed. The compiler settings format of Dev-C++ has changed. 小熊猫C++的编译器设置格式已发生改变。 - + Please update your settings at Project >> Project Options >> Compiler and save your project. 请在项目 >> 项目属性 >> 编译器设置中修改您的设置并保存您的项目 - + Compiler not found 未找到编译器 - + The compiler set you have selected for this project, no longer exists. 您为该项目设置的编译器不存在。 - + It will be substituted by the global compiler set. 它将会被全局编译器设置代替。 - + Developed using the Red Panda C++ IDE Developed using the Red Panda Dev-C++ IDE 使用小熊猫C++编辑器开发 @@ -8485,32 +8512,32 @@ Are you really want to continue? ProjectModel - + File exists 文件已存在 - + File '%1' already exists. Delete it now? 文件'%1'已存在。是否删除? - + Remove failed 删除失败 - + Failed to remove file '%1' 无法删除文件'%1' - + Rename failed 改名失败 - + Failed to rename file '%1' to '%2' 无法将文件'%1'改名为'%2' @@ -8967,7 +8994,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -9178,7 +9205,7 @@ Are you really want to continue? 只生成汇编代码(-S) - + Confirm 确认 @@ -9199,13 +9226,13 @@ Are you really want to continue? 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -9574,7 +9601,7 @@ Are you really want to continue? - + Can't open file '%1' for read. @@ -10588,12 +10615,12 @@ Are you really want to continue? Settings - + Error 错误 - + Can't find terminal program! 找不到合适的终端程序! @@ -10792,8 +10819,8 @@ Are you really want to continue? - - + + Compiler Set @@ -10801,7 +10828,7 @@ Are you really want to continue? - + Compiler @@ -10813,7 +10840,7 @@ Are you really want to continue? 自动链接 - + @@ -10889,15 +10916,15 @@ Are you really want to continue? 杂项 - - + + Program Runner 程序运行 - + Problem Set 试题集 @@ -10957,7 +10984,7 @@ Are you really want to continue? - + diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index 414bbe66..462425c4 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -5096,6 +5096,18 @@ Ignore spaces + + Folder Not Empty + + + + The project folder is not empty, existing files may be overwritten. + + + + Do you want to proceed? + + MemoryModel