work save: project support

This commit is contained in:
royqh1979 2021-09-05 23:45:05 +08:00
parent 6d027d612c
commit 538d44990d
3 changed files with 257 additions and 0 deletions

View File

@ -31,6 +31,7 @@ SOURCES += \
parser/cpptokenizer.cpp \
parser/parserutils.cpp \
parser/statementmodel.cpp \
project.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \
@ -109,6 +110,7 @@ HEADERS += \
parser/parserutils.h \
parser/statementmodel.h \
platform.h \
project.h \
qsynedit/Search.h \
qsynedit/SearchBase.h \
qsynedit/SearchRegex.h \

180
RedPandaIDE/project.cpp Normal file
View File

@ -0,0 +1,180 @@
#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;
}

75
RedPandaIDE/project.h Normal file
View File

@ -0,0 +1,75 @@
#ifndef PROJECT_H
#define PROJECT_H
#include <QObject>
#include <memory>
enum class ProjectType {
GUI,
Console,
StaticLib,
DynamicLib
};
class Project;
class Editor;
class ProjectUnit {
public:
const std::weak_ptr<Project> &parent() const;
void setParent(const std::weak_ptr<Project> &newParent);
Editor *editor() const;
void setEditor(Editor *newEditor);
const QString &fileName() const;
void setFileName(const QString &newFileName);
bool isNew() const;
void setNew(bool newNew);
const QString &folder() const;
void setFolder(const QString &newFolder);
bool compile() const;
void setCompile(bool newCompile);
bool compileCpp() const;
void setCompileCpp(bool newCompileCpp);
bool overrideBuildCmd() const;
void setOverrideBuildCmd(bool newOverrideBuildCmd);
const QString &buildCmd() const;
void setBuildCmd(const QString &newBuildCmd);
bool link() const;
void setLink(bool newLink);
int priority() const;
void setPriority(int newPriority);
bool detectEncoding() const;
void setDetectEncoding(bool newDetectEncoding);
const QByteArray &encoding() const;
void setEncoding(const QByteArray &newEncoding);
bool modified();
void setModified(bool value);
bool save();
private:
std::weak_ptr<Project> mParent;
Editor* mEditor;
QString mFileName;
bool mNew;
QString mFolder;
bool mCompile;
bool mCompileCpp;
bool mOverrideBuildCmd;
QString mBuildCmd;
bool mLink;
int mPriority;
bool mDetectEncoding;
QByteArray mEncoding;
};
class Project : public QObject
{
Q_OBJECT
public:
explicit Project(QObject *parent = nullptr);
signals:
};
#endif // PROJECT_H