- fix: crash when create non C/C++ source file in project

- fix: can't open text project file in the editor
  - change: when create non-text project file, don't auto open it
This commit is contained in:
Roy Qu 2022-09-23 10:27:44 +08:00
parent 5ba802c0ee
commit 9b09b4263f
5 changed files with 16 additions and 9 deletions

View File

@ -1,6 +1,9 @@
Red Panda C++ Version 1.4
- fix: "Encode in UTF-8" is not correctly checked, when the editor is openned using UTF-8 encoding.
- fix: crash when create non C/C++ source file in project
- fix: can't open text project file in the editor
- change: when create non-text project file, don't auto open it
Red Panda C++ Version 1.3

View File

@ -6179,7 +6179,7 @@ void MainWindow::newProjectUnitFile()
newProjectUnitDialog.setSuffix("c");
break;
default:
newProjectUnitDialog.setSuffix("");
newProjectUnitDialog.setSuffix("txt");
}
}
QString folder = mProject->fileSystemNodeFolderPath(pNode);
@ -6221,10 +6221,11 @@ void MainWindow::newProjectUnitFile()
mProject->saveAll();
updateProjectView();
idx = mProject->units().count()-1;
Editor * editor = mProject->openUnit(idx);
Editor * editor = mProject->openUnit(idx, false);
//editor->setUseCppSyntax(mProject->options().useGPP);
//editor->setModified(true);
editor->activate();
if (editor)
editor->activate();
QString branch;
if (pSettings->vcs().gitOk() && mProject->model()->iconProvider()->VCSRepository()->hasRepository(branch)) {
QString output;

View File

@ -309,7 +309,7 @@ PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& custo
return newUnit;
}
Editor *Project::openUnit(int index)
Editor *Project::openUnit(int index, bool forceOpen)
{
if ((index < 0) || (index >= mUnits.count()))
return nullptr;
@ -318,11 +318,8 @@ Editor *Project::openUnit(int index)
if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
if (getFileType(unit->fileName())==FileType::Other) {
QMimeDatabase db;
QMimeType mimeType=db.mimeTypeForFile(unit->fileName());
if (!mimeType.isValid() || !mimeType.name().startsWith("text/")) {
if (forceOpen)
QDesktopServices::openUrl(QUrl::fromLocalFile(unit->fileName()));
}
return nullptr;
}

View File

@ -186,7 +186,7 @@ public:
int indexInUnits(const Editor* editor) const;
PProjectUnit newUnit(PProjectModelNode parentNode,
const QString& customFileName="");
Editor* openUnit(int index);
Editor* openUnit(int index, bool forceOpen=true);
Editor* unitEditor(const PProjectUnit& unit) const;
Editor* unitEditor(const ProjectUnit* unit) const;
Editor* unitEditor(int index) const {

View File

@ -40,6 +40,7 @@
#include "project.h"
#include "compiler/executablerunner.h"
#ifdef Q_OS_WIN
#include <QMimeDatabase>
#include <windows.h>
#endif
@ -276,6 +277,11 @@ FileType getFileType(const QString &filename)
if (filename.endsWith(".dat",PATH_SENSITIVITY)) {
return FileType::Text;
}
QMimeDatabase db;
QMimeType mimeType=db.mimeTypeForFile(filename);
if (mimeType.isValid() && mimeType.name().startsWith("text/")) {
return FileType::Text;
}
return FileType::Other;
}