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

This commit is contained in:
Le Tan 2018-04-03 19:38:59 +08:00
parent 5cd114e549
commit eb734f591e
2 changed files with 23 additions and 10 deletions

View File

@ -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);

View File

@ -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);