mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
add switch for per-notebook history
This commit is contained in:
parent
5c2a14e6a7
commit
54a71ae977
@ -24,7 +24,7 @@
|
|||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
#define VX_DEBUG_WEB
|
// #define VX_DEBUG_WEB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const QString ConfigMgr::c_orgName = "VNote";
|
const QString ConfigMgr::c_orgName = "VNote";
|
||||||
|
@ -63,6 +63,8 @@ void CoreConfig::init(const QJsonObject &p_app,
|
|||||||
if (m_historyMaxCount < 0) {
|
if (m_historyMaxCount < 0) {
|
||||||
m_historyMaxCount = 100;
|
m_historyMaxCount = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_perNotebookHistoryEnabled = READBOOL(QStringLiteral("per_notebook_history"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject CoreConfig::toJson() const
|
QJsonObject CoreConfig::toJson() const
|
||||||
@ -76,6 +78,7 @@ QJsonObject CoreConfig::toJson() const
|
|||||||
obj[QStringLiteral("recover_last_session_on_start")] = m_recoverLastSessionOnStartEnabled;
|
obj[QStringLiteral("recover_last_session_on_start")] = m_recoverLastSessionOnStartEnabled;
|
||||||
obj[QStringLiteral("check_for_updates_on_start")] = m_checkForUpdatesOnStartEnabled;
|
obj[QStringLiteral("check_for_updates_on_start")] = m_checkForUpdatesOnStartEnabled;
|
||||||
obj[QStringLiteral("history_max_count")] = m_historyMaxCount;
|
obj[QStringLiteral("history_max_count")] = m_historyMaxCount;
|
||||||
|
obj[QStringLiteral("per_notebook_history")] = m_perNotebookHistoryEnabled;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,3 +206,13 @@ int CoreConfig::getHistoryMaxCount() const
|
|||||||
{
|
{
|
||||||
return m_historyMaxCount;
|
return m_historyMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CoreConfig::isPerNotebookHistoryEnabled() const
|
||||||
|
{
|
||||||
|
return m_perNotebookHistoryEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreConfig::setPerNotebookHistoryEnabled(bool p_enabled)
|
||||||
|
{
|
||||||
|
updateConfig(m_perNotebookHistoryEnabled, p_enabled, this);
|
||||||
|
}
|
||||||
|
@ -104,6 +104,9 @@ namespace vnotex
|
|||||||
|
|
||||||
int getHistoryMaxCount() const;
|
int getHistoryMaxCount() const;
|
||||||
|
|
||||||
|
bool isPerNotebookHistoryEnabled() const;
|
||||||
|
void setPerNotebookHistoryEnabled(bool p_enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MainConfig;
|
friend class MainConfig;
|
||||||
|
|
||||||
@ -138,6 +141,9 @@ namespace vnotex
|
|||||||
// Max count of the history items for each notebook and session config.
|
// Max count of the history items for each notebook and session config.
|
||||||
int m_historyMaxCount = 100;
|
int m_historyMaxCount = 100;
|
||||||
|
|
||||||
|
// Whether store history in each notebook.
|
||||||
|
bool m_perNotebookHistoryEnabled = true;
|
||||||
|
|
||||||
static QStringList s_availableLocales;
|
static QStringList s_availableLocales;
|
||||||
};
|
};
|
||||||
} // ns vnotex
|
} // ns vnotex
|
||||||
|
@ -25,12 +25,9 @@ bool HistoryItemFull::operator<(const HistoryItemFull &p_other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int HistoryMgr::s_maxHistoryCount = 100;
|
|
||||||
|
|
||||||
HistoryMgr::HistoryMgr()
|
HistoryMgr::HistoryMgr()
|
||||||
|
: m_perNotebookHistoryEnabled(ConfigMgr::getInst().getCoreConfig().isPerNotebookHistoryEnabled())
|
||||||
{
|
{
|
||||||
s_maxHistoryCount = ConfigMgr::getInst().getCoreConfig().getHistoryMaxCount();
|
|
||||||
|
|
||||||
connect(&VNoteX::getInst().getNotebookMgr(), &NotebookMgr::notebooksUpdated,
|
connect(&VNoteX::getInst().getNotebookMgr(), &NotebookMgr::notebooksUpdated,
|
||||||
this, &HistoryMgr::loadHistory);
|
this, &HistoryMgr::loadHistory);
|
||||||
|
|
||||||
@ -57,7 +54,7 @@ void HistoryMgr::loadHistory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load from notebooks.
|
// Load from notebooks.
|
||||||
{
|
if (m_perNotebookHistoryEnabled) {
|
||||||
const auto ¬ebooks = VNoteX::getInst().getNotebookMgr().getNotebooks();
|
const auto ¬ebooks = VNoteX::getInst().getNotebookMgr().getNotebooks();
|
||||||
for (const auto &nb : notebooks) {
|
for (const auto &nb : notebooks) {
|
||||||
const auto &history = nb->getHistory();
|
const auto &history = nb->getHistory();
|
||||||
@ -98,13 +95,14 @@ void HistoryMgr::add(const QString &p_path,
|
|||||||
bool p_readOnly,
|
bool p_readOnly,
|
||||||
Notebook *p_notebook)
|
Notebook *p_notebook)
|
||||||
{
|
{
|
||||||
if (p_path.isEmpty() || s_maxHistoryCount == 0) {
|
const int maxHistoryCount = ConfigMgr::getInst().getCoreConfig().getHistoryMaxCount();
|
||||||
|
if (p_path.isEmpty() || maxHistoryCount == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem item(p_path, p_lineNumber, QDateTime::currentDateTimeUtc());
|
HistoryItem item(p_path, p_lineNumber, QDateTime::currentDateTimeUtc());
|
||||||
|
|
||||||
if (p_notebook) {
|
if (p_notebook && m_perNotebookHistoryEnabled) {
|
||||||
p_notebook->addHistory(item);
|
p_notebook->addHistory(item);
|
||||||
} else {
|
} else {
|
||||||
auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
|
auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
|
||||||
@ -145,8 +143,8 @@ void HistoryMgr::add(const QString &p_path,
|
|||||||
file.m_mode = p_mode;
|
file.m_mode = p_mode;
|
||||||
file.m_readOnly = p_readOnly;
|
file.m_readOnly = p_readOnly;
|
||||||
|
|
||||||
if (m_lastClosedFiles.size() > s_maxHistoryCount) {
|
if (m_lastClosedFiles.size() > maxHistoryCount) {
|
||||||
m_lastClosedFiles.remove(0, m_lastClosedFiles.size() - s_maxHistoryCount);
|
m_lastClosedFiles.remove(0, m_lastClosedFiles.size() - maxHistoryCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +163,9 @@ void HistoryMgr::insertHistoryItem(QVector<HistoryItem> &p_history, const Histor
|
|||||||
|
|
||||||
p_history.append(p_item);
|
p_history.append(p_item);
|
||||||
|
|
||||||
if (p_history.size() > s_maxHistoryCount) {
|
const int maxHistoryCount = ConfigMgr::getInst().getCoreConfig().getHistoryMaxCount();
|
||||||
p_history.remove(0, p_history.size() - s_maxHistoryCount);
|
if (p_history.size() > maxHistoryCount) {
|
||||||
|
p_history.remove(0, p_history.size() - maxHistoryCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,9 +173,11 @@ void HistoryMgr::clear()
|
|||||||
{
|
{
|
||||||
ConfigMgr::getInst().getSessionConfig().clearHistory();
|
ConfigMgr::getInst().getSessionConfig().clearHistory();
|
||||||
|
|
||||||
const auto ¬ebooks = VNoteX::getInst().getNotebookMgr().getNotebooks();
|
if (m_perNotebookHistoryEnabled) {
|
||||||
for (const auto &nb : notebooks) {
|
const auto ¬ebooks = VNoteX::getInst().getNotebookMgr().getNotebooks();
|
||||||
nb->clearHistory();
|
for (const auto &nb : notebooks) {
|
||||||
|
nb->clearHistory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadHistory();
|
loadHistory();
|
||||||
|
@ -74,7 +74,7 @@ namespace vnotex
|
|||||||
|
|
||||||
QVector<LastClosedFile> m_lastClosedFiles;
|
QVector<LastClosedFile> m_lastClosedFiles;
|
||||||
|
|
||||||
static int s_maxHistoryCount;
|
const bool m_perNotebookHistoryEnabled = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@
|
|||||||
"recover_last_session_on_start" : true,
|
"recover_last_session_on_start" : true,
|
||||||
"check_for_updates_on_start" : true,
|
"check_for_updates_on_start" : true,
|
||||||
"//comment" : "Max count of the history items for each notebook and session config",
|
"//comment" : "Max count of the history items for each notebook and session config",
|
||||||
"history_max_count" : 100
|
"history_max_count" : 100,
|
||||||
|
"per_notebook_history" : true
|
||||||
},
|
},
|
||||||
"editor" : {
|
"editor" : {
|
||||||
"core": {
|
"core": {
|
||||||
|
@ -516,7 +516,7 @@ QMainWindow > QTabBar::tab:right {
|
|||||||
border-right: 3px solid transparent;
|
border-right: 3px solid transparent;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: -10px 2px 5px 2px;
|
padding: 6px 2px -10px 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tabified QDockWidget */
|
/* Tabified QDockWidget */
|
||||||
@ -524,7 +524,7 @@ QMainWindow > QTabBar::tab:left {
|
|||||||
border-left: 3px solid transparent;
|
border-left: 3px solid transparent;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: -10px 2px 5px 2px;
|
padding: -10px 2px 6px 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar::tab:hover {
|
QTabBar::tab:hover {
|
||||||
|
@ -516,7 +516,7 @@ QMainWindow > QTabBar::tab:right {
|
|||||||
border-right: 3px solid transparent;
|
border-right: 3px solid transparent;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: -10px 2px 5px 2px;
|
padding: 6px 2px -10px 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tabified QDockWidget */
|
/* Tabified QDockWidget */
|
||||||
@ -524,7 +524,7 @@ QMainWindow > QTabBar::tab:left {
|
|||||||
border-left: 3px solid transparent;
|
border-left: 3px solid transparent;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: -10px 2px 5px 2px;
|
padding: -10px 2px 6px 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar::tab:hover {
|
QTabBar::tab:hover {
|
||||||
|
54
src/widgets/dialogs/settings/notemanagementpage.cpp
Normal file
54
src/widgets/dialogs/settings/notemanagementpage.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "notemanagementpage.h"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QFormLayout>
|
||||||
|
|
||||||
|
#include <widgets/widgetsfactory.h>
|
||||||
|
#include <core/coreconfig.h>
|
||||||
|
#include <core/configmgr.h>
|
||||||
|
#include <utils/widgetutils.h>
|
||||||
|
#include <core/vnotex.h>
|
||||||
|
|
||||||
|
using namespace vnotex;
|
||||||
|
|
||||||
|
NoteManagementPage::NoteManagementPage(QWidget *p_parent)
|
||||||
|
: SettingsPage(p_parent)
|
||||||
|
{
|
||||||
|
setupUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoteManagementPage::setupUI()
|
||||||
|
{
|
||||||
|
auto mainLayout = WidgetsFactory::createFormLayout(this);
|
||||||
|
|
||||||
|
{
|
||||||
|
const QString label(tr("Per-Notebook access history"));
|
||||||
|
m_perNotebookHistoryCheckBox = WidgetsFactory::createCheckBox(label, this);
|
||||||
|
m_perNotebookHistoryCheckBox->setToolTip(tr("Store note access history in its notebook"));
|
||||||
|
mainLayout->addRow(m_perNotebookHistoryCheckBox);
|
||||||
|
addSearchItem(label, m_perNotebookHistoryCheckBox->toolTip(), m_perNotebookHistoryCheckBox);
|
||||||
|
connect(m_perNotebookHistoryCheckBox, &QCheckBox::stateChanged,
|
||||||
|
this, &NoteManagementPage::pageIsChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoteManagementPage::loadInternal()
|
||||||
|
{
|
||||||
|
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
||||||
|
|
||||||
|
m_perNotebookHistoryCheckBox->setChecked(coreConfig.isPerNotebookHistoryEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NoteManagementPage::saveInternal()
|
||||||
|
{
|
||||||
|
auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
||||||
|
|
||||||
|
coreConfig.setPerNotebookHistoryEnabled(m_perNotebookHistoryCheckBox->isChecked());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString NoteManagementPage::title() const
|
||||||
|
{
|
||||||
|
return tr("Note Management");
|
||||||
|
}
|
30
src/widgets/dialogs/settings/notemanagementpage.h
Normal file
30
src/widgets/dialogs/settings/notemanagementpage.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef NOTEMANAGEMENTPAGE_H
|
||||||
|
#define NOTEMANAGEMENTPAGE_H
|
||||||
|
|
||||||
|
#include "settingspage.h"
|
||||||
|
|
||||||
|
class QCheckBox;
|
||||||
|
|
||||||
|
namespace vnotex
|
||||||
|
{
|
||||||
|
class NoteManagementPage : public SettingsPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit NoteManagementPage(QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
|
QString title() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void loadInternal() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
bool saveInternal() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupUI();
|
||||||
|
|
||||||
|
QCheckBox *m_perNotebookHistoryCheckBox = nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NOTEMANAGEMENTPAGE_H
|
@ -19,6 +19,7 @@
|
|||||||
#include "themepage.h"
|
#include "themepage.h"
|
||||||
#include "imagehostpage.h"
|
#include "imagehostpage.h"
|
||||||
#include "vipage.h"
|
#include "vipage.h"
|
||||||
|
#include "notemanagementpage.h"
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
@ -90,6 +91,12 @@ void SettingsDialog::setupPages()
|
|||||||
addPage(page);
|
addPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note Management.
|
||||||
|
{
|
||||||
|
auto page = new NoteManagementPage(this);
|
||||||
|
addPage(page);
|
||||||
|
}
|
||||||
|
|
||||||
// Appearance.
|
// Appearance.
|
||||||
{
|
{
|
||||||
auto page = new AppearancePage(this);
|
auto page = new AppearancePage(this);
|
||||||
|
@ -23,6 +23,7 @@ SOURCES += \
|
|||||||
$$PWD/dialogs/settings/markdowneditorpage.cpp \
|
$$PWD/dialogs/settings/markdowneditorpage.cpp \
|
||||||
$$PWD/dialogs/settings/miscpage.cpp \
|
$$PWD/dialogs/settings/miscpage.cpp \
|
||||||
$$PWD/dialogs/settings/newimagehostdialog.cpp \
|
$$PWD/dialogs/settings/newimagehostdialog.cpp \
|
||||||
|
$$PWD/dialogs/settings/notemanagementpage.cpp \
|
||||||
$$PWD/dialogs/settings/quickaccesspage.cpp \
|
$$PWD/dialogs/settings/quickaccesspage.cpp \
|
||||||
$$PWD/dialogs/settings/settingspage.cpp \
|
$$PWD/dialogs/settings/settingspage.cpp \
|
||||||
$$PWD/dialogs/settings/settingsdialog.cpp \
|
$$PWD/dialogs/settings/settingsdialog.cpp \
|
||||||
@ -138,6 +139,7 @@ HEADERS += \
|
|||||||
$$PWD/dialogs/settings/markdowneditorpage.h \
|
$$PWD/dialogs/settings/markdowneditorpage.h \
|
||||||
$$PWD/dialogs/settings/miscpage.h \
|
$$PWD/dialogs/settings/miscpage.h \
|
||||||
$$PWD/dialogs/settings/newimagehostdialog.h \
|
$$PWD/dialogs/settings/newimagehostdialog.h \
|
||||||
|
$$PWD/dialogs/settings/notemanagementpage.h \
|
||||||
$$PWD/dialogs/settings/quickaccesspage.h \
|
$$PWD/dialogs/settings/quickaccesspage.h \
|
||||||
$$PWD/dialogs/settings/settingspage.h \
|
$$PWD/dialogs/settings/settingspage.h \
|
||||||
$$PWD/dialogs/settings/settingsdialog.h \
|
$$PWD/dialogs/settings/settingsdialog.h \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user