From 538d44990d2ae72ba3e7f3b98bb1e46ea75ab386 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 5 Sep 2021 23:45:05 +0800 Subject: [PATCH] work save: project support --- RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/project.cpp | 180 ++++++++++++++++++++++++++++++++++++ RedPandaIDE/project.h | 75 +++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 RedPandaIDE/project.cpp create mode 100644 RedPandaIDE/project.h diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 6550d33c..3c4d02fe 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -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 \ diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp new file mode 100644 index 00000000..5bf3177a --- /dev/null +++ b/RedPandaIDE/project.cpp @@ -0,0 +1,180 @@ +#include "project.h" +#include "editor.h" +#include "mainwindow.h" + +Project::Project(QObject *parent) : QObject(parent) +{ + +} + +const std::weak_ptr &ProjectUnit::parent() const +{ + return mParent; +} + +void ProjectUnit::setParent(const std::weak_ptr &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 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; +} diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h new file mode 100644 index 00000000..8c355013 --- /dev/null +++ b/RedPandaIDE/project.h @@ -0,0 +1,75 @@ +#ifndef PROJECT_H +#define PROJECT_H + +#include +#include + +enum class ProjectType { + GUI, + Console, + StaticLib, + DynamicLib +}; + +class Project; +class Editor; +class ProjectUnit { + +public: + const std::weak_ptr &parent() const; + void setParent(const std::weak_ptr &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 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