mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Editor: remember last used browse path when inserting image
This commit is contained in:
parent
7928874936
commit
a7ba7e9d58
@ -7,6 +7,9 @@
|
||||
#include "vmetawordlineedit.h"
|
||||
#include "vdownloader.h"
|
||||
#include "vlineedit.h"
|
||||
#include "vconfigmanager.h"
|
||||
|
||||
extern VConfigManager *g_config;
|
||||
|
||||
VInsertImageDialog::VInsertImageDialog(const QString &p_title,
|
||||
const QString &p_imageTitle,
|
||||
@ -166,15 +169,22 @@ QString VInsertImageDialog::getPathInput() const
|
||||
|
||||
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"),
|
||||
lastPath, tr("Images (*.png *.xpm *.jpg *.bmp *.gif *.svg)"));
|
||||
bpath, tr("Images (*.png *.xpm *.jpg *.bmp *.gif *.svg)"));
|
||||
if (filePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update lastPath
|
||||
lastPath = QFileInfo(filePath).path();
|
||||
// Update browse path.
|
||||
g_config->setImageBrowsePath(QFileInfo(filePath).path());
|
||||
|
||||
m_imageType = ImageType::LocalFile;
|
||||
|
||||
@ -360,3 +370,8 @@ void VInsertImageDialog::autoCompleteTitleFromPath()
|
||||
m_imageTitleEdit->setText(QFileInfo(imgPath).baseName());
|
||||
m_imageTitleEdit->selectAll();
|
||||
}
|
||||
|
||||
void VInsertImageDialog::setBrowsePath(const QString &p_path)
|
||||
{
|
||||
m_browsePath = p_path;
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
// Return 0 if no override.
|
||||
int getOverridenWidth() const;
|
||||
|
||||
void setBrowsePath(const QString &p_path);
|
||||
|
||||
public slots:
|
||||
void imageDownloaded(const QByteArray &data);
|
||||
|
||||
@ -90,6 +92,9 @@ private:
|
||||
ImageType m_imageType;
|
||||
|
||||
QSharedPointer<QTemporaryFile> m_tempFile;
|
||||
|
||||
// Default path when browsing images to insert.
|
||||
QString m_browsePath;
|
||||
};
|
||||
|
||||
inline VInsertImageDialog::ImageType VInsertImageDialog::getImageType() const
|
||||
|
@ -620,6 +620,10 @@ public:
|
||||
bool getEnableSplitTagFileList() const;
|
||||
void setEnableSplitTagFileList(bool p_enable);
|
||||
|
||||
// Get the path to browse when inserting image.
|
||||
QString getImageBrowsePath() const;
|
||||
void setImageBrowsePath(const QString &p_path);
|
||||
|
||||
private:
|
||||
// Look up a config from user and default settings.
|
||||
QVariant getConfigFromSettings(const QString §ion, const QString &key) const;
|
||||
@ -2840,4 +2844,14 @@ inline void VConfigManager::setEnableSplitTagFileList(bool 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user