RedPanda-CPP/RedPandaIDE/project.h

220 lines
5.8 KiB
C
Raw Normal View History

2021-09-05 23:45:05 +08:00
#ifndef PROJECT_H
#define PROJECT_H
#include <QObject>
2021-09-06 08:45:53 +08:00
#include <QSettings>
2021-09-05 23:45:05 +08:00
#include <memory>
enum class ProjectType {
GUI,
Console,
StaticLib,
DynamicLib
};
class Project;
class Editor;
2021-09-06 08:45:53 +08:00
class CppParser;
2021-09-07 00:32:16 +08:00
struct FolderNode;
using PFolderNode = std::shared_ptr<FolderNode>;
struct FolderNode {
QString text;
FolderNode * parent;
int unitIndex;
QList<PFolderNode> children;
};
2021-09-05 23:45:05 +08:00
class ProjectUnit {
public:
2021-09-07 00:32:16 +08:00
explicit ProjectUnit(Project* parent);
Project* parent() const;
void setParent(Project* newParent);
2021-09-05 23:45:05 +08:00
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);
2021-09-06 12:58:29 +08:00
bool modified() const;
2021-09-05 23:45:05 +08:00
void setModified(bool value);
bool save();
2021-09-07 10:28:40 +08:00
PFolderNode &node();
void setNode(const PFolderNode &newNode);
2021-09-05 23:45:05 +08:00
private:
2021-09-07 00:32:16 +08:00
Project* mParent;
2021-09-05 23:45:05 +08:00
Editor* mEditor;
QString mFileName;
bool mNew;
QString mFolder;
bool mCompile;
bool mCompileCpp;
bool mOverrideBuildCmd;
QString mBuildCmd;
bool mLink;
int mPriority;
bool mDetectEncoding;
QByteArray mEncoding;
2021-09-07 00:32:16 +08:00
PFolderNode mNode;
2021-09-05 23:45:05 +08:00
};
2021-09-06 08:45:53 +08:00
using PProjectUnit = std::shared_ptr<ProjectUnit>;
2021-09-06 01:47:07 +08:00
struct ProjectVersionInfo{
int major;
int minor;
int release;
int build;
int languageID;
int charsetID;
QString companyName;
QString fileVersion;
QString fileDescription;
QString internalName;
QString legalCopyright;
QString legalTrademarks;
QString originalFilename;
QString productName;
QString productVersion;
bool autoIncBuildNr;
bool syncProduct;
};
struct ProjectOptions{
ProjectType type;
int version;
bool useUTF8;
QStringList objfiles;
QString compilerCmd;
QString cppCompilerCmd;
QString linkerCmd;
QStringList includes;
QStringList libs;
QString privateResource;
QStringList resourceIncludes;
QStringList makeIncludes;
bool useGPP;
QString icon;
QString exeOutput;
QString objectOutput;
QString logOutput;
bool logOutputEnabled;
bool useCustomMakefile;
QString customMakefile;
bool usePrecompiledHeader;
bool precompiledHeader;
bool overrideOutput;
QString overridenOutput;
QString hostApplication;
bool includeVersionInfo;
bool supportXPThemes;
int compilerSet;
QString compilerOptions;
2021-09-07 14:04:48 +08:00
ProjectVersionInfo versionInfo;
2021-09-06 01:47:07 +08:00
QString cmdLineArgs;
2021-09-07 14:04:48 +08:00
bool staticLink;
bool addCharset;
2021-09-06 01:47:07 +08:00
};
2021-09-05 23:45:05 +08:00
class Project : public QObject
{
Q_OBJECT
public:
2021-09-07 16:49:35 +08:00
explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr);
2021-09-06 08:45:53 +08:00
QString directory();
2021-09-07 10:28:40 +08:00
QString executable();
2021-09-06 08:45:53 +08:00
QString makeFileName();
2021-09-06 12:58:29 +08:00
bool modified();
2021-09-07 00:32:16 +08:00
void setFileName(const QString& value);
void setModified(bool value);
2021-09-07 10:28:40 +08:00
void addFolder(const QString& s);
2021-09-07 00:32:16 +08:00
PProjectUnit addUnit(const QString& inFileName,
PFolderNode parentNode,
bool rebuild);
2021-09-07 10:28:40 +08:00
void buildPrivateResource(bool forceSave);
2021-09-07 16:49:35 +08:00
void checkProjectFileForUpdate();
void closeUnit(int index);
void createFolderNodes();
void doAutoOpen();
2021-09-09 00:15:12 +08:00
bool fileAlreadyExists(const QString& s);
PFolderNode folderNodeFromName(const QString& name);
2021-09-07 10:28:40 +08:00
int newUnit(bool newProject,
PFolderNode parentNode,
const QString customFileName);
QString getFolderPath(PFolderNode node);
void updateFolders();
Editor* openUnit(int index);
void saveUnitAs(int i, const QString& sFileName); // save single [UnitX]
void saveAll(); // save [Project] and all [UnitX]
void loadLayout(); // load all [UnitX]
void loadUnitLayout(Editor *e, int index); // load single [UnitX] cursor positions
void saveLayout(); // save all [UnitX]
void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions
PFolderNode makeProjectNode();
PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent);
void loadOptions();
void saveOptions();
bool saveUnits();
2021-09-07 00:32:16 +08:00
// procedure Open;
2021-09-07 10:28:40 +08:00
bool removeFolder(PFolderNode node);
bool removeEditor(int index, bool doClose);
int getUnitFromString(const QString& s);
void rebuildNodes();
QString listUnitStr(const QChar& separator);
2021-09-09 00:15:12 +08:00
2021-09-07 10:28:40 +08:00
void showOptions();
// bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
void updateNodeIndexes();
void setNodeValue(PFolderNode value);
void incrementBuildNumber();
QChar getCompilerOption(const QString& optionString);
void setCompilerOption(const QString& optionString, const QChar& value);
void saveToLog();
2021-09-07 16:49:35 +08:00
std::shared_ptr<CppParser> cppParser();
2021-09-09 00:15:12 +08:00
const QString &filename() const;
2021-09-05 23:45:05 +08:00
signals:
2021-09-07 10:28:40 +08:00
void nodesChanged();
void modifyChanged(bool value);
2021-09-07 00:32:16 +08:00
private:
void open();
void sortUnitsByPriority();
2021-09-06 08:45:53 +08:00
private:
QList<PProjectUnit> mUnits;
ProjectOptions mOptions;
2021-09-07 00:32:16 +08:00
std::shared_ptr<QSettings> mIniFile;
2021-09-06 08:45:53 +08:00
QString mFilename;
QString mName;
bool mModified;
QStringList mFolders;
std::shared_ptr<CppParser> mParser;
2021-09-07 16:49:35 +08:00
QList<PFolderNode> mFolderNodes;
2021-09-07 00:32:16 +08:00
PFolderNode mNode;
2021-09-05 23:45:05 +08:00
};
#endif // PROJECT_H