Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickAccess: add quick note #2373

Merged
merged 9 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/core/notebook/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ void Node::setReadOnly(bool p_readOnly)
}
}


QString Node::fetchAbsolutePath() const
{
return m_manualAbsolutePath;
}

void Node::setManualAbsolutePath(const QString &p_path)
{
m_manualAbsolutePath = p_path;
}

QString Node::fetchPath() const
{
if (!m_parent) {
Expand Down
4 changes: 4 additions & 0 deletions src/core/notebook/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace vnotex
// This may not be the same as the actual file path. It depends on the config mgr.
virtual QString fetchPath() const;

void setManualAbsolutePath(const QString &p_path);

// Fetch absolute file path if available.
virtual QString fetchAbsolutePath() const = 0;

Expand Down Expand Up @@ -207,6 +209,8 @@ namespace vnotex
Node *m_parent = nullptr;

QVector<QSharedPointer<Node>> m_children;

QString m_manualAbsolutePath;
feloxx marked this conversation as resolved.
Show resolved Hide resolved
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Node::Flags)
Expand Down
45 changes: 45 additions & 0 deletions src/core/sessionconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#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 @@ -136,6 +138,9 @@ 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 @@ -151,6 +156,8 @@ 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 @@ -541,3 +548,41 @@ QJsonObject SessionConfig::saveExportOption() const

return obj;
}

const QString &SessionConfig::getQuickNoteStoragePath() const
{
return m_quickNoteStoragePath;
}

void SessionConfig::setQuickNoteStoragePath(const QString &p_path)
{
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;
}
14 changes: 13 additions & 1 deletion src/core/sessionconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ 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);

private:
void loadCore(const QJsonObject &p_session);

Expand Down Expand Up @@ -215,7 +221,13 @@ namespace vnotex
QVector<HistoryItem> m_history;

// Default folder path to open for external media like images and files.
QString m_externalMediaDefaultPath;;
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;
};
} // ns vnotex

Expand Down
2 changes: 1 addition & 1 deletion src/core/vnotex.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace vnotex

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

// Requested to new a folder in current notebook.
void newFolderRequested();
Expand Down
100 changes: 100 additions & 0 deletions src/widgets/dialogs/settings/quickaccesspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
#include <QPlainTextEdit>
#include <QDebug>
#include <QFileDialog>
#include <QCheckBox>

#include <widgets/widgetsfactory.h>
#include "core/vnotex.h"
#include <core/notebookmgr.h>
#include <core/sessionconfig.h>
#include <core/coreconfig.h>
#include <core/configmgr.h>
#include <utils/widgetutils.h>
#include <widgets/locationinputwithbrowsebutton.h>

#include "core/buffer/filetypehelper.h"

using namespace vnotex;

QuickAccessPage::QuickAccessPage(QWidget *p_parent)
Expand All @@ -29,6 +34,9 @@ void QuickAccessPage::setupUI()
auto flashPageBox = setupFlashPageGroup();
mainLayout->addWidget(flashPageBox);

auto quickNoteBox = setupQuickNotePageGroup();
mainLayout->addWidget(quickNoteBox);

auto quickAccessBox = setupQuickAccessGroup();
mainLayout->addWidget(quickAccessBox);
}
Expand All @@ -45,6 +53,22 @@ void QuickAccessPage::loadInternal()
m_quickAccessTextEdit->setPlainText(quickAccess.join(QChar('\n')));
}
}

{
m_quickNoteStoragePath->setText(sessionConfig.getQuickNoteStoragePath());

for(int typ : sessionConfig.getQuickNoteType()) {
if (FileType::Markdown == typ) {
m_quickMarkdownCheckBox->setChecked(true);
}
if (FileType::Text == typ) {
m_quickTextCheckBox->setChecked(true);
}
if (FileType::MindMap == typ) {
m_quickMindmapCheckBox->setChecked(true);
}
}
}
}

bool QuickAccessPage::saveInternal()
Expand All @@ -60,6 +84,25 @@ bool QuickAccessPage::saveInternal()
}
}

{
auto storagePath = m_quickNoteStoragePath->text();
if (!storagePath.isEmpty()) {
sessionConfig.setQuickNoteStoragePath(static_cast<QString>(storagePath));
}

QVector<int> quickNoteTypeList = QVector<int>();
if (m_quickMarkdownCheckBox->isChecked()) {
quickNoteTypeList.append(FileType::Markdown);
}
if (m_quickTextCheckBox->isChecked()) {
quickNoteTypeList.append(FileType::Text);
}
if (m_quickMindmapCheckBox->isChecked()) {
quickNoteTypeList.append(FileType::MindMap);
}
sessionConfig.setQuickNoteType(quickNoteTypeList);
}

