2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-09-05 23:45:05 +08:00
|
|
|
#include "project.h"
|
|
|
|
#include "editor.h"
|
2021-09-06 08:45:53 +08:00
|
|
|
#include "utils.h"
|
|
|
|
#include "systemconsts.h"
|
2021-09-07 16:49:35 +08:00
|
|
|
#include "editorlist.h"
|
|
|
|
#include <parser/cppparser.h>
|
|
|
|
#include "utils.h"
|
2022-09-26 12:01:45 +08:00
|
|
|
#include "qt_utils/charsetinfo.h"
|
2021-09-16 23:51:05 +08:00
|
|
|
#include "projecttemplate.h"
|
2021-09-17 09:56:52 +08:00
|
|
|
#include "systemconsts.h"
|
2021-10-23 23:10:34 +08:00
|
|
|
#include "iconsmanager.h"
|
2021-09-06 08:45:53 +08:00
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
#include <QFileSystemWatcher>
|
2021-09-06 08:45:53 +08:00
|
|
|
#include <QDir>
|
2021-09-09 00:15:12 +08:00
|
|
|
#include <QFileDialog>
|
2021-09-06 08:45:53 +08:00
|
|
|
#include <QFileInfo>
|
2021-09-06 12:58:29 +08:00
|
|
|
#include <QMessageBox>
|
2021-09-11 18:42:49 +08:00
|
|
|
#include <QTextCodec>
|
2021-09-26 22:39:26 +08:00
|
|
|
#include <QMessageBox>
|
2022-03-21 09:08:05 +08:00
|
|
|
#include <QDirIterator>
|
2022-07-07 20:08:58 +08:00
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QDesktopServices>
|
2022-10-08 23:30:30 +08:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
2022-02-13 20:08:18 +08:00
|
|
|
#include "customfileiconprovider.h"
|
2021-10-24 12:04:37 +08:00
|
|
|
#include <QMimeData>
|
2021-09-09 11:47:04 +08:00
|
|
|
#include "settings.h"
|
2022-02-15 21:39:17 +08:00
|
|
|
#include "vcs/gitrepository.h"
|
2021-09-16 12:03:10 +08:00
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
Project::Project(const QString &filename, const QString &name,
|
|
|
|
EditorList* editorList,
|
|
|
|
QFileSystemWatcher* fileSystemWatcher,
|
|
|
|
QObject *parent) :
|
2021-09-11 09:21:44 +08:00
|
|
|
QObject(parent),
|
2022-10-09 22:19:18 +08:00
|
|
|
mName(name),
|
2022-10-19 10:37:30 +08:00
|
|
|
mModified(false),
|
2022-03-21 09:08:05 +08:00
|
|
|
mModel(this),
|
|
|
|
mEditorList(editorList),
|
|
|
|
mFileSystemWatcher(fileSystemWatcher)
|
2021-09-05 23:45:05 +08:00
|
|
|
{
|
2021-10-23 19:27:50 +08:00
|
|
|
mFilename = QFileInfo(filename).absoluteFilePath();
|
2021-09-07 16:49:35 +08:00
|
|
|
mParser = std::make_shared<CppParser>();
|
|
|
|
mParser->setOnGetFileStream(
|
|
|
|
std::bind(
|
2022-03-21 09:08:05 +08:00
|
|
|
&EditorList::getContentFromOpenedEditor,mEditorList,
|
2021-09-07 16:49:35 +08:00
|
|
|
std::placeholders::_1, std::placeholders::_2));
|
2022-10-09 22:19:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Project> Project::load(const QString &filename, EditorList *editorList, QFileSystemWatcher *fileSystemWatcher, QObject *parent)
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project=std::make_shared<Project>(filename,
|
|
|
|
"",
|
|
|
|
editorList,
|
|
|
|
fileSystemWatcher,
|
|
|
|
parent);
|
|
|
|
project->open();
|
|
|
|
project->mModified = false;
|
2022-10-18 12:24:59 +08:00
|
|
|
resetCppParser(project->mParser, project->mOptions.compilerSet);
|
2022-10-09 22:19:18 +08:00
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Project> Project::create(
|
|
|
|
const QString &filename, const QString &name,
|
|
|
|
EditorList *editorList, QFileSystemWatcher *fileSystemWatcher,
|
|
|
|
const std::shared_ptr<ProjectTemplate> pTemplate,
|
|
|
|
bool useCpp, QObject *parent)
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project=std::make_shared<Project>(filename,
|
|
|
|
name,
|
|
|
|
editorList,
|
|
|
|
fileSystemWatcher,
|
|
|
|
parent);
|
|
|
|
SimpleIni ini;
|
|
|
|
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<Project>();
|
2022-10-18 12:24:59 +08:00
|
|
|
resetCppParser(project->mParser, project->mOptions.compilerSet);
|
2022-10-09 22:19:18 +08:00
|
|
|
|
|
|
|
project->mModified = true;
|
|
|
|
return project;
|
2021-09-05 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
2021-09-11 18:42:49 +08:00
|
|
|
Project::~Project()
|
|
|
|
{
|
2022-03-21 09:08:05 +08:00
|
|
|
mEditorList->beginUpdate();
|
2021-09-11 18:42:49 +08:00
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * editor = unitEditor(unit);
|
|
|
|
if (editor) {
|
2022-10-09 22:19:18 +08:00
|
|
|
editor->setProject(nullptr);
|
2022-03-21 09:08:05 +08:00
|
|
|
mEditorList->forceCloseEditor(editor);
|
2021-09-11 18:42:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-21 09:08:05 +08:00
|
|
|
mEditorList->endUpdate();
|
2021-09-11 18:42:49 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 11:47:04 +08:00
|
|
|
QString Project::directory() const
|
2021-09-06 08:45:53 +08:00
|
|
|
{
|
|
|
|
QFileInfo fileInfo(mFilename);
|
|
|
|
return fileInfo.absolutePath();
|
|
|
|
}
|
|
|
|
|
2021-09-09 11:47:04 +08:00
|
|
|
QString Project::executable() const
|
2021-09-06 08:45:53 +08:00
|
|
|
{
|
|
|
|
QString exeFileName;
|
|
|
|
if (mOptions.overrideOutput && !mOptions.overridenOutput.isEmpty()) {
|
|
|
|
exeFileName = mOptions.overridenOutput;
|
|
|
|
} else {
|
|
|
|
switch(mOptions.type) {
|
|
|
|
case ProjectType::StaticLib:
|
2021-09-10 12:37:02 +08:00
|
|
|
exeFileName = changeFileExt(extractFileName(mFilename),STATIC_LIB_EXT);
|
2022-12-21 09:15:39 +08:00
|
|
|
if (!exeFileName.startsWith("lib"))
|
|
|
|
exeFileName = "lib" + exeFileName;
|
2021-09-06 08:45:53 +08:00
|
|
|
break;
|
|
|
|
case ProjectType::DynamicLib:
|
2021-09-10 12:37:02 +08:00
|
|
|
exeFileName = changeFileExt(extractFileName(mFilename),DYNAMIC_LIB_EXT);
|
2022-12-21 09:15:39 +08:00
|
|
|
if (!exeFileName.startsWith("lib"))
|
|
|
|
exeFileName = "lib" + exeFileName;
|
2021-09-06 08:45:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2022-10-12 19:48:35 +08:00
|
|
|
exeFileName = changeFileExt(extractFileName(mFilename),DEFAULT_EXECUTABLE_SUFFIX);
|
2021-09-06 08:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
QString exePath;
|
|
|
|
if (!mOptions.exeOutput.isEmpty()) {
|
|
|
|
QDir baseDir(directory());
|
|
|
|
exePath = baseDir.filePath(mOptions.exeOutput);
|
|
|
|
} else {
|
|
|
|
exePath = directory();
|
|
|
|
}
|
|
|
|
QDir exeDir(exePath);
|
|
|
|
return exeDir.filePath(exeFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Project::makeFileName()
|
|
|
|
{
|
2021-09-06 12:58:29 +08:00
|
|
|
if (mOptions.useCustomMakefile)
|
|
|
|
return mOptions.customMakefile;
|
2021-09-06 08:45:53 +08:00
|
|
|
else
|
2021-09-06 12:58:29 +08:00
|
|
|
return QDir(directory()).filePath(MAKEFILE_NAME);
|
|
|
|
}
|
|
|
|
|
2023-02-16 22:27:04 +08:00
|
|
|
QString Project::xmakeFileName()
|
|
|
|
{
|
|
|
|
return QDir(directory()).filePath(XMAKEFILE_NAME);
|
|
|
|
}
|
|
|
|
|
2022-10-25 19:09:46 +08:00
|
|
|
bool Project::unitsModifiedSince(const QDateTime& time)
|
|
|
|
{
|
|
|
|
foreach(const PProjectUnit& unit, mUnits) {
|
|
|
|
QFileInfo info(unit->fileName());
|
|
|
|
if (info.lastModified()>time) {
|
2023-01-24 11:31:30 +08:00
|
|
|
//qDebug()<<info.lastModified()<<time;
|
2022-10-25 19:09:46 +08:00
|
|
|
return true;
|
|
|
|
}
|
2022-10-29 18:19:45 +08:00
|
|
|
Editor * e=unitEditor(unit);
|
|
|
|
if (e && e->modified())
|
|
|
|
return true;
|
2022-10-25 19:09:46 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-09 11:47:04 +08:00
|
|
|
bool Project::modified() const
|
2021-09-06 12:58:29 +08:00
|
|
|
{
|
2022-10-21 12:43:02 +08:00
|
|
|
return mModified;
|
2023-02-13 10:24:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::modifiedSince(const QDateTime &time)
|
|
|
|
{
|
|
|
|
if (modified())
|
|
|
|
return true;
|
|
|
|
if (unitsModifiedSince(time))
|
|
|
|
return true;
|
|
|
|
QFileInfo info(filename());
|
|
|
|
return (info.lastModified()>time);
|
2021-09-06 12:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Project::open()
|
|
|
|
{
|
2021-09-11 09:21:44 +08:00
|
|
|
mModel.beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
mModel.endUpdate();
|
|
|
|
});
|
2021-09-12 19:50:44 +08:00
|
|
|
// QFile fileInfo(mFilename);
|
|
|
|
SimpleIni ini;
|
|
|
|
ini.LoadFile(mFilename.toLocal8Bit());
|
|
|
|
loadOptions(ini);
|
2021-09-06 12:58:29 +08:00
|
|
|
|
2022-02-08 12:33:10 +08:00
|
|
|
mRootNode = makeProjectNode();
|
2021-09-06 12:58:29 +08:00
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
checkProjectFileForUpdate(ini);
|
|
|
|
int uCount = ini.GetLongValue("Project","UnitCount",0);
|
2022-10-02 13:29:51 +08:00
|
|
|
if (mOptions.modelType==ProjectModelType::FileSystem) {
|
|
|
|
createFileSystemFolderNodes();
|
|
|
|
} else {
|
|
|
|
createFolderNodes();
|
|
|
|
}
|
2021-09-06 12:58:29 +08:00
|
|
|
QDir dir(directory());
|
|
|
|
for (int i=0;i<uCount;i++) {
|
2021-09-11 18:42:49 +08:00
|
|
|
PProjectUnit newUnit = std::make_shared<ProjectUnit>(this);
|
2021-09-12 19:50:44 +08:00
|
|
|
QByteArray groupName = toByteArray(QString("Unit%1").arg(i+1));
|
|
|
|
newUnit->setFileName(
|
2022-10-24 17:23:37 +08:00
|
|
|
cleanPath(dir.absoluteFilePath(
|
|
|
|
fromByteArray(ini.GetValue(groupName,"FileName","")))));
|
2022-03-28 16:57:58 +08:00
|
|
|
// if (!QFileInfo(newUnit->fileName()).exists()) {
|
|
|
|
// QMessageBox::critical(nullptr,
|
|
|
|
// tr("File Not Found"),
|
|
|
|
// tr("Project file '%1' can't be found!")
|
|
|
|
// .arg(newUnit->fileName()),
|
|
|
|
// QMessageBox::Ok);
|
|
|
|
// newUnit->setModified(true);
|
|
|
|
// } else {
|
|
|
|
newUnit->setFileMissing(!QFileInfo(newUnit->fileName()).exists());
|
|
|
|
newUnit->setFolder(fromByteArray(ini.GetValue(groupName,"Folder","")));
|
|
|
|
newUnit->setCompile(ini.GetBoolValue(groupName,"Compile", true));
|
|
|
|
newUnit->setCompileCpp(
|
|
|
|
ini.GetBoolValue(groupName,"CompileCpp",mOptions.isCpp));
|
|
|
|
|
|
|
|
newUnit->setLink(ini.GetBoolValue(groupName,"Link", true));
|
|
|
|
newUnit->setPriority(ini.GetLongValue(groupName,"Priority", 1000));
|
|
|
|
newUnit->setOverrideBuildCmd(ini.GetBoolValue(groupName,"OverrideBuildCmd", false));
|
|
|
|
newUnit->setBuildCmd(fromByteArray(ini.GetValue(groupName,"BuildCmd", "")));
|
2023-01-24 11:31:30 +08:00
|
|
|
newUnit->setEncoding(ini.GetValue(groupName, "FileEncoding",ENCODING_PROJECT));
|
2022-03-28 16:57:58 +08:00
|
|
|
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
|
2023-01-24 11:31:30 +08:00
|
|
|
newUnit->setEncoding(ENCODING_PROJECT);
|
2023-01-19 20:04:05 +08:00
|
|
|
}
|
|
|
|
newUnit->setRealEncoding(ini.GetValue(groupName, "RealEncoding",ENCODING_ASCII));
|
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
PProjectModelNode parentNode;
|
|
|
|
if (mOptions.modelType==ProjectModelType::FileSystem) {
|
|
|
|
parentNode = getParentFileSystemFolderNode(newUnit->fileName());
|
|
|
|
} else {
|
|
|
|
parentNode = getCustomeFolderNodeFromName(newUnit->folder());
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectModelNode node = makeNewFileNode(newUnit,
|
2022-10-01 08:54:44 +08:00
|
|
|
newUnit->priority(),
|
2022-10-02 13:29:51 +08:00
|
|
|
parentNode
|
|
|
|
);
|
2022-10-01 08:54:44 +08:00
|
|
|
newUnit->setNode(node);
|
2022-10-08 23:30:30 +08:00
|
|
|
mUnits.insert(newUnit->fileName(),newUnit);
|
2021-09-07 00:32:16 +08:00
|
|
|
}
|
|
|
|
}
|
2021-09-06 18:59:06 +08:00
|
|
|
|
2021-10-23 19:27:50 +08:00
|
|
|
void Project::setFileName(QString value)
|
2021-09-07 00:32:16 +08:00
|
|
|
{
|
2021-10-23 19:27:50 +08:00
|
|
|
value = QFileInfo(value).absoluteFilePath();
|
2021-09-07 00:32:16 +08:00
|
|
|
if (mFilename!=value) {
|
2021-09-10 23:41:38 +08:00
|
|
|
QFile::rename(mFilename,value);
|
2021-09-07 00:32:16 +08:00
|
|
|
mFilename = value;
|
|
|
|
setModified(true);
|
|
|
|
}
|
|
|
|
}
|
2021-09-06 12:58:29 +08:00
|
|
|
|
2021-09-07 00:32:16 +08:00
|
|
|
void Project::setModified(bool value)
|
|
|
|
{
|
2021-11-25 20:50:51 +08:00
|
|
|
if (mModified!=value) {
|
2021-09-07 00:32:16 +08:00
|
|
|
mModified=value;
|
2021-09-07 10:28:40 +08:00
|
|
|
emit modifyChanged(mModified);
|
2021-09-07 00:32:16 +08:00
|
|
|
}
|
2021-09-07 10:28:40 +08:00
|
|
|
}
|
2021-09-06 12:58:29 +08:00
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectModelNode Project::makeNewFolderNode(
|
|
|
|
const QString &folderName, PProjectModelNode newParent,
|
|
|
|
ProjectModelNodeType nodeType,int priority)
|
2021-09-10 10:27:01 +08:00
|
|
|
{
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode node = std::make_shared<ProjectModelNode>();
|
2021-09-17 17:15:35 +08:00
|
|
|
if (!newParent) {
|
2022-02-08 12:33:10 +08:00
|
|
|
newParent = mRootNode;
|
2021-09-17 17:15:35 +08:00
|
|
|
}
|
2021-09-10 10:27:01 +08:00
|
|
|
node->parent = newParent;
|
2022-10-01 08:54:44 +08:00
|
|
|
node->text = folderName;
|
2021-09-10 21:37:52 +08:00
|
|
|
if (newParent) {
|
|
|
|
node->level = newParent->level+1;
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
node->isUnit=false;
|
2022-10-01 08:54:44 +08:00
|
|
|
node->priority = priority;
|
|
|
|
node->folderNodeType = nodeType;
|
|
|
|
QModelIndex parentIndex=mModel.getNodeIndex(newParent.get());
|
2022-10-02 13:29:51 +08:00
|
|
|
newParent->children.append(node);
|
|
|
|
mModel.insertRow(newParent->children.count()-1,parentIndex);
|
2022-10-01 08:54:44 +08:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectModelNode Project::makeNewFileNode(PProjectUnit unit,int priority, PProjectModelNode newParent)
|
2022-10-01 08:54:44 +08:00
|
|
|
{
|
|
|
|
PProjectModelNode node = std::make_shared<ProjectModelNode>();
|
|
|
|
if (!newParent) {
|
|
|
|
newParent = mRootNode;
|
|
|
|
}
|
|
|
|
node->parent = newParent;
|
2022-10-08 23:30:30 +08:00
|
|
|
node->text = extractFileName(unit->fileName());
|
2022-10-01 08:54:44 +08:00
|
|
|
if (newParent) {
|
|
|
|
node->level = newParent->level+1;
|
2022-02-08 12:33:10 +08:00
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
node->isUnit = true;
|
|
|
|
node->pUnit = unit;
|
2022-10-01 08:54:44 +08:00
|
|
|
node->priority = priority;
|
|
|
|
node->folderNodeType = ProjectModelNodeType::File;
|
2022-10-02 13:29:51 +08:00
|
|
|
|
|
|
|
newParent->children.append(node);
|
2022-10-01 08:54:44 +08:00
|
|
|
QModelIndex parentIndex=mModel.getNodeIndex(newParent.get());
|
2022-10-02 13:29:51 +08:00
|
|
|
mModel.insertRow(newParent->children.count()-1,parentIndex);
|
2021-09-11 18:42:49 +08:00
|
|
|
return node;
|
2021-09-10 10:27:01 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode Project::makeProjectNode()
|
2021-09-10 10:27:01 +08:00
|
|
|
{
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode node = std::make_shared<ProjectModelNode>();
|
2021-09-10 10:27:01 +08:00
|
|
|
node->text = mName;
|
2021-09-10 21:37:52 +08:00
|
|
|
node->level = 0;
|
2022-10-08 23:30:30 +08:00
|
|
|
node->isUnit = false;
|
2022-09-30 17:51:26 +08:00
|
|
|
node->folderNodeType = ProjectModelNodeType::Folder;
|
2021-09-11 18:42:49 +08:00
|
|
|
return node;
|
2021-09-10 10:27:01 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& customFileName)
|
2021-09-10 12:37:02 +08:00
|
|
|
{
|
|
|
|
// Select folder to add unit to
|
|
|
|
if (!parentNode)
|
2022-02-08 12:33:10 +08:00
|
|
|
parentNode = mRootNode; // project root node
|
2021-09-10 12:37:02 +08:00
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
if (parentNode->isUnit) { //it's a file
|
2022-02-08 12:33:10 +08:00
|
|
|
parentNode = mRootNode;
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
|
|
|
QString s;
|
|
|
|
QDir dir(directory());
|
|
|
|
// Find unused 'new' filename
|
|
|
|
if (customFileName.isEmpty()) {
|
|
|
|
do {
|
2022-10-30 11:58:42 +08:00
|
|
|
s = cleanPath(dir.absoluteFilePath(QString("untitled%1").arg(getNewFileNumber())));
|
2021-09-10 12:37:02 +08:00
|
|
|
} while (fileExists(s));
|
|
|
|
} else {
|
2022-10-24 17:23:37 +08:00
|
|
|
s = cleanPath(dir.absoluteFilePath(customFileName));
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
2022-11-07 21:44:12 +08:00
|
|
|
PProjectUnit newUnit = internalAddUnit(s,parentNode);
|
2022-11-07 12:07:15 +08:00
|
|
|
emit unitAdded(newUnit->fileName());
|
2021-09-16 23:51:05 +08:00
|
|
|
return newUnit;
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
Editor* Project::openUnit(PProjectUnit& unit, bool forceOpen) {
|
2021-09-10 12:37:02 +08:00
|
|
|
|
2022-03-28 16:57:58 +08:00
|
|
|
if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
|
2022-07-07 20:08:58 +08:00
|
|
|
if (getFileType(unit->fileName())==FileType::Other) {
|
2022-09-23 10:27:44 +08:00
|
|
|
if (forceOpen)
|
2022-07-07 20:08:58 +08:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(unit->fileName()));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-28 16:57:58 +08:00
|
|
|
Editor * editor = mEditorList->getOpenedEditorByFilename(unit->fileName());
|
2021-09-10 12:37:02 +08:00
|
|
|
if (editor) {//already opened in the editors
|
2022-10-09 22:19:18 +08:00
|
|
|
editor->setProject(this);
|
2021-09-15 14:35:37 +08:00
|
|
|
editor->activate();
|
2021-09-10 12:37:02 +08:00
|
|
|
return editor;
|
|
|
|
}
|
2021-09-10 15:03:47 +08:00
|
|
|
QByteArray encoding;
|
2021-09-12 22:45:00 +08:00
|
|
|
encoding = unit->encoding();
|
2023-02-07 10:46:06 +08:00
|
|
|
if (encoding==ENCODING_PROJECT)
|
|
|
|
encoding=options().encoding;
|
|
|
|
|
2022-10-21 12:43:02 +08:00
|
|
|
editor = mEditorList->newEditor(unit->fileName(), encoding, this, false);
|
2022-03-28 16:57:58 +08:00
|
|
|
if (editor) {
|
2022-10-09 22:19:18 +08:00
|
|
|
//editor->setProject(this);
|
2022-03-28 16:57:58 +08:00
|
|
|
//unit->setEncoding(encoding);
|
2022-10-02 23:32:33 +08:00
|
|
|
loadUnitLayout(editor);
|
2022-10-08 23:30:30 +08:00
|
|
|
editor->activate();
|
2022-03-28 16:57:58 +08:00
|
|
|
return editor;
|
|
|
|
}
|
2021-09-10 15:03:47 +08:00
|
|
|
}
|
2021-09-11 18:42:49 +08:00
|
|
|
return nullptr;
|
2021-09-10 15:03:47 +08:00
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
Editor *Project::openUnit(PProjectUnit &unit, const PProjectEditorLayout &layout)
|
2022-10-02 23:32:33 +08:00
|
|
|
{
|
|
|
|
if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
|
|
|
|
if (getFileType(unit->fileName())==FileType::Other) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Editor * editor = mEditorList->getOpenedEditorByFilename(unit->fileName());
|
|
|
|
if (editor) {//already opened in the editors
|
2022-10-09 22:19:18 +08:00
|
|
|
editor->setProject(this);
|
2022-10-02 23:32:33 +08:00
|
|
|
editor->activate();
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
QByteArray encoding;
|
|
|
|
encoding = unit->encoding();
|
2023-02-07 10:46:06 +08:00
|
|
|
if (encoding==ENCODING_PROJECT)
|
|
|
|
encoding=options().encoding;
|
2022-10-21 12:43:02 +08:00
|
|
|
editor = mEditorList->newEditor(unit->fileName(), encoding, this, false);
|
2022-10-02 23:32:33 +08:00
|
|
|
if (editor) {
|
2022-10-09 22:19:18 +08:00
|
|
|
//editor->setInProject(true);
|
2022-10-08 23:30:30 +08:00
|
|
|
editor->setCaretY(layout->caretY);
|
|
|
|
editor->setCaretX(layout->caretX);
|
|
|
|
editor->setTopLine(layout->topLine);
|
|
|
|
editor->setLeftChar(layout->leftChar);
|
2022-10-02 23:32:33 +08:00
|
|
|
editor->activate();
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor *Project::unitEditor(const PProjectUnit &unit) const
|
|
|
|
{
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!unit)
|
|
|
|
return nullptr;
|
2022-03-28 16:57:58 +08:00
|
|
|
return mEditorList->getOpenedEditorByFilename(unit->fileName());
|
2022-03-21 09:08:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Editor *Project::unitEditor(const ProjectUnit *unit) const
|
|
|
|
{
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!unit)
|
|
|
|
return nullptr;
|
2022-03-28 16:57:58 +08:00
|
|
|
return mEditorList->getOpenedEditorByFilename(unit->fileName());
|
2022-03-21 09:08:05 +08:00
|
|
|
}
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
QList<PProjectUnit> Project::unitList()
|
|
|
|
{
|
|
|
|
QList<PProjectUnit> units;
|
|
|
|
foreach(PProjectUnit unit, mUnits) {
|
|
|
|
units.append(unit);
|
|
|
|
}
|
|
|
|
return units;
|
|
|
|
}
|
|
|
|
|
2022-10-22 23:29:12 +08:00
|
|
|
QStringList Project::unitFiles()
|
|
|
|
{
|
|
|
|
QStringList units;
|
|
|
|
foreach(PProjectUnit unit, mUnits) {
|
|
|
|
units.append(unit->fileName());
|
|
|
|
}
|
|
|
|
return units;
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:03:47 +08:00
|
|
|
void Project::rebuildNodes()
|
|
|
|
{
|
2021-09-11 09:21:44 +08:00
|
|
|
mModel.beginUpdate();
|
2021-09-10 15:03:47 +08:00
|
|
|
// Delete everything
|
2022-02-08 12:33:10 +08:00
|
|
|
mRootNode->children.clear();
|
2022-10-02 13:29:51 +08:00
|
|
|
mCustomFolderNodes.clear();
|
2022-02-08 12:33:10 +08:00
|
|
|
mSpecialNodes.clear();
|
|
|
|
mFileSystemFolderNodes.clear();
|
2021-09-10 15:03:47 +08:00
|
|
|
|
|
|
|
// Recreate everything
|
2022-02-08 00:24:08 +08:00
|
|
|
switch(mOptions.modelType) {
|
|
|
|
case ProjectModelType::Custom:
|
|
|
|
createFolderNodes();
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (PProjectUnit pUnit, mUnits) {
|
|
|
|
QFileInfo fileInfo(pUnit->fileName());
|
|
|
|
pUnit->setNode(
|
2022-02-08 00:24:08 +08:00
|
|
|
makeNewFileNode(
|
2022-10-08 23:30:30 +08:00
|
|
|
pUnit,
|
2022-10-01 08:54:44 +08:00
|
|
|
pUnit->priority(),
|
2022-10-02 13:29:51 +08:00
|
|
|
getCustomeFolderNodeFromName(pUnit->folder())
|
2022-02-08 00:24:08 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProjectModelType::FileSystem:
|
|
|
|
createFileSystemFolderNodes();
|
2021-09-10 12:37:02 +08:00
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (PProjectUnit pUnit, mUnits) {
|
|
|
|
QFileInfo fileInfo(pUnit->fileName());
|
|
|
|
pUnit->setNode(
|
2022-02-08 12:33:10 +08:00
|
|
|
makeNewFileNode(
|
2022-10-08 23:30:30 +08:00
|
|
|
pUnit,
|
2022-10-01 08:54:44 +08:00
|
|
|
pUnit->priority(),
|
2022-10-02 13:29:51 +08:00
|
|
|
getParentFileSystemFolderNode(
|
2022-10-01 08:54:44 +08:00
|
|
|
pUnit->fileName())
|
2022-02-08 12:33:10 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2022-04-08 17:22:24 +08:00
|
|
|
|
2022-02-08 12:33:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-09-10 15:03:47 +08:00
|
|
|
|
2021-09-11 09:21:44 +08:00
|
|
|
mModel.endUpdate();
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
bool Project::removeUnit(PProjectUnit& unit, bool doClose , bool removeFile)
|
2022-11-07 11:24:23 +08:00
|
|
|
{
|
|
|
|
bool result=internalRemoveUnit(unit,doClose,removeFile);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
emit unitRemoved(unit->fileName());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::internalRemoveUnit(PProjectUnit& unit, bool doClose , bool removeFile)
|
2021-09-10 21:37:52 +08:00
|
|
|
{
|
2022-10-01 08:54:44 +08:00
|
|
|
if (!unit)
|
2021-09-10 21:37:52 +08:00
|
|
|
return false;
|
|
|
|
|
2022-01-23 21:04:08 +08:00
|
|
|
// qDebug()<<unit->fileName();
|
|
|
|
// qDebug()<<(qint64)unit->editor();
|
2021-09-10 21:37:52 +08:00
|
|
|
// Attempt to close it
|
2022-03-21 09:08:05 +08:00
|
|
|
if (doClose) {
|
|
|
|
Editor* editor = unitEditor(unit);
|
|
|
|
if (editor) {
|
2022-10-09 22:19:18 +08:00
|
|
|
editor->setProject(nullptr);
|
2022-03-21 09:08:05 +08:00
|
|
|
mEditorList->closeEditor(editor);
|
|
|
|
}
|
2021-09-10 21:37:52 +08:00
|
|
|
}
|
|
|
|
|
2021-11-15 22:08:35 +08:00
|
|
|
if (removeFile) {
|
|
|
|
QFile::remove(unit->fileName());
|
|
|
|
}
|
|
|
|
|
2021-09-10 21:37:52 +08:00
|
|
|
//if not fUnits.GetItem(index).fNew then
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode node = unit->node();
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectModelNode parentNode = node->parent.lock();
|
2022-10-02 13:29:51 +08:00
|
|
|
if (!parentNode) {
|
2022-10-08 23:30:30 +08:00
|
|
|
mUnits.remove(unit->fileName());
|
2022-10-01 08:54:44 +08:00
|
|
|
return true;
|
2022-10-02 13:29:51 +08:00
|
|
|
}
|
2022-10-01 08:54:44 +08:00
|
|
|
|
|
|
|
int row = parentNode->children.indexOf(unit->node());
|
2022-10-02 13:29:51 +08:00
|
|
|
if (row<0) {
|
2022-10-08 23:30:30 +08:00
|
|
|
mUnits.remove(unit->fileName());
|
2022-10-01 08:54:44 +08:00
|
|
|
return true;
|
2022-10-02 13:29:51 +08:00
|
|
|
}
|
2022-10-01 08:54:44 +08:00
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
QModelIndex parentIndex = mModel.getNodeIndex(parentNode.get());
|
2022-10-01 08:54:44 +08:00
|
|
|
|
|
|
|
mModel.removeRow(row,parentIndex);
|
2022-10-08 23:30:30 +08:00
|
|
|
mUnits.remove(unit->fileName());
|
2022-10-01 08:54:44 +08:00
|
|
|
|
2022-10-02 16:25:00 +08:00
|
|
|
//remove empty parent node
|
|
|
|
PProjectModelNode currentNode = parentNode;
|
|
|
|
while (currentNode && currentNode->folderNodeType == ProjectModelNodeType::Folder && currentNode->children.isEmpty()) {
|
|
|
|
parentNode = currentNode->parent.lock();
|
|
|
|
if (!parentNode)
|
|
|
|
break;
|
|
|
|
row = parentNode->children.indexOf(currentNode);
|
|
|
|
if (row<0)
|
|
|
|
break;
|
|
|
|
parentIndex = mModel.getNodeIndex(parentNode.get());
|
|
|
|
mModel.removeRow(row,parentIndex);
|
|
|
|
currentNode = parentNode;
|
|
|
|
}
|
|
|
|
|
2021-09-10 21:37:52 +08:00
|
|
|
setModified(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
bool Project::removeFolder(PProjectModelNode node)
|
2021-09-10 21:37:52 +08:00
|
|
|
{
|
2021-09-11 09:21:44 +08:00
|
|
|
mModel.beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
mModel.endUpdate();
|
|
|
|
});
|
2021-09-10 21:37:52 +08:00
|
|
|
// Sanity check
|
|
|
|
if (!node)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if this is actually a folder
|
2022-10-08 23:30:30 +08:00
|
|
|
if (node->isUnit || node->level<1)
|
2021-09-10 21:37:52 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Let this function call itself
|
|
|
|
removeFolderRecurse(node);
|
|
|
|
|
|
|
|
// Update list of folders (sets modified)
|
|
|
|
updateFolders();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-11 18:42:49 +08:00
|
|
|
void Project::resetParserProjectFiles()
|
|
|
|
{
|
|
|
|
mParser->clearProjectFiles();
|
|
|
|
mParser->clearProjectIncludePaths();
|
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
2023-02-09 09:45:09 +08:00
|
|
|
if (isCFile(unit->fileName())
|
|
|
|
|| isHFile(unit->fileName()))
|
|
|
|
mParser->addProjectFile(unit->fileName(),true);
|
2021-09-11 18:42:49 +08:00
|
|
|
}
|
2022-06-16 21:34:31 +08:00
|
|
|
foreach (const QString& s, mOptions.includeDirs) {
|
2021-09-11 18:42:49 +08:00
|
|
|
mParser->addProjectIncludePath(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 21:37:52 +08:00
|
|
|
void Project::saveAll()
|
|
|
|
{
|
|
|
|
if (!saveUnits())
|
|
|
|
return;
|
|
|
|
saveOptions(); // update other data, and save to disk
|
|
|
|
saveLayout(); // save current opened files, and which is "active".
|
|
|
|
|
|
|
|
// We have saved everything to disk, so mark unmodified
|
|
|
|
setModified(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::saveLayout()
|
|
|
|
{
|
2022-10-09 22:19:18 +08:00
|
|
|
QHash<QString, PProjectEditorLayout> oldLayouts = loadLayout();
|
|
|
|
|
2022-10-02 23:32:33 +08:00
|
|
|
QHash<QString,int> editorOrderSet;
|
2021-09-10 21:37:52 +08:00
|
|
|
// Write list of open project files
|
2022-10-02 23:32:33 +08:00
|
|
|
int order=0;
|
2022-03-21 09:08:05 +08:00
|
|
|
for (int i=0;i<mEditorList->pageCount();i++) {
|
2022-10-02 23:32:33 +08:00
|
|
|
Editor* e=(*mEditorList)[i];
|
|
|
|
if (e && e->inProject() && !editorOrderSet.contains(e->filename())) {
|
|
|
|
editorOrderSet.insert(e->filename(),order);
|
|
|
|
order++;
|
|
|
|
}
|
2021-09-10 21:37:52 +08:00
|
|
|
}
|
2022-10-02 23:32:33 +08:00
|
|
|
// layIni.SetValue("Editors","Order",sl.join(",").toUtf8());
|
2021-09-10 21:37:52 +08:00
|
|
|
|
|
|
|
Editor *e, *e2;
|
|
|
|
// Remember what files were visible
|
2022-03-21 09:08:05 +08:00
|
|
|
mEditorList->getVisibleEditors(e, e2);
|
2022-10-08 23:30:30 +08:00
|
|
|
|
|
|
|
QJsonArray jsonLayouts;
|
2021-09-10 21:37:52 +08:00
|
|
|
// save editor info
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (const PProjectUnit& unit,mUnits) {
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor* editor = unitEditor(unit);
|
2021-09-10 21:37:52 +08:00
|
|
|
if (editor) {
|
2022-10-08 23:30:30 +08:00
|
|
|
QJsonObject jsonLayout;
|
|
|
|
jsonLayout["filename"]=unit->fileName();
|
|
|
|
jsonLayout["caretX"]=editor->caretX();
|
|
|
|
jsonLayout["caretY"]=editor->caretY();
|
|
|
|
jsonLayout["topLine"]=editor->topLine();
|
|
|
|
jsonLayout["leftChar"]=editor->leftChar();
|
2022-10-09 22:19:18 +08:00
|
|
|
jsonLayout["isOpen"]=true;
|
|
|
|
jsonLayout["focused"]=(editor==e);
|
2022-10-02 23:32:33 +08:00
|
|
|
int order=editorOrderSet.value(editor->filename(),-1);
|
|
|
|
if (order>=0) {
|
2022-10-08 23:30:30 +08:00
|
|
|
jsonLayout["order"]=order;
|
2022-10-02 23:32:33 +08:00
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
jsonLayouts.append(jsonLayout);
|
2022-10-09 22:19:18 +08:00
|
|
|
} else {
|
|
|
|
PProjectEditorLayout oldLayout = oldLayouts.value(unit->fileName(),PProjectEditorLayout());
|
|
|
|
if (oldLayout) {
|
|
|
|
QJsonObject jsonLayout;
|
|
|
|
jsonLayout["filename"]=unit->fileName();
|
|
|
|
jsonLayout["caretX"]=oldLayout->caretX;
|
|
|
|
jsonLayout["caretY"]=oldLayout->caretY;
|
|
|
|
jsonLayout["topLine"]=oldLayout->topLine;
|
|
|
|
jsonLayout["leftChar"]=oldLayout->leftChar;
|
|
|
|
jsonLayout["isOpen"]=false;
|
|
|
|
jsonLayout["focused"]=false;
|
|
|
|
jsonLayouts.append(jsonLayout);
|
|
|
|
}
|
2021-09-10 21:37:52 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-09 22:19:18 +08:00
|
|
|
|
|
|
|
QString jsonFilename = changeFileExt(filename(), "layout");
|
2022-10-08 23:30:30 +08:00
|
|
|
QFile file(jsonFilename);
|
|
|
|
if (file.open(QFile::WriteOnly|QFile::Truncate)) {
|
2022-10-09 22:19:18 +08:00
|
|
|
QJsonDocument doc(jsonLayouts);
|
2022-10-08 23:30:30 +08:00
|
|
|
file.write(doc.toJson(QJsonDocument::Indented));
|
|
|
|
file.close();
|
|
|
|
} else {
|
|
|
|
throw FileError(QObject::tr("Can't open file '%1' for write.")
|
|
|
|
.arg(jsonFilename));
|
|
|
|
}
|
2021-09-10 21:37:52 +08:00
|
|
|
}
|
|
|
|
|
2022-11-07 11:24:23 +08:00
|
|
|
void Project::renameUnit(PProjectUnit& unit, const QString &newFileName)
|
2021-09-10 23:41:38 +08:00
|
|
|
{
|
2022-10-01 08:54:44 +08:00
|
|
|
if (!unit)
|
2021-09-10 23:41:38 +08:00
|
|
|
return;
|
2022-11-07 11:24:23 +08:00
|
|
|
if (newFileName.compare(unit->fileName(),PATH_SENSITIVITY)==0)
|
2022-10-08 23:30:30 +08:00
|
|
|
return;
|
2022-11-07 11:24:23 +08:00
|
|
|
|
2022-11-06 22:51:14 +08:00
|
|
|
if (mParser) {
|
|
|
|
mParser->removeProjectFile(unit->fileName());
|
2022-11-07 11:24:23 +08:00
|
|
|
mParser->addProjectFile(newFileName,true);
|
2022-11-06 22:51:14 +08:00
|
|
|
}
|
2022-11-07 11:24:23 +08:00
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * editor=unitEditor(unit);
|
2022-10-01 08:54:44 +08:00
|
|
|
if (editor) {
|
2021-09-18 10:47:35 +08:00
|
|
|
//prevent recurse
|
2022-11-07 11:24:23 +08:00
|
|
|
editor->saveAs(newFileName,true);
|
2022-10-21 12:43:02 +08:00
|
|
|
} else {
|
2022-11-06 22:51:14 +08:00
|
|
|
if (mParser)
|
|
|
|
mParser->invalidateFile(unit->fileName());
|
2022-11-07 11:24:23 +08:00
|
|
|
copyFile(unit->fileName(),newFileName,true);
|
2022-11-06 22:51:14 +08:00
|
|
|
if (mParser)
|
2022-11-07 11:24:23 +08:00
|
|
|
mParser->parseFile(newFileName,true);
|
2021-09-18 10:47:35 +08:00
|
|
|
}
|
2022-11-07 11:24:23 +08:00
|
|
|
|
|
|
|
internalRemoveUnit(unit,false,true);
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectModelNode parentNode = unit->node()->parent.lock();
|
2022-11-07 11:24:23 +08:00
|
|
|
internalAddUnit(newFileName,parentNode);
|
2021-09-10 23:41:38 +08:00
|
|
|
setModified(true);
|
2022-10-08 23:30:30 +08:00
|
|
|
|
2022-11-07 11:24:23 +08:00
|
|
|
emit unitRenamed(unit->fileName(),newFileName);
|
2022-10-08 23:30:30 +08:00
|
|
|
emit nodeRenamed();
|
2021-09-10 23:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::saveUnits()
|
|
|
|
{
|
|
|
|
int count = 0;
|
2021-09-12 19:50:44 +08:00
|
|
|
SimpleIni ini;
|
2021-11-17 10:55:18 +08:00
|
|
|
SI_Error error = ini.LoadFile(mFilename.toLocal8Bit());
|
|
|
|
if (error != SI_Error::SI_OK)
|
|
|
|
return false;
|
2022-10-01 08:54:44 +08:00
|
|
|
int i=0;
|
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
|
|
|
i++;
|
|
|
|
QByteArray groupName = toByteArray(QString("Unit%1").arg(i));
|
2022-10-21 12:43:02 +08:00
|
|
|
// if (!unit->FileMissing()) {
|
|
|
|
// bool rd_only = false;
|
|
|
|
// if (unit->modified() && fileExists(unit->fileName())
|
|
|
|
// && isReadOnly(unit->fileName())) {
|
|
|
|
// // file is read-only
|
|
|
|
// QMessageBox::critical(nullptr,
|
|
|
|
// tr("Can't save file"),
|
|
|
|
// tr("Can't save file '%1'").arg(unit->fileName()),
|
|
|
|
// QMessageBox::Ok
|
|
|
|
// );
|
|
|
|
// rd_only = true;
|
|
|
|
// }
|
|
|
|
// if (!rd_only) {
|
|
|
|
// if (!unit->save() && unit->isNew())
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
2021-09-10 23:41:38 +08:00
|
|
|
|
|
|
|
// saved new file or an existing file add to project file
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue(
|
|
|
|
groupName,
|
|
|
|
"FileName",
|
|
|
|
toByteArray(
|
|
|
|
extractRelativePath(
|
|
|
|
directory(),
|
|
|
|
unit->fileName())));
|
2021-09-10 23:41:38 +08:00
|
|
|
count++;
|
|
|
|
switch(getFileType(unit->fileName())) {
|
|
|
|
case FileType::CHeader:
|
|
|
|
case FileType::CSource:
|
|
|
|
case FileType::CppHeader:
|
|
|
|
case FileType::CppSource:
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue(groupName,"CompileCpp", unit->compileCpp());
|
2021-09-10 23:41:38 +08:00
|
|
|
break;
|
|
|
|
case FileType::WindowsResourceSource:
|
|
|
|
unit->setFolder("Resources");
|
2021-10-20 18:05:43 +08:00
|
|
|
default:
|
|
|
|
break;
|
2021-09-10 23:41:38 +08:00
|
|
|
}
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue(groupName,"Folder", toByteArray(unit->folder()));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue(groupName,"Compile", unit->compile());
|
|
|
|
ini.SetLongValue(groupName,"Link", unit->link());
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetLongValue(groupName,"Priority", unit->priority());
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue(groupName,"OverrideBuildCmd", unit->overrideBuildCmd());
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue(groupName,"BuildCmd", toByteArray(unit->buildCmd()));
|
2023-01-02 16:50:30 +08:00
|
|
|
//ini.SetLongValue(groupName,"DetectEncoding", unit->encoding()==ENCODING_AUTO_DETECT);
|
|
|
|
ini.Delete(groupName,"DetectEncoding");
|
2023-01-24 11:31:30 +08:00
|
|
|
ini.SetValue(groupName,"FileEncoding", unit->encoding());
|
2023-01-19 20:04:05 +08:00
|
|
|
ini.SetValue(groupName,"RealEncoding",unit->realEncoding());
|
2021-09-10 23:41:38 +08:00
|
|
|
}
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetLongValue("Project","UnitCount",count);
|
|
|
|
ini.SaveFile(mFilename.toLocal8Bit());
|
2021-09-10 23:41:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectUnit Project::findUnit(const QString &filename)
|
2022-01-13 16:47:48 +08:00
|
|
|
{
|
2022-10-08 23:30:30 +08:00
|
|
|
return mUnits.value(filename,PProjectUnit());
|
2022-01-13 17:15:57 +08:00
|
|
|
}
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectUnit Project::findUnit(const Editor *editor)
|
2022-01-13 17:15:57 +08:00
|
|
|
{
|
|
|
|
if (!editor)
|
2022-10-01 08:54:44 +08:00
|
|
|
return PProjectUnit();
|
|
|
|
return findUnit(editor->filename());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::associateEditor(Editor *editor)
|
|
|
|
{
|
|
|
|
PProjectUnit unit = findUnit(editor);
|
2022-01-13 17:15:57 +08:00
|
|
|
associateEditorToUnit(editor,unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit)
|
|
|
|
{
|
2022-03-22 18:39:53 +08:00
|
|
|
if (!unit) {
|
|
|
|
if (editor)
|
2022-10-09 22:19:18 +08:00
|
|
|
editor->setProject(nullptr);
|
2022-01-13 17:15:57 +08:00
|
|
|
return;
|
2022-03-22 18:39:53 +08:00
|
|
|
}
|
2022-01-13 17:15:57 +08:00
|
|
|
if (editor) {
|
2023-01-24 11:31:30 +08:00
|
|
|
Editor * e= unitEditor(unit);
|
|
|
|
if (e) {
|
|
|
|
if (editor==e)
|
|
|
|
return;
|
|
|
|
e->setProject(nullptr);
|
|
|
|
e->close();
|
2023-01-24 10:21:19 +08:00
|
|
|
}
|
2023-01-24 11:31:30 +08:00
|
|
|
editor->setProject(this);
|
|
|
|
// if (editor->encodingOption()==ENCODING_AUTO_DETECT) {
|
|
|
|
// if (editor->fileEncoding()==ENCODING_ASCII) {
|
|
|
|
// editor->setEncodingOption(mOptions.encoding);
|
|
|
|
// } else {
|
|
|
|
// editor->setEncodingOption(editor->fileEncoding());
|
|
|
|
// }
|
|
|
|
// }
|
2023-02-07 10:46:06 +08:00
|
|
|
if (unit->encoding()==ENCODING_PROJECT) {
|
|
|
|
if (editor->encodingOption()!=mOptions.encoding)
|
|
|
|
unit->setEncoding(editor->encodingOption());
|
|
|
|
} else if (editor->encodingOption()!=unit->encoding()) {
|
2023-01-24 11:31:30 +08:00
|
|
|
unit->setEncoding(editor->encodingOption());
|
2023-02-07 10:46:06 +08:00
|
|
|
}
|
2023-01-19 20:04:05 +08:00
|
|
|
unit->setRealEncoding(editor->fileEncoding());
|
2022-01-13 16:47:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:22:16 +08:00
|
|
|
//bool Project::setCompileOption(const QString &key, int valIndex)
|
|
|
|
//{
|
|
|
|
// Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
|
|
|
|
// if (!pSet)
|
|
|
|
// return false;
|
|
|
|
// PCompilerOption op = CompilerInfoManager::getCompilerOption(
|
|
|
|
// pSet->compilerType(), key);
|
|
|
|
// if (!op)
|
|
|
|
// return false;
|
|
|
|
// if (op->choices.isEmpty()) {
|
|
|
|
// if (valIndex>0)
|
|
|
|
// mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON);
|
|
|
|
// else
|
|
|
|
// mOptions.compilerOptions.insert(key,"");
|
|
|
|
// } else {
|
|
|
|
// if (valIndex>0 && valIndex <= op->choices.length()) {
|
|
|
|
// mOptions.compilerOptions.insert(key,op->choices[valIndex-1].second);
|
|
|
|
// } else {
|
|
|
|
// mOptions.compilerOptions.insert(key,"");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
//}
|
2022-05-12 15:28:08 +08:00
|
|
|
|
|
|
|
bool Project::setCompileOption(const QString &key, const QString &value)
|
|
|
|
{
|
2022-05-13 20:22:16 +08:00
|
|
|
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
|
|
|
|
if (!pSet)
|
|
|
|
return false;
|
|
|
|
PCompilerOption op = CompilerInfoManager::getCompilerOption(
|
|
|
|
pSet->compilerType(), key);
|
2022-05-12 15:28:08 +08:00
|
|
|
if (!op)
|
|
|
|
return false;
|
|
|
|
mOptions.compilerOptions.insert(key,value);
|
|
|
|
return true;
|
2021-09-10 23:41:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-14 11:21:59 +08:00
|
|
|
QString Project::getCompileOption(const QString &key) const
|
|
|
|
{
|
|
|
|
return mOptions.compilerOptions.value(key,"");
|
|
|
|
}
|
|
|
|
|
2021-09-11 09:21:44 +08:00
|
|
|
void Project::updateFolders()
|
|
|
|
{
|
|
|
|
mFolders.clear();
|
2022-02-08 12:33:10 +08:00
|
|
|
updateFolderNode(mRootNode);
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (PProjectUnit unit, mUnits) {
|
|
|
|
unit->setFolder(
|
|
|
|
getNodePath(
|
|
|
|
unit->node()->parent.lock()
|
2021-09-11 09:21:44 +08:00
|
|
|
)
|
|
|
|
);
|
2022-10-01 08:54:44 +08:00
|
|
|
}
|
2021-09-11 09:21:44 +08:00
|
|
|
setModified(true);
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode Project::pointerToNode(ProjectModelNode *p, PProjectModelNode parent)
|
2021-09-17 13:35:50 +08:00
|
|
|
{
|
2022-05-19 17:57:31 +08:00
|
|
|
if (!p)
|
|
|
|
return PProjectModelNode();
|
2021-09-17 19:58:37 +08:00
|
|
|
if (!parent) {
|
2022-02-08 12:33:10 +08:00
|
|
|
parent = mRootNode;
|
2021-09-17 19:58:37 +08:00
|
|
|
}
|
2022-02-08 12:33:10 +08:00
|
|
|
if (p==mRootNode.get())
|
|
|
|
return mRootNode;
|
2022-02-08 00:24:08 +08:00
|
|
|
foreach (const PProjectModelNode& node , parent->children) {
|
2021-09-17 13:35:50 +08:00
|
|
|
if (node.get()==p)
|
|
|
|
return node;
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode result = pointerToNode(p,node);
|
2021-09-17 19:58:37 +08:00
|
|
|
if (result)
|
|
|
|
return result;
|
2021-09-17 13:35:50 +08:00
|
|
|
}
|
2022-02-08 00:24:08 +08:00
|
|
|
return PProjectModelNode();
|
2021-09-17 13:35:50 +08:00
|
|
|
}
|
|
|
|
|
2021-10-25 21:36:23 +08:00
|
|
|
void Project::setCompilerSet(int compilerSetIndex)
|
|
|
|
{
|
|
|
|
if (mOptions.compilerSet != compilerSetIndex) {
|
|
|
|
mOptions.compilerSet = compilerSetIndex;
|
2023-02-18 12:08:03 +08:00
|
|
|
updateCompilerSetting();
|
2022-03-30 19:50:55 +08:00
|
|
|
setModified(true);
|
2021-10-25 21:36:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 21:36:12 +08:00
|
|
|
bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, bool useCpp)
|
2021-09-16 23:51:05 +08:00
|
|
|
{
|
|
|
|
if (!aTemplate) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
mModel.beginUpdate();
|
|
|
|
mRootNode = makeProjectNode();
|
2022-10-09 22:19:18 +08:00
|
|
|
rebuildNodes();
|
2021-09-16 23:51:05 +08:00
|
|
|
mOptions = aTemplate->options();
|
2021-09-18 22:37:07 +08:00
|
|
|
mOptions.compilerSet = pSettings->compilerSets().defaultIndex();
|
2022-02-01 16:17:28 +08:00
|
|
|
mOptions.isCpp = useCpp;
|
2023-02-18 12:08:03 +08:00
|
|
|
updateCompilerSetting();
|
2021-09-17 09:56:52 +08:00
|
|
|
mOptions.icon = aTemplate->icon();
|
2021-09-16 23:51:05 +08:00
|
|
|
|
2023-02-15 16:24:24 +08:00
|
|
|
QTextCodec* codec=QTextCodec::codecForName(mOptions.encoding);
|
|
|
|
if (!codec)
|
|
|
|
mOptions.encoding=ENCODING_SYSTEM_DEFAULT;
|
|
|
|
codec=QTextCodec::codecForName(mOptions.execEncoding);
|
|
|
|
if (!codec)
|
|
|
|
mOptions.execEncoding=ENCODING_SYSTEM_DEFAULT;
|
|
|
|
|
2021-09-16 23:51:05 +08:00
|
|
|
// Copy icon to project directory
|
|
|
|
if (!mOptions.icon.isEmpty()) {
|
2022-10-24 17:23:37 +08:00
|
|
|
QString originIcon = cleanPath(QFileInfo(aTemplate->fileName()).absoluteDir().absoluteFilePath(mOptions.icon));
|
2021-09-16 23:51:05 +08:00
|
|
|
if (fileExists(originIcon)) {
|
2022-10-24 17:23:37 +08:00
|
|
|
QString destIcon = cleanPath(QFileInfo(mFilename).absoluteDir().absoluteFilePath("app.ico"));
|
2021-09-16 23:51:05 +08:00
|
|
|
QFile::copy(originIcon,destIcon);
|
|
|
|
mOptions.icon = destIcon;
|
|
|
|
} else {
|
|
|
|
mOptions.icon = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add list of files
|
|
|
|
if (aTemplate->version() > 0) {
|
2022-08-07 12:09:22 +08:00
|
|
|
QDir dir(aTemplate->folder());
|
2021-09-16 23:51:05 +08:00
|
|
|
for (int i=0;i<aTemplate->unitCount();i++) {
|
|
|
|
// Pick file contents
|
|
|
|
PTemplateUnit templateUnit = aTemplate->unit(i);
|
2022-01-10 10:53:16 +08:00
|
|
|
if (!templateUnit->Source.isEmpty()) {
|
|
|
|
QString target = templateUnit->Source;
|
|
|
|
PProjectUnit unit;
|
|
|
|
if (!templateUnit->Target.isEmpty())
|
|
|
|
target = templateUnit->Target;
|
|
|
|
QFile::copy(
|
2022-10-24 17:23:37 +08:00
|
|
|
cleanPath(dir.absoluteFilePath(templateUnit->Source)),
|
2022-01-10 10:53:16 +08:00
|
|
|
includeTrailingPathDelimiter(this->directory())+target);
|
2022-02-08 12:33:10 +08:00
|
|
|
unit = newUnit(mRootNode, target);
|
2023-02-10 19:28:18 +08:00
|
|
|
|
|
|
|
FileType fileType=getFileType(unit->fileName());
|
|
|
|
if (fileType==FileType::ASM
|
2023-02-12 12:53:14 +08:00
|
|
|
|| fileType==FileType::GAS
|
2023-02-10 19:28:18 +08:00
|
|
|
|| isCFile(unit->fileName()) || isHFile(unit->fileName())) {
|
|
|
|
Editor * editor = mEditorList->newEditor(
|
|
|
|
unit->fileName(),
|
|
|
|
unit->encoding()==ENCODING_PROJECT?options().encoding:unit->encoding(),
|
|
|
|
this,
|
|
|
|
false);
|
|
|
|
editor->activate();
|
|
|
|
}
|
2021-09-16 23:51:05 +08:00
|
|
|
} else {
|
2022-01-10 10:53:16 +08:00
|
|
|
QString s;
|
|
|
|
PProjectUnit unit;
|
2022-02-01 16:17:28 +08:00
|
|
|
if (mOptions.isCpp) {
|
2022-01-10 10:53:16 +08:00
|
|
|
s = templateUnit->CppText;
|
2022-02-08 12:33:10 +08:00
|
|
|
unit = newUnit(mRootNode, templateUnit->CppName);
|
2022-01-10 10:53:16 +08:00
|
|
|
} else {
|
|
|
|
s = templateUnit->CText;
|
2022-02-08 12:33:10 +08:00
|
|
|
unit = newUnit(mRootNode,templateUnit->CName);
|
2022-01-10 10:53:16 +08:00
|
|
|
}
|
2021-09-26 22:39:26 +08:00
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * editor = mEditorList->newEditor(
|
2022-03-28 16:57:58 +08:00
|
|
|
unit->fileName(),
|
2023-02-07 10:46:06 +08:00
|
|
|
unit->encoding()==ENCODING_PROJECT?options().encoding:unit->encoding(),
|
2022-10-09 22:19:18 +08:00
|
|
|
this,
|
2022-01-10 10:53:16 +08:00
|
|
|
true);
|
|
|
|
|
2022-10-24 17:23:37 +08:00
|
|
|
QString s2 = cleanPath(dir.absoluteFilePath(s));
|
2022-01-10 10:53:16 +08:00
|
|
|
if (fileExists(s2) && !s.isEmpty()) {
|
|
|
|
try {
|
|
|
|
editor->loadFile(s2);
|
|
|
|
} catch(FileError& e) {
|
2022-03-21 09:08:05 +08:00
|
|
|
QMessageBox::critical(nullptr,
|
2022-01-10 10:53:16 +08:00
|
|
|
tr("Error Load File"),
|
|
|
|
e.reason());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s.replace("#13#10","\r\n");
|
|
|
|
editor->insertString(s,false);
|
2021-10-25 00:30:53 +08:00
|
|
|
}
|
2022-01-10 10:53:16 +08:00
|
|
|
editor->save(true,false);
|
|
|
|
editor->activate();
|
2021-09-16 23:51:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
mModel.endUpdate();
|
2021-09-16 23:51:05 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-07 21:41:57 +08:00
|
|
|
bool Project::saveAsTemplate(const QString &templateFolder,
|
|
|
|
const QString& name,
|
|
|
|
const QString& description,
|
|
|
|
const QString& category)
|
|
|
|
{
|
|
|
|
QDir dir(templateFolder);
|
|
|
|
if (!dir.mkpath(templateFolder)) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
tr("Error"),
|
|
|
|
tr("Can't create folder %1 ").arg(templateFolder),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-24 17:23:37 +08:00
|
|
|
QString fileName = cleanPath(dir.absoluteFilePath(TEMPLATE_INFO_FILE));
|
2022-08-07 21:41:57 +08:00
|
|
|
PSimpleIni ini = std::make_shared<SimpleIni>();
|
|
|
|
|
|
|
|
ini->SetLongValue("Template","Ver",3);
|
|
|
|
// template info
|
|
|
|
ini->SetValue("Template", "Name", name.toUtf8());
|
|
|
|
ini->SetValue("Template", "Category", category.toUtf8());
|
|
|
|
ini->SetValue("Template", "Description", description.toUtf8());
|
|
|
|
if (fileExists(mOptions.icon)) {
|
|
|
|
QString iconName = extractFileName(mOptions.icon);
|
2022-10-24 17:23:37 +08:00
|
|
|
copyFile(mOptions.icon, cleanPath(dir.absoluteFilePath(iconName)),true);
|
2022-08-07 21:41:57 +08:00
|
|
|
if (dir.exists(iconName))
|
|
|
|
ini->SetValue("Template", "Icon", iconName.toUtf8());
|
|
|
|
}
|
|
|
|
|
|
|
|
ini->SetLongValue("Project", "Type", static_cast<int>(mOptions.type));
|
|
|
|
if (!mOptions.includeDirs.isEmpty())
|
2022-11-16 09:24:42 +08:00
|
|
|
ini->SetValue("Project", "Includes", relativePaths(mOptions.includeDirs).join(";").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.resourceIncludes.isEmpty())
|
2022-11-16 09:24:42 +08:00
|
|
|
ini->SetValue("Project", "ResourceIncludes", relativePaths(mOptions.resourceIncludes).join(";").toUtf8());
|
2022-11-10 13:35:13 +08:00
|
|
|
if (!mOptions.makeIncludes.isEmpty())
|
2022-11-16 09:24:42 +08:00
|
|
|
ini->SetValue("Project", "MakeIncludes", relativePaths(mOptions.makeIncludes).join(";").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.binDirs.isEmpty())
|
2022-11-16 09:24:42 +08:00
|
|
|
ini->SetValue("Project", "Bins", relativePaths(mOptions.binDirs).join(";").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.libDirs.isEmpty())
|
2022-11-16 09:24:42 +08:00
|
|
|
ini->SetValue("Project", "Libs", relativePaths(mOptions.libDirs).join(";").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.compilerCmd.isEmpty())
|
2023-02-10 09:42:55 +08:00
|
|
|
ini->SetValue("Project", "Compiler", textToLines(mOptions.compilerCmd).join(";CONFIG_LINE;").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.cppCompilerCmd.isEmpty())
|
2023-02-10 09:42:55 +08:00
|
|
|
ini->SetValue("Project", "CppCompiler", textToLines(mOptions.cppCompilerCmd).join(";CONFIG_LINE;").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.linkerCmd.isEmpty())
|
2023-02-10 09:42:55 +08:00
|
|
|
ini->SetValue("Project", "Linker",textToLines(mOptions.linkerCmd).join(";CONFIG_LINE;").toUtf8());
|
2022-12-26 22:55:00 +08:00
|
|
|
if (!mOptions.resourceCmd.isEmpty())
|
2023-02-10 09:42:55 +08:00
|
|
|
ini->SetValue("Project", "ResourceCommand",textToLines(mOptions.resourceCmd).join(";CONFIG_LINE;").toUtf8());
|
2023-02-09 16:33:25 +08:00
|
|
|
if (!mOptions.assemblerArgs.isEmpty())
|
2023-02-10 09:42:55 +08:00
|
|
|
ini->SetValue("Project", "AssemblerArgs",textToLines(mOptions.assemblerArgs).join(";CONFIG_LINE;").toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
ini->SetBoolValue("Project", "IsCpp", mOptions.isCpp);
|
|
|
|
if (mOptions.includeVersionInfo)
|
|
|
|
ini->SetBoolValue("Project", "IncludeVersionInfo", true);
|
|
|
|
if (mOptions.supportXPThemes)
|
|
|
|
ini->SetBoolValue("Project", "SupportXPThemes", true);
|
|
|
|
if (!mOptions.exeOutput.isEmpty())
|
2022-11-10 14:47:44 +08:00
|
|
|
ini->SetValue("Project", "ExeOutput", extractRelativePath(directory(),mOptions.exeOutput).toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.objectOutput.isEmpty())
|
2022-11-10 14:47:44 +08:00
|
|
|
ini->SetValue("Project", "ObjectOutput", extractRelativePath(directory(),mOptions.objectOutput).toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.logOutput.isEmpty())
|
2022-11-10 14:47:44 +08:00
|
|
|
ini->SetValue("Project", "LogOutput", extractRelativePath(directory(),mOptions.logOutput).toUtf8());
|
2022-08-07 21:41:57 +08:00
|
|
|
if (mOptions.execEncoding!=ENCODING_SYSTEM_DEFAULT)
|
|
|
|
ini->SetValue("Project","ExecEncoding", mOptions.execEncoding);
|
|
|
|
|
2022-08-08 10:45:35 +08:00
|
|
|
// if (!mOptions.staticLink)
|
|
|
|
// ini->SetBoolValue("Project", "StaticLink",false);
|
2022-08-07 21:41:57 +08:00
|
|
|
if (!mOptions.addCharset)
|
|
|
|
ini->SetBoolValue("Project", "AddCharset",false);
|
|
|
|
if (mOptions.encoding!=ENCODING_AUTO_DETECT)
|
2023-01-24 10:21:19 +08:00
|
|
|
ini->SetValue("Project","Encoding",mOptions.encoding);
|
2022-08-07 21:41:57 +08:00
|
|
|
if (mOptions.modelType!=ProjectModelType::FileSystem)
|
|
|
|
ini->SetLongValue("Project", "ModelType", (int)mOptions.modelType);
|
2022-10-23 15:22:26 +08:00
|
|
|
ini->SetLongValue("Project","ClassBrowserType", (int)mOptions.classBrowserType);
|
2022-08-07 21:41:57 +08:00
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
int i=0;
|
|
|
|
foreach (const PProjectUnit &unit, mUnits) {
|
2022-08-07 21:41:57 +08:00
|
|
|
QString unitName = extractFileName(unit->fileName());
|
|
|
|
QByteArray section = toByteArray(QString("Unit%1").arg(i));
|
2022-10-24 17:23:37 +08:00
|
|
|
if (!copyFile(unit->fileName(), cleanPath(dir.absoluteFilePath(unitName)),true)) {
|
2022-08-07 21:41:57 +08:00
|
|
|
QMessageBox::warning(nullptr,
|
|
|
|
tr("Warning"),
|
2022-10-24 17:23:37 +08:00
|
|
|
tr("Can't save file %1").arg(cleanPath(dir.absoluteFilePath(unitName))),
|
2022-08-07 21:41:57 +08:00
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
switch(getFileType(unit->fileName())) {
|
|
|
|
case FileType::CSource:
|
|
|
|
ini->SetValue(section,"C", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"CName", unitName.toUtf8());
|
|
|
|
break;
|
|
|
|
case FileType::CppSource:
|
|
|
|
ini->SetValue(section,"Cpp", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"CppName", unitName.toUtf8());
|
|
|
|
break;
|
|
|
|
case FileType::CHeader:
|
|
|
|
case FileType::CppHeader:
|
|
|
|
ini->SetValue(section,"C", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"CName", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"Cpp", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"CppName", unitName.toUtf8());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ini->SetValue(section,"Source", unitName.toUtf8());
|
|
|
|
ini->SetValue(section,"Target", unitName.toUtf8());
|
|
|
|
}
|
2022-10-01 08:54:44 +08:00
|
|
|
i++;
|
2022-08-07 21:41:57 +08:00
|
|
|
}
|
|
|
|
ini->SetLongValue("Project","UnitCount",mUnits.count());
|
|
|
|
if (ini->SaveFile(fileName.toLocal8Bit())!=SI_OK) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
tr("Error"),
|
|
|
|
tr("Can't save file %1").arg(fileName),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-08 12:20:20 +08:00
|
|
|
void Project::setEncoding(const QByteArray &encoding)
|
|
|
|
{
|
|
|
|
if (encoding!=mOptions.encoding) {
|
|
|
|
mOptions.encoding=encoding;
|
|
|
|
foreach (const PProjectUnit& unit,mUnits) {
|
|
|
|
if (unit->encoding()!=ENCODING_PROJECT)
|
|
|
|
continue;
|
|
|
|
Editor * e=unitEditor(unit);
|
|
|
|
if (e) {
|
|
|
|
e->setEncodingOption(mOptions.encoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 21:37:52 +08:00
|
|
|
void Project::saveOptions()
|
|
|
|
{
|
2021-09-12 19:50:44 +08:00
|
|
|
SimpleIni ini;
|
|
|
|
ini.LoadFile(mFilename.toLocal8Bit());
|
|
|
|
ini.SetValue("Project","FileName", toByteArray(extractRelativePath(directory(), mFilename)));
|
|
|
|
ini.SetValue("Project","Name", toByteArray(mName));
|
|
|
|
ini.SetLongValue("Project","Type", static_cast<int>(mOptions.type));
|
2021-12-30 19:25:47 +08:00
|
|
|
ini.SetLongValue("Project","Ver", 3); // Is 3 as of Red Panda C++.0
|
2022-11-16 09:24:42 +08:00
|
|
|
ini.SetValue("Project","Includes", toByteArray(relativePaths(mOptions.includeDirs).join(";")));
|
|
|
|
ini.SetValue("Project","Libs", toByteArray(relativePaths(mOptions.libDirs).join(";")));
|
|
|
|
ini.SetValue("Project","Bins", toByteArray(relativePaths(mOptions.binDirs).join(";")));
|
|
|
|
ini.SetValue("Project","ResourceIncludes", toByteArray(relativePaths(mOptions.resourceIncludes).join(";")));
|
|
|
|
ini.SetValue("Project","MakeIncludes", toByteArray(relativePaths(mOptions.makeIncludes).join(";")));
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue("Project","PrivateResource", toByteArray(mOptions.privateResource));
|
2023-02-10 09:42:55 +08:00
|
|
|
ini.SetValue("Project","Compiler", toByteArray(textToLines(mOptions.compilerCmd).join(";CONFIG_LINE;")));
|
|
|
|
ini.SetValue("Project","CppCompiler", toByteArray(textToLines(mOptions.cppCompilerCmd).join(";CONFIG_LINE;")));
|
|
|
|
ini.SetValue("Project","AssemblerArgs",toByteArray(textToLines(mOptions.assemblerArgs).join(";CONFIG_LINE;")));
|
|
|
|
ini.SetValue("Project","Linker", toByteArray(textToLines(mOptions.linkerCmd).join(";CONFIG_LINE;")));
|
|
|
|
ini.SetValue("Project", "ResourceCommand", toByteArray(textToLines(mOptions.resourceCmd).join(";CONFIG_LINE;")));
|
2022-02-01 16:17:28 +08:00
|
|
|
ini.SetLongValue("Project","IsCpp", mOptions.isCpp);
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue("Project","Icon", toByteArray(extractRelativePath(directory(), mOptions.icon)));
|
2022-11-10 14:47:44 +08:00
|
|
|
ini.SetValue("Project","ExeOutput", toByteArray(extractRelativePath(directory(),mOptions.exeOutput)));
|
|
|
|
ini.SetValue("Project","ObjectOutput", toByteArray(extractRelativePath(directory(),mOptions.objectOutput)));
|
|
|
|
ini.SetValue("Project","LogOutput", toByteArray(extractRelativePath(directory(),mOptions.logOutput)));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","LogOutputEnabled", mOptions.logOutputEnabled);
|
|
|
|
ini.SetLongValue("Project","OverrideOutput", mOptions.overrideOutput);
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue("Project","OverrideOutputName", toByteArray(mOptions.overridenOutput));
|
2022-11-10 13:35:13 +08:00
|
|
|
ini.SetValue("Project","HostApplication", toByteArray(extractRelativePath(directory(), mOptions.hostApplication)));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","UseCustomMakefile", mOptions.useCustomMakefile);
|
2022-11-10 13:35:13 +08:00
|
|
|
ini.SetValue("Project","CustomMakefile", toByteArray(extractRelativePath(directory(),mOptions.customMakefile)));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","UsePrecompiledHeader", mOptions.usePrecompiledHeader);
|
2022-11-10 13:35:13 +08:00
|
|
|
ini.SetValue("Project","PrecompiledHeader", toByteArray(extractRelativePath(directory(), mOptions.precompiledHeader)));
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue("Project","CommandLine", toByteArray(mOptions.cmdLineArgs));
|
|
|
|
ini.SetValue("Project","Folders", toByteArray(mFolders.join(";")));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","IncludeVersionInfo", mOptions.includeVersionInfo);
|
|
|
|
ini.SetLongValue("Project","SupportXPThemes", mOptions.supportXPThemes);
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetLongValue("Project","CompilerSet", mOptions.compilerSet);
|
2022-06-10 22:08:10 +08:00
|
|
|
ini.Delete("Project","CompilerSettings"); // remove old compiler settings
|
|
|
|
ini.Delete("CompilerSettings",nullptr); // remove old compiler settings
|
2022-05-12 15:28:08 +08:00
|
|
|
foreach (const QString& key, mOptions.compilerOptions.keys()) {
|
|
|
|
ini.SetValue("CompilerSettings",toByteArray(key),toByteArray(mOptions.compilerOptions.value(key)));
|
|
|
|
}
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","StaticLink", mOptions.staticLink);
|
|
|
|
ini.SetLongValue("Project","AddCharset", mOptions.addCharset);
|
2022-06-22 17:08:35 +08:00
|
|
|
ini.SetValue("Project","ExecEncoding", mOptions.execEncoding);
|
2023-01-24 10:21:19 +08:00
|
|
|
ini.SetValue("Project","Encoding",mOptions.encoding);
|
2022-02-08 00:24:08 +08:00
|
|
|
ini.SetLongValue("Project","ModelType", (int)mOptions.modelType);
|
2022-10-23 15:22:26 +08:00
|
|
|
ini.SetLongValue("Project","ClassBrowserType", (int)mOptions.classBrowserType);
|
2022-11-06 22:51:14 +08:00
|
|
|
ini.SetBoolValue("Project","AllowParallelBuilding",mOptions.allowParallelBuilding);
|
|
|
|
ini.SetLongValue("Project","ParellelBuildingJobs",mOptions.parellelBuildingJobs);
|
|
|
|
|
|
|
|
|
2021-09-10 23:41:38 +08:00
|
|
|
//for Red Panda Dev C++ 6 compatibility
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("Project","UseUTF8",mOptions.encoding == ENCODING_UTF8);
|
2021-09-12 19:50:44 +08:00
|
|
|
|
|
|
|
ini.SetLongValue("VersionInfo","Major", mOptions.versionInfo.major);
|
|
|
|
ini.SetLongValue("VersionInfo","Minor", mOptions.versionInfo.minor);
|
|
|
|
ini.SetLongValue("VersionInfo","Release", mOptions.versionInfo.release);
|
|
|
|
ini.SetLongValue("VersionInfo","Build", mOptions.versionInfo.build);
|
|
|
|
ini.SetLongValue("VersionInfo","LanguageID", mOptions.versionInfo.languageID);
|
|
|
|
ini.SetLongValue("VersionInfo","CharsetID", mOptions.versionInfo.charsetID);
|
|
|
|
ini.SetValue("VersionInfo","CompanyName", toByteArray(mOptions.versionInfo.companyName));
|
|
|
|
ini.SetValue("VersionInfo","FileVersion", toByteArray(mOptions.versionInfo.fileVersion));
|
|
|
|
ini.SetValue("VersionInfo","FileDescription", toByteArray(mOptions.versionInfo.fileDescription));
|
|
|
|
ini.SetValue("VersionInfo","InternalName", toByteArray(mOptions.versionInfo.internalName));
|
|
|
|
ini.SetValue("VersionInfo","LegalCopyright", toByteArray(mOptions.versionInfo.legalCopyright));
|
|
|
|
ini.SetValue("VersionInfo","LegalTrademarks", toByteArray(mOptions.versionInfo.legalTrademarks));
|
|
|
|
ini.SetValue("VersionInfo","OriginalFilename", toByteArray(mOptions.versionInfo.originalFilename));
|
|
|
|
ini.SetValue("VersionInfo","ProductName", toByteArray(mOptions.versionInfo.productName));
|
|
|
|
ini.SetValue("VersionInfo","ProductVersion", toByteArray(mOptions.versionInfo.productVersion));
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue("VersionInfo","AutoIncBuildNr", mOptions.versionInfo.autoIncBuildNr);
|
|
|
|
ini.SetLongValue("VersionInfo","SyncProduct", mOptions.versionInfo.syncProduct);
|
2021-09-10 23:41:38 +08:00
|
|
|
|
2021-09-10 21:37:52 +08:00
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
//delete outdated dev4 project options
|
|
|
|
ini.Delete("Project","NoConsole");
|
|
|
|
ini.Delete("Project","IsDLL");
|
|
|
|
ini.Delete("Project","ResFiles");
|
|
|
|
ini.Delete("Project","IncludeDirs");
|
|
|
|
ini.Delete("Project","CompilerOptions");
|
|
|
|
ini.Delete("Project","Use_GPP");
|
|
|
|
|
|
|
|
ini.SaveFile(mFilename.toLocal8Bit());
|
2021-09-10 21:37:52 +08:00
|
|
|
}
|
|
|
|
|
2022-10-02 23:32:33 +08:00
|
|
|
PProjectModelNode Project::addFolder(PProjectModelNode parentFolder,const QString &s)
|
2021-09-07 10:28:40 +08:00
|
|
|
{
|
2022-10-02 23:32:33 +08:00
|
|
|
QString fullPath;
|
|
|
|
QString path = getNodePath(parentFolder);
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
fullPath = s;
|
|
|
|
} else {
|
|
|
|
fullPath = path + '/' +s;
|
|
|
|
}
|
|
|
|
if (mFolders.indexOf(fullPath)<0) {
|
2021-09-11 09:21:44 +08:00
|
|
|
mModel.beginUpdate();
|
|
|
|
auto action = finally([this]{
|
|
|
|
mModel.endUpdate();
|
|
|
|
});
|
2022-10-02 23:32:33 +08:00
|
|
|
mFolders.append(fullPath);
|
|
|
|
PProjectModelNode node = makeNewFolderNode(s,parentFolder);
|
2021-09-07 10:28:40 +08:00
|
|
|
setModified(true);
|
2022-10-02 23:32:33 +08:00
|
|
|
return node;
|
2021-09-07 10:28:40 +08:00
|
|
|
}
|
2022-10-02 23:32:33 +08:00
|
|
|
return PProjectModelNode();
|
2021-09-07 10:28:40 +08:00
|
|
|
}
|
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
PProjectUnit Project::addUnit(const QString &inFileName, PProjectModelNode parentNode)
|
2022-11-07 11:24:23 +08:00
|
|
|
{
|
|
|
|
PProjectUnit newUnit=internalAddUnit(inFileName, parentNode);
|
|
|
|
if (newUnit) {
|
|
|
|
emit unitAdded(newUnit->fileName());
|
|
|
|
}
|
|
|
|
return newUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
PProjectUnit Project::internalAddUnit(const QString &inFileName, PProjectModelNode parentNode)
|
2021-09-07 10:28:40 +08:00
|
|
|
{
|
|
|
|
// Don't add if it already exists
|
|
|
|
if (fileAlreadyExists(inFileName)) {
|
2022-03-21 09:08:05 +08:00
|
|
|
QMessageBox::critical(nullptr,
|
2021-09-07 10:28:40 +08:00
|
|
|
tr("File Exists"),
|
|
|
|
tr("File '%1' is already in the project"),
|
|
|
|
QMessageBox::Ok);
|
2022-10-02 13:29:51 +08:00
|
|
|
return PProjectUnit();
|
2021-09-07 10:28:40 +08:00
|
|
|
}
|
2022-10-02 13:29:51 +08:00
|
|
|
if (mOptions.modelType == ProjectModelType::FileSystem) {
|
|
|
|
// in file system mode, parentNode is determined by file's path
|
|
|
|
parentNode = getParentFileSystemFolderNode(inFileName);
|
|
|
|
}
|
|
|
|
PProjectUnit newUnit = std::make_shared<ProjectUnit>(this);
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
// Set all properties
|
|
|
|
newUnit->setFileName(QDir(directory()).filePath(inFileName));
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * e= unitEditor(newUnit);
|
2021-11-15 22:08:35 +08:00
|
|
|
if (e) {
|
2023-01-24 10:21:19 +08:00
|
|
|
associateEditorToUnit(e,newUnit);
|
|
|
|
// newUnit->setEncoding(e->encodingOption());
|
|
|
|
// newUnit->setRealEncoding(e->fileEncoding());
|
|
|
|
// e->setProject(this);
|
2021-11-15 22:08:35 +08:00
|
|
|
} else {
|
2023-01-24 11:31:30 +08:00
|
|
|
newUnit->setEncoding(ENCODING_PROJECT);
|
2021-11-15 22:08:35 +08:00
|
|
|
}
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
// Determine compilation flags
|
|
|
|
switch(getFileType(inFileName)) {
|
2023-02-12 12:53:14 +08:00
|
|
|
case FileType::GAS:
|
|
|
|
newUnit->setCompile(true);
|
|
|
|
newUnit->setCompileCpp(false);
|
|
|
|
newUnit->setLink(true);
|
|
|
|
break;
|
2023-02-08 21:07:41 +08:00
|
|
|
case FileType::ASM:
|
|
|
|
newUnit->setCompile(true);
|
|
|
|
newUnit->setCompileCpp(false);
|
|
|
|
newUnit->setLink(true);
|
|
|
|
break;
|
2021-09-07 10:28:40 +08:00
|
|
|
case FileType::CSource:
|
|
|
|
newUnit->setCompile(true);
|
2022-06-10 08:41:52 +08:00
|
|
|
newUnit->setCompileCpp(false);
|
2021-09-07 10:28:40 +08:00
|
|
|
newUnit->setLink(true);
|
|
|
|
break;
|
|
|
|
case FileType::CppSource:
|
|
|
|
newUnit->setCompile(true);
|
|
|
|
newUnit->setCompileCpp(true);
|
|
|
|
newUnit->setLink(true);
|
|
|
|
break;
|
|
|
|
case FileType::WindowsResourceSource:
|
|
|
|
newUnit->setCompile(true);
|
2022-02-01 16:17:28 +08:00
|
|
|
newUnit->setCompileCpp(mOptions.isCpp);
|
2021-09-07 10:28:40 +08:00
|
|
|
newUnit->setLink(false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newUnit->setCompile(false);
|
|
|
|
newUnit->setCompileCpp(false);
|
|
|
|
newUnit->setLink(false);
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
if (mOptions.modelType == ProjectModelType::FileSystem)
|
|
|
|
newUnit->setFolder(getNodePath(parentNode));
|
2021-09-07 10:28:40 +08:00
|
|
|
newUnit->setPriority(1000);
|
|
|
|
newUnit->setOverrideBuildCmd(false);
|
|
|
|
newUnit->setBuildCmd("");
|
2022-10-02 13:29:51 +08:00
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectModelNode node = makeNewFileNode(newUnit,
|
2022-10-02 13:29:51 +08:00
|
|
|
newUnit->priority(), parentNode);
|
|
|
|
newUnit->setNode(node);
|
2022-10-08 23:30:30 +08:00
|
|
|
mUnits.insert(newUnit->fileName(),newUnit);
|
2022-10-02 13:29:51 +08:00
|
|
|
|
2021-09-07 10:28:40 +08:00
|
|
|
setModified(true);
|
|
|
|
return newUnit;
|
|
|
|
}
|
|
|
|
|
2022-01-27 18:34:18 +08:00
|
|
|
QString Project::folder()
|
|
|
|
{
|
|
|
|
return extractFileDir(filename());
|
|
|
|
}
|
|
|
|
|
2022-12-30 19:48:12 +08:00
|
|
|
void Project::buildPrivateResource()
|
2021-09-07 10:28:40 +08:00
|
|
|
{
|
|
|
|
int comp = 0;
|
|
|
|
foreach (const PProjectUnit& unit,mUnits) {
|
|
|
|
if (
|
|
|
|
(getFileType(unit->fileName()) == FileType::WindowsResourceSource)
|
|
|
|
&& unit->compile() )
|
|
|
|
comp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if project has no other resources included
|
|
|
|
// and does not have an icon
|
|
|
|
// and does not include the XP style manifest
|
|
|
|
// and does not include version info
|
|
|
|
// then do not create a private resource file
|
|
|
|
if ((comp == 0) &&
|
|
|
|
(! mOptions.supportXPThemes)
|
|
|
|
&& (! mOptions.includeVersionInfo)
|
|
|
|
&& (mOptions.icon == "")) {
|
|
|
|
mOptions.privateResource="";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// change private resource from <project_filename>.res
|
|
|
|
// to <project_filename>_private.res
|
|
|
|
//
|
|
|
|
// in many cases (like in importing a MSVC project)
|
|
|
|
// the project's resource file has already the
|
|
|
|
// <project_filename>.res filename.
|
2021-09-07 14:04:48 +08:00
|
|
|
QString rcFile;
|
2021-09-07 10:28:40 +08:00
|
|
|
if (!mOptions.privateResource.isEmpty()) {
|
2021-09-07 14:04:48 +08:00
|
|
|
rcFile = QDir(directory()).filePath(mOptions.privateResource);
|
2021-09-15 11:23:42 +08:00
|
|
|
if (changeFileExt(rcFile, DEV_PROJECT_EXT) == mFilename) {
|
|
|
|
QFileInfo fileInfo(mFilename);
|
|
|
|
rcFile = includeTrailingPathDelimiter(fileInfo.absolutePath())
|
|
|
|
+ fileInfo.baseName()
|
|
|
|
+ "_private."
|
|
|
|
+ RC_EXT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QFileInfo fileInfo(mFilename);
|
|
|
|
rcFile = includeTrailingPathDelimiter(fileInfo.absolutePath())
|
|
|
|
+ fileInfo.baseName()
|
|
|
|
+ "_private."
|
|
|
|
+ RC_EXT;
|
|
|
|
}
|
2021-09-07 14:04:48 +08:00
|
|
|
rcFile = extractRelativePath(mFilename, rcFile);
|
|
|
|
rcFile.replace(' ','_');
|
2021-09-07 10:28:40 +08:00
|
|
|
|
2021-09-07 16:49:35 +08:00
|
|
|
QStringList contents;
|
2021-12-30 19:25:47 +08:00
|
|
|
contents.append("/* THIS FILE WILL BE OVERWRITTEN BY Red Panda C++ */");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("/* DO NOT EDIT! */");
|
|
|
|
contents.append("");
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
if (mOptions.includeVersionInfo) {
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("#include <windows.h> // include for version info constants");
|
|
|
|
contents.append("");
|
2021-09-07 14:04:48 +08:00
|
|
|
}
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
|
|
|
if (
|
|
|
|
(getFileType(unit->fileName()) == FileType::WindowsResourceSource)
|
|
|
|
&& unit->compile() )
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("#include \"" +
|
2021-09-07 10:28:40 +08:00
|
|
|
genMakePath(
|
|
|
|
extractRelativePath(directory(), unit->fileName()),
|
|
|
|
false,
|
|
|
|
false) + "\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOptions.icon.isEmpty()) {
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("");
|
2021-09-15 12:19:09 +08:00
|
|
|
QString icon = mOptions.icon;
|
2021-09-07 10:28:40 +08:00
|
|
|
if (fileExists(icon)) {
|
|
|
|
icon = extractRelativePath(mFilename, icon);
|
|
|
|
icon.replace('\\', '/');
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("A ICON \"" + icon + '"');
|
2021-09-07 10:28:40 +08:00
|
|
|
} else
|
|
|
|
mOptions.icon = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOptions.supportXPThemes) {
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("");
|
|
|
|
contents.append("//");
|
|
|
|
contents.append("// SUPPORT FOR WINDOWS XP THEMES:");
|
|
|
|
contents.append("// THIS WILL MAKE THE PROGRAM USE THE COMMON CONTROLS");
|
|
|
|
contents.append("// LIBRARY VERSION 6.0 (IF IT IS AVAILABLE)");
|
|
|
|
contents.append("//");
|
2021-09-07 10:28:40 +08:00
|
|
|
if (!mOptions.exeOutput.isEmpty())
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(
|
2021-09-07 10:28:40 +08:00
|
|
|
"1 24 \"" +
|
|
|
|
genMakePath2(
|
|
|
|
includeTrailingPathDelimiter(mOptions.exeOutput)
|
2021-09-10 12:37:02 +08:00
|
|
|
+ extractFileName(executable()))
|
2021-09-07 10:28:40 +08:00
|
|
|
+ ".Manifest\"");
|
|
|
|
else
|
2021-09-10 12:37:02 +08:00
|
|
|
contents.append("1 24 \"" + extractFileName(executable()) + ".Manifest\"");
|
2021-09-07 14:04:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mOptions.includeVersionInfo) {
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("");
|
|
|
|
contents.append("//");
|
|
|
|
contents.append("// TO CHANGE VERSION INFORMATION, EDIT PROJECT OPTIONS...");
|
|
|
|
contents.append("//");
|
|
|
|
contents.append("1 VERSIONINFO");
|
|
|
|
contents.append("FILEVERSION " +
|
2021-09-07 14:04:48 +08:00
|
|
|
QString("%1,%2,%3,%4")
|
|
|
|
.arg(mOptions.versionInfo.major)
|
|
|
|
.arg(mOptions.versionInfo.minor)
|
|
|
|
.arg(mOptions.versionInfo.release)
|
|
|
|
.arg(mOptions.versionInfo.build));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("PRODUCTVERSION " +
|
2021-09-07 14:04:48 +08:00
|
|
|
QString("%1,%2,%3,%4")
|
|
|
|
.arg(mOptions.versionInfo.major)
|
|
|
|
.arg(mOptions.versionInfo.minor)
|
|
|
|
.arg(mOptions.versionInfo.release)
|
|
|
|
.arg(mOptions.versionInfo.build));
|
|
|
|
switch(mOptions.type) {
|
|
|
|
case ProjectType::GUI:
|
|
|
|
case ProjectType::Console:
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("FILETYPE VFT_APP");
|
2021-09-07 14:04:48 +08:00
|
|
|
break;
|
|
|
|
case ProjectType::StaticLib:
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("FILETYPE VFT_STATIC_LIB");
|
2021-09-07 14:04:48 +08:00
|
|
|
break;
|
|
|
|
case ProjectType::DynamicLib:
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("FILETYPE VFT_DLL");
|
2021-09-07 14:04:48 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("{");
|
|
|
|
contents.append(" BLOCK \"StringFileInfo\"");
|
|
|
|
contents.append(" {");
|
|
|
|
contents.append(" BLOCK \"" +
|
2021-09-07 14:04:48 +08:00
|
|
|
QString("%1%2")
|
|
|
|
.arg(mOptions.versionInfo.languageID,4,16,QChar('0'))
|
|
|
|
.arg(mOptions.versionInfo.charsetID,4,16,QChar('0'))
|
|
|
|
+ '"');
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" {");
|
|
|
|
contents.append(" VALUE \"CompanyName\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.companyName
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"FileVersion\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.fileVersion
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"FileDescription\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.fileDescription
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"InternalName\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.internalName
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"LegalCopyright\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.legalCopyright
|
|
|
|
+ '"');
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"LegalTrademarks\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.legalTrademarks
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"OriginalFilename\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.originalFilename
|
|
|
|
+ "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"ProductName\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.productName + "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" VALUE \"ProductVersion\", \""
|
2021-09-07 14:04:48 +08:00
|
|
|
+ mOptions.versionInfo.productVersion + "\"");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" }");
|
|
|
|
contents.append(" }");
|
2021-09-07 14:04:48 +08:00
|
|
|
|
|
|
|
// additional block for windows 95->NT
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" BLOCK \"VarFileInfo\"");
|
|
|
|
contents.append(" {");
|
|
|
|
contents.append(" VALUE \"Translation\", " +
|
2021-09-07 14:04:48 +08:00
|
|
|
QString("0x%1, %2")
|
|
|
|
.arg(mOptions.versionInfo.languageID,4,16,QChar('0'))
|
|
|
|
.arg(mOptions.versionInfo.charsetID));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(" }");
|
2021-09-07 14:04:48 +08:00
|
|
|
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("}");
|
2021-09-07 10:28:40 +08:00
|
|
|
}
|
|
|
|
|
2022-11-16 09:24:42 +08:00
|
|
|
rcFile = generateAbsolutePath(directory(),rcFile);
|
2021-09-07 16:49:35 +08:00
|
|
|
if (contents.count() > 3) {
|
2021-11-12 10:51:00 +08:00
|
|
|
stringsToFile(contents,rcFile);
|
2021-09-07 14:04:48 +08:00
|
|
|
mOptions.privateResource = extractRelativePath(directory(), rcFile);
|
|
|
|
} else {
|
|
|
|
if (fileExists(rcFile))
|
|
|
|
QFile::remove(rcFile);
|
|
|
|
QString resFile = changeFileExt(rcFile, RES_EXT);
|
|
|
|
if (fileExists(resFile))
|
|
|
|
QFile::remove(resFile);
|
|
|
|
mOptions.privateResource = "";
|
|
|
|
}
|
|
|
|
// if fileExists(Res) then
|
|
|
|
// FileSetDate(Res, DateTimeToFileDate(Now)); // fix the "Clock skew detected" warning ;)
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
// create XP manifest
|
2021-09-07 14:04:48 +08:00
|
|
|
if (mOptions.supportXPThemes) {
|
|
|
|
QStringList content;
|
|
|
|
content.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
|
|
|
content.append("<assembly");
|
|
|
|
content.append(" xmlns=\"urn:schemas-microsoft-com:asm.v1\"");
|
|
|
|
content.append(" manifestVersion=\"1.0\">");
|
|
|
|
content.append("<assemblyIdentity");
|
|
|
|
QString name = mName;
|
|
|
|
name.replace(' ','_');
|
|
|
|
content.append(" name=\"DevCpp.Apps." + name + '\"');
|
|
|
|
content.append(" processorArchitecture=\"*\"");
|
|
|
|
content.append(" version=\"1.0.0.0\"");
|
|
|
|
content.append(" type=\"win32\"/>");
|
|
|
|
content.append("<description>" + name + "</description>");
|
|
|
|
content.append("<dependency>");
|
|
|
|
content.append(" <dependentAssembly>");
|
|
|
|
content.append(" <assemblyIdentity");
|
|
|
|
content.append(" type=\"win32\"");
|
|
|
|
content.append(" name=\"Microsoft.Windows.Common-Controls\"");
|
|
|
|
content.append(" version=\"6.0.0.0\"");
|
|
|
|
content.append(" processorArchitecture=\"*\"");
|
|
|
|
content.append(" publicKeyToken=\"6595b64144ccf1df\"");
|
|
|
|
content.append(" language=\"*\"");
|
|
|
|
content.append(" />");
|
|
|
|
content.append(" </dependentAssembly>");
|
|
|
|
content.append("</dependency>");
|
|
|
|
content.append("</assembly>");
|
2021-11-12 10:51:00 +08:00
|
|
|
stringsToFile(content,executable() + ".Manifest");
|
2021-09-07 14:04:48 +08:00
|
|
|
} else if (fileExists(executable() + ".Manifest"))
|
|
|
|
QFile::remove(executable() + ".Manifest");
|
2021-09-07 10:28:40 +08:00
|
|
|
|
|
|
|
// create private header file
|
2021-09-07 14:04:48 +08:00
|
|
|
QString hFile = changeFileExt(rcFile, H_EXT);
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.clear();
|
2021-09-10 12:37:02 +08:00
|
|
|
QString def = extractFileName(rcFile);
|
2021-09-07 14:04:48 +08:00
|
|
|
def.replace(".","_");
|
2021-12-30 19:25:47 +08:00
|
|
|
contents.append("/* THIS FILE WILL BE OVERWRITTEN BY Red Panda C++ */");
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("/* DO NOT EDIT ! */");
|
|
|
|
contents.append("");
|
|
|
|
contents.append("#ifndef " + def);
|
|
|
|
contents.append("#define " + def);
|
|
|
|
contents.append("");
|
|
|
|
contents.append("/* VERSION DEFINITIONS */");
|
|
|
|
contents.append("#define VER_STRING\t" +
|
2021-09-15 11:23:42 +08:00
|
|
|
QString("\"%1.%2.%3.%4\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.major)
|
|
|
|
.arg(mOptions.versionInfo.minor)
|
|
|
|
.arg(mOptions.versionInfo.release)
|
|
|
|
.arg(mOptions.versionInfo.build));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define VER_MAJOR\t%1").arg(mOptions.versionInfo.major));
|
|
|
|
contents.append(QString("#define VER_MINOR\t%1").arg(mOptions.versionInfo.minor));
|
2021-09-15 11:23:42 +08:00
|
|
|
contents.append(QString("#define VER_RELEASE\t%1").arg(mOptions.versionInfo.release));
|
|
|
|
contents.append(QString("#define VER_BUILD\t%1").arg(mOptions.versionInfo.build));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define COMPANY_NAME\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.companyName));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define FILE_VERSION\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.fileVersion));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define FILE_DESCRIPTION\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.fileDescription));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define INTERNAL_NAME\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.internalName));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define LEGAL_COPYRIGHT\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.legalCopyright));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define LEGAL_TRADEMARKS\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.legalTrademarks));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define ORIGINAL_FILENAME\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.originalFilename));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define PRODUCT_NAME\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.productName));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append(QString("#define PRODUCT_VERSION\t\"%1\"")
|
2021-09-07 14:04:48 +08:00
|
|
|
.arg(mOptions.versionInfo.productVersion));
|
2021-09-07 16:49:35 +08:00
|
|
|
contents.append("");
|
|
|
|
contents.append("#endif /*" + def + "*/");
|
2021-11-12 10:51:00 +08:00
|
|
|
stringsToFile(contents,hFile);
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
void Project::checkProjectFileForUpdate(SimpleIni &ini)
|
2021-09-07 16:49:35 +08:00
|
|
|
{
|
|
|
|
bool cnvt = false;
|
2021-09-12 19:50:44 +08:00
|
|
|
int uCount = ini.GetLongValue("Project","UnitCount", 0);
|
2021-09-07 16:49:35 +08:00
|
|
|
// check if using old way to store resources and fix it
|
2021-09-12 19:50:44 +08:00
|
|
|
QString oldRes = QString::fromLocal8Bit(ini.GetValue("Project","Resources", ""));
|
2021-09-07 16:49:35 +08:00
|
|
|
if (!oldRes.isEmpty()) {
|
|
|
|
QFile::copy(mFilename,mFilename+".bak");
|
|
|
|
QStringList sl;
|
2022-07-04 11:39:06 +08:00
|
|
|
sl = oldRes.split(';',
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
|
|
|
);
|
2021-09-07 16:49:35 +08:00
|
|
|
for (int i=0;i<sl.count();i++){
|
|
|
|
const QString& s = sl[i];
|
2021-09-12 19:50:44 +08:00
|
|
|
QByteArray groupName = toByteArray(QString("Unit%1").arg(uCount+i));
|
|
|
|
ini.SetValue(groupName,"Filename", toByteArray(s));
|
|
|
|
ini.SetValue(groupName,"Folder", "Resources");
|
2021-09-15 11:23:42 +08:00
|
|
|
ini.SetLongValue(groupName,"Compile",true);
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetLongValue("Project","UnitCount",uCount+sl.count());
|
|
|
|
QString folders = QString::fromLocal8Bit(ini.GetValue("Project","Folders",""));
|
2021-09-07 16:49:35 +08:00
|
|
|
if (!folders.isEmpty())
|
|
|
|
folders += ",Resources";
|
|
|
|
else
|
|
|
|
folders = "Resources";
|
2021-09-12 19:50:44 +08:00
|
|
|
ini.SetValue("Project","Folders",toByteArray(folders));
|
|
|
|
cnvt = true;
|
|
|
|
ini.Delete("Project","Resources");
|
|
|
|
ini.Delete("Project","Focused");
|
|
|
|
ini.Delete("Project","Order");
|
|
|
|
ini.Delete("Project","DebugInfo");
|
|
|
|
ini.Delete("Project","ProfileInfo");
|
|
|
|
ini.SaveFile(mFilename.toLocal8Bit());
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cnvt)
|
|
|
|
QMessageBox::information(
|
2022-03-21 09:08:05 +08:00
|
|
|
nullptr,
|
2021-09-07 16:49:35 +08:00
|
|
|
tr("Project Updated"),
|
|
|
|
tr("Your project was succesfully updated to a newer file format!")
|
|
|
|
+"<br />"
|
|
|
|
+tr("If something has gone wrong, we kept a backup-file: '%1'...")
|
|
|
|
.arg(mFilename+".bak"),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
void Project::closeUnit(PProjectUnit& unit)
|
2021-09-07 16:49:35 +08:00
|
|
|
{
|
2022-10-08 23:30:30 +08:00
|
|
|
saveLayout();
|
|
|
|
Editor * editor = unitEditor(unit);
|
2022-03-21 09:08:05 +08:00
|
|
|
if (editor) {
|
|
|
|
mEditorList->forceCloseEditor(editor);
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::createFolderNodes()
|
|
|
|
{
|
|
|
|
for (int idx=0;idx<mFolders.count();idx++) {
|
2022-02-08 12:33:10 +08:00
|
|
|
PProjectModelNode node = mRootNode;
|
2021-09-07 16:49:35 +08:00
|
|
|
QString s = mFolders[idx];
|
|
|
|
int i = s.indexOf('/');
|
|
|
|
while (i>=0) {
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode findnode;
|
2021-09-07 16:49:35 +08:00
|
|
|
for (int c=0;c<node->children.count();c++) {
|
|
|
|
if (node->children[c]->text == s.mid(0,i))
|
|
|
|
findnode = node->children[c];
|
|
|
|
}
|
|
|
|
if (!findnode)
|
2022-10-01 08:54:44 +08:00
|
|
|
node = makeNewFolderNode(s.mid(0,i),node);
|
2021-09-07 16:49:35 +08:00
|
|
|
else
|
|
|
|
node = findnode;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!node->isUnit) {
|
|
|
|
qDebug()<<"node "<<node->text<<"is not a folder:"<<s;
|
|
|
|
node = mRootNode;
|
|
|
|
}
|
2021-09-18 10:47:35 +08:00
|
|
|
s.remove(0,i+1);
|
2021-09-07 16:49:35 +08:00
|
|
|
i = s.indexOf('/');
|
|
|
|
}
|
2022-10-01 08:54:44 +08:00
|
|
|
node = makeNewFolderNode(s, node);
|
2022-10-02 13:29:51 +08:00
|
|
|
mCustomFolderNodes.append(node);
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-08 17:22:24 +08:00
|
|
|
static void addFolderRecursively(QSet<QString>& folders, QString folder) {
|
|
|
|
if (folder.isEmpty())
|
|
|
|
return;
|
|
|
|
folders.insert(excludeTrailingPathDelimiter(folder));
|
|
|
|
QString parentFolder = QFileInfo(folder).absolutePath();
|
|
|
|
if (parentFolder==folder)
|
|
|
|
return;
|
|
|
|
addFolderRecursively(folders, parentFolder);
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void Project::createFileSystemFolderNodes()
|
|
|
|
{
|
2022-04-08 17:22:24 +08:00
|
|
|
QSet<QString> headerFolders;
|
|
|
|
QSet<QString> sourceFolders;
|
|
|
|
QSet<QString> otherFolders;
|
2022-10-02 13:29:51 +08:00
|
|
|
mRootNode->children.clear();
|
|
|
|
mSpecialNodes.clear();
|
|
|
|
mFileSystemFolderNodes.clear();
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
|
|
|
QFileInfo fileInfo(unit->fileName());
|
2022-04-08 17:22:24 +08:00
|
|
|
if (isHFile(fileInfo.fileName())) {
|
|
|
|
addFolderRecursively(headerFolders,fileInfo.absolutePath());
|
|
|
|
} else if (isCFile(fileInfo.fileName())) {
|
|
|
|
addFolderRecursively(sourceFolders,fileInfo.absolutePath());
|
|
|
|
} else {
|
|
|
|
addFolderRecursively(otherFolders,fileInfo.absolutePath());
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectModelNode node = makeNewFolderNode(tr("Headers"),
|
|
|
|
mRootNode,
|
|
|
|
ProjectModelNodeType::DUMMY_HEADERS_FOLDER,
|
|
|
|
1000);
|
2022-09-30 17:51:26 +08:00
|
|
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_HEADERS_FOLDER,folder(),node, headerFolders);
|
2022-10-02 13:29:51 +08:00
|
|
|
mCustomFolderNodes.append(node);
|
2022-09-30 17:51:26 +08:00
|
|
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_HEADERS_FOLDER,node);
|
2022-02-08 12:33:10 +08:00
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
node = makeNewFolderNode(tr("Sources"),
|
|
|
|
mRootNode,
|
|
|
|
ProjectModelNodeType::DUMMY_SOURCES_FOLDER,
|
|
|
|
900);
|
2022-09-30 17:51:26 +08:00
|
|
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_SOURCES_FOLDER,folder(),node, sourceFolders);
|
2022-10-02 13:29:51 +08:00
|
|
|
mCustomFolderNodes.append(node);
|
2022-09-30 17:51:26 +08:00
|
|
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_SOURCES_FOLDER,node);
|
2022-02-08 12:33:10 +08:00
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
node = makeNewFolderNode(tr("Others"),
|
|
|
|
mRootNode,
|
|
|
|
ProjectModelNodeType::DUMMY_OTHERS_FOLDER,
|
|
|
|
800);
|
2022-09-30 17:51:26 +08:00
|
|
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_OTHERS_FOLDER,folder(),node, otherFolders);
|
2022-10-02 13:29:51 +08:00
|
|
|
mCustomFolderNodes.append(node);
|
2022-09-30 17:51:26 +08:00
|
|
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_OTHERS_FOLDER,node);
|
2022-02-08 12:33:10 +08:00
|
|
|
}
|
2022-02-08 00:24:08 +08:00
|
|
|
|
2022-04-08 17:22:24 +08:00
|
|
|
void Project::createFileSystemFolderNode(
|
2022-09-30 17:51:26 +08:00
|
|
|
ProjectModelNodeType folderType,
|
2022-04-08 17:22:24 +08:00
|
|
|
const QString &folderName,
|
|
|
|
PProjectModelNode parent,
|
|
|
|
const QSet<QString>& validFolders)
|
2022-02-08 12:33:10 +08:00
|
|
|
{
|
|
|
|
QDirIterator iter(folderName);
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
iter.next();
|
|
|
|
QFileInfo fileInfo = iter.fileInfo();
|
|
|
|
if (fileInfo.isHidden() || fileInfo.fileName().startsWith('.'))
|
|
|
|
continue;
|
2022-04-08 17:22:24 +08:00
|
|
|
if (fileInfo.isDir() && validFolders.contains(fileInfo.absoluteFilePath())) {
|
2022-10-01 08:54:44 +08:00
|
|
|
PProjectModelNode node = makeNewFolderNode(fileInfo.fileName(),parent);
|
2022-03-07 21:10:59 +08:00
|
|
|
mFileSystemFolderNodes.insert(QString("%1/%2").arg((int)folderType).arg(fileInfo.absoluteFilePath()),node);
|
2022-04-08 17:22:24 +08:00
|
|
|
createFileSystemFolderNode(folderType,fileInfo.absoluteFilePath(), node, validFolders);
|
2022-02-08 12:33:10 +08:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 00:24:08 +08:00
|
|
|
}
|
|
|
|
|
2022-10-02 17:23:27 +08:00
|
|
|
PProjectUnit Project::doAutoOpen()
|
2021-09-07 16:49:35 +08:00
|
|
|
{
|
2022-10-09 22:19:18 +08:00
|
|
|
QHash<QString,PProjectEditorLayout> layouts = loadLayout();
|
|
|
|
|
|
|
|
QHash<int,PProjectEditorLayout> opennedMap;
|
|
|
|
|
|
|
|
QString focusedFilename;
|
|
|
|
foreach (const PProjectEditorLayout &layout,layouts) {
|
|
|
|
if (layout->isOpen && layout->order>=0) {
|
|
|
|
if (layout->isFocused)
|
|
|
|
focusedFilename = layout->filename;
|
|
|
|
opennedMap.insert(layout->order,layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0;i<mUnits.count();i++) {
|
|
|
|
PProjectEditorLayout editorLayout = opennedMap.value(i,PProjectEditorLayout());
|
|
|
|
if (editorLayout) {
|
|
|
|
PProjectUnit unit = findUnit(editorLayout->filename);
|
|
|
|
openUnit(unit,editorLayout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!focusedFilename.isEmpty()) {
|
|
|
|
PProjectUnit unit = findUnit(focusedFilename);
|
|
|
|
if (unit) {
|
|
|
|
Editor * editor = unitEditor(unit);
|
|
|
|
if (editor)
|
|
|
|
editor->activate();
|
|
|
|
}
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
return PProjectUnit();
|
2021-09-07 16:49:35 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 00:15:12 +08:00
|
|
|
bool Project::fileAlreadyExists(const QString &s)
|
|
|
|
{
|
|
|
|
foreach (const PProjectUnit& unit, mUnits) {
|
|
|
|
if (unit->fileName() == s)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
PProjectModelNode Project::findFileSystemFolderNode(const QString &folderPath, ProjectModelNodeType nodeType)
|
2022-02-08 12:33:10 +08:00
|
|
|
{
|
|
|
|
PProjectModelNode node = mFileSystemFolderNodes.value(QString("%1/%2").arg((int)nodeType).arg(folderPath),
|
|
|
|
PProjectModelNode());
|
|
|
|
if (node)
|
|
|
|
return node;
|
|
|
|
PProjectModelNode parentNode = mSpecialNodes.value(nodeType,PProjectModelNode());
|
2022-10-02 13:29:51 +08:00
|
|
|
if (parentNode) {
|
|
|
|
QString projectFolder = includeTrailingPathDelimiter(directory());
|
|
|
|
if (folderPath.startsWith(projectFolder)) {
|
|
|
|
QString pathStr = folderPath.mid(projectFolder.length());
|
|
|
|
QStringList paths = pathStr.split("/");
|
|
|
|
PProjectModelNode currentParentNode = parentNode;
|
|
|
|
QString currentFolderFullPath=directory();
|
|
|
|
for (int i=0;i<paths.length();i++) {
|
|
|
|
QString currentFolderName = paths[i];
|
|
|
|
currentFolderFullPath = currentFolderFullPath+"/"+currentFolderName;
|
|
|
|
bool found=false;
|
|
|
|
foreach(PProjectModelNode tempNode, parentNode->children) {
|
|
|
|
if (tempNode->folderNodeType == ProjectModelNodeType::Folder
|
|
|
|
&& tempNode->text == currentFolderName) {
|
|
|
|
found=true;
|
|
|
|
currentParentNode = tempNode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
PProjectModelNode newNode = makeNewFolderNode(currentFolderName,currentParentNode);
|
|
|
|
mFileSystemFolderNodes.insert(QString("%1/%2").arg((int)nodeType).arg(currentFolderFullPath),newNode);
|
|
|
|
currentParentNode = newNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return currentParentNode;
|
|
|
|
}
|
2022-02-08 12:33:10 +08:00
|
|
|
return parentNode;
|
2022-10-02 13:29:51 +08:00
|
|
|
}
|
2022-02-08 12:33:10 +08:00
|
|
|
return mRootNode;
|
|
|
|
}
|
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
PProjectModelNode Project::getCustomeFolderNodeFromName(const QString &name)
|
2021-09-09 00:15:12 +08:00
|
|
|
{
|
|
|
|
int index = mFolders.indexOf(name);
|
|
|
|
if (index>=0) {
|
2022-10-02 13:29:51 +08:00
|
|
|
return mCustomFolderNodes[index];
|
2021-09-09 00:15:12 +08:00
|
|
|
}
|
2022-02-08 12:33:10 +08:00
|
|
|
return mRootNode;
|
2021-09-09 00:15:12 +08:00
|
|
|
}
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
QString Project::getNodePath(PProjectModelNode node)
|
2021-09-09 11:47:04 +08:00
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
if (!node)
|
|
|
|
return result;
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
if (node->isUnit) // not a folder
|
2021-09-09 11:47:04 +08:00
|
|
|
return result;
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode p = node;
|
2022-10-08 23:30:30 +08:00
|
|
|
while (p && !p->isUnit && p!=mRootNode) {
|
2021-09-09 11:47:04 +08:00
|
|
|
if (!result.isEmpty())
|
|
|
|
result = p->text + "/" + result;
|
2021-09-18 10:47:35 +08:00
|
|
|
else
|
|
|
|
result = p->text;
|
2021-09-10 10:27:01 +08:00
|
|
|
p = p->parent.lock();
|
2021-09-09 11:47:04 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-10-02 13:29:51 +08:00
|
|
|
PProjectModelNode Project::getParentFileSystemFolderNode(const QString &filename)
|
2022-02-08 12:33:10 +08:00
|
|
|
{
|
|
|
|
QFileInfo fileInfo(filename);
|
2022-09-30 17:51:26 +08:00
|
|
|
ProjectModelNodeType folderNodeType;
|
2022-10-02 13:29:51 +08:00
|
|
|
if (isHFile(fileInfo.fileName()) && !fileInfo.suffix().isEmpty()) {
|
2022-09-30 17:51:26 +08:00
|
|
|
folderNodeType = ProjectModelNodeType::DUMMY_HEADERS_FOLDER;
|
2022-02-13 20:08:18 +08:00
|
|
|
} else if (isCFile(fileInfo.fileName())) {
|
2022-09-30 17:51:26 +08:00
|
|
|
folderNodeType = ProjectModelNodeType::DUMMY_SOURCES_FOLDER;
|
2022-02-08 12:33:10 +08:00
|
|
|
} else {
|
2022-09-30 17:51:26 +08:00
|
|
|
folderNodeType = ProjectModelNodeType::DUMMY_OTHERS_FOLDER;
|
2022-02-08 12:33:10 +08:00
|
|
|
}
|
2022-10-02 13:29:51 +08:00
|
|
|
return findFileSystemFolderNode(fileInfo.absolutePath(),folderNodeType);
|
2022-02-08 12:33:10 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 18:36:54 +08:00
|
|
|
void Project::incrementBuildNumber()
|
|
|
|
{
|
|
|
|
mOptions.versionInfo.build++;
|
|
|
|
mOptions.versionInfo.fileVersion = QString("%1.%2.%3.%3")
|
|
|
|
.arg(mOptions.versionInfo.major)
|
|
|
|
.arg(mOptions.versionInfo.minor)
|
|
|
|
.arg(mOptions.versionInfo.release)
|
|
|
|
.arg(mOptions.versionInfo.build);
|
|
|
|
if (mOptions.versionInfo.syncProduct)
|
|
|
|
mOptions.versionInfo.productVersion = mOptions.versionInfo.fileVersion;
|
|
|
|
setModified(true);
|
|
|
|
}
|
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
QHash<QString, PProjectEditorLayout> Project::loadLayout()
|
2021-09-09 18:36:54 +08:00
|
|
|
{
|
2022-10-09 22:19:18 +08:00
|
|
|
QHash<QString,PProjectEditorLayout> layouts;
|
2022-10-08 23:30:30 +08:00
|
|
|
QString jsonFilename = changeFileExt(filename(), "layout");
|
|
|
|
QFile file(jsonFilename);
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
2022-10-09 22:19:18 +08:00
|
|
|
return layouts;
|
2022-10-08 23:30:30 +08:00
|
|
|
QByteArray content = file.readAll();
|
|
|
|
QJsonParseError parseError;
|
|
|
|
QJsonDocument doc(QJsonDocument::fromJson(content,&parseError));
|
|
|
|
file.close();
|
2022-10-09 22:19:18 +08:00
|
|
|
if (parseError.error!=QJsonParseError::NoError || !doc.isArray())
|
|
|
|
return layouts;
|
2022-10-08 23:30:30 +08:00
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
QJsonArray jsonLayouts=doc.array();
|
2022-10-08 23:30:30 +08:00
|
|
|
|
|
|
|
for (int i=0;i<jsonLayouts.size();i++) {
|
|
|
|
QJsonObject jsonLayout = jsonLayouts[i].toObject();
|
|
|
|
QString unitFilename = jsonLayout["filename"].toString();
|
|
|
|
if (mUnits.contains(unitFilename)) {
|
2022-10-02 23:32:33 +08:00
|
|
|
PProjectEditorLayout editorLayout = std::make_shared<ProjectEditorLayout>();
|
2022-10-08 23:30:30 +08:00
|
|
|
editorLayout->filename=unitFilename;
|
|
|
|
editorLayout->topLine=jsonLayout["topLine"].toInt();
|
|
|
|
editorLayout->leftChar=jsonLayout["leftChar"].toInt();
|
|
|
|
editorLayout->caretX=jsonLayout["caretX"].toInt();
|
|
|
|
editorLayout->caretY=jsonLayout["caretY"].toInt();
|
2022-10-09 22:19:18 +08:00
|
|
|
editorLayout->order=jsonLayout["order"].toInt(-1);
|
|
|
|
editorLayout->isFocused=jsonLayout["focused"].toBool();
|
|
|
|
editorLayout->isOpen=jsonLayout["isOpen"].toBool();
|
|
|
|
layouts.insert(unitFilename,editorLayout);
|
2021-09-09 18:36:54 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
return layouts;
|
2021-09-09 18:36:54 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
void Project::loadOptions(SimpleIni& ini)
|
2021-09-09 23:20:00 +08:00
|
|
|
{
|
2021-09-12 19:50:44 +08:00
|
|
|
mName = fromByteArray(ini.GetValue("Project","name", ""));
|
2021-09-17 09:56:52 +08:00
|
|
|
QString icon = fromByteArray(ini.GetValue("Project", "icon", ""));
|
|
|
|
if (icon.isEmpty()) {
|
|
|
|
mOptions.icon = "";
|
|
|
|
} else {
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.icon = generateAbsolutePath(directory(),icon);
|
2021-09-17 09:56:52 +08:00
|
|
|
}
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.version = ini.GetLongValue("Project", "Ver", 0);
|
2021-09-09 23:20:00 +08:00
|
|
|
if (mOptions.version > 0) { // ver > 0 is at least a v5 project
|
2022-05-13 20:22:16 +08:00
|
|
|
if (mOptions.version < 3) {
|
|
|
|
mOptions.version = 3;
|
2022-03-21 09:08:05 +08:00
|
|
|
QMessageBox::information(nullptr,
|
2021-09-09 23:20:00 +08:00
|
|
|
tr("Settings need update"),
|
2021-12-30 19:25:47 +08:00
|
|
|
tr("The compiler settings format of Red Panda C++ has changed.")
|
2021-09-09 23:20:00 +08:00
|
|
|
+"<BR /><BR />"
|
|
|
|
+tr("Please update your settings at Project >> Project Options >> Compiler and save your project."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.type = static_cast<ProjectType>(ini.GetLongValue("Project", "type", 0));
|
2023-02-10 09:42:55 +08:00
|
|
|
mOptions.compilerCmd = fromByteArray(ini.GetValue("Project", "Compiler", "")).replace(";CONFIG_LINE;","\n");
|
|
|
|
mOptions.cppCompilerCmd = fromByteArray(ini.GetValue("Project", "CppCompiler", "")).replace(";CONFIG_LINE;","\n");
|
|
|
|
mOptions.linkerCmd = fromByteArray(ini.GetValue("Project", "Linker", "")).replace(";CONFIG_LINE;","\n");
|
|
|
|
mOptions.resourceCmd = fromByteArray(ini.GetValue("Project", "ResourceCommand", "")).replace(";CONFIG_LINE;","\n");
|
|
|
|
mOptions.assemblerArgs = fromByteArray(ini.GetValue("Project","AssemblerArgs","")).replace(";CONFIG_LINE;","\n");
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.binDirs = absolutePaths(fromByteArray(ini.GetValue("Project", "Bins", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
2022-11-10 13:35:13 +08:00
|
|
|
));
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.libDirs = absolutePaths(fromByteArray(ini.GetValue("Project", "Libs", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
2022-11-10 13:35:13 +08:00
|
|
|
));
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.includeDirs = absolutePaths(fromByteArray(ini.GetValue("Project", "Includes", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
2022-11-10 13:35:13 +08:00
|
|
|
));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.privateResource = fromByteArray(ini.GetValue("Project", "PrivateResource", ""));
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.resourceIncludes = absolutePaths(fromByteArray(ini.GetValue("Project", "ResourceIncludes", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
2022-11-10 13:35:13 +08:00
|
|
|
));
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.makeIncludes = absolutePaths(fromByteArray(ini.GetValue("Project", "MakeIncludes", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
2022-11-10 13:35:13 +08:00
|
|
|
));
|
2022-02-01 16:17:28 +08:00
|
|
|
mOptions.isCpp = ini.GetBoolValue("Project", "IsCpp", false);
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.exeOutput = generateAbsolutePath(directory(), fromByteArray(ini.GetValue("Project", "ExeOutput", "")));
|
|
|
|
mOptions.objectOutput = generateAbsolutePath(directory(), fromByteArray(ini.GetValue("Project", "ObjectOutput", "")));
|
|
|
|
mOptions.logOutput = generateAbsolutePath(directory(), fromByteArray(ini.GetValue("Project", "LogOutput", "")));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.logOutputEnabled = ini.GetBoolValue("Project", "LogOutputEnabled", false);
|
|
|
|
mOptions.overrideOutput = ini.GetBoolValue("Project", "OverrideOutput", false);
|
|
|
|
mOptions.overridenOutput = fromByteArray(ini.GetValue("Project", "OverrideOutputName", ""));
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.hostApplication = generateAbsolutePath(directory(), fromByteArray(ini.GetValue("Project", "HostApplication", "")));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.useCustomMakefile = ini.GetBoolValue("Project", "UseCustomMakefile", false);
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.customMakefile = generateAbsolutePath(directory(),fromByteArray(ini.GetValue("Project", "CustomMakefile", "")));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.usePrecompiledHeader = ini.GetBoolValue("Project", "UsePrecompiledHeader", false);
|
2022-11-16 09:24:42 +08:00
|
|
|
mOptions.precompiledHeader = generateAbsolutePath(directory(),fromByteArray(ini.GetValue("Project", "PrecompiledHeader", "")));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.cmdLineArgs = fromByteArray(ini.GetValue("Project", "CommandLine", ""));
|
2022-07-04 11:39:06 +08:00
|
|
|
mFolders = fromByteArray(ini.GetValue("Project", "Folders", "")).split(";",
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
Qt::SkipEmptyParts
|
|
|
|
#else
|
|
|
|
QString::SkipEmptyParts
|
|
|
|
#endif
|
|
|
|
);
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.includeVersionInfo = ini.GetBoolValue("Project", "IncludeVersionInfo", false);
|
|
|
|
mOptions.supportXPThemes = ini.GetBoolValue("Project", "SupportXPThemes", false);
|
|
|
|
mOptions.compilerSet = ini.GetLongValue("Project", "CompilerSet", pSettings->compilerSets().defaultIndex());
|
2022-02-08 00:24:08 +08:00
|
|
|
mOptions.modelType = (ProjectModelType)ini.GetLongValue("Project", "ModelType", (int)ProjectModelType::Custom);
|
2022-10-23 15:22:26 +08:00
|
|
|
mOptions.classBrowserType = (ProjectClassBrowserType)ini.GetLongValue("Project", "ClassBrowserType", (int)ProjectClassBrowserType::CurrentFile);
|
2021-09-10 10:27:01 +08:00
|
|
|
|
2022-07-04 11:39:06 +08:00
|
|
|
if (mOptions.compilerSet >= (int)pSettings->compilerSets().size()
|
2021-09-10 10:27:01 +08:00
|
|
|
|| mOptions.compilerSet < 0) { // TODO: change from indices to names
|
|
|
|
QMessageBox::critical(
|
2022-03-21 09:08:05 +08:00
|
|
|
nullptr,
|
2021-09-10 10:27:01 +08:00
|
|
|
tr("Compiler not found"),
|
|
|
|
tr("The compiler set you have selected for this project, no longer exists.")
|
|
|
|
+"<BR />"
|
|
|
|
+tr("It will be substituted by the global compiler set."),
|
|
|
|
QMessageBox::Ok
|
|
|
|
);
|
2022-03-30 20:15:15 +08:00
|
|
|
setCompilerSet(pSettings->compilerSets().defaultIndex());
|
2022-10-24 17:23:37 +08:00
|
|
|
saveOptions();
|
2021-09-10 10:27:01 +08:00
|
|
|
}
|
2022-05-12 22:42:19 +08:00
|
|
|
|
2022-05-13 20:22:16 +08:00
|
|
|
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
|
|
|
|
if (pSet) {
|
|
|
|
QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", "");
|
|
|
|
if (!oldCompilerOptions.isEmpty()) {
|
|
|
|
//version 2 compatibility
|
2022-09-24 21:24:58 +08:00
|
|
|
// test if it is created by old dev-c++
|
|
|
|
SimpleIni::TNamesDepend oKeys;
|
|
|
|
ini.GetAllKeys("Project", oKeys);
|
|
|
|
bool isNewDev=false;
|
|
|
|
for(const SimpleIni::Entry& entry:oKeys) {
|
|
|
|
QString key(entry.pItem);
|
|
|
|
if (key=="UsePrecompiledHeader"
|
|
|
|
|| key == "CompilerSetType"
|
|
|
|
|| key == "StaticLink"
|
|
|
|
|| key == "AddCharset"
|
|
|
|
|| key == "ExecEncoding"
|
|
|
|
|| key == "Encoding"
|
|
|
|
|| key == "UseUTF8") {
|
|
|
|
isNewDev = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isNewDev && oldCompilerOptions.length()>=25) {
|
|
|
|
char t = oldCompilerOptions[18];
|
|
|
|
oldCompilerOptions[18]=oldCompilerOptions[21];
|
|
|
|
oldCompilerOptions[21]=t;
|
|
|
|
}
|
2022-05-13 20:22:16 +08:00
|
|
|
for (int i=0;i<oldCompilerOptions.length();i++) {
|
|
|
|
QString key = pSettings->compilerSets().getKeyFromCompilerCompatibleIndex(i);
|
|
|
|
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(
|
|
|
|
pSet->compilerType(), key);
|
|
|
|
if (pOption) {
|
|
|
|
int val = Settings::CompilerSet::charToValue(oldCompilerOptions[i]);
|
|
|
|
if (pOption->choices.isEmpty()) {
|
|
|
|
if (val>0)
|
|
|
|
mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON);
|
|
|
|
else
|
|
|
|
mOptions.compilerOptions.insert(key,"");
|
|
|
|
} else {
|
|
|
|
if (val>0 && val <= pOption->choices.length())
|
|
|
|
mOptions.compilerOptions.insert(key,pOption->choices[val-1].second);
|
|
|
|
else
|
|
|
|
mOptions.compilerOptions.insert(key,"");
|
|
|
|
}
|
2022-05-12 22:42:19 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-13 20:22:16 +08:00
|
|
|
} else {
|
|
|
|
//version 3
|
|
|
|
SimpleIni::TNamesDepend oKeys;
|
|
|
|
ini.GetAllKeys("CompilerSettings", oKeys);
|
|
|
|
for(const SimpleIni::Entry& entry:oKeys) {
|
|
|
|
QString key(entry.pItem);
|
2022-05-12 22:42:19 +08:00
|
|
|
mOptions.compilerOptions.insert(
|
2022-05-13 20:22:16 +08:00
|
|
|
key,
|
|
|
|
ini.GetValue("CompilerSettings", entry.pItem, ""));
|
2022-05-12 22:42:19 +08:00
|
|
|
}
|
2022-05-12 15:28:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.staticLink = ini.GetBoolValue("Project", "StaticLink", true);
|
2022-06-22 17:08:35 +08:00
|
|
|
mOptions.execEncoding = ini.GetValue("Project","ExecEncoding", ENCODING_SYSTEM_DEFAULT);
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.addCharset = ini.GetBoolValue("Project", "AddCharset", true);
|
2021-10-25 21:36:23 +08:00
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
bool useUTF8 = ini.GetBoolValue("Project", "UseUTF8", false);
|
2021-09-10 23:41:38 +08:00
|
|
|
if (useUTF8) {
|
2023-01-24 10:21:19 +08:00
|
|
|
mOptions.encoding = ini.GetValue("Project","Encoding", ENCODING_UTF8);
|
2021-09-12 22:45:00 +08:00
|
|
|
} else {
|
2023-02-08 12:20:20 +08:00
|
|
|
mOptions.encoding = ini.GetValue("Project","Encoding", pSettings->editor().defaultEncoding());
|
2021-09-10 23:41:38 +08:00
|
|
|
}
|
2023-01-24 10:21:19 +08:00
|
|
|
if (mOptions.encoding == ENCODING_AUTO_DETECT)
|
|
|
|
mOptions.encoding = pSettings->editor().defaultEncoding();
|
|
|
|
if (mOptions.encoding == ENCODING_AUTO_DETECT)
|
|
|
|
mOptions.encoding = ENCODING_SYSTEM_DEFAULT;
|
2021-09-12 19:50:44 +08:00
|
|
|
|
2022-11-06 22:51:14 +08:00
|
|
|
mOptions.allowParallelBuilding = ini.GetBoolValue("Project","AllowParallelBuilding");
|
|
|
|
mOptions.parellelBuildingJobs = ini.GetLongValue("Project","ParellelBuildingJobs");
|
|
|
|
|
|
|
|
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.versionInfo.major = ini.GetLongValue("VersionInfo", "Major", 0);
|
|
|
|
mOptions.versionInfo.minor = ini.GetLongValue("VersionInfo", "Minor", 1);
|
|
|
|
mOptions.versionInfo.release = ini.GetLongValue("VersionInfo", "Release", 1);
|
|
|
|
mOptions.versionInfo.build = ini.GetLongValue("VersionInfo", "Build", 1);
|
|
|
|
mOptions.versionInfo.languageID = ini.GetLongValue("VersionInfo", "LanguageID", 0x0409);
|
|
|
|
mOptions.versionInfo.charsetID = ini.GetLongValue("VersionInfo", "CharsetID", 0x04E4);
|
|
|
|
mOptions.versionInfo.companyName = fromByteArray(ini.GetValue("VersionInfo", "CompanyName", ""));
|
|
|
|
mOptions.versionInfo.fileVersion = fromByteArray(ini.GetValue("VersionInfo", "FileVersion", "0.1"));
|
|
|
|
mOptions.versionInfo.fileDescription = fromByteArray(ini.GetValue("VersionInfo", "FileDescription",
|
2021-12-30 19:25:47 +08:00
|
|
|
toByteArray(tr("Developed using the Red Panda C++ IDE"))));
|
2021-09-12 19:50:44 +08:00
|
|
|
mOptions.versionInfo.internalName = fromByteArray(ini.GetValue("VersionInfo", "InternalName", ""));
|
|
|
|
mOptions.versionInfo.legalCopyright = fromByteArray(ini.GetValue("VersionInfo", "LegalCopyright", ""));
|
|
|
|
mOptions.versionInfo.legalTrademarks = fromByteArray(ini.GetValue("VersionInfo", "LegalTrademarks", ""));
|
|
|
|
mOptions.versionInfo.originalFilename = fromByteArray(ini.GetValue("VersionInfo", "OriginalFilename",
|
|
|
|
toByteArray(extractFileName(executable()))));
|
|
|
|
mOptions.versionInfo.productName = fromByteArray(ini.GetValue("VersionInfo", "ProductName", toByteArray(mName)));
|
|
|
|
mOptions.versionInfo.productVersion = fromByteArray(ini.GetValue("VersionInfo", "ProductVersion", "0.1.1.1"));
|
|
|
|
mOptions.versionInfo.autoIncBuildNr = ini.GetBoolValue("VersionInfo", "AutoIncBuildNr", false);
|
|
|
|
mOptions.versionInfo.syncProduct = ini.GetBoolValue("VersionInfo", "SyncProduct", false);
|
|
|
|
|
2021-09-10 10:27:01 +08:00
|
|
|
}
|
2021-09-09 23:20:00 +08:00
|
|
|
}
|
|
|
|
|
2022-10-02 23:32:33 +08:00
|
|
|
void Project::loadUnitLayout(Editor *e)
|
2021-09-10 15:03:47 +08:00
|
|
|
{
|
|
|
|
if (!e)
|
|
|
|
return;
|
2022-10-08 23:30:30 +08:00
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
QHash<QString, PProjectEditorLayout> layouts = loadLayout();
|
2021-09-06 12:58:29 +08:00
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
PProjectEditorLayout layout = layouts.value(e->filename(),PProjectEditorLayout());
|
|
|
|
if (layout) {
|
|
|
|
e->setCaretY(layout->caretY);
|
|
|
|
e->setCaretX(layout->caretX);
|
|
|
|
e->setTopLine(layout->topLine);
|
|
|
|
e->setLeftChar(layout->leftChar);
|
2021-09-09 11:47:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 09:24:42 +08:00
|
|
|
QString Project::relativePath(const QString &filename)
|
|
|
|
{
|
|
|
|
QString appPath = includeTrailingPathDelimiter(pSettings->dirs().appDir());
|
|
|
|
QString projectPath = includeTrailingPathDelimiter(directory());
|
|
|
|
if (filename.startsWith(appPath) && !filename.startsWith(projectPath)) {
|
|
|
|
return "%APP_PATH%/"+filename.mid(appPath.length());
|
|
|
|
}
|
|
|
|
QDir projectDir(directory());
|
|
|
|
QDir grandparentDir(projectDir.absoluteFilePath("../../"));
|
|
|
|
QString grandparentPath=grandparentDir.absolutePath();
|
|
|
|
if (grandparentDir.exists()
|
|
|
|
&& filename.startsWith(grandparentPath))
|
|
|
|
return extractRelativePath(directory(),filename);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Project::relativePaths(const QStringList &files)
|
|
|
|
{
|
|
|
|
QStringList lst;
|
|
|
|
foreach(const QString& file,files) {
|
|
|
|
lst.append(relativePath(file));
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Project::absolutePath(const QString &filename)
|
|
|
|
{
|
|
|
|
QString appSuffix = "%APP_PATH%/";
|
|
|
|
if (filename.startsWith(appSuffix)) {
|
|
|
|
return includeTrailingPathDelimiter(pSettings->dirs().appDir()) + filename.mid(appSuffix.length());
|
|
|
|
}
|
|
|
|
return generateAbsolutePath(directory(),filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Project::absolutePaths(const QStringList &files)
|
|
|
|
{
|
|
|
|
QStringList lst;
|
|
|
|
foreach(const QString& file,files) {
|
|
|
|
lst.append(absolutePath(file));
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
PCppParser Project::cppParser()
|
2021-09-09 11:47:04 +08:00
|
|
|
{
|
2022-10-08 23:30:30 +08:00
|
|
|
return mParser;
|
2021-09-09 11:47:04 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void Project::removeFolderRecurse(PProjectModelNode node)
|
2021-09-10 21:37:52 +08:00
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return ;
|
|
|
|
// Recursively remove folders
|
|
|
|
for (int i=node->children.count()-1;i>=0;i++) {
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode childNode = node->children[i];
|
2021-09-10 21:37:52 +08:00
|
|
|
// Remove folder inside folder
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!childNode->isUnit && childNode->level>0) {
|
2021-09-10 21:37:52 +08:00
|
|
|
removeFolderRecurse(childNode);
|
|
|
|
// Or remove editors at this level
|
2022-10-08 23:30:30 +08:00
|
|
|
} else if (childNode->isUnit && childNode->level > 0) {
|
2021-09-10 21:37:52 +08:00
|
|
|
// Remove editor in folder from project
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectUnit unit = childNode->pUnit.lock();
|
|
|
|
if (!removeUnit(unit,true))
|
2021-09-10 21:37:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode parent = node->parent.lock();
|
2021-09-10 21:37:52 +08:00
|
|
|
if (parent) {
|
|
|
|
parent->children.removeAll(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void Project::updateFolderNode(PProjectModelNode node)
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
|
|
|
for (int i=0;i<node->children.count();i++){
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode child = node->children[i];
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!child->isUnit) {
|
2022-10-01 08:54:44 +08:00
|
|
|
mFolders.append(getNodePath(child));
|
2021-09-11 09:21:44 +08:00
|
|
|
updateFolderNode(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 12:08:03 +08:00
|
|
|
void Project::updateCompilerSetting()
|
2021-10-25 21:36:23 +08:00
|
|
|
{
|
|
|
|
Settings::PCompilerSet defaultSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
|
|
|
|
if (defaultSet) {
|
|
|
|
mOptions.staticLink = defaultSet->staticLink();
|
2022-05-12 15:28:08 +08:00
|
|
|
mOptions.compilerOptions = defaultSet->compileOptions();
|
2021-10-25 21:36:23 +08:00
|
|
|
} else {
|
|
|
|
mOptions.staticLink = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
QFileSystemWatcher *Project::fileSystemWatcher() const
|
|
|
|
{
|
|
|
|
return mFileSystemWatcher;
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:12:40 +08:00
|
|
|
QString Project::fileSystemNodeFolderPath(const PProjectModelNode &node)
|
|
|
|
{
|
|
|
|
QString result;
|
2022-05-19 17:57:31 +08:00
|
|
|
if (node != mRootNode) {
|
|
|
|
PProjectModelNode pNode = node;
|
2022-09-30 17:51:26 +08:00
|
|
|
while (pNode && pNode->folderNodeType == ProjectModelNodeType::Folder) {
|
2022-05-19 17:57:31 +08:00
|
|
|
result = node->text + "/" +result;
|
|
|
|
pNode = pNode->parent.lock();
|
|
|
|
}
|
2022-04-08 18:12:40 +08:00
|
|
|
}
|
|
|
|
result = folder() + "/" + result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-06-16 21:34:31 +08:00
|
|
|
QStringList Project::binDirs()
|
|
|
|
{
|
|
|
|
QStringList lst = options().binDirs;
|
|
|
|
Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(options().compilerSet);
|
|
|
|
if (compilerSet) {
|
|
|
|
lst.append(compilerSet->binDirs());
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
void Project::renameFolderNode(PProjectModelNode node, const QString newName)
|
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
if (node->isUnit)
|
|
|
|
return;
|
|
|
|
node->text = newName;
|
|
|
|
updateFolders();
|
|
|
|
setModified(true);
|
|
|
|
emit nodeRenamed();
|
|
|
|
}
|
|
|
|
|
2022-03-21 09:08:05 +08:00
|
|
|
EditorList *Project::editorList() const
|
|
|
|
{
|
|
|
|
return mEditorList;
|
|
|
|
}
|
|
|
|
|
2022-02-08 12:33:10 +08:00
|
|
|
ProjectModelType Project::modelType() const
|
|
|
|
{
|
|
|
|
return mOptions.modelType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::setModelType(ProjectModelType type)
|
|
|
|
{
|
|
|
|
if (type!=mOptions.modelType) {
|
|
|
|
mOptions.modelType = type;
|
|
|
|
rebuildNodes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 17:33:47 +08:00
|
|
|
ProjectOptions &Project::options()
|
2021-09-10 15:03:47 +08:00
|
|
|
{
|
|
|
|
return mOptions;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModel *Project::model()
|
2021-09-11 11:42:20 +08:00
|
|
|
{
|
|
|
|
return &mModel;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
const PProjectModelNode &Project::rootNode() const
|
2021-09-10 12:37:02 +08:00
|
|
|
{
|
2022-02-08 12:33:10 +08:00
|
|
|
return mRootNode;
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Project::name() const
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Project::setName(const QString &newName)
|
|
|
|
{
|
2021-09-14 17:33:47 +08:00
|
|
|
if (newName != mName) {
|
|
|
|
mName = newName;
|
2022-02-08 12:33:10 +08:00
|
|
|
mRootNode->text = newName;
|
2021-11-27 09:36:49 +08:00
|
|
|
setModified(true);
|
2021-09-14 17:33:47 +08:00
|
|
|
}
|
2021-09-10 12:37:02 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 00:15:12 +08:00
|
|
|
const QString &Project::filename() const
|
|
|
|
{
|
|
|
|
return mFilename;
|
|
|
|
}
|
|
|
|
|
2021-09-07 00:32:16 +08:00
|
|
|
ProjectUnit::ProjectUnit(Project* parent)
|
|
|
|
{
|
|
|
|
mNode = nullptr;
|
|
|
|
mParent = parent;
|
2022-03-28 16:57:58 +08:00
|
|
|
mFileMissing = false;
|
2022-10-01 08:54:44 +08:00
|
|
|
mPriority=0;
|
2022-10-21 12:43:02 +08:00
|
|
|
mNew = true;
|
2023-01-24 11:31:30 +08:00
|
|
|
mEncoding=ENCODING_PROJECT;
|
2023-01-19 20:04:05 +08:00
|
|
|
mRealEncoding="";
|
2021-09-06 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 00:32:16 +08:00
|
|
|
Project *ProjectUnit::parent() const
|
2021-09-05 23:45:05 +08:00
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &ProjectUnit::fileName() const
|
|
|
|
{
|
|
|
|
return mFileName;
|
|
|
|
}
|
|
|
|
|
2021-10-23 19:27:50 +08:00
|
|
|
void ProjectUnit::setFileName(QString newFileName)
|
2021-09-05 23:45:05 +08:00
|
|
|
{
|
2021-10-23 19:27:50 +08:00
|
|
|
newFileName = QFileInfo(newFileName).absoluteFilePath();
|
2021-09-18 10:47:35 +08:00
|
|
|
if (mFileName != newFileName) {
|
|
|
|
mFileName = newFileName;
|
|
|
|
if (mNode) {
|
|
|
|
mNode->text = extractFileName(mFileName);
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setNew(bool newNew)
|
|
|
|
{
|
|
|
|
mNew = newNew;
|
|
|
|
}
|
|
|
|
|
2023-01-19 20:04:05 +08:00
|
|
|
const QByteArray &ProjectUnit::realEncoding() const
|
|
|
|
{
|
|
|
|
return mRealEncoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setRealEncoding(const QByteArray &newRealEncoding)
|
|
|
|
{
|
|
|
|
mRealEncoding = newRealEncoding;
|
|
|
|
}
|
|
|
|
|
2021-09-05 23:45:05 +08:00
|
|
|
const QString &ProjectUnit::folder() const
|
|
|
|
{
|
|
|
|
return mFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setFolder(const QString &newFolder)
|
|
|
|
{
|
|
|
|
mFolder = newFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectUnit::compile() const
|
|
|
|
{
|
|
|
|
return mCompile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setCompile(bool newCompile)
|
|
|
|
{
|
|
|
|
mCompile = newCompile;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectUnit::compileCpp() const
|
|
|
|
{
|
|
|
|
return mCompileCpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setCompileCpp(bool newCompileCpp)
|
|
|
|
{
|
|
|
|
mCompileCpp = newCompileCpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectUnit::overrideBuildCmd() const
|
|
|
|
{
|
|
|
|
return mOverrideBuildCmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setOverrideBuildCmd(bool newOverrideBuildCmd)
|
|
|
|
{
|
|
|
|
mOverrideBuildCmd = newOverrideBuildCmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &ProjectUnit::buildCmd() const
|
|
|
|
{
|
|
|
|
return mBuildCmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setBuildCmd(const QString &newBuildCmd)
|
|
|
|
{
|
|
|
|
mBuildCmd = newBuildCmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectUnit::link() const
|
|
|
|
{
|
|
|
|
return mLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setLink(bool newLink)
|
|
|
|
{
|
|
|
|
mLink = newLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProjectUnit::priority() const
|
|
|
|
{
|
|
|
|
return mPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setPriority(int newPriority)
|
|
|
|
{
|
2022-02-08 12:33:10 +08:00
|
|
|
if (mPriority!=newPriority) {
|
|
|
|
mPriority = newPriority;
|
|
|
|
if (mNode)
|
|
|
|
mNode->priority = mPriority;
|
|
|
|
}
|
2021-09-05 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QByteArray &ProjectUnit::encoding() const
|
|
|
|
{
|
|
|
|
return mEncoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setEncoding(const QByteArray &newEncoding)
|
|
|
|
{
|
2022-01-24 09:24:43 +08:00
|
|
|
if (mEncoding != newEncoding) {
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * editor=mParent->unitEditor(this);
|
|
|
|
if (editor) {
|
|
|
|
editor->setEncodingOption(newEncoding);
|
2022-01-24 09:24:43 +08:00
|
|
|
}
|
|
|
|
mEncoding = newEncoding;
|
|
|
|
}
|
2021-09-05 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode &ProjectUnit::node()
|
2021-09-07 10:28:40 +08:00
|
|
|
{
|
|
|
|
return mNode;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void ProjectUnit::setNode(const PProjectModelNode &newNode)
|
2021-09-07 10:28:40 +08:00
|
|
|
{
|
|
|
|
mNode = newNode;
|
|
|
|
}
|
2021-09-11 09:21:44 +08:00
|
|
|
|
2022-03-28 16:57:58 +08:00
|
|
|
bool ProjectUnit::FileMissing() const
|
|
|
|
{
|
|
|
|
return mFileMissing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectUnit::setFileMissing(bool newDontSave)
|
|
|
|
{
|
|
|
|
mFileMissing = newDontSave;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModel::ProjectModel(Project *project, QObject *parent):
|
2021-09-11 09:21:44 +08:00
|
|
|
QAbstractItemModel(parent),
|
|
|
|
mProject(project)
|
|
|
|
{
|
|
|
|
mUpdateCount = 0;
|
2022-10-10 18:05:18 +08:00
|
|
|
//delete in the destructor
|
2022-02-15 00:01:50 +08:00
|
|
|
mIconProvider = new CustomFileIconProvider();
|
2022-02-14 00:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectModel::~ProjectModel()
|
|
|
|
{
|
2022-02-15 00:01:50 +08:00
|
|
|
delete mIconProvider;
|
2021-09-11 09:21:44 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void ProjectModel::beginUpdate()
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
2022-01-07 19:20:42 +08:00
|
|
|
if (mUpdateCount==0) {
|
2021-09-11 09:21:44 +08:00
|
|
|
beginResetModel();
|
2022-01-07 19:20:42 +08:00
|
|
|
}
|
2021-09-11 09:21:44 +08:00
|
|
|
mUpdateCount++;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
void ProjectModel::endUpdate()
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
|
|
|
mUpdateCount--;
|
2022-01-07 19:20:42 +08:00
|
|
|
if (mUpdateCount==0) {
|
2022-02-15 00:01:50 +08:00
|
|
|
mIconProvider->setRootFolder(mProject->folder());
|
2021-09-11 09:21:44 +08:00
|
|
|
endResetModel();
|
2022-01-07 19:20:42 +08:00
|
|
|
}
|
2021-09-11 09:21:44 +08:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:39:17 +08:00
|
|
|
CustomFileIconProvider *ProjectModel::iconProvider() const
|
|
|
|
{
|
|
|
|
return mIconProvider;
|
|
|
|
}
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
bool ProjectModel::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
beginInsertRows(parent,row,row+count-1);
|
|
|
|
endInsertRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
beginRemoveRows(parent,row,row+count-1);
|
2022-10-02 13:29:51 +08:00
|
|
|
if (!parent.isValid())
|
|
|
|
return false;
|
|
|
|
ProjectModelNode* parentNode = static_cast<ProjectModelNode*>(parent.internalPointer());
|
|
|
|
if (!parentNode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
parentNode->children.removeAt(row);
|
|
|
|
|
2022-10-01 08:54:44 +08:00
|
|
|
endRemoveRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
Project *ProjectModel::project() const
|
2022-01-08 08:52:50 +08:00
|
|
|
{
|
|
|
|
return mProject;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const
|
2021-09-11 11:42:20 +08:00
|
|
|
{
|
|
|
|
if (!parent.isValid()) {
|
2022-01-27 18:34:18 +08:00
|
|
|
return createIndex(row,column,mProject->rootNode().get());
|
2021-09-11 11:42:20 +08:00
|
|
|
}
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* parentNode = static_cast<ProjectModelNode*>(parent.internalPointer());
|
2021-09-11 11:42:20 +08:00
|
|
|
if (!parentNode) {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
2021-10-24 00:17:08 +08:00
|
|
|
if (row<0 || row>=parentNode->children.count())
|
|
|
|
return QModelIndex();
|
2021-09-11 11:42:20 +08:00
|
|
|
return createIndex(row,column,parentNode->children[row].get());
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
QModelIndex ProjectModel::parent(const QModelIndex &child) const
|
2021-09-11 11:42:20 +08:00
|
|
|
{
|
|
|
|
if (!child.isValid())
|
|
|
|
return QModelIndex();
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode * node = static_cast<ProjectModelNode*>(child.internalPointer());
|
2021-09-11 11:42:20 +08:00
|
|
|
if (!node)
|
|
|
|
return QModelIndex();
|
2021-10-24 12:04:37 +08:00
|
|
|
return getParentIndex(node);
|
2021-09-11 11:42:20 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
int ProjectModel::rowCount(const QModelIndex &parent) const
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
|
|
|
if (!parent.isValid())
|
|
|
|
return 1;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p = static_cast<ProjectModelNode*>(parent.internalPointer());
|
2021-09-11 09:21:44 +08:00
|
|
|
if (p) {
|
|
|
|
return p->children.count();
|
|
|
|
} else {
|
2022-01-27 18:34:18 +08:00
|
|
|
return mProject->rootNode()->children.count();
|
2021-09-11 09:21:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
int ProjectModel::columnCount(const QModelIndex &) const
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
2021-09-11 09:21:44 +08:00
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
2021-09-11 09:21:44 +08:00
|
|
|
if (!p)
|
|
|
|
return QVariant();
|
2022-02-14 00:13:00 +08:00
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
if (p == mProject->rootNode().get()) {
|
|
|
|
QString branch;
|
2022-02-15 21:39:17 +08:00
|
|
|
if (mIconProvider->VCSRepository()->hasRepository(branch))
|
2022-02-14 00:13:00 +08:00
|
|
|
return QString("%1 [%2]").arg(p->text,branch);
|
|
|
|
}
|
|
|
|
return p->text;
|
|
|
|
} else if (role==Qt::EditRole) {
|
2021-09-11 11:42:20 +08:00
|
|
|
return p->text;
|
2021-10-23 23:10:34 +08:00
|
|
|
} else if (role == Qt::DecorationRole) {
|
2022-02-13 20:08:18 +08:00
|
|
|
QIcon icon;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (p->isUnit) {
|
|
|
|
PProjectUnit unit = p->pUnit.lock();
|
|
|
|
if (unit)
|
|
|
|
icon = mIconProvider->icon(unit->fileName());
|
2021-10-23 23:10:34 +08:00
|
|
|
} else {
|
2022-02-14 00:13:00 +08:00
|
|
|
if (p == mProject->rootNode().get()) {
|
|
|
|
QString branch;
|
2022-02-15 21:39:17 +08:00
|
|
|
if (mIconProvider->VCSRepository()->hasRepository(branch))
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT);
|
|
|
|
} else {
|
|
|
|
switch(p->folderNodeType) {
|
2022-09-30 17:51:26 +08:00
|
|
|
case ProjectModelNodeType::DUMMY_HEADERS_FOLDER:
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HEADERS_FOLDER);
|
|
|
|
break;
|
2022-09-30 17:51:26 +08:00
|
|
|
case ProjectModelNodeType::DUMMY_SOURCES_FOLDER:
|
2022-02-14 00:13:00 +08:00
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_SOURCES_FOLDER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
|
|
|
|
}
|
2022-02-13 20:08:18 +08:00
|
|
|
}
|
2021-10-23 23:10:34 +08:00
|
|
|
if (icon.isNull())
|
2022-02-15 00:01:50 +08:00
|
|
|
icon = mIconProvider->icon(QFileIconProvider::Folder);
|
2021-10-23 23:10:34 +08:00
|
|
|
}
|
2022-02-13 20:08:18 +08:00
|
|
|
return icon;
|
2021-09-11 09:21:44 +08:00
|
|
|
}
|
2021-09-11 11:42:20 +08:00
|
|
|
return QVariant();
|
2021-09-11 09:21:44 +08:00
|
|
|
}
|
2021-09-18 10:47:35 +08:00
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const
|
2021-09-18 10:47:35 +08:00
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return Qt::NoItemFlags;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
2021-09-18 10:47:35 +08:00
|
|
|
if (!p)
|
|
|
|
return Qt::NoItemFlags;
|
2022-01-27 18:34:18 +08:00
|
|
|
if (p==mProject->rootNode().get())
|
2021-11-27 09:36:49 +08:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable;
|
2022-02-08 12:33:10 +08:00
|
|
|
if (mProject && mProject->modelType() == ProjectModelType::FileSystem) {
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (p->isUnit)
|
2022-02-08 12:33:10 +08:00
|
|
|
flags.setFlag(Qt::ItemIsEditable);
|
|
|
|
return flags;
|
|
|
|
} else {
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!p->isUnit) {
|
2022-02-08 12:33:10 +08:00
|
|
|
flags.setFlag(Qt::ItemIsDropEnabled);
|
|
|
|
flags.setFlag(Qt::ItemIsDragEnabled,false);
|
|
|
|
}
|
|
|
|
return flags;
|
2021-10-24 12:37:00 +08:00
|
|
|
}
|
2021-09-18 10:47:35 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2021-09-18 10:47:35 +08:00
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return false;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
|
|
|
PProjectModelNode node = mProject->pointerToNode(p);
|
2021-09-18 10:47:35 +08:00
|
|
|
if (!node)
|
|
|
|
return false;
|
|
|
|
if (role == Qt::EditRole) {
|
2022-01-27 18:34:18 +08:00
|
|
|
if (node == mProject->rootNode()) {
|
2021-11-27 09:36:49 +08:00
|
|
|
QString newName = value.toString().trimmed();
|
|
|
|
if (newName.isEmpty())
|
|
|
|
return false;
|
|
|
|
mProject->setName(newName);
|
2022-01-08 08:52:50 +08:00
|
|
|
emit dataChanged(index,index);
|
2021-11-27 09:36:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectUnit unit = node->pUnit.lock();
|
|
|
|
if (unit) {
|
2021-09-18 10:47:35 +08:00
|
|
|
//change unit name
|
2022-10-08 23:30:30 +08:00
|
|
|
|
2021-09-18 10:47:35 +08:00
|
|
|
QString newName = value.toString().trimmed();
|
|
|
|
if (newName.isEmpty())
|
|
|
|
return false;
|
|
|
|
if (newName == node->text)
|
|
|
|
return false;
|
|
|
|
QString oldName = unit->fileName();
|
|
|
|
QString curDir = extractFilePath(oldName);
|
2022-11-16 09:24:42 +08:00
|
|
|
newName = generateAbsolutePath(curDir,newName);
|
2021-09-18 10:47:35 +08:00
|
|
|
// Only continue if the user says so...
|
|
|
|
if (fileExists(newName) && newName.compare(oldName, PATH_SENSITIVITY)!=0) {
|
|
|
|
// don't remove when changing case for example
|
2022-03-21 09:08:05 +08:00
|
|
|
if (QMessageBox::question(nullptr,
|
2021-09-18 10:47:35 +08:00
|
|
|
tr("File exists"),
|
|
|
|
tr("File '%1' already exists. Delete it now?")
|
|
|
|
.arg(newName),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::No) == QMessageBox::Yes) {
|
|
|
|
// Close the target file...
|
2022-03-21 09:08:05 +08:00
|
|
|
Editor * e=mProject->editorList()->getOpenedEditorByFilename(newName);
|
2021-09-18 10:47:35 +08:00
|
|
|
if (e)
|
2022-03-21 09:08:05 +08:00
|
|
|
mProject->editorList()->closeEditor(e);
|
2021-09-18 10:47:35 +08:00
|
|
|
|
|
|
|
// Remove it from the current project...
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectUnit unit = mProject->findUnit(newName);
|
|
|
|
if (unit) {
|
|
|
|
mProject->removeUnit(unit,false);
|
2021-09-18 10:47:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// All references to the file are removed. Delete the file from disk
|
|
|
|
if (!QFile::remove(newName)) {
|
2022-03-21 09:08:05 +08:00
|
|
|
QMessageBox::critical(nullptr,
|
2021-09-18 10:47:35 +08:00
|
|
|
tr("Remove failed"),
|
|
|
|
tr("Failed to remove file '%1'")
|
|
|
|
.arg(newName),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Target filename does not exist anymore. Do a rename
|
|
|
|
// change name in project file first (no actual file renaming on disk)
|
2022-03-01 22:03:54 +08:00
|
|
|
//save old file, if it is openned;
|
2021-09-18 10:47:35 +08:00
|
|
|
// remove old file from monitor list
|
2022-03-21 09:08:05 +08:00
|
|
|
mProject->fileSystemWatcher()->removePath(oldName);
|
2021-09-18 10:47:35 +08:00
|
|
|
|
2022-03-01 22:03:54 +08:00
|
|
|
if (!QFile::rename(oldName,newName)) {
|
2022-03-21 09:08:05 +08:00
|
|
|
QMessageBox::critical(nullptr,
|
2022-03-01 22:03:54 +08:00
|
|
|
tr("Rename failed"),
|
|
|
|
tr("Failed to rename file '%1' to '%2'")
|
|
|
|
.arg(oldName,newName),
|
2021-09-18 10:47:35 +08:00
|
|
|
QMessageBox::Ok);
|
|
|
|
return false;
|
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
mProject->renameUnit(unit,newName);
|
2021-09-18 10:47:35 +08:00
|
|
|
|
|
|
|
// Add new filename to file minitor
|
2022-03-21 09:08:05 +08:00
|
|
|
mProject->fileSystemWatcher()->addPath(newName);
|
2022-03-01 22:03:54 +08:00
|
|
|
|
2022-10-08 23:30:30 +08:00
|
|
|
mProject->saveAll();
|
|
|
|
|
2021-09-18 10:47:35 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
//change folder name
|
|
|
|
QString newName = value.toString().trimmed();
|
|
|
|
if (newName.isEmpty())
|
|
|
|
return false;
|
|
|
|
if (newName == node->text)
|
|
|
|
return false;
|
2022-10-08 23:30:30 +08:00
|
|
|
mProject->renameFolderNode(node,newName);
|
|
|
|
|
2022-01-08 08:52:50 +08:00
|
|
|
emit dataChanged(index,index);
|
2022-10-08 23:30:30 +08:00
|
|
|
|
|
|
|
mProject->saveAll();
|
2021-09-18 10:47:35 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-23 23:10:34 +08:00
|
|
|
|
2022-10-24 17:23:37 +08:00
|
|
|
void ProjectModel::refreshIcon(const QModelIndex &index, bool update)
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
if (update)
|
|
|
|
mIconProvider->update();
|
|
|
|
QVector<int> roles;
|
|
|
|
roles.append(Qt::DecorationRole);
|
|
|
|
emit dataChanged(index,index, roles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectModel::refreshIcon(const QString &filename)
|
|
|
|
{
|
|
|
|
PProjectUnit unit=mProject->findUnit(filename);
|
|
|
|
if (!unit)
|
|
|
|
return;
|
|
|
|
PProjectModelNode node=unit->node();
|
|
|
|
QModelIndex index = getNodeIndex(node.get());
|
|
|
|
refreshIcon(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectModel::refreshIcons()
|
|
|
|
{
|
|
|
|
mIconProvider->update();
|
|
|
|
mProject->rootNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectModel::refreshNodeIconRecursive(PProjectModelNode node)
|
|
|
|
{
|
|
|
|
QModelIndex index=getNodeIndex(node.get());
|
|
|
|
refreshIcon(index,false);
|
|
|
|
foreach( PProjectModelNode child, node->children) {
|
|
|
|
refreshNodeIconRecursive(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:51:26 +08:00
|
|
|
QModelIndex ProjectModel::getNodeIndex(ProjectModelNode *node) const
|
|
|
|
{
|
2022-10-01 08:54:44 +08:00
|
|
|
if (!node)
|
|
|
|
return QModelIndex();
|
2022-09-30 17:51:26 +08:00
|
|
|
PProjectModelNode parent = node->parent.lock();
|
|
|
|
if (!parent) // root node
|
2022-10-01 08:54:44 +08:00
|
|
|
return createIndex(0,0,node);
|
2022-09-30 17:51:26 +08:00
|
|
|
int row = -1;
|
|
|
|
for (int i=0;i<parent->children.count();i++) {
|
|
|
|
const PProjectModelNode& pNode=parent->children[i];
|
|
|
|
if (pNode.get()==node) {
|
|
|
|
row = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (row<0)
|
|
|
|
return QModelIndex();
|
|
|
|
return createIndex(row,0,node);
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
QModelIndex ProjectModel::getParentIndex(ProjectModelNode * node) const
|
2021-10-23 23:10:34 +08:00
|
|
|
{
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode parent = node->parent.lock();
|
2021-10-24 12:04:37 +08:00
|
|
|
if (!parent) // root node
|
|
|
|
return QModelIndex();
|
2022-02-08 00:24:08 +08:00
|
|
|
PProjectModelNode grand = parent->parent.lock();
|
2021-10-24 12:04:37 +08:00
|
|
|
if (!grand) {
|
|
|
|
return createIndex(0,0,parent.get());
|
2021-10-24 00:17:08 +08:00
|
|
|
}
|
2021-10-24 12:04:37 +08:00
|
|
|
|
|
|
|
int row = grand->children.indexOf(parent);
|
|
|
|
if (row<0)
|
|
|
|
return QModelIndex();
|
|
|
|
return createIndex(row,0,parent.get());
|
|
|
|
}
|
|
|
|
|
2022-10-02 23:32:33 +08:00
|
|
|
QModelIndex ProjectModel::rootIndex() const
|
|
|
|
{
|
|
|
|
return getNodeIndex(mProject->rootNode().get());
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
bool ProjectModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) const
|
2021-10-24 12:04:37 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!data || action != Qt::MoveAction)
|
2021-10-23 23:10:34 +08:00
|
|
|
return false;
|
2021-10-24 12:04:37 +08:00
|
|
|
if (!parent.isValid())
|
|
|
|
return false;
|
|
|
|
// check if the format is supported
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
if (types.isEmpty())
|
|
|
|
return false;
|
|
|
|
QString format = types.at(0);
|
|
|
|
if (!data->hasFormat(format))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QModelIndex idx = parent;
|
|
|
|
// if (row >= rowCount(parent) || row < 0) {
|
|
|
|
// return false;
|
|
|
|
// } else {
|
|
|
|
// idx= index(row,column,parent);
|
|
|
|
// }
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p= static_cast<ProjectModelNode*>(idx.internalPointer());
|
|
|
|
PProjectModelNode node = mProject->pointerToNode(p);
|
2022-10-08 23:30:30 +08:00
|
|
|
if (node->isUnit)
|
2021-10-23 23:10:34 +08:00
|
|
|
return false;
|
2021-10-24 12:04:37 +08:00
|
|
|
QByteArray encoded = data->data(format);
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
while (!stream.atEnd()) {
|
2021-12-24 23:18:20 +08:00
|
|
|
qint32 r, c;
|
|
|
|
quintptr v;
|
2021-10-24 12:04:37 +08:00
|
|
|
stream >> r >> c >> v;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* droppedPointer= (ProjectModelNode*)(v);
|
|
|
|
PProjectModelNode droppedNode = mProject->pointerToNode(droppedPointer);
|
|
|
|
PProjectModelNode oldParent = droppedNode->parent.lock();
|
2021-10-24 12:04:37 +08:00
|
|
|
if (oldParent == node)
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-23 23:10:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-24 00:17:08 +08:00
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
Qt::DropActions ProjectModel::supportedDropActions() const
|
2021-10-24 00:17:08 +08:00
|
|
|
{
|
2021-10-24 12:04:37 +08:00
|
|
|
return Qt::MoveAction;
|
2021-10-24 00:17:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
bool ProjectModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent)
|
2021-10-24 00:17:08 +08:00
|
|
|
{
|
2021-10-24 12:04:37 +08:00
|
|
|
// check if the action is supported
|
|
|
|
if (!data || action != Qt::MoveAction)
|
|
|
|
return false;
|
|
|
|
// check if the format is supported
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
if (types.isEmpty())
|
|
|
|
return false;
|
|
|
|
QString format = types.at(0);
|
|
|
|
if (!data->hasFormat(format))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
return false;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p= static_cast<ProjectModelNode*>(parent.internalPointer());
|
|
|
|
PProjectModelNode node = mProject->pointerToNode(p);
|
2021-10-24 12:04:37 +08:00
|
|
|
|
|
|
|
QByteArray encoded = data->data(format);
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
QVector<int> rows,cols;
|
|
|
|
QVector<intptr_t> pointers;
|
|
|
|
while (!stream.atEnd()) {
|
2021-12-24 23:18:20 +08:00
|
|
|
qint32 r, c;
|
|
|
|
quintptr v;
|
2021-10-24 12:04:37 +08:00
|
|
|
stream >> r >> c >> v;
|
|
|
|
rows.append(r);
|
|
|
|
cols.append(c);
|
|
|
|
pointers.append(v);
|
|
|
|
}
|
|
|
|
for (int i=pointers.count()-1;i>=0;i--) {
|
|
|
|
int r = rows[i];
|
|
|
|
intptr_t v = pointers[i];
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* droppedPointer= (ProjectModelNode*)(v);
|
|
|
|
PProjectModelNode droppedNode = mProject->pointerToNode(droppedPointer);
|
|
|
|
PProjectModelNode oldParent = droppedNode->parent.lock();
|
2022-10-02 13:29:51 +08:00
|
|
|
if (oldParent) {
|
|
|
|
QModelIndex oldParentIndex = getNodeIndex(oldParent.get());
|
|
|
|
beginRemoveRows(oldParentIndex,r,r);
|
2021-10-24 12:04:37 +08:00
|
|
|
oldParent->children.removeAt(r);
|
2022-10-02 13:29:51 +08:00
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
QModelIndex newParentIndex = getNodeIndex(node.get());
|
|
|
|
beginInsertRows(newParentIndex,node->children.count(),node->children.count());
|
2021-10-24 12:04:37 +08:00
|
|
|
droppedNode->parent = node;
|
|
|
|
node->children.append(droppedNode);
|
2022-10-08 23:30:30 +08:00
|
|
|
if (droppedNode->isUnit) {
|
|
|
|
PProjectUnit unit = droppedNode->pUnit.lock();
|
2022-10-01 08:54:44 +08:00
|
|
|
unit->setFolder(mProject->getNodePath(node));
|
2021-10-24 12:04:37 +08:00
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
mProject->saveAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-10-24 00:17:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 00:24:08 +08:00
|
|
|
QMimeData *ProjectModel::mimeData(const QModelIndexList &indexes) const
|
2021-10-24 00:17:08 +08:00
|
|
|
{
|
2021-10-24 12:04:37 +08:00
|
|
|
if (indexes.count() <= 0)
|
|
|
|
return nullptr;
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
if (types.isEmpty())
|
|
|
|
return nullptr;
|
|
|
|
QMimeData *data = new QMimeData();
|
|
|
|
QString format = types.at(0);
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
QModelIndexList::ConstIterator it = indexes.begin();
|
|
|
|
QList<QUrl> urls;
|
|
|
|
for (; it != indexes.end(); ++it) {
|
2021-12-24 23:18:20 +08:00
|
|
|
stream << (qint32)((*it).row()) << (qint32)((*it).column()) << (quintptr)((*it).internalPointer());
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* p = static_cast<ProjectModelNode*>((*it).internalPointer());
|
2022-10-08 23:30:30 +08:00
|
|
|
if (p && p->isUnit) {
|
|
|
|
PProjectUnit unit = p->pUnit.lock();
|
|
|
|
if (unit)
|
|
|
|
urls.append(QUrl::fromLocalFile(unit->fileName()));
|
2021-10-24 12:04:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!urls.isEmpty())
|
|
|
|
data->setUrls(urls);
|
|
|
|
data->setData(format, encoded);
|
|
|
|
return data;
|
2021-10-24 00:17:08 +08:00
|
|
|
}
|
2022-01-08 08:52:50 +08:00
|
|
|
|
|
|
|
ProjectModelSortFilterProxy::ProjectModelSortFilterProxy(QObject *parent):
|
|
|
|
QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectModelSortFilterProxy::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
|
|
|
{
|
|
|
|
if (!sourceModel())
|
|
|
|
return false;
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* pLeft=nullptr;
|
2022-01-08 08:52:50 +08:00
|
|
|
if (source_left.isValid())
|
2022-02-08 00:24:08 +08:00
|
|
|
pLeft = static_cast<ProjectModelNode*>(source_left.internalPointer());
|
|
|
|
ProjectModelNode* pRight=nullptr;
|
2022-01-08 08:52:50 +08:00
|
|
|
if (source_right.isValid())
|
2022-02-08 00:24:08 +08:00
|
|
|
pRight = static_cast<ProjectModelNode*>(source_right.internalPointer());
|
2022-01-08 08:52:50 +08:00
|
|
|
if (!pLeft)
|
|
|
|
return true;
|
|
|
|
if (!pRight)
|
|
|
|
return false;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!pLeft->isUnit && pRight->isUnit)
|
2022-01-08 08:52:50 +08:00
|
|
|
return true;
|
2022-10-08 23:30:30 +08:00
|
|
|
if (pLeft->isUnit && !pRight->isUnit)
|
2022-01-08 08:52:50 +08:00
|
|
|
return false;
|
2022-02-08 12:33:10 +08:00
|
|
|
if (pLeft->priority!=pRight->priority)
|
|
|
|
return pLeft->priority>pRight->priority;
|
2022-01-08 08:52:50 +08:00
|
|
|
return QString::compare(pLeft->text, pRight->text)<0;
|
|
|
|
}
|