mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
do not allow changing type of note
This commit is contained in:
parent
1ae30b645e
commit
a36b512e94
@ -3,6 +3,7 @@
|
|||||||
#include "vdirectory.h"
|
#include "vdirectory.h"
|
||||||
#include "vfile.h"
|
#include "vfile.h"
|
||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
|
#include "utils/vutils.h"
|
||||||
|
|
||||||
extern VConfigManager *g_config;
|
extern VConfigManager *g_config;
|
||||||
|
|
||||||
@ -74,6 +75,14 @@ void VFileInfoDialog::handleInputChanged()
|
|||||||
"Please choose another name.")
|
"Please choose another name.")
|
||||||
.arg(g_config->c_warningTextStyle);
|
.arg(g_config->c_warningTextStyle);
|
||||||
m_warnLabel->setText(nameConflictText);
|
m_warnLabel->setText(nameConflictText);
|
||||||
|
} else if (VUtils::docTypeFromName(name) != m_file->getDocType()) {
|
||||||
|
// Check if the name change the doc type.
|
||||||
|
nameOk = false;
|
||||||
|
showWarnLabel = true;
|
||||||
|
QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Changing type of the note is not supported. "
|
||||||
|
"Please use the same suffix as the old one.")
|
||||||
|
.arg(g_config->c_warningTextStyle);
|
||||||
|
m_warnLabel->setText(nameConflictText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,9 +528,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (docType != newDocType) {
|
Q_ASSERT(docType == newDocType);
|
||||||
destFile->convert(docType, newDocType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to copy internal images when it is still markdown.
|
// We need to copy internal images when it is still markdown.
|
||||||
if (!images.isEmpty()) {
|
if (!images.isEmpty()) {
|
||||||
|
@ -69,27 +69,6 @@ bool VFile::save()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFile::convert(DocType p_curType, DocType p_targetType)
|
|
||||||
{
|
|
||||||
Q_ASSERT(!m_opened);
|
|
||||||
m_docType = p_targetType;
|
|
||||||
if (p_curType == p_targetType) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString path = fetchPath();
|
|
||||||
QString fileText = VUtils::readFileFromDisk(path);
|
|
||||||
QTextEdit editor;
|
|
||||||
if (p_curType == DocType::Markdown) {
|
|
||||||
editor.setPlainText(fileText);
|
|
||||||
fileText = editor.toHtml();
|
|
||||||
} else {
|
|
||||||
editor.setHtml(fileText);
|
|
||||||
fileText = editor.toPlainText();
|
|
||||||
}
|
|
||||||
VUtils::writeFileToDisk(path, fileText);
|
|
||||||
qDebug() << getName() << "converted" << (int)p_curType << (int)p_targetType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VFile::setModified(bool p_modified)
|
void VFile::setModified(bool p_modified)
|
||||||
{
|
{
|
||||||
m_modified = p_modified;
|
m_modified = p_modified;
|
||||||
@ -264,12 +243,8 @@ bool VFile::rename(const QString &p_name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle DocType change.
|
// Can't not change doc type.
|
||||||
DocType newType = VUtils::docTypeFromName(m_name);
|
Q_ASSERT(m_docType == VUtils::docTypeFromName(m_name));
|
||||||
if (m_docType != newType) {
|
|
||||||
convert(m_docType, newType);
|
|
||||||
m_docType = newType;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "note renamed from" << oldName << "to" << m_name;
|
qDebug() << "note renamed from" << oldName << "to" << m_name;
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ public:
|
|||||||
virtual bool open();
|
virtual bool open();
|
||||||
virtual void close();
|
virtual void close();
|
||||||
virtual bool save();
|
virtual bool save();
|
||||||
// Convert current file type.
|
|
||||||
virtual void convert(DocType p_curType, DocType p_targetType);
|
|
||||||
|
|
||||||
const QString &getName() const;
|
const QString &getName() const;
|
||||||
virtual void setName(const QString &p_name);
|
virtual void setName(const QString &p_name);
|
||||||
|
@ -198,9 +198,7 @@ void VFileList::fileInfo(VFile *p_file)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!promptForDocTypeChange(p_file, QDir(p_file->fetchBasePath()).filePath(name))) {
|
Q_ASSERT(p_file->getDocType() == VUtils::docTypeFromName(name));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p_file->rename(name)) {
|
if (!p_file->rename(name)) {
|
||||||
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
@ -579,10 +577,8 @@ bool VFileList::copyFile(VDirectory *p_destDir, const QString &p_destName, VFile
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If change the file type, we need to close it first
|
// DocType is not allowed to change.
|
||||||
if (!promptForDocTypeChange(p_file, destPath)) {
|
Q_ASSERT(p_file->getDocType() == VUtils::docTypeFromName(destPath));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VFile *destFile = VDirectory::copyFile(p_destDir, p_destName, p_file, p_cut);
|
VFile *destFile = VDirectory::copyFile(p_destDir, p_destName, p_file, p_cut);
|
||||||
updateFileList();
|
updateFileList();
|
||||||
@ -592,31 +588,6 @@ bool VFileList::copyFile(VDirectory *p_destDir, const QString &p_destName, VFile
|
|||||||
return destFile != NULL;
|
return destFile != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFileList::promptForDocTypeChange(const VFile *p_file, const QString &p_newFilePath)
|
|
||||||
{
|
|
||||||
DocType docType = p_file->getDocType();
|
|
||||||
DocType newDocType = VUtils::docTypeFromName(p_newFilePath);
|
|
||||||
|
|
||||||
if (docType != newDocType) {
|
|
||||||
if (editArea->isFileOpened(p_file)) {
|
|
||||||
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
|
||||||
tr("The renaming will change the note type."),
|
|
||||||
tr("You should close the note <span style=\"%1\">%2</span> before continue.")
|
|
||||||
.arg(g_config->c_dataTextStyle).arg(p_file->getName()),
|
|
||||||
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok, this);
|
|
||||||
if (QMessageBox::Ok == ret) {
|
|
||||||
if (!editArea->closeFile(p_file, false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VFileList::keyPressEvent(QKeyEvent *event)
|
void VFileList::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
int key = event->key();
|
int key = event->key();
|
||||||
|
@ -91,13 +91,6 @@ private:
|
|||||||
bool identicalListWithDirectory() const;
|
bool identicalListWithDirectory() const;
|
||||||
QList<QListWidgetItem *> getVisibleItems() const;
|
QList<QListWidgetItem *> getVisibleItems() const;
|
||||||
|
|
||||||
// @p_file: the file to be renamed or copied.
|
|
||||||
// @p_newFilePath: the new file path of @p_file.
|
|
||||||
// Check if the rename/copy will change the DocType. If yes, then ask
|
|
||||||
// user for confirmation.
|
|
||||||
// Return true if we can continue.
|
|
||||||
bool promptForDocTypeChange(const VFile *p_file, const QString &p_newFilePath);
|
|
||||||
|
|
||||||
// Fill the info of @p_item according to @p_file.
|
// Fill the info of @p_item according to @p_file.
|
||||||
void fillItem(QListWidgetItem *p_item, const VFile *p_file);
|
void fillItem(QListWidgetItem *p_item, const VFile *p_file);
|
||||||
|
|
||||||
|
@ -69,11 +69,6 @@ bool VOrphanFile::save()
|
|||||||
return VUtils::writeFileToDisk(fetchPath(), m_content);
|
return VUtils::writeFileToDisk(fetchPath(), m_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VOrphanFile::convert(DocType /* p_curType */, DocType /* p_targetType */)
|
|
||||||
{
|
|
||||||
V_ASSERT(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VOrphanFile::setName(const QString & /* p_name */)
|
void VOrphanFile::setName(const QString & /* p_name */)
|
||||||
{
|
{
|
||||||
V_ASSERT(false);
|
V_ASSERT(false);
|
||||||
|
@ -40,7 +40,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool save() Q_DECL_OVERRIDE;
|
bool save() Q_DECL_OVERRIDE;
|
||||||
void convert(DocType p_curType, DocType p_targetType) Q_DECL_OVERRIDE;
|
|
||||||
void setName(const QString &p_name) Q_DECL_OVERRIDE;
|
void setName(const QString &p_name) Q_DECL_OVERRIDE;
|
||||||
QString fetchImagePath() const Q_DECL_OVERRIDE;
|
QString fetchImagePath() const Q_DECL_OVERRIDE;
|
||||||
void setContent(const QString &p_content) Q_DECL_OVERRIDE;
|
void setContent(const QString &p_content) Q_DECL_OVERRIDE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user