work save

This commit is contained in:
royqh1979@gmail.com 2021-09-09 11:47:04 +08:00
parent c120d0a23f
commit 98db43420c
4 changed files with 87 additions and 12 deletions

View File

@ -11,6 +11,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include "settings.h"
Project::Project(const QString &filename, const QString &name, QObject *parent) : QObject(parent) Project::Project(const QString &filename, const QString &name, QObject *parent) : QObject(parent)
{ {
@ -34,13 +35,13 @@ Project::Project(const QString &filename, const QString &name, QObject *parent)
} }
} }
QString Project::directory() QString Project::directory() const
{ {
QFileInfo fileInfo(mFilename); QFileInfo fileInfo(mFilename);
return fileInfo.absolutePath(); return fileInfo.absolutePath();
} }
QString Project::executable() QString Project::executable() const
{ {
QString exeFileName; QString exeFileName;
if (mOptions.overrideOutput && !mOptions.overridenOutput.isEmpty()) { if (mOptions.overrideOutput && !mOptions.overridenOutput.isEmpty()) {
@ -76,7 +77,7 @@ QString Project::makeFileName()
return QDir(directory()).filePath(MAKEFILE_NAME); return QDir(directory()).filePath(MAKEFILE_NAME);
} }
bool Project::modified() bool Project::modified() const
{ {
// Project file modified? Done // Project file modified? Done
if (mModified) if (mModified)
@ -633,6 +634,42 @@ PFolderNode Project::folderNodeFromName(const QString &name)
return mNode; return mNode;
} }
QChar Project::getCompilerOption(const QString &optionString)
{
// Does the option exist?
Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
if (!compilerSet)
return '0';
int index = compilerSet->findOptionIndex(optionString);
if (index>=0 && index<mOptions.compilerOptions.length()) {
return mOptions.compilerOptions[index];
}
return '0';
}
QString Project::getFolderPath(PFolderNode node)
{
QString result;
if (!node)
return result;
if (node->unitIndex>=0) // not a folder
return result;
FolderNode* p = node.get();
while (p && p->unitIndex==-1) {
if (!result.isEmpty())
result = p->text + "/" + result;
p = p->parent;
}
return result;
}
int Project::getUnitFromString(const QString &s)
{
return indexInUnits(s);
}
PCppParser Project::cppParser() PCppParser Project::cppParser()
{ {
return mParser; return mParser;
@ -645,6 +682,24 @@ void Project::sortUnitsByPriority()
}); });
} }
int Project::indexInUnits(const QString &fileName) const
{
QDir dir(directory());
for (int i=0;i<mUnits.count();i++) {
PProjectUnit unit = mUnits[i];
if (dir.absoluteFilePath(fileName) == dir.absoluteFilePath(unit->fileName()))
return i;
}
return -1;
}
int Project::indexInUnits(const Editor *editor) const
{
if (!editor)
return -1;
return indexInUnits(editor->filename());
}
const QString &Project::filename() const const QString &Project::filename() const
{ {
return mFilename; return mFilename;

View File

@ -142,10 +142,10 @@ class Project : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr); explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr);
QString directory(); QString directory() const;
QString executable(); QString executable() const;
QString makeFileName(); QString makeFileName();
bool modified(); bool modified() const;
void setFileName(const QString& value); void setFileName(const QString& value);
void setModified(bool value); void setModified(bool value);
@ -160,11 +160,13 @@ public:
void doAutoOpen(); void doAutoOpen();
bool fileAlreadyExists(const QString& s); bool fileAlreadyExists(const QString& s);
PFolderNode folderNodeFromName(const QString& name); PFolderNode folderNodeFromName(const QString& name);
QChar getCompilerOption(const QString& optionString);
QString getFolderPath(PFolderNode node);
int getUnitFromString(const QString& s);
int newUnit(bool newProject, int newUnit(bool newProject,
PFolderNode parentNode, PFolderNode parentNode,
const QString customFileName); const QString customFileName);
QString getFolderPath(PFolderNode node);
void updateFolders(); void updateFolders();
Editor* openUnit(int index); Editor* openUnit(int index);
void saveUnitAs(int i, const QString& sFileName); // save single [UnitX] void saveUnitAs(int i, const QString& sFileName); // save single [UnitX]
@ -181,7 +183,6 @@ public:
// procedure Open; // procedure Open;
bool removeFolder(PFolderNode node); bool removeFolder(PFolderNode node);
bool removeEditor(int index, bool doClose); bool removeEditor(int index, bool doClose);
int getUnitFromString(const QString& s);
void rebuildNodes(); void rebuildNodes();
QString listUnitStr(const QChar& separator); QString listUnitStr(const QChar& separator);
@ -190,7 +191,6 @@ public:
void updateNodeIndexes(); void updateNodeIndexes();
void setNodeValue(PFolderNode value); void setNodeValue(PFolderNode value);
void incrementBuildNumber(); void incrementBuildNumber();
QChar getCompilerOption(const QString& optionString);
void setCompilerOption(const QString& optionString, const QChar& value); void setCompilerOption(const QString& optionString, const QChar& value);
void saveToLog(); void saveToLog();
@ -203,6 +203,8 @@ signals:
private: private:
void open(); void open();
void sortUnitsByPriority(); void sortUnitsByPriority();
int indexInUnits(const QString& fileName) const;
int indexInUnits(const Editor* editor) const;
private: private:
QList<PProjectUnit> mUnits; QList<PProjectUnit> mUnits;
ProjectOptions mOptions; ProjectOptions mOptions;

