Browse Source

import: do not copy files when import if they locate in current folder

Le Tan 7 years ago
parent
commit
eb734f591e
2 changed files with 23 additions and 10 deletions
  1. 21 9
      src/vfilelist.cpp
  2. 2 1
      src/vmainwindow.cpp

+ 21 - 9
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);

+ 2 - 1
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);