mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
fix bugs when copying/cutting folders across notebooks
- Maintain tags of the destination notebook; - Fix the notebook of the source directory;
This commit is contained in:
parent
a96c23fff1
commit
b139e77173
@ -100,9 +100,9 @@ QString VDirectory::fetchPath(const VDirectory *p_dir) const
|
||||
VDirectory *parentDir = (VDirectory *)p_dir->parent();
|
||||
if (parentDir) {
|
||||
// Not the root directory
|
||||
return QDir(fetchPath(parentDir)).filePath(p_dir->getName());
|
||||
return QDir(parentDir->fetchPath()).filePath(p_dir->getName());
|
||||
} else {
|
||||
return m_notebook->getPath();
|
||||
return p_dir->getNotebook()->getPath();
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,6 +349,12 @@ bool VDirectory::addFile(VNoteFile *p_file, int p_index)
|
||||
|
||||
p_file->setParent(this);
|
||||
|
||||
// Add tags from this file to the notebook.
|
||||
const QStringList &tags = p_file->getTags();
|
||||
for (auto const & tag : tags) {
|
||||
m_notebook->addTag(tag);
|
||||
}
|
||||
|
||||
qDebug() << "note" << p_file->getName() << "added to folder" << m_name;
|
||||
|
||||
return true;
|
||||
@ -402,6 +408,9 @@ bool VDirectory::addSubDirectory(VDirectory *p_dir, int p_index)
|
||||
}
|
||||
|
||||
p_dir->setParent(this);
|
||||
p_dir->m_notebook = m_notebook;
|
||||
|
||||
m_notebook->addTags(p_dir);
|
||||
|
||||
qDebug() << "folder" << p_dir->getName() << "added to folder" << m_name;
|
||||
|
||||
@ -588,8 +597,6 @@ bool VDirectory::copyDirectory(VDirectory *p_destDir,
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "copyDirectory:" << p_dir << "to" << destDir;
|
||||
|
||||
*p_targetDir = destDir;
|
||||
return ret;
|
||||
}
|
||||
@ -741,6 +748,32 @@ QList<QString> VDirectory::collectFiles()
|
||||
return files;
|
||||
}
|
||||
|
||||
QStringList VDirectory::collectTags()
|
||||
{
|
||||
QStringList tags;
|
||||
bool opened = isOpened();
|
||||
if (!opened && !open()) {
|
||||
qWarning() << "fail to open directory" << fetchPath();
|
||||
return tags;
|
||||
}
|
||||
|
||||
// Files.
|
||||
for (auto const & file : m_files) {
|
||||
tags.append(file->getTags());
|
||||
}
|
||||
|
||||
// Subfolders.
|
||||
for (auto const & dir : m_subDirs) {
|
||||
tags.append(dir->collectTags());
|
||||
}
|
||||
|
||||
if (!opened) {
|
||||
close();
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
VDirectory *VDirectory::buildDirectory(const QString &p_path,
|
||||
VDirectory *p_parent,
|
||||
QString *p_errMsg)
|
||||
|
@ -122,6 +122,9 @@ public:
|
||||
// Return path of files in this directory recursively.
|
||||
QList<QString> collectFiles();
|
||||
|
||||
// Return tags of files in this directory recursively.
|
||||
QStringList collectTags();
|
||||
|
||||
// Delete directory @p_dir.
|
||||
static bool deleteDirectory(VDirectory *p_dir,
|
||||
bool p_skipRecycleBin = false,
|
||||
|
@ -151,7 +151,14 @@ void VEditTab::checkFileChangeOutside()
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_file->isChangedOutside()) {
|
||||
bool missing = false;
|
||||
if (m_file->isChangedOutside(missing)) {
|
||||
// It may be caused by cutting files.
|
||||
if (missing) {
|
||||
qWarning() << "file is missing when check file's outside change" << m_file->fetchPath();
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = VUtils::showMessage(QMessageBox::Information,
|
||||
tr("Information"),
|
||||
tr("Note <span style=\"%1\">%2</span> has been modified by another program.")
|
||||
|
@ -45,6 +45,7 @@ bool VFile::open()
|
||||
|
||||
QString filePath = fetchPath();
|
||||
if (!QFileInfo::exists(filePath)) {
|
||||
qWarning() << "file does not exist" << filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -112,8 +113,15 @@ bool VFile::isInternalImageFolder(const QString &p_path) const
|
||||
|| VUtils::equalPath(p_path, fetchImageFolderPath());
|
||||
}
|
||||
|
||||
bool VFile::isChangedOutside() const
|
||||
bool VFile::isChangedOutside(bool &p_missing) const
|
||||
{
|
||||
QFileInfo fi(fetchPath());
|
||||
if (!fi.exists()) {
|
||||
p_missing = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
p_missing = false;
|
||||
QDateTime lm = QFileInfo(fetchPath()).lastModified();
|
||||
return lm.toSecsSinceEpoch() != m_lastModified.toSecsSinceEpoch();
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
QDateTime getModifiedTimeUtc() const;
|
||||
|
||||
// Whether this file was changed outside VNote.
|
||||
bool isChangedOutside() const;
|
||||
bool isChangedOutside(bool &p_missing) const;
|
||||
|
||||
// Return backup file of previous session if there exists one.
|
||||
QString backupFileOfPreviousSession() const;
|
||||
|
@ -443,6 +443,27 @@ bool VNotebook::addTag(const QString &p_tag)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VNotebook::addTags(VDirectory *p_dir)
|
||||
{
|
||||
QStringList tags = p_dir->collectTags();
|
||||
|
||||
for (auto const & tag : tags) {
|
||||
if (tag.isEmpty() || hasTag(tag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_tags.append(tag);
|
||||
}
|
||||
|
||||
if (!writeConfigNotebook()) {
|
||||
qWarning() << "fail to update config of notebook" << m_name
|
||||
<< "in directory" << m_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VNotebook::removeTag(const QString &p_tag)
|
||||
{
|
||||
if (p_tag.isEmpty() || m_tags.isEmpty()) {
|
||||
|
@ -60,6 +60,9 @@ public:
|
||||
|
||||
bool addTag(const QString &p_tag);
|
||||
|
||||
// Walk through @p_dir recursively to add all tags to notebook.
|
||||
bool addTags(VDirectory *p_dir);
|
||||
|
||||
void removeTag(const QString &p_tag);
|
||||
|
||||
bool hasTag(const QString &p_tag) const;
|
||||
|
@ -513,6 +513,14 @@ bool VNoteFile::copyFile(VDirectory *p_destDir,
|
||||
}
|
||||
} else {
|
||||
destFile = p_destDir->addFile(p_destName, -1);
|
||||
// Copy tags to this file.
|
||||
if (destFile) {
|
||||
const QStringList &tags = p_file->getTags();
|
||||
for (auto const & tag : tags) {
|
||||
destFile->addTag(tag);
|
||||
destFile->getNotebook()->addTag(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!destFile) {
|
||||
@ -636,8 +644,6 @@ void VNoteFile::removeTag(const QString &p_tag)
|
||||
|
||||
bool VNoteFile::addTag(const QString &p_tag)
|
||||
{
|
||||
Q_ASSERT(isOpened());
|
||||
|
||||
if (p_tag.isEmpty() || hasTag(p_tag)) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user