return true;
}

Expand Down Expand Up @@ -114,3 +157,60 @@ QGroupBox *QuickAccessPage::setupQuickAccessGroup()

return box;
}

QGroupBox *QuickAccessPage::setupQuickNotePageGroup()
{
auto box = new QGroupBox(tr("Quick Note"), this);
auto layout = WidgetsFactory::createFormLayout(box);

{
m_quickNoteStoragePath = new LocationInputWithBrowseButton(box);
m_quickNoteStoragePath->setToolTip(tr("Quick Note storage path (default path is current notebook root)"));
// TODO default ?
// if (m_quickNoteStoragePath->text().isEmpty()) {
// m_quickNoteStoragePath->setText(VNoteX::getInst().getNotebookMgr().getCurrentNotebook()->getRootFolderAbsolutePath());
// }

const QString storagePathLabel(tr("Storage path:"));
layout->addRow(storagePathLabel, m_quickNoteStoragePath);
addSearchItem(storagePathLabel, m_quickNoteStoragePath->toolTip(), m_quickNoteStoragePath);
connect(m_quickNoteStoragePath, &LocationInputWithBrowseButton::textChanged,
this, &QuickAccessPage::pageIsChanged);
connect(m_quickNoteStoragePath, &LocationInputWithBrowseButton::clicked,
this, [this]() {
auto notebookRootPath = VNoteX::getInst().getNotebookMgr().getCurrentNotebook()->getRootFolderAbsolutePath();
auto filePath = QFileDialog::getExistingDirectory(this,
tr("Select Quick Note storage path"),
notebookRootPath);
if (!filePath.isEmpty()) {
m_quickNoteStoragePath->setText(filePath);
}
});

const QString mdLabel(tr("Markdown"));
m_quickMarkdownCheckBox = WidgetsFactory::createCheckBox(mdLabel, box);
m_quickMarkdownCheckBox->setToolTip(tr("Suppet Quick Note for Markdown"));
layout->addRow(m_quickMarkdownCheckBox);
addSearchItem(mdLabel, m_quickMarkdownCheckBox->toolTip(), m_quickMarkdownCheckBox);
connect(m_quickMarkdownCheckBox, &QCheckBox::stateChanged,
this, &QuickAccessPage::pageIsChanged);

const QString txtlabel(tr("Text"));
m_quickTextCheckBox = WidgetsFactory::createCheckBox(txtlabel, box);
m_quickTextCheckBox->setToolTip(tr("Suppet Quick note for Text"));
layout->addRow(m_quickTextCheckBox);
addSearchItem(txtlabel, m_quickTextCheckBox->toolTip(), m_quickTextCheckBox);
connect(m_quickTextCheckBox, &QCheckBox::stateChanged,
this, &QuickAccessPage::pageIsChanged);

const QString mindmapLabel(tr("Mind Map"));
m_quickMindmapCheckBox = WidgetsFactory::createCheckBox(mindmapLabel, box);
m_quickMindmapCheckBox->setToolTip(tr("Suppet Quick Note for Mind Map"));
layout->addRow(m_quickMindmapCheckBox);
addSearchItem(mindmapLabel, m_quickMindmapCheckBox->toolTip(), m_quickMindmapCheckBox);
connect(m_quickMindmapCheckBox, &QCheckBox::stateChanged,
this, &QuickAccessPage::pageIsChanged);
}

return box;
}
9 changes: 9 additions & 0 deletions src/widgets/dialogs/settings/quickaccesspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "settingspage.h"

class QCheckBox;
class QGroupBox;
class QPlainTextEdit;

Expand Down Expand Up @@ -30,9 +31,17 @@ namespace vnotex

QGroupBox *setupQuickAccessGroup();

QGroupBox *setupQuickNotePageGroup();

LocationInputWithBrowseButton *m_flashPageInput = nullptr;

QPlainTextEdit *m_quickAccessTextEdit = nullptr;

LocationInputWithBrowseButton *m_quickNoteStoragePath;

QCheckBox *m_quickMarkdownCheckBox = nullptr;
QCheckBox *m_quickTextCheckBox = nullptr;
QCheckBox *m_quickMindmapCheckBox = nullptr;
};
}

Expand Down
Loading