mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +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;
|
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 fileNameFromPath(const QString &path);
|
||||||
static QString basePathFromPath(const QString &path);
|
static QString basePathFromPath(const QString &path);
|
||||||
static QVector<QString> imagesFromMarkdownFile(const QString &filePath);
|
static QVector<QString> imagesFromMarkdownFile(const QString &filePath);
|
||||||
|
static void makeDirectory(const QString &path);
|
||||||
private:
|
private:
|
||||||
static inline void addQssVarToMap(QVector<QPair<QString, QString> > &map,
|
static inline void addQssVarToMap(QVector<QPair<QString, QString> > &map,
|
||||||
const QString &key, const QString &value);
|
const QString &key, const QString &value);
|
||||||
|
@ -44,6 +44,7 @@ void VMdEditOperations::insertImageFromQImage(const QString &title, const QStrin
|
|||||||
qDebug() << "insert image" << path << title << fileName;
|
qDebug() << "insert image" << path << title << fileName;
|
||||||
QString filePath = QDir(path).filePath(fileName);
|
QString filePath = QDir(path).filePath(fileName);
|
||||||
Q_ASSERT(!QFile(filePath).exists());
|
Q_ASSERT(!QFile(filePath).exists());
|
||||||
|
VUtils::makeDirectory(path);
|
||||||
bool ret = image.save(filePath);
|
bool ret = image.save(filePath);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("Warning"), QString("Fail to save image %1").arg(filePath),
|
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;
|
qDebug() << "insert image" << path << title << fileName << oriImagePath;
|
||||||
QString filePath = QDir(path).filePath(fileName);
|
QString filePath = QDir(path).filePath(fileName);
|
||||||
Q_ASSERT(!QFile(filePath).exists());
|
Q_ASSERT(!QFile(filePath).exists());
|
||||||
|
VUtils::makeDirectory(path);
|
||||||
bool ret = QFile::copy(oriImagePath, filePath);
|
bool ret = QFile::copy(oriImagePath, filePath);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
qWarning() << "error: fail to copy" << oriImagePath << "to" << filePath;
|
qWarning() << "error: fail to copy" << oriImagePath << "to" << filePath;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user