181 lines
3.1 KiB
C++
181 lines
3.1 KiB
C++
|
#include "project.h"
|
||
|
#include "editor.h"
|
||
|
#include "mainwindow.h"
|
||
|
|
||
|
Project::Project(QObject *parent) : QObject(parent)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
const std::weak_ptr<Project> &ProjectUnit::parent() const
|
||
|
{
|
||
|
return mParent;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setParent(const std::weak_ptr<Project> &newParent)
|
||
|
{
|
||
|
mParent = newParent;
|
||
|
}
|
||
|
|
||
|
Editor *ProjectUnit::editor() const
|
||
|
{
|
||
|
return mEditor;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setEditor(Editor *newEditor)
|
||
|
{
|
||
|
mEditor = newEditor;
|
||
|
}
|
||
|
|
||
|
const QString &ProjectUnit::fileName() const
|
||
|
{
|
||
|
return mFileName;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setFileName(const QString &newFileName)
|
||
|
{
|
||
|
mFileName = newFileName;
|
||
|
}
|
||
|
|
||
|
bool ProjectUnit::isNew() const
|
||
|
{
|
||
|
return mNew;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setNew(bool newNew)
|
||
|
{
|
||
|
mNew = newNew;
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
mPriority = newPriority;
|
||
|
}
|
||
|
|
||
|
bool ProjectUnit::detectEncoding() const
|
||
|
{
|
||
|
return mDetectEncoding;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setDetectEncoding(bool newDetectEncoding)
|
||
|
{
|
||
|
mDetectEncoding = newDetectEncoding;
|
||
|
}
|
||
|
|
||
|
const QByteArray &ProjectUnit::encoding() const
|
||
|
{
|
||
|
return mEncoding;
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setEncoding(const QByteArray &newEncoding)
|
||
|
{
|
||
|
mEncoding = newEncoding;
|
||
|
}
|
||
|
|
||
|
bool ProjectUnit::modified()
|
||
|
{
|
||
|
if (mEditor) {
|
||
|
return mEditor->modified();
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ProjectUnit::setModified(bool value)
|
||
|
{
|
||
|
// Mark the change in the coupled editor
|
||
|
if (mEditor) {
|
||
|
return mEditor->setModified(value);
|
||
|
}
|
||
|
|
||
|
// If modified is set to true, mark project as modified too
|
||
|
if (value) {
|
||
|
std::shared_ptr<Project> parent = mParent.lock();
|
||
|
if (parent) {
|
||
|
parent->setModified(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool ProjectUnit::save()
|
||
|
{
|
||
|
bool previous=pMainWindow->fileSystemWatcher()->blockSignals(true);
|
||
|
auto action = finally([&previous](){
|
||
|
pMainWindow->fileSystemWatcher()->blockSignals(previous);
|
||
|
});
|
||
|
bool result=true;
|
||
|
if (!mEditor && !QFile(mFileName).exists()) {
|
||
|
// file is neither open, nor saved
|
||
|
QStringList temp;
|
||
|
StringsToFile(temp,mFileName);
|
||
|
} else if (mEditor and modified()) {
|
||
|
result = mEditor->save();
|
||
|
}
|
||
|
return result;
|
||
|
}
|