Skip to content

Commit 39f4e55

Browse files
committed
fix
1 parent 66ebb5c commit 39f4e55

29 files changed

+676
-343
lines changed

src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ void VXNotebookConfigMgr::addChildNode(Node *p_parent, const QSharedPointer<Node
461461
QSharedPointer<Node> VXNotebookConfigMgr::loadNodeByPath(const QSharedPointer<Node> &p_root, const QString &p_relativePath)
462462
{
463463
auto p = PathUtils::cleanPath(p_relativePath);
464+
if (p == ".") {
465+
return p_root;
466+
}
467+
464468
auto paths = p.split('/', QString::SkipEmptyParts);
465469
auto node = p_root;
466470
for (auto &pa : paths) {

src/core/sessionconfig.cpp

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "mainconfig.h"
1212
#include "historymgr.h"
1313

14-
#include "core/buffer/filetypehelper.h"
15-
1614
using namespace vnotex;
1715

1816
bool SessionConfig::NotebookItem::operator==(const NotebookItem &p_other) const
@@ -40,6 +38,34 @@ QJsonObject SessionConfig::NotebookItem::toJson() const
4038
return jobj;
4139
}
4240

41+
bool SessionConfig::QuickNoteScheme::operator==(const QuickNoteScheme &p_other) const
42+
{
43+
return m_name == p_other.m_name &&
44+
m_folderPath == p_other.m_folderPath &&
45+
m_noteName == p_other.m_noteName &&
46+
m_template == p_other.m_template;
47+
}
48+
49+
void SessionConfig::QuickNoteScheme::fromJson(const QJsonObject &p_jobj)
50+
{
51+
m_name = p_jobj[QStringLiteral("name")].toString();
52+
m_folderPath = p_jobj[QStringLiteral("folder_path")].toString();
53+
m_noteName = p_jobj[QStringLiteral("note_name")].toString();
54+
m_template = p_jobj[QStringLiteral("template")].toString();
55+
}
56+
57+
QJsonObject SessionConfig::QuickNoteScheme::toJson() const
58+
{
59+
QJsonObject jobj;
60+
61+
jobj[QStringLiteral("name")] = m_name;
62+
jobj[QStringLiteral("folder_path")] = m_folderPath;
63+
jobj[QStringLiteral("note_name")] = m_noteName;
64+
jobj[QStringLiteral("template")] = m_template;
65+
66+
return jobj;
67+
}
68+
4369
void SessionConfig::ExternalProgram::fromJson(const QJsonObject &p_jobj)
4470
{
4571
m_name = p_jobj[QStringLiteral("name")].toString();
@@ -99,6 +125,8 @@ void SessionConfig::init()
99125

100126
loadHistory(sessionJobj);
101127

128+
loadQuickNoteSchemes(sessionJobj);
129+
102130
if (MainConfig::isVersionChanged()) {
103131
doVersionSpecificOverride();
104132
}
@@ -138,9 +166,6 @@ void SessionConfig::loadCore(const QJsonObject &p_session)
138166
if (m_externalMediaDefaultPath.isEmpty()) {
139167
m_externalMediaDefaultPath = QDir::homePath();
140168
}
141-
142-
m_quickNoteStoragePath = readString(coreObj, QStringLiteral("quick_note_storage_path"));
143-
m_quickNoteType = stringListToFileType(readStringList(coreObj, QStringLiteral("quick_note_type")));
144169
}
145170

146171
QJsonObject SessionConfig::saveCore() const
@@ -156,8 +181,6 @@ QJsonObject SessionConfig::saveCore() const
156181
coreObj[QStringLiteral("flash_page")] = m_flashPage;
157182
writeStringList(coreObj, QStringLiteral("quick_access"), m_quickAccessFiles);
158183
coreObj[QStringLiteral("external_media_default_path")] = m_externalMediaDefaultPath;
159-
coreObj[QStringLiteral("quick_note_storage_path")] = m_quickNoteStoragePath;
160-
writeStringList(coreObj, QStringLiteral("quick_note_type"), fileTypeToStringList(m_quickNoteType));
161184
return coreObj;
162185
}
163186

@@ -242,6 +265,7 @@ QJsonObject SessionConfig::toJson() const
242265
writeByteArray(obj, QStringLiteral("notebook_explorer_session"), m_notebookExplorerSession);
243266
obj[QStringLiteral("external_programs")] = saveExternalPrograms();
244267
obj[QStringLiteral("history")] = saveHistory();
268+
obj[QStringLiteral("quick_note_schemes")] = saveQuickNoteSchemes();
245269
return obj;
246270
}
247271

@@ -465,6 +489,24 @@ QJsonArray SessionConfig::saveExternalPrograms() const
465489
return arr;
466490
}
467491

492+
void SessionConfig::loadQuickNoteSchemes(const QJsonObject &p_session)
493+
{
494+
const auto arr = p_session.value(QStringLiteral("quick_note_schemes")).toArray();
495+
m_quickNoteSchemes.resize(arr.size());
496+
for (int i = 0; i < arr.size(); ++i) {
497+
m_quickNoteSchemes[i].fromJson(arr[i].toObject());
498+
}
499+
}
500+
501+
QJsonArray SessionConfig::saveQuickNoteSchemes() const
502+
{
503+
QJsonArray arr;
504+
for (const auto &scheme : m_quickNoteSchemes) {
505+
arr.append(scheme.toJson());
506+
}
507+
return arr;
508+
}
509+
468510
const QVector<SessionConfig::ExternalProgram> &SessionConfig::getExternalPrograms() const
469511
{
470512
return m_externalPrograms;
@@ -549,40 +591,12 @@ QJsonObject SessionConfig::saveExportOption() const
549591
return obj;
550592
}
551593

