diff --git a/NEWS.md b/NEWS.md index b9300a12..e67be16f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ Version 0.8.10 For Dev-C++ 7 Beta - fix: Shouldn't update auto link settings, if the header name to be modified is unchanged - fix: add unit to project not correctly set new unit file's encoding + - fix: correctly set encoding for the new added project unit file + - fix: if there's a project openned, new file should ask user if he want to add the new file to the project + - fix: when adding a file openned in the editor to the project, properties of it are not correctly setted. + - enhancement: when remove a file from the project, also ask if user want to remove it from disk + - fix: double click a project's .dev file in the Files panel should load the project Version 0.8.9 For Dev-C++ 7 Beta - fix: text color of labels in statusbar not correctly updated when change theme diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.qm b/RedPandaIDE/RedPandaIDE_zh_CN.qm index 0587e6c1..a8bb9e70 100644 Binary files a/RedPandaIDE/RedPandaIDE_zh_CN.qm and b/RedPandaIDE/RedPandaIDE_zh_CN.qm differ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts index 875cf2d7..0103efed 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -82,12 +82,12 @@ 链接参数 - + Header exists 头文件已存在 - + Header already exists. 头文件已存在。 @@ -2857,11 +2857,11 @@ Are you really want to continue? - - - - - + + + + + Issues 编译器 @@ -3269,7 +3269,7 @@ Are you really want to continue? - + New Problem Set 新建试题集 @@ -3288,14 +3288,14 @@ Are you really want to continue? - + Save Problem Set 保存试题集 - + Load Problem Set 载入试题集 @@ -3630,7 +3630,7 @@ Are you really want to continue? - + Clear all breakpoints 删除所有断点 @@ -3731,7 +3731,7 @@ Are you really want to continue? - + Rename Symbol 重命名符号 @@ -3752,13 +3752,13 @@ Are you really want to continue? - + Export As RTF 导出为RTF - + Export As HTML 导出为HTML @@ -3824,7 +3824,7 @@ Are you really want to continue? - + Open Folder 打开文件夹 @@ -4055,7 +4055,7 @@ Are you really want to continue? - + Problem Set %1 试题集%1 @@ -4122,15 +4122,15 @@ Are you really want to continue? - - + + Bookmark Description 书签描述 - - + + Description: 描述: @@ -4294,183 +4294,203 @@ Are you really want to continue? - + Do you want to save it? 需要保存吗? - - - - + + New Project File? + 新建项目文件? + + + + Do you want to add the new file to the project? + 您是否要将新建的文件加入项目? + + + + + + Save Error 保存失败 - + Change Project Compiler Set 改变项目编译器配置集 - + Change the project's compiler set will lose all custom compiler set options. 改变项目的编译器配置集会导致所有的自定义编译器选项被重置。 - + Do you really want to do that? 你真的想要做那些吗? - + Do you really want to clear all breakpoints in this file? 您真的要清除该文件的所有断点吗? - + New project 新建项目 - + Close %1 and start new project? 关闭'%1'以打开新项目? - + Folder not exist 文件夹不存在 - + Folder '%1' doesn't exist. Create it now? 文件夹'%1'不存在。是否创建? - + Can't create folder 无法创建文件夹 - + Failed to create folder '%1'. 创建文件夹'%1'失败。 - + Save new project as - + Red panda Dev-C++ project file (*.dev) 小熊猫Dev-C++项目文件 (*.dev) - + New project fail 新建项目失败 - + Can't assign project template 无法使用模板创建项目 - + + Remove file + 删除文件 + + + + Remove the file from disk? + 同时从硬盘上删除文件? + + + untitled 无标题 - + New Project File Name 新的项目文件名 - + File Name: 文件名: - + File Already Exists! 文件已存在! - + File '%1' already exists! 文件'%1'已经存在! - + Add to project 添加到项目 - + 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 @@ -4485,11 +4505,11 @@ Are you really want to continue? - - - - - + + + + + Error 错误 @@ -4519,55 +4539,55 @@ Are you really want to continue? 是否保持它在小熊猫C++中打开的编辑窗口? - + Open 打开 - + Compile Failed 编译失败 - + Run Failed 运行失败 - - + + Confirm Convertion 确认转换 - - + + 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 />你确定要继续吗? - + New Watch Expression 新监视表达式 - + Enter Watch Expression (it is recommended to use 'this->' for class members): 输入监视表达式 - + Parsing file %1 of %2: "%3" (%1/%2)正在解析文件"%3" - - + + Done parsing %1 files in %2 seconds 完成%1个文件的解析,用时%2秒 - + (%1 files per second) (每秒%1个文件) @@ -4695,77 +4715,77 @@ Are you really want to continue? 无标题 - + Can't save file 无法保存文件 - + Can't save file '%1' 无法保存文件'%1'. - + Error Load File 载入文件错误 - + 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'。 - + Settings need update 设置需要更新 - + The compiler settings format of Dev-C++ has changed. Dev-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 Dev-C++ IDE 使用小熊猫Dev-C++编辑器开发 @@ -5156,24 +5176,24 @@ 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' @@ -6483,7 +6503,7 @@ Are you really want to continue? 自动链接 - + @@ -6559,7 +6579,7 @@ Are you really want to continue? 杂项 - + Program Runner diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index abbce54d..58eb48a6 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3211,6 +3211,15 @@ CPUDialog *MainWindow::cpuDialog() const void MainWindow::on_actionNew_triggered() { + if (mProject) { + if (QMessageBox::question(this, + tr("New Project File?"), + tr("Do you want to add the new file to the project?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + newProjectUnitFile(); + return; + } + } newEditor(); } @@ -4654,46 +4663,7 @@ void MainWindow::on_actionSaveAll_triggered() void MainWindow::on_actionProject_New_File_triggered() { - int idx = -1; - if (!mProject) - return; - QModelIndex current = ui->projectView->currentIndex(); - FolderNode * node = nullptr; - if (current.isValid()) { - node = static_cast(current.internalPointer()); - } - QString newFileName; - do { - newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber()); - if (mProject->options().useGPP) { - newFileName+=".cpp"; - } else { - newFileName+=".c"; - } - } while (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))); - - newFileName = QInputDialog::getText( - this, - tr("New Project File Name"), - tr("File Name:"), - QLineEdit::Normal, - newFileName); - if (newFileName.isEmpty()) - return; - if (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))) { - QMessageBox::critical(this,tr("File Already Exists!"), - tr("File '%1' already exists!").arg(newFileName)); - return; - } - PProjectUnit newUnit = mProject->newUnit( - mProject->pointerToNode(node),newFileName); - idx = mProject->units().count()-1; - mProject->saveUnits(); - updateProjectView(); - Editor * editor = mProject->openUnit(idx); - //editor->setUseCppSyntax(mProject->options().useGPP); - //editor->setModified(true); - editor->activate(); + newProjectUnitFile(); } @@ -4742,9 +4712,14 @@ void MainWindow::on_actionRemove_from_project_triggered() continue; selected.insert(folderNode->unitIndex); }; + + bool removeFile = (QMessageBox::question(this,tr("Remove file"), + tr("Remove the file from disk?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes); + for (int i=mProject->units().count()-1;i>=0;i--) { if (selected.contains(i)) { - mProject->removeEditor(i,true); + mProject->removeUnit(i,true,removeFile); } } @@ -4952,6 +4927,50 @@ void MainWindow::prepareTabMessagesData() mTabMessagesData[widget]=info; } } + +void MainWindow::newProjectUnitFile() +{ + if (!mProject) + return; + int idx = -1; + QModelIndex current = ui->projectView->currentIndex(); + FolderNode * node = nullptr; + if (current.isValid()) { + node = static_cast(current.internalPointer()); + } + QString newFileName; + do { + newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber()); + if (mProject->options().useGPP) { + newFileName+=".cpp"; + } else { + newFileName+=".c"; + } + } while (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))); + + newFileName = QInputDialog::getText( + this, + tr("New Project File Name"), + tr("File Name:"), + QLineEdit::Normal, + newFileName); + if (newFileName.isEmpty()) + return; + if (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))) { + QMessageBox::critical(this,tr("File Already Exists!"), + tr("File '%1' already exists!").arg(newFileName)); + return; + } + PProjectUnit newUnit = mProject->newUnit( + mProject->pointerToNode(node),newFileName); + idx = mProject->units().count()-1; + mProject->saveUnits(); + updateProjectView(); + Editor * editor = mProject->openUnit(idx); + //editor->setUseCppSyntax(mProject->options().useGPP); + //editor->setModified(true); + editor->activate(); +} void MainWindow::on_EditorTabsLeft_currentChanged(int) { Editor * editor = mEditorList->getEditor(-1,ui->EditorTabsLeft); @@ -5383,9 +5402,10 @@ void MainWindow::on_treeFiles_doubleClicked(const QModelIndex &index) QString filepath = mFileSystemModel.filePath(index); QFileInfo file(filepath); if (file.isFile()) { - Editor * editor = mEditorList->getEditorByFilename(filepath); - if (editor) { - editor->activate(); + if (getFileType(filepath)==FileType::Project) { + openProject(filepath); + } else { + openFile(filepath); } } } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 03a9b403..c11f45b7 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -226,6 +226,7 @@ private: void showHideMessagesTab(QWidget *widget, bool show); void prepareTabInfosData(); void prepareTabMessagesData(); + void newProjectUnitFile(); private slots: void onAutoSaveTimeout(); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 507115f3..70747547 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 1 + 3 true diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index fc228a73..3e55b7a3 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -340,7 +340,7 @@ void Project::rebuildNodes() emit nodesChanged(); } -bool Project::removeEditor(int index, bool doClose) +bool Project::removeUnit(int index, bool doClose , bool removeFile) { mModel.beginUpdate(); auto action = finally([this]{ @@ -357,6 +357,10 @@ bool Project::removeEditor(int index, bool doClose) return false; } + if (removeFile) { + QFile::remove(unit->fileName()); + } + //if not fUnits.GetItem(index).fNew then PFolderNode node = unit->node(); PFolderNode parent = node->parent.lock(); @@ -788,10 +792,17 @@ PProjectUnit Project::addUnit(const QString &inFileName, PFolderNode parentNode, newUnit = std::make_shared(this); // Set all properties - newUnit->setEncoding(toByteArray(mOptions.encoding)); newUnit->setFileName(QDir(directory()).filePath(inFileName)); newUnit->setNew(false); - newUnit->setEditor(nullptr); + Editor * e= pMainWindow->editorList()->getOpenedEditorByFilename(newUnit->fileName()); + if (e) { + newUnit->setEditor(e); + newUnit->setEncoding(e->encodingOption()); + e->setInProject(true); + } else { + newUnit->setEditor(nullptr); + newUnit->setEncoding(ENCODING_AUTO_DETECT); + } newUnit->setFolder(getFolderPath(parentNode)); newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()), false, parentNode)); newUnit->node()->unitIndex = mUnits.count(); @@ -1515,7 +1526,7 @@ void Project::removeFolderRecurse(PFolderNode node) } else if (childNode->unitIndex >= 0 && childNode->level > 0) { // Remove editor in folder from project int editorIndex = childNode->unitIndex; - if (!removeEditor(editorIndex,true)) + if (!removeUnit(editorIndex,true)) return; } } @@ -1920,7 +1931,7 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int // Remove it from the current project... int projindex = mProject->indexInUnits(newName); if (projindex>=0) { - mProject->removeEditor(projindex,false); + mProject->removeUnit(projindex,false); } // All references to the file are removed. Delete the file from disk diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 3c37f000..e5f6f392 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -148,7 +148,7 @@ public: const QString& customFileName=""); Editor* openUnit(int index); void rebuildNodes(); - bool removeEditor(int index, bool doClose); + bool removeUnit(int index, bool doClose, bool removeFile = false); bool removeFolder(PFolderNode node); void resetParserProjectFiles(); void saveAll(); // save [Project] and all [UnitX]