From c120d0a23f4b115133e5ebec52f0bd88224a3a2a Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 9 Sep 2021 00:15:12 +0800 Subject: [PATCH] work save --- RedPandaIDE/project.cpp | 24 ++++++++++++++++++++ RedPandaIDE/project.h | 8 ++++--- RedPandaIDE/systemconsts.cpp | 6 +++++ RedPandaIDE/systemconsts.h | 1 + RedPandaIDE/utils.cpp | 13 +++++++++++ RedPandaIDE/utils.h | 1 + RedPandaIDE/widgets/filepropertiesdialog.cpp | 10 +------- 7 files changed, 51 insertions(+), 12 deletions(-) diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 9ec5c9de..3e724c2a 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -8,6 +8,7 @@ #include "utils.h" #include +#include #include #include @@ -614,6 +615,24 @@ void Project::doAutoOpen() } +bool Project::fileAlreadyExists(const QString &s) +{ + foreach (const PProjectUnit& unit, mUnits) { + if (unit->fileName() == s) + return true; + } + return false; +} + +PFolderNode Project::folderNodeFromName(const QString &name) +{ + int index = mFolders.indexOf(name); + if (index>=0) { + return mFolderNodes[index]; + } + return mNode; +} + PCppParser Project::cppParser() { return mParser; @@ -626,6 +645,11 @@ void Project::sortUnitsByPriority() }); } +const QString &Project::filename() const +{ + return mFilename; +} + ProjectUnit::ProjectUnit(Project* parent) { mEditor = nullptr; diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 851bc0ff..6a7c9369 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -158,6 +158,8 @@ public: void closeUnit(int index); void createFolderNodes(); void doAutoOpen(); + bool fileAlreadyExists(const QString& s); + PFolderNode folderNodeFromName(const QString& name); int newUnit(bool newProject, PFolderNode parentNode, @@ -177,16 +179,14 @@ public: void saveOptions(); bool saveUnits(); // procedure Open; - bool fileAlreadyExists(const QString& s); bool removeFolder(PFolderNode node); bool removeEditor(int index, bool doClose); int getUnitFromString(const QString& s); void rebuildNodes(); QString listUnitStr(const QChar& separator); - void exportToHTML(); + void showOptions(); // bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate); - PFolderNode folderNodeFromName(const QString& name); void updateNodeIndexes(); void setNodeValue(PFolderNode value); void incrementBuildNumber(); @@ -195,6 +195,8 @@ public: void saveToLog(); std::shared_ptr cppParser(); + const QString &filename() const; + signals: void nodesChanged(); void modifyChanged(bool value); diff --git a/RedPandaIDE/systemconsts.cpp b/RedPandaIDE/systemconsts.cpp index 7e2b74cf..3d1e00c1 100644 --- a/RedPandaIDE/systemconsts.cpp +++ b/RedPandaIDE/systemconsts.cpp @@ -11,6 +11,7 @@ SystemConsts::SystemConsts(): mDefaultFileFilters() addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx"); addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh"); addDefaultFileFilter(QObject::tr("Text files"),"*.txt"); + addDefaultFileFilter(QObject::tr("HTML files"),"*.html *.htm"); addDefaultFileFilter(QObject::tr("All files"),"*"); } @@ -34,6 +35,11 @@ const QString &SystemConsts::defaultAllFileFilter() const noexcept return mDefaultFileFilters.back(); } +const QString &SystemConsts::defaultHTMLFileFilter() const noexcept +{ + return mDefaultFileFilters[4]; +} + void SystemConsts::addDefaultFileFilter(const QString &name, const QString &fileExtensions) { mDefaultFileFilters.append(name+ " (" + fileExtensions+")"); diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index 323a93b1..62a96274 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -52,6 +52,7 @@ public: const QString& defaultCFileFilter() const noexcept; const QString& defaultCPPFileFilter() const noexcept; const QString& defaultAllFileFilter() const noexcept; + const QString& defaultHTMLFileFilter() const noexcept; void addDefaultFileFilter(const QString& name, const QString& fileExtensions); private: QStringList mDefaultFileFilters; diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index d8c306ed..792743da 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -657,3 +657,16 @@ QString genMakePath2(const QString &fileName) { return genMakePath(fileName, true, false); } + +QString getSizeString(int size) +{ + if (size < 1024) { + return QString("%1 ").arg(size)+QObject::tr("bytes"); + } else if (size < 1024 * 1024) { + return QString("%1 ").arg(size / 1024.0)+QObject::tr("KB"); + } else if (size < 1024 * 1024 * 1024) { + return QString("%1 ").arg(size / 1024.0 / 1024.0)+QObject::tr("MB"); + } else { + return QString("%1 ").arg(size / 1024.0 / 1024.0 / 1024.0)+QObject::tr("GB"); + } +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index a1cccf59..063b1f21 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -163,6 +163,7 @@ bool findComplement(const QString& s, void logToFile(const QString& s, const QString& filename, bool append=true); QString baseFileName(const QString& fileName); +QString getSizeString(int size); class CppParser; void resetCppParser(std::shared_ptr parser); diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index e0c16cb1..389b04c1 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -111,15 +111,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index) int fileSize = info.size(); // Pretty print total file size - if (fileSize < 1024) { - ui->txtFileSize->setText(QString("%1 ").arg(fileSize)+tr("bytes")); - } else if (fileSize < 1024 * 1024) { - ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0)+tr("KB")); - } else if (fileSize < 1024 * 1024 * 1024) { - ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0)+tr("MB")); - } else { - ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0 / 1024.0)+tr("GB")); - } + ui->txtFileSize->setText(getSizeString(fileSize)); ui->txtFileDate->setText( QLocale::system().toString(info.lastModified(), QLocale::LongFormat)); ui->txtProject->setText("-"); ui->txtPath->setText(editor->filename());