552-
const QString &SessionConfig::getQuickNoteStoragePath() const
594+
const QVector<SessionConfig::QuickNoteScheme> &SessionConfig::getQuickNoteSchemes() const
553595
{
554-
return m_quickNoteStoragePath;
596+
return m_quickNoteSchemes;
555597
}
556598

557-
void SessionConfig::setQuickNoteStoragePath(const QString &p_path)
599+
void SessionConfig::setQuickNoteSchemes(const QVector<QuickNoteScheme>& p_schemes)
558600
{
559-
updateConfig(m_quickNoteStoragePath, p_path, this);
560-
}
561-
562-
const QVector<int> &SessionConfig::getQuickNoteType() const
563-
{
564-
return m_quickNoteType;
565-
}
566-
567-
void SessionConfig::setQuickNoteType(const QVector<int> &p_type)
568-
{
569-
updateConfig(m_quickNoteType, p_type, this);
570-
}
571-
572-
QStringList SessionConfig::fileTypeToStringList(const QVector<int> &p_type) const
573-
{
574-
QStringList list;
575-
for (const int typ : p_type) {
576-
list << FileTypeHelper::getInst().getFileType(typ).m_typeName;
577-
}
578-
return list;
579-
}
580-
581-
QVector<int> SessionConfig::stringListToFileType(const QStringList &p_strList) const
582-
{
583-
QVector<int> vec;
584-
for (const QString &str : p_strList) {
585-
vec.append(FileTypeHelper::getInst().getFileTypeByName(str).m_type);
586-
}
587-
return vec;
601+
updateConfig(m_quickNoteSchemes, p_schemes, this);
588602
}

src/core/sessionconfig.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ namespace vnotex
5757

5858
struct QuickNoteScheme
5959
{
60+
bool operator==(const QuickNoteScheme &p_other) const;
61+
62+
void fromJson(const QJsonObject &p_jobj);
63+
64+
QJsonObject toJson() const;
65+
66+
QString m_name;
67+
6068
// Where to create the quick note.
6169
QString m_folderPath;
62-
// Name of the quick note.
63-
QString m_name;
64-
QString m_templatePath;
70+
71+
// Name of the quick note. Snippet is supported.
72+
QString m_noteName;
73+
74+
QString m_template;
6575
};
6676

6777
enum OpenGL
@@ -158,11 +168,8 @@ namespace vnotex
158168
void removeHistory(const QString &p_itemPath);
159169
void clearHistory();
160170

161-
const QString &getQuickNoteStoragePath() const;
162-
void setQuickNoteStoragePath(const QString &p_path);
163-
164-
const QVector<int> &getQuickNoteType() const;
165-
void setQuickNoteType(const QVector<int> &p_type);
171+
const QVector<QuickNoteScheme> &getQuickNoteSchemes() const;
172+
void setQuickNoteSchemes(const QVector<QuickNoteScheme>& p_schemes);
166173

167174
private:
168175
void loadCore(const QJsonObject &p_session);
@@ -181,6 +188,10 @@ namespace vnotex
181188

182189
QJsonArray saveExternalPrograms() const;
183190

191+
void loadQuickNoteSchemes(const QJsonObject &p_session);
192+
193+
QJsonArray saveQuickNoteSchemes() const;
194+
184195
void doVersionSpecificOverride();
185196

186197
void loadHistory(const QJsonObject &p_session);
@@ -232,11 +243,7 @@ namespace vnotex
232243
// Default folder path to open for external media like images and files.
233244
QString m_externalMediaDefaultPath;
234245

235-
QString m_quickNoteStoragePath;
236-
QVector<int> m_quickNoteType;
237-
238-
QStringList fileTypeToStringList(const QVector<int> &p_type) const;
239-
QVector<int> stringListToFileType(const QStringList &p_strList) const;
246+
QVector<QuickNoteScheme> m_quickNoteSchemes;
240247
};
241248
} // ns vnotex
242249

src/core/templatemgr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <QDir>
44

5+
#include <utils/fileutils.h>
6+
57
#include "configmgr.h"
68

79
using namespace vnotex;
@@ -20,5 +22,17 @@ QStringList TemplateMgr::getTemplates() const
2022

2123
QString TemplateMgr::getTemplateFilePath(const QString &p_name) const
2224
{
25+
if (p_name.isEmpty()) {
26+
return QString();
27+
}
2328
return QDir(getTemplateFolder()).filePath(p_name);
2429
}
30+
31+
QString TemplateMgr::getTemplateContent(const QString &p_name) const
32+
{
33+
const auto filePath = getTemplateFilePath(p_name);
34+
if (filePath.isEmpty()) {
35+
return QString();
36+
}
37+
return FileUtils::readTextFile(filePath);
38+
}

src/core/templatemgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace vnotex
2424

2525
QString getTemplateFilePath(const QString &p_name) const;
2626

27+
QString getTemplateContent(const QString &p_name) const;
28+
2729
private:
2830
TemplateMgr() = default;
2931
};

src/core/vnotex.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ namespace vnotex
7777

7878
// Requested to new a note in current notebook.
7979
// The handler should determine in which folder this note belongs to.
80-
void newNoteRequested(const QVector<int> &p_type = QVector<int>(), const QString &p_path = QString());
80+
void newNoteRequested();
81+
82+
// Requested to new a quick note (maybe in current folder).
83+
void newQuickNoteRequested();
8184

8285
// Requested to new a folder in current notebook.
8386
void newFolderRequested();

0 commit comments

Comments
 (0)