Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Aug 24, 2023
1 parent 66ebb5c commit 39f4e55
Show file tree
Hide file tree
Showing 29 changed files with 676 additions and 343 deletions.
4 changes: 4 additions & 0 deletions src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ void VXNotebookConfigMgr::addChildNode(Node *p_parent, const QSharedPointer<Node
QSharedPointer<Node> VXNotebookConfigMgr::loadNodeByPath(const QSharedPointer<Node> &p_root, const QString &p_relativePath)
{
auto p = PathUtils::cleanPath(p_relativePath);
if (p == ".") {
return p_root;
}

auto paths = p.split('/', QString::SkipEmptyParts);
auto node = p_root;
for (auto &pa : paths) {
Expand Down
92 changes: 53 additions & 39 deletions src/core/sessionconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "mainconfig.h"
#include "historymgr.h"

#include "core/buffer/filetypehelper.h"

using namespace vnotex;

bool SessionConfig::NotebookItem::operator==(const NotebookItem &p_other) const
Expand Down Expand Up @@ -40,6 +38,34 @@ QJsonObject SessionConfig::NotebookItem::toJson() const
return jobj;
}

bool SessionConfig::QuickNoteScheme::operator==(const QuickNoteScheme &p_other) const
{
return m_name == p_other.m_name &&
m_folderPath == p_other.m_folderPath &&
m_noteName == p_other.m_noteName &&
m_template == p_other.m_template;
}

void SessionConfig::QuickNoteScheme::fromJson(const QJsonObject &p_jobj)
{
m_name = p_jobj[QStringLiteral("name")].toString();
m_folderPath = p_jobj[QStringLiteral("folder_path")].toString();
m_noteName = p_jobj[QStringLiteral("note_name")].toString();
m_template = p_jobj[QStringLiteral("template")].toString();
}

QJsonObject SessionConfig::QuickNoteScheme::toJson() const
{
QJsonObject jobj;

jobj[QStringLiteral("name")] = m_name;
jobj[QStringLiteral("folder_path")] = m_folderPath;
jobj[QStringLiteral("note_name")] = m_noteName;
jobj[QStringLiteral("template")] = m_template;

return jobj;
}

void SessionConfig::ExternalProgram::fromJson(const QJsonObject &p_jobj)
{
m_name = p_jobj[QStringLiteral("name")].toString();
Expand Down Expand Up @@ -99,6 +125,8 @@ void SessionConfig::init()

loadHistory(sessionJobj);

loadQuickNoteSchemes(sessionJobj);

if (MainConfig::isVersionChanged()) {
doVersionSpecificOverride();
}
Expand Down Expand Up @@ -138,9 +166,6 @@ void SessionConfig::loadCore(const QJsonObject &p_session)
if (m_externalMediaDefaultPath.isEmpty()) {
m_externalMediaDefaultPath = QDir::homePath();
}

m_quickNoteStoragePath = readString(coreObj, QStringLiteral("quick_note_storage_path"));
m_quickNoteType = stringListToFileType(readStringList(coreObj, QStringLiteral("quick_note_type")));
}

QJsonObject SessionConfig::saveCore() const
Expand All @@ -156,8 +181,6 @@ QJsonObject SessionConfig::saveCore() const
coreObj[QStringLiteral("flash_page")] = m_flashPage;
writeStringList(coreObj, QStringLiteral("quick_access"), m_quickAccessFiles);
coreObj[QStringLiteral("external_media_default_path")] = m_externalMediaDefaultPath;
coreObj[QStringLiteral("quick_note_storage_path")] = m_quickNoteStoragePath;
writeStringList(coreObj, QStringLiteral("quick_note_type"), fileTypeToStringList(m_quickNoteType));
return coreObj;
}

Expand Down Expand Up @@ -242,6 +265,7 @@ QJsonObject SessionConfig::toJson() const
writeByteArray(obj, QStringLiteral("notebook_explorer_session"), m_notebookExplorerSession);
obj[QStringLiteral("external_programs")] = saveExternalPrograms();
obj[QStringLiteral("history")] = saveHistory();
obj[QStringLiteral("quick_note_schemes")] = saveQuickNoteSchemes();
return obj;
}

Expand Down Expand Up @@ -465,6 +489,24 @@ QJsonArray SessionConfig::saveExternalPrograms() const
return arr;
}

void SessionConfig::loadQuickNoteSchemes(const QJsonObject &p_session)
{
const auto arr = p_session.value(QStringLiteral("quick_note_schemes")).toArray();
m_quickNoteSchemes.resize(arr.size());
for (int i = 0; i < arr.size(); ++i) {
m_quickNoteSchemes[i].fromJson(arr[i].toObject());
}
}

