mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support import existing notebook
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
5d028e29fb
commit
b0ec4c312a
@ -41,6 +41,10 @@ void VNewNotebookDialog::setupUI()
|
||||
pathLayout->addWidget(pathEdit);
|
||||
pathLayout->addWidget(browseBtn);
|
||||
|
||||
importCheck = new QCheckBox(tr("Import existing notebook"), this);
|
||||
importCheck->setChecked(true);
|
||||
importCheck->setToolTip(tr("When checked, VNote won't create a new config file if there already exists one."));
|
||||
|
||||
okBtn = new QPushButton(tr("&OK"));
|
||||
okBtn->setDefault(true);
|
||||
cancelBtn = new QPushButton(tr("&Cancel"));
|
||||
@ -55,6 +59,7 @@ void VNewNotebookDialog::setupUI()
|
||||
}
|
||||
mainLayout->addLayout(nameLayout);
|
||||
mainLayout->addLayout(pathLayout);
|
||||
mainLayout->addWidget(importCheck);
|
||||
mainLayout->addLayout(btmLayout);
|
||||
setLayout(mainLayout);
|
||||
|
||||
@ -82,3 +87,8 @@ void VNewNotebookDialog::handleBrowseBtnClicked()
|
||||
QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
pathEdit->setText(dirPath);
|
||||
}
|
||||
|
||||
bool VNewNotebookDialog::getImportCheck() const
|
||||
{
|
||||
return importCheck->isChecked();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QString;
|
||||
class QCheckBox;
|
||||
|
||||
class VNewNotebookDialog : public QDialog
|
||||
{
|
||||
@ -16,6 +17,7 @@ public:
|
||||
const QString &defaultPath, QWidget *parent = 0);
|
||||
QString getNameInput() const;
|
||||
QString getPathInput() const;
|
||||
bool getImportCheck() const;
|
||||
|
||||
private slots:
|
||||
void enableOkButton();
|
||||
@ -28,6 +30,7 @@ private:
|
||||
QLabel *nameLabel;
|
||||
QLineEdit *nameEdit;
|
||||
QLineEdit *pathEdit;
|
||||
QCheckBox *importCheck;
|
||||
QPushButton *browseBtn;
|
||||
QPushButton *okBtn;
|
||||
QPushButton *cancelBtn;
|
||||
|
@ -159,6 +159,13 @@ QJsonObject VConfigManager::readDirectoryConfig(const QString &path)
|
||||
return QJsonDocument::fromJson(configData).object();
|
||||
}
|
||||
|
||||
bool VConfigManager::directoryConfigExist(const QString &path)
|
||||
{
|
||||
QString configFile = QDir(path).filePath(dirConfigFileName);
|
||||
QFile config(configFile);
|
||||
return config.exists();
|
||||
}
|
||||
|
||||
bool VConfigManager::writeDirectoryConfig(const QString &path, const QJsonObject &configJson)
|
||||
{
|
||||
QString configFile = QDir(path).filePath(dirConfigFileName);
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
// Read config from the directory config json file into a QJsonObject
|
||||
static QJsonObject readDirectoryConfig(const QString &path);
|
||||
static bool writeDirectoryConfig(const QString &path, const QJsonObject &configJson);
|
||||
static bool directoryConfigExist(const QString &path);
|
||||
static bool deleteDirectoryConfig(const QString &path);
|
||||
|
||||
// Constants
|
||||
|
@ -38,13 +38,19 @@ bool VNotebook::open()
|
||||
}
|
||||
|
||||
VNotebook *VNotebook::createNotebook(const QString &p_name, const QString &p_path,
|
||||
QObject *p_parent)
|
||||
bool p_import, QObject *p_parent)
|
||||
{
|
||||
VNotebook *nb = new VNotebook(p_name, p_path, p_parent);
|
||||
if (!nb) {
|
||||
return nb;
|
||||
}
|
||||
|
||||
// Check if there alread exists a config file.
|
||||
if (p_import && VConfigManager::directoryConfigExist(p_path)) {
|
||||
qDebug() << "import existing notebook";
|
||||
return nb;
|
||||
}
|
||||
|
||||
// Create directory config in @p_path
|
||||
QJsonObject configJson = VDirectory::createDirectoryJson();
|
||||
if (!VConfigManager::writeDirectoryConfig(p_path, configJson)) {
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
inline VDirectory *getRootDir();
|
||||
void rename(const QString &p_name);
|
||||
|
||||
static VNotebook *createNotebook(const QString &p_name, const QString &p_path,
|
||||
static VNotebook *createNotebook(const QString &p_name, const QString &p_path, bool p_import,
|
||||
QObject *p_parent = 0);
|
||||
static void deleteNotebook(VNotebook *p_notebook);
|
||||
|
||||
|
@ -169,7 +169,7 @@ bool VNotebookSelector::newNotebook()
|
||||
defaultPath = path;
|
||||
continue;
|
||||
}
|
||||
createNotebook(name, path);
|
||||
createNotebook(name, path, dialog.getImportCheck());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -187,9 +187,9 @@ VNotebook *VNotebookSelector::findNotebook(const QString &p_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void VNotebookSelector::createNotebook(const QString &p_name, const QString &p_path)
|
||||
void VNotebookSelector::createNotebook(const QString &p_name, const QString &p_path, bool p_import)
|
||||
{
|
||||
VNotebook *nb = VNotebook::createNotebook(p_name, p_path, m_vnote);
|
||||
VNotebook *nb = VNotebook::createNotebook(p_name, p_path, p_import, m_vnote);
|
||||
m_notebooks.append(nb);
|
||||
vconfig.setNotebooks(m_notebooks);
|
||||
|
||||
|
@ -44,7 +44,8 @@ private:
|
||||
VNotebook *findNotebook(const QString &p_name);
|
||||
// Return the index of @p_notebook in m_noteboks.
|
||||
int indexOfNotebook(const VNotebook *p_notebook);
|
||||
void createNotebook(const QString &p_name, const QString &p_path);
|
||||
// if @p_import is true, we will use the existing config file.
|
||||
void createNotebook(const QString &p_name, const QString &p_path, bool p_import);
|
||||
void deleteNotebook(VNotebook *p_notebook);
|
||||
void addNotebookItem(const QString &p_name);
|
||||
// @p_index is the index of m_notebooks, NOT of QComboBox.
|
||||
|
Loading…
x
Reference in New Issue
Block a user