mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-04 21:39:52 +08:00
recursive import external folders (#332)
* recursive import external folders * rollback translation * fix when path does not exist * add blank line
This commit is contained in:
parent
19bd159aba
commit
09c610e3a9
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/VNote.pro.user
|
@ -14,7 +14,7 @@ VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info
|
||||
QWidget *parent)
|
||||
: QDialog(parent),
|
||||
defaultName(defaultName), defaultPath(defaultPath),
|
||||
m_importNotebook(false), m_manualPath(false), m_manualName(false),
|
||||
m_importNotebook(false), m_importExternalProject(false), m_manualPath(false), m_manualName(false),
|
||||
m_notebooks(p_notebooks)
|
||||
{
|
||||
setupUI(title, info);
|
||||
@ -185,6 +185,11 @@ bool VNewNotebookDialog::isImportExistingNotebook() const
|
||||
return m_importNotebook;
|
||||
}
|
||||
|
||||
bool VNewNotebookDialog::isImportExternalProject() const
|
||||
{
|
||||
return m_importExternalProject;
|
||||
}
|
||||
|
||||
void VNewNotebookDialog::showEvent(QShowEvent *event)
|
||||
{
|
||||
m_nameEdit->setFocus();
|
||||
@ -227,20 +232,25 @@ void VNewNotebookDialog::handleInputChanged()
|
||||
} else if (QFileInfo::exists(path)) {
|
||||
QDir dir(path);
|
||||
QStringList files = dir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
|
||||
if (files.isEmpty()) {
|
||||
pathOk = true;
|
||||
} else {
|
||||
if (!files.isEmpty()) {
|
||||
// Folder is not empty.
|
||||
configExist = VConfigManager::directoryConfigExist(path);
|
||||
if (configExist) {
|
||||
pathOk = true;
|
||||
m_warnLabel->setText(infoText);
|
||||
} else {
|
||||
QString warnText = tr("<span style=\"%1\">WARNING</span>: The folder chosen is NOT empty! "
|
||||
"VNote will try to create a new notebook and import existing files.")
|
||||
.arg(g_config->c_warningTextStyle);
|
||||
m_warnLabel->setText(warnText);
|
||||
|
||||
m_importExternalProject = true;
|
||||
// If ok button is clicked, automatically create a configuration file
|
||||
configExist = true;
|
||||
}
|
||||
|
||||
showWarnLabel = true;
|
||||
}
|
||||
pathOk = true;
|
||||
} else {
|
||||
pathOk = true;
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ public:
|
||||
|
||||
// Whether import existing notebook by reading the config file.
|
||||
bool isImportExistingNotebook() const;
|
||||
|
||||
// Whether import external project
|
||||
bool isImportExternalProject() const;
|
||||
|
||||
// Get the custom image folder for this notebook.
|
||||
// Empty string indicates using global config.
|
||||
@ -71,6 +74,9 @@ private:
|
||||
|
||||
// Whether import existing notebook config file.
|
||||
bool m_importNotebook;
|
||||
|
||||
// Whether import external project
|
||||
bool m_importExternalProject;
|
||||
|
||||
// True if user has change the content of the path edit.
|
||||
bool m_manualPath;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "vnotebookselector.h"
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QListWidget>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
@ -118,6 +119,46 @@ int VNotebookSelector::itemIndexOfNotebook(const VNotebook *p_notebook) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void VNotebookSelector::createConfigFiles(const QString &p_path)
|
||||
{
|
||||
QDir root(p_path);
|
||||
QStringList filters;
|
||||
filters << "*.md" << "*.markdown";
|
||||
|
||||
QJsonObject dirJson;
|
||||
dirJson[DirConfig::c_version] = "1";
|
||||
dirJson[DirConfig::c_createdTime] = QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||
|
||||
QJsonArray subDirs;
|
||||
QJsonArray files;
|
||||
|
||||
QFileInfoList dirInfoList = root.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
QFileInfoList fileInfoList = root.entryInfoList(filters,QDir::Files);
|
||||
|
||||
for(const QFileInfo &dirInfo : dirInfoList) {
|
||||
const QString dirname = dirInfo.fileName();
|
||||
if (dirname != "_v_recycle_bin") {
|
||||
QJsonObject item;
|
||||
item[DirConfig::c_name] = dirname;
|
||||
subDirs.append(item);
|
||||
|
||||
createConfigFiles(dirInfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
for(const QFileInfo &fileInfo : fileInfoList) {
|
||||
QJsonObject item;
|
||||
item[DirConfig::c_createdTime] = fileInfo.created().toString(Qt::ISODate);
|
||||
item[DirConfig::c_name] = fileInfo.fileName();
|
||||
files.append(item);
|
||||
}
|
||||
|
||||
dirJson[DirConfig::c_subDirectories] = subDirs;
|
||||
dirJson[DirConfig::c_files] = files;
|
||||
|
||||
g_config->writeDirectoryConfig(p_path,dirJson);
|
||||
}
|
||||
|
||||
void VNotebookSelector::insertAddNotebookItem()
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem();
|
||||
@ -199,6 +240,11 @@ bool VNotebookSelector::newNotebook()
|
||||
m_notebooks,
|
||||
this);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
|
||||
if(dialog.isImportExternalProject()) {
|
||||
createConfigFiles(dialog.getPathInput());
|
||||
}
|
||||
|
||||
createNotebook(dialog.getNameInput(),
|
||||
dialog.getPathInput(),
|
||||
dialog.isImportExistingNotebook(),
|
||||
|
@ -71,6 +71,9 @@ private:
|
||||
// Return the item index of @p_notebook.
|
||||
int itemIndexOfNotebook(const VNotebook *p_notebook) const;
|
||||
|
||||
// Recursively create config files
|
||||
void createConfigFiles(const QString &p_path);
|
||||
|
||||
// If @p_import is true, we will use the existing config file.
|
||||
// If @p_imageFolder is empty, we will use the global one.
|
||||
// If @p_attachmentFolder is empty, we will use the global one.
|
||||
|
Loading…
x
Reference in New Issue
Block a user