View File

@ -1223,6 +1223,17 @@ PCompilerOption Settings::CompilerSet::findOption(const QString &setting)
return PCompilerOption(); return PCompilerOption();
} }
int Settings::CompilerSet::findOptionIndex(const QString &setting)
{
for (int i=0;i<mOptions.size();i++) {
PCompilerOption pOption = mOptions[i];
if (pOption->setting == setting) {
return i;
}
}
return -1;
}
char Settings::CompilerSet::getOptionValue(const QString &setting) char Settings::CompilerSet::getOptionValue(const QString &setting)
{ {
PCompilerOption pOption = findOption(setting); PCompilerOption pOption = findOption(setting);
@ -2270,8 +2281,13 @@ void Settings::CompilerSets::setDefaultIndex(int value)
Settings::PCompilerSet Settings::CompilerSets::defaultSet() Settings::PCompilerSet Settings::CompilerSets::defaultSet()
{ {
if (mDefaultIndex>=0 && mDefaultIndex<mList.size()) { return getSet(mDefaultIndex);
return mList[mDefaultIndex]; }
Settings::PCompilerSet Settings::CompilerSets::getSet(int index)
{
if (index>=0 && index<mList.size()) {
return mList[index];
} }
return PCompilerSet(); return PCompilerSet();
} }

View File

@ -46,7 +46,7 @@ typedef struct {
using PCompilerOption = std::shared_ptr<CompilerOption>; using PCompilerOption = std::shared_ptr<CompilerOption>;
using CompilerOptionList=std::vector<std::shared_ptr<CompilerOption>>; using CompilerOptionList=QVector<std::shared_ptr<CompilerOption>>;
class Settings class Settings
{ {
@ -802,6 +802,7 @@ public:
int value, const QString& setting, int value, const QString& setting,
const QStringList& choices = QStringList()); const QStringList& choices = QStringList());
PCompilerOption findOption(const QString& setting); PCompilerOption findOption(const QString& setting);
int findOptionIndex(const QString& setting);
char getOptionValue(const QString& setting); char getOptionValue(const QString& setting);
void setOption(const QString& setting, char valueChar); void setOption(const QString& setting, char valueChar);
void setOption(PCompilerOption& option, char valueChar); void setOption(PCompilerOption& option, char valueChar);
@ -941,6 +942,7 @@ public:
int defaultIndex() const; int defaultIndex() const;
void setDefaultIndex(int value); void setDefaultIndex(int value);
PCompilerSet defaultSet(); PCompilerSet defaultSet();
PCompilerSet getSet(int index);
private: private:
void savePath(const QString& name, const QString& path); void savePath(const QString& name, const QString& path);
void savePathList(const QString& name, const QStringList& pathList); void savePathList(const QString& name, const QStringList& pathList);