Editor: remember last used browse path when inserting image

This commit is contained in:
Le Tan 2018-11-29 21:27:00 +08:00
parent 7928874936
commit a7ba7e9d58
3 changed files with 38 additions and 4 deletions

View File

@ -7,6 +7,9 @@
#include "vmetawordlineedit.h" #include "vmetawordlineedit.h"
#include "vdownloader.h" #include "vdownloader.h"
#include "vlineedit.h" #include "vlineedit.h"
#include "vconfigmanager.h"
extern VConfigManager *g_config;
VInsertImageDialog::VInsertImageDialog(const QString &p_title, VInsertImageDialog::VInsertImageDialog(const QString &p_title,
const QString &p_imageTitle, const QString &p_imageTitle,
@ -166,15 +169,22 @@ QString VInsertImageDialog::getPathInput() const
void VInsertImageDialog::handleBrowseBtnClicked() void VInsertImageDialog::handleBrowseBtnClicked()
{ {
static QString lastPath = QDir::homePath(); QString bpath(m_browsePath);
if (bpath.isEmpty()) {
bpath = g_config->getImageBrowsePath();
if (bpath.isEmpty()) {
bpath = QDir::homePath();
}
}
QString filePath = QFileDialog::getOpenFileName(this, tr("Select The Image To Be Inserted"), QString filePath = QFileDialog::getOpenFileName(this, tr("Select The Image To Be Inserted"),
lastPath, tr("Images (*.png *.xpm *.jpg *.bmp *.gif *.svg)")); bpath, tr("Images (*.png *.xpm *.jpg *.bmp *.gif *.svg)"));
if (filePath.isEmpty()) { if (filePath.isEmpty()) {
return; return;
} }
// Update lastPath // Update browse path.
lastPath = QFileInfo(filePath).path(); g_config->setImageBrowsePath(QFileInfo(filePath).path());
m_imageType = ImageType::LocalFile; m_imageType = ImageType::LocalFile;
@ -360,3 +370,8 @@ void VInsertImageDialog::autoCompleteTitleFromPath()
m_imageTitleEdit->setText(QFileInfo(imgPath).baseName()); m_imageTitleEdit->setText(QFileInfo(imgPath).baseName());
m_imageTitleEdit->selectAll(); m_imageTitleEdit->selectAll();
} }
void VInsertImageDialog::setBrowsePath(const QString &p_path)
{
m_browsePath = p_path;
}

View File

@ -46,6 +46,8 @@ public:
// Return 0 if no override. // Return 0 if no override.
int getOverridenWidth() const; int getOverridenWidth() const;
void setBrowsePath(const QString &p_path);
public slots: public slots:
void imageDownloaded(const QByteArray &data); void imageDownloaded(const QByteArray &data);
@ -90,6 +92,9 @@ private:
ImageType m_imageType; ImageType m_imageType;
QSharedPointer<QTemporaryFile> m_tempFile; QSharedPointer<QTemporaryFile> m_tempFile;
// Default path when browsing images to insert.
QString m_browsePath;
}; };
inline VInsertImageDialog::ImageType VInsertImageDialog::getImageType() const inline VInsertImageDialog::ImageType VInsertImageDialog::getImageType() const

View File

@ -620,6 +620,10 @@ public:
bool getEnableSplitTagFileList() const; bool getEnableSplitTagFileList() const;
void setEnableSplitTagFileList(bool p_enable); void setEnableSplitTagFileList(bool p_enable);
// Get the path to browse when inserting image.
QString getImageBrowsePath() const;
void setImageBrowsePath(const QString &p_path);
private: private:
// Look up a config from user and default settings. // Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const; QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -2840,4 +2844,14 @@ inline void VConfigManager::setEnableSplitTagFileList(bool p_enable)
{ {
setConfigToSettings("global", "split_tag_file_list", p_enable); setConfigToSettings("global", "split_tag_file_list", p_enable);
} }
inline QString VConfigManager::getImageBrowsePath() const
{
return getConfigFromSessionSettings("global", "image_browse_path").toString();
}
inline void VConfigManager::setImageBrowsePath(const QString &p_path)
{
setConfigToSessionSettings("global", "image_browse_path", p_path);
}
#endif // VCONFIGMANAGER_H #endif // VCONFIGMANAGER_H