QJsonArray SessionConfig::saveQuickNoteSchemes() const
{
QJsonArray arr;
for (const auto &scheme : m_quickNoteSchemes) {
arr.append(scheme.toJson());
}
return arr;
}

const QVector<SessionConfig::ExternalProgram> &SessionConfig::getExternalPrograms() const
{
return m_externalPrograms;
Expand Down Expand Up @@ -549,40 +591,12 @@ QJsonObject SessionConfig::saveExportOption() const
return obj;
}

const QString &SessionConfig::getQuickNoteStoragePath() const
const QVector<SessionConfig::QuickNoteScheme> &SessionConfig::getQuickNoteSchemes() const
{
return m_quickNoteStoragePath;
return m_quickNoteSchemes;
}

void SessionConfig::setQuickNoteStoragePath(const QString &p_path)
void SessionConfig::setQuickNoteSchemes(const QVector<QuickNoteScheme>& p_schemes)
{
updateConfig(m_quickNoteStoragePath, p_path, this);
}

const QVector<int> &SessionConfig::getQuickNoteType() const
{
return m_quickNoteType;
}

void SessionConfig::setQuickNoteType(const QVector<int> &p_type)
{
updateConfig(m_quickNoteType, p_type, this);
}

QStringList SessionConfig::fileTypeToStringList(const QVector<int> &p_type) const
{
QStringList list;
for (const int typ : p_type) {
list << FileTypeHelper::getInst().getFileType(typ).m_typeName;
}
return list;
}

QVector<int> SessionConfig::stringListToFileType(const QStringList &p_strList) const
{
QVector<int> vec;
for (const QString &str : p_strList) {
vec.append(FileTypeHelper::getInst().getFileTypeByName(str).m_type);
}
return vec;
updateConfig(m_quickNoteSchemes, p_schemes, this);
}
33 changes: 20 additions & 13 deletions src/core/sessionconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ namespace vnotex

struct QuickNoteScheme
{
bool operator==(const QuickNoteScheme &p_other) const;

void fromJson(const QJsonObject &p_jobj);

QJsonObject toJson() const;

QString m_name;

// Where to create the quick note.
QString m_folderPath;
// Name of the quick note.
QString m_name;
QString m_templatePath;

// Name of the quick note. Snippet is supported.
QString m_noteName;

QString m_template;
};

enum OpenGL
Expand Down Expand Up @@ -158,11 +168,8 @@ namespace vnotex
void removeHistory(const QString &p_itemPath);
void clearHistory();

const QString &getQuickNoteStoragePath() const;
void setQuickNoteStoragePath(const QString &p_path);

const QVector<int> &getQuickNoteType() const;
void setQuickNoteType(const QVector<int> &p_type);
const QVector<QuickNoteScheme> &getQuickNoteSchemes() const;
void setQuickNoteSchemes(const QVector<QuickNoteScheme>& p_schemes);

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

QJsonArray saveExternalPrograms() const;

void loadQuickNoteSchemes(const QJsonObject &p_session);

QJsonArray saveQuickNoteSchemes() const;

void doVersionSpecificOverride();

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

QString m_quickNoteStoragePath;
QVector<int> m_quickNoteType;

QStringList fileTypeToStringList(const QVector<int> &p_type) const;
QVector<int> stringListToFileType(const QStringList &p_strList) const;
QVector<QuickNoteScheme> m_quickNoteSchemes;
};
} // ns vnotex

Expand Down
14 changes: 14 additions & 0 deletions src/core/templatemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <QDir>

#include <utils/fileutils.h>

#include "configmgr.h"

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

QString TemplateMgr::getTemplateFilePath(const QString &p_name) const
{
if (p_name.isEmpty()) {
return QString();
}
return QDir(getTemplateFolder()).filePath(p_name);
}

QString TemplateMgr::getTemplateContent(const QString &p_name) const
{
const auto filePath = getTemplateFilePath(p_name);
if (filePath.isEmpty()) {
return QString();
}
return FileUtils::readTextFile(filePath);
}
2 changes: 2 additions & 0 deletions src/core/templatemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace vnotex

QString getTemplateFilePath(const QString &p_name) const;

QString getTemplateContent(const QString &p_name) const;

private:
TemplateMgr() = default;
};
Expand Down
5 changes: 4 additions & 1 deletion src/core/vnotex.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ namespace vnotex

// Requested to new a note in current notebook.
// The handler should determine in which folder this note belongs to.
void newNoteRequested(const QVector<int> &p_type = QVector<int>(), const QString &p_path = QString());
void newNoteRequested();

// Requested to new a quick note (maybe in current folder).
void newQuickNoteRequested();

// Requested to new a folder in current notebook.
void newFolderRequested();
Expand Down
Loading

0 comments on commit 39f4e55

Please sign in to comment.