From eb734f591e0c1423df49f9f6275e1e741fdae8a6 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 3 Apr 2018 19:38:59 +0800 Subject: [PATCH] import: do not copy files when import if they locate in current folder --- src/vfilelist.cpp | 30 +++++++++++++++++++++--------- src/vmainwindow.cpp | 3 ++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 9cbe40e8..f026d2e5 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -744,15 +744,27 @@ bool VFileList::importFiles(const QStringList &p_files, QString *p_errMsg) QString name = VUtils::fileNameFromPath(file); Q_ASSERT(!name.isEmpty()); - name = VUtils::getFileNameWithSequence(dirPath, name, true); - QString targetFilePath = dir.filePath(name); - bool ret = VUtils::copyFile(file, targetFilePath, false); - if (!ret) { - VUtils::addErrMsg(p_errMsg, tr("Fail to copy file %1 as %2.") - .arg(file) - .arg(targetFilePath)); - ret = false; - continue; + + bool copyNeeded = true; + if (VUtils::equalPath(dirPath, fi.absolutePath())) { + qDebug() << "skip cpoy file" << file << "locates in" << dirPath; + copyNeeded = false; + } + + QString targetFilePath; + if (copyNeeded) { + name = VUtils::getFileNameWithSequence(dirPath, name, true); + targetFilePath = dir.filePath(name); + bool ret = VUtils::copyFile(file, targetFilePath, false); + if (!ret) { + VUtils::addErrMsg(p_errMsg, tr("Fail to copy file %1 as %2.") + .arg(file) + .arg(targetFilePath)); + ret = false; + continue; + } + } else { + targetFilePath = file; } VNoteFile *destFile = m_directory->addFile(name, -1); diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 76be4cb9..9b00baa7 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -987,7 +987,8 @@ void VMainWindow::initFileMenu() // Import notes from files. m_importNoteAct = newAction(VIconUtils::menuIcon(":/resources/icons/import_note.svg"), tr("&New Notes From Files"), this); - m_importNoteAct->setToolTip(tr("Create notes from external files in current folder by copy")); + m_importNoteAct->setToolTip(tr("Create notes from external files in current folder " + "(will copy files if they do not locate in current folder)")); connect(m_importNoteAct, &QAction::triggered, this, &VMainWindow::importNoteFromFile); m_importNoteAct->setEnabled(false);