work save

This commit is contained in:
royqh1979@gmail.com 2021-09-09 00:15:12 +08:00
parent fef7deaa50
commit c120d0a23f
7 changed files with 51 additions and 12 deletions

View File

@ -8,6 +8,7 @@
#include "utils.h" #include "utils.h"
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
@ -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() PCppParser Project::cppParser()
{ {
return mParser; return mParser;
@ -626,6 +645,11 @@ void Project::sortUnitsByPriority()
}); });
} }
const QString &Project::filename() const
{
return mFilename;
}
ProjectUnit::ProjectUnit(Project* parent) ProjectUnit::ProjectUnit(Project* parent)
{ {
mEditor = nullptr; mEditor = nullptr;

View File

@ -158,6 +158,8 @@ public:
void closeUnit(int index); void closeUnit(int index);
void createFolderNodes(); void createFolderNodes();
void doAutoOpen(); void doAutoOpen();
bool fileAlreadyExists(const QString& s);
PFolderNode folderNodeFromName(const QString& name);
int newUnit(bool newProject, int newUnit(bool newProject,
PFolderNode parentNode, PFolderNode parentNode,
@ -177,16 +179,14 @@ public:
void saveOptions(); void saveOptions();
bool saveUnits(); bool saveUnits();
// procedure Open; // procedure Open;
bool fileAlreadyExists(const QString& s);
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); int getUnitFromString(const QString& s);
void rebuildNodes(); void rebuildNodes();
QString listUnitStr(const QChar& separator); QString listUnitStr(const QChar& separator);
void exportToHTML();
void showOptions(); void showOptions();
// bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate); // bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
PFolderNode folderNodeFromName(const QString& name);
void updateNodeIndexes(); void updateNodeIndexes();
void setNodeValue(PFolderNode value); void setNodeValue(PFolderNode value);
void incrementBuildNumber(); void incrementBuildNumber();
@ -195,6 +195,8 @@ public:
void saveToLog(); void saveToLog();
std::shared_ptr<CppParser> cppParser(); std::shared_ptr<CppParser> cppParser();
const QString &filename() const;
signals: signals:
void nodesChanged(); void nodesChanged();
void modifyChanged(bool value); void modifyChanged(bool value);

View File

@ -11,6 +11,7 @@ SystemConsts::SystemConsts(): mDefaultFileFilters()
addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx"); addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx");
addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh"); addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh");
addDefaultFileFilter(QObject::tr("Text files"),"*.txt"); addDefaultFileFilter(QObject::tr("Text files"),"*.txt");
addDefaultFileFilter(QObject::tr("HTML files"),"*.html *.htm");
addDefaultFileFilter(QObject::tr("All files"),"*"); addDefaultFileFilter(QObject::tr("All files"),"*");
} }
@ -34,6 +35,11 @@ const QString &SystemConsts::defaultAllFileFilter() const noexcept
return mDefaultFileFilters.back(); return mDefaultFileFilters.back();
} }
const QString &SystemConsts::defaultHTMLFileFilter() const noexcept
{
return mDefaultFileFilters[4];
}
void SystemConsts::addDefaultFileFilter(const QString &name, const QString &fileExtensions) void SystemConsts::addDefaultFileFilter(const QString &name, const QString &fileExtensions)
{ {
mDefaultFileFilters.append(name+ " (" + fileExtensions+")"); mDefaultFileFilters.append(name+ " (" + fileExtensions+")");

View File

@ -52,6 +52,7 @@ public:
const QString& defaultCFileFilter() const noexcept; const QString& defaultCFileFilter() const noexcept;
const QString& defaultCPPFileFilter() const noexcept; const QString& defaultCPPFileFilter() const noexcept;
const QString& defaultAllFileFilter() const noexcept; const QString& defaultAllFileFilter() const noexcept;
const QString& defaultHTMLFileFilter() const noexcept;
void addDefaultFileFilter(const QString& name, const QString& fileExtensions); void addDefaultFileFilter(const QString& name, const QString& fileExtensions);
private: private:
QStringList mDefaultFileFilters; QStringList mDefaultFileFilters;

View File

@ -657,3 +657,16 @@ QString genMakePath2(const QString &fileName)
{ {
return genMakePath(fileName, true, false); 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");
}
}

View File

@ -163,6 +163,7 @@ bool findComplement(const QString& s,
void logToFile(const QString& s, const QString& filename, bool append=true); void logToFile(const QString& s, const QString& filename, bool append=true);
QString baseFileName(const QString& fileName); QString baseFileName(const QString& fileName);
QString getSizeString(int size);
class CppParser; class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser); void resetCppParser(std::shared_ptr<CppParser> parser);

View File

@ -111,15 +111,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index)
int fileSize = info.size(); int fileSize = info.size();
// Pretty print total file size // Pretty print total file size
if (fileSize < 1024) { ui->txtFileSize->setText(getSizeString(fileSize));
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->txtFileDate->setText( QLocale::system().toString(info.lastModified(), QLocale::LongFormat)); ui->txtFileDate->setText( QLocale::system().toString(info.lastModified(), QLocale::LongFormat));
ui->txtProject->setText("-"); ui->txtProject->setText("-");
ui->txtPath->setText(editor->filename()); ui->txtPath->setText(editor->filename());