mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
fix images inserting when images folder does not exist
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
0306256863
commit
00982eaacc
@ -144,3 +144,18 @@ QVector<QString> VUtils::imagesFromMarkdownFile(const QString &filePath)
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
void VUtils::makeDirectory(const QString &path)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// mkdir will return false if it already exists
|
||||
QString basePath = basePathFromPath(path);
|
||||
QString dirName = directoryNameFromPath(path);
|
||||
QDir dir(basePath);
|
||||
if (dir.mkdir(dirName)) {
|
||||
qDebug() << "mkdir" << path;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
static QString fileNameFromPath(const QString &path);
|
||||
static QString basePathFromPath(const QString &path);
|
||||
static QVector<QString> imagesFromMarkdownFile(const QString &filePath);
|
||||
static void makeDirectory(const QString &path);
|
||||
private:
|
||||
static inline void addQssVarToMap(QVector<QPair<QString, QString> > &map,
|
||||
const QString &key, const QString &value);
|
||||
|
@ -44,6 +44,7 @@ void VMdEditOperations::insertImageFromQImage(const QString &title, const QStrin
|
||||
qDebug() << "insert image" << path << title << fileName;
|
||||
QString filePath = QDir(path).filePath(fileName);
|
||||
Q_ASSERT(!QFile(filePath).exists());
|
||||
VUtils::makeDirectory(path);
|
||||
bool ret = image.save(filePath);
|
||||
if (!ret) {
|
||||
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("Warning"), QString("Fail to save image %1").arg(filePath),
|
||||
@ -63,6 +64,7 @@ void VMdEditOperations::insertImageFromPath(const QString &title,
|
||||
qDebug() << "insert image" << path << title << fileName << oriImagePath;
|
||||
QString filePath = QDir(path).filePath(fileName);
|
||||
Q_ASSERT(!QFile(filePath).exists());
|
||||
VUtils::makeDirectory(path);
|
||||
bool ret = QFile::copy(oriImagePath, filePath);
|
||||
if (!ret) {
|
||||
qWarning() << "error: fail to copy" << oriImagePath << "to" << filePath;
|
||||
|
Loading…
x
Reference in New Issue
Block a user