diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..901273aa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/VNote.pro.user
diff --git a/src/dialog/vnewnotebookdialog.cpp b/src/dialog/vnewnotebookdialog.cpp
index 0f17ad99..b5cba5b3 100644
--- a/src/dialog/vnewnotebookdialog.cpp
+++ b/src/dialog/vnewnotebookdialog.cpp
@@ -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("WARNING: 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;
}
diff --git a/src/dialog/vnewnotebookdialog.h b/src/dialog/vnewnotebookdialog.h
index a31e49c6..027354f4 100644
--- a/src/dialog/vnewnotebookdialog.h
+++ b/src/dialog/vnewnotebookdialog.h
@@ -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;
diff --git a/src/vnotebookselector.cpp b/src/vnotebookselector.cpp
index 7bc780ce..24d6bcd8 100644
--- a/src/vnotebookselector.cpp
+++ b/src/vnotebookselector.cpp
@@ -1,6 +1,7 @@
#include "vnotebookselector.h"
#include
#include
+#include
#include
#include
#include
@@ -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(),
diff --git a/src/vnotebookselector.h b/src/vnotebookselector.h
index 43985a2c..35605078 100644
--- a/src/vnotebookselector.h
+++ b/src/vnotebookselector.h
@@ -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.