mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support edit/read mode
This commit is contained in:
parent
3c64b86297
commit
08c597513c
@ -82,12 +82,16 @@ void CoreConfig::init(const QJsonObject &p_app,
|
|||||||
|
|
||||||
m_perNotebookHistoryEnabled = READBOOL(QStringLiteral("per_notebook_history"));
|
m_perNotebookHistoryEnabled = READBOOL(QStringLiteral("per_notebook_history"));
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto lineEnding = READSTR(QStringLiteral("line_ending"));
|
auto lineEnding = READSTR(QStringLiteral("line_ending"));
|
||||||
m_lineEnding = stringToLineEndingPolicy(lineEnding);
|
m_lineEnding = stringToLineEndingPolicy(lineEnding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto mode = READSTR(QStringLiteral("default_open_mode"));
|
||||||
|
m_defaultOpenMode = stringToViewWindowMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
loadFileTypeSuffixes(appObj, userObj);
|
loadFileTypeSuffixes(appObj, userObj);
|
||||||
|
|
||||||
loadUnitedEntry(appObj, userObj);
|
loadUnitedEntry(appObj, userObj);
|
||||||
@ -109,6 +113,7 @@ QJsonObject CoreConfig::toJson() const
|
|||||||
obj[QStringLiteral("line_ending")] = lineEndingPolicyToString(m_lineEnding);
|
obj[QStringLiteral("line_ending")] = lineEndingPolicyToString(m_lineEnding);
|
||||||
obj[QStringLiteral("file_type_suffixes")] = saveFileTypeSuffixes();
|
obj[QStringLiteral("file_type_suffixes")] = saveFileTypeSuffixes();
|
||||||
obj[QStringLiteral("united_entry")] = saveUnitedEntry();
|
obj[QStringLiteral("united_entry")] = saveUnitedEntry();
|
||||||
|
obj[QStringLiteral("default_open_mode")] = viewWindowModeToString(m_defaultOpenMode);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,3 +367,33 @@ void CoreConfig::setUnitedEntryAlias(const QJsonArray &p_alias)
|
|||||||
{
|
{
|
||||||
updateConfig(m_unitedEntryAlias, p_alias, this);
|
updateConfig(m_unitedEntryAlias, p_alias, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewWindowMode CoreConfig::getDefaultOpenMode() const
|
||||||
|
{
|
||||||
|
return m_defaultOpenMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreConfig::setDefaultOpenMode(ViewWindowMode p_mode)
|
||||||
|
{
|
||||||
|
updateConfig(m_defaultOpenMode, p_mode, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewWindowMode CoreConfig::stringToViewWindowMode(const QString &p_mode)
|
||||||
|
{
|
||||||
|
if (p_mode == "edit") {
|
||||||
|
return ViewWindowMode::Edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ViewWindowMode::Read;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CoreConfig::viewWindowModeToString(ViewWindowMode p_mode)
|
||||||
|
{
|
||||||
|
switch (p_mode) {
|
||||||
|
case ViewWindowMode::Edit:
|
||||||
|
return "edit";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "read";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -146,6 +146,9 @@ namespace vnotex
|
|||||||
const QJsonArray &getUnitedEntryAlias() const;
|
const QJsonArray &getUnitedEntryAlias() const;
|
||||||
void setUnitedEntryAlias(const QJsonArray &p_alias);
|
void setUnitedEntryAlias(const QJsonArray &p_alias);
|
||||||
|
|
||||||
|
ViewWindowMode getDefaultOpenMode() const;
|
||||||
|
void setDefaultOpenMode(ViewWindowMode p_mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MainConfig;
|
friend class MainConfig;
|
||||||
|
|
||||||
@ -163,6 +166,9 @@ namespace vnotex
|
|||||||
|
|
||||||
QJsonObject saveUnitedEntry() const;
|
QJsonObject saveUnitedEntry() const;
|
||||||
|
|
||||||
|
static ViewWindowMode stringToViewWindowMode(const QString &p_mode);
|
||||||
|
static QString viewWindowModeToString(ViewWindowMode p_mode);
|
||||||
|
|
||||||
// Theme name.
|
// Theme name.
|
||||||
QString m_theme;
|
QString m_theme;
|
||||||
|
|
||||||
@ -200,6 +206,8 @@ namespace vnotex
|
|||||||
|
|
||||||
QJsonArray m_unitedEntryAlias;
|
QJsonArray m_unitedEntryAlias;
|
||||||
|
|
||||||
|
ViewWindowMode m_defaultOpenMode = ViewWindowMode::Read;
|
||||||
|
|
||||||
static QStringList s_availableLocales;
|
static QStringList s_availableLocales;
|
||||||
};
|
};
|
||||||
} // ns vnotex
|
} // ns vnotex
|
||||||
|
@ -109,6 +109,8 @@
|
|||||||
"per_notebook_history" : false,
|
"per_notebook_history" : false,
|
||||||
"//comment" : "Line ending policy for config files, platform/lf/crlf/cr",
|
"//comment" : "Line ending policy for config files, platform/lf/crlf/cr",
|
||||||
"line_ending" : "lf",
|
"line_ending" : "lf",
|
||||||
|
"//comment" : "read/edit",
|
||||||
|
"default_open_mode" : "read",
|
||||||
"united_entry" : {
|
"united_entry" : {
|
||||||
"alias" : [
|
"alias" : [
|
||||||
{
|
{
|
||||||
|
@ -47,6 +47,20 @@ void NoteManagementPage::setupUI()
|
|||||||
connect(m_lineEndingComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
connect(m_lineEndingComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
this, &NoteManagementPage::pageIsChanged);
|
this, &NoteManagementPage::pageIsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
m_defaultOpenModeComboBox = WidgetsFactory::createComboBox(this);
|
||||||
|
m_defaultOpenModeComboBox->setToolTip(tr("Default mode when opening notes"));
|
||||||
|
|
||||||
|
m_defaultOpenModeComboBox->addItem(tr("Read"), (int)ViewWindowMode::Read);
|
||||||
|
m_defaultOpenModeComboBox->addItem(tr("Edit"), (int)ViewWindowMode::Edit);
|
||||||
|
|
||||||
|
const QString label(tr("Default open mode:"));
|
||||||
|
mainLayout->addRow(label, m_defaultOpenModeComboBox);
|
||||||
|
addSearchItem(label, m_defaultOpenModeComboBox->toolTip(), m_defaultOpenModeComboBox);
|
||||||
|
connect(m_defaultOpenModeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
|
this, &NoteManagementPage::pageIsChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoteManagementPage::loadInternal()
|
void NoteManagementPage::loadInternal()
|
||||||
@ -62,6 +76,14 @@ void NoteManagementPage::loadInternal()
|
|||||||
}
|
}
|
||||||
m_lineEndingComboBox->setCurrentIndex(idx);
|
m_lineEndingComboBox->setCurrentIndex(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int idx = m_defaultOpenModeComboBox->findData(static_cast<int>(coreConfig.getDefaultOpenMode()));
|
||||||
|
if (idx == -1) {
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
|
m_defaultOpenModeComboBox->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NoteManagementPage::saveInternal()
|
bool NoteManagementPage::saveInternal()
|
||||||
@ -75,6 +97,11 @@ bool NoteManagementPage::saveInternal()
|
|||||||
coreConfig.setLineEndingPolicy(static_cast<LineEndingPolicy>(ending));
|
coreConfig.setLineEndingPolicy(static_cast<LineEndingPolicy>(ending));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto mode = m_defaultOpenModeComboBox->currentData().toInt();
|
||||||
|
coreConfig.setDefaultOpenMode(static_cast<ViewWindowMode>(mode));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ namespace vnotex
|
|||||||
QCheckBox *m_perNotebookHistoryCheckBox = nullptr;
|
QCheckBox *m_perNotebookHistoryCheckBox = nullptr;
|
||||||
|
|
||||||
QComboBox *m_lineEndingComboBox = nullptr;
|
QComboBox *m_lineEndingComboBox = nullptr;
|
||||||
|
|
||||||
|
QComboBox *m_defaultOpenModeComboBox = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,23 +291,32 @@ void NotebookNodeExplorer::activateItemNode(const NodeData &p_data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
||||||
|
auto defaultMode = coreConfig.getDefaultOpenMode();
|
||||||
|
|
||||||
if (p_data.isNode()) {
|
if (p_data.isNode()) {
|
||||||
if (checkInvalidNode(p_data.getNode())) {
|
if (checkInvalidNode(p_data.getNode())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit nodeActivated(p_data.getNode(), QSharedPointer<FileOpenParameters>::create());
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_mode = defaultMode;
|
||||||
|
emit nodeActivated(p_data.getNode(), paras);
|
||||||
} else if (p_data.isExternalNode()) {
|
} else if (p_data.isExternalNode()) {
|
||||||
// Import to config first.
|
// Import to config first.
|
||||||
if (m_autoImportExternalFiles) {
|
if (m_autoImportExternalFiles) {
|
||||||
auto importedNode = importToIndex(p_data.getExternalNode());
|
auto importedNode = importToIndex(p_data.getExternalNode());
|
||||||
if (importedNode) {
|
if (importedNode) {
|
||||||
emit nodeActivated(importedNode.data(), QSharedPointer<FileOpenParameters>::create());
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_mode = defaultMode;
|
||||||
|
emit nodeActivated(importedNode.data(), paras);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just open it.
|
// Just open it.
|
||||||
emit fileActivated(p_data.getExternalNode()->fetchAbsolutePath(), QSharedPointer<FileOpenParameters>::create());
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_mode = defaultMode;
|
||||||
|
emit fileActivated(p_data.getExternalNode()->fetchAbsolutePath(), paras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,7 +955,9 @@ void NotebookNodeExplorer::createContextMenuOnNode(QMenu *p_menu, const Node *p_
|
|||||||
{
|
{
|
||||||
const int selectedSize = p_master ? m_masterExplorer->selectedItems().size() : m_slaveExplorer->selectedItems().size();
|
const int selectedSize = p_master ? m_masterExplorer->selectedItems().size() : m_slaveExplorer->selectedItems().size();
|
||||||
|
|
||||||
createAndAddAction(Action::Open, p_menu, p_master);
|
createAndAddAction(Action::Edit, p_menu, p_master);
|
||||||
|
|
||||||
|
createAndAddAction(Action::Read, p_menu, p_master);
|
||||||
|
|
||||||
addOpenWithMenu(p_menu, p_master);
|
addOpenWithMenu(p_menu, p_master);
|
||||||
|
|
||||||
@ -1009,7 +1020,9 @@ void NotebookNodeExplorer::createContextMenuOnExternalNode(QMenu *p_menu, const
|
|||||||
|
|
||||||
const int selectedSize = p_master ? m_masterExplorer->selectedItems().size() : m_slaveExplorer->selectedItems().size();
|
const int selectedSize = p_master ? m_masterExplorer->selectedItems().size() : m_slaveExplorer->selectedItems().size();
|
||||||
|
|
||||||
createAndAddAction(Action::Open, p_menu, p_master);
|
createAndAddAction(Action::Edit, p_menu, p_master);
|
||||||
|
|
||||||
|
createAndAddAction(Action::Read, p_menu, p_master);
|
||||||
|
|
||||||
addOpenWithMenu(p_menu, p_master);
|
addOpenWithMenu(p_menu, p_master);
|
||||||
|
|
||||||
@ -1194,7 +1207,7 @@ QAction *NotebookNodeExplorer::createAction(Action p_act, QObject *p_parent, boo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Action::RemoveFromConfig:
|
case Action::RemoveFromConfig:
|
||||||
act = new QAction(tr("&Remove From Index"), p_parent);
|
act = new QAction(tr("Remo&ve From Index"), p_parent);
|
||||||
connect(act, &QAction::triggered,
|
connect(act, &QAction::triggered,
|
||||||
this, [this, p_master]() {
|
this, [this, p_master]() {
|
||||||
removeSelectedNodesFromConfig(p_master);
|
removeSelectedNodesFromConfig(p_master);
|
||||||
@ -1247,6 +1260,8 @@ QAction *NotebookNodeExplorer::createAction(Action p_act, QObject *p_parent, boo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Action::Open:
|
case Action::Open:
|
||||||
|
// Use Edit and Read instead.
|
||||||
|
Q_ASSERT(false);
|
||||||
act = new QAction(tr("&Open"), p_parent);
|
act = new QAction(tr("&Open"), p_parent);
|
||||||
connect(act, &QAction::triggered,
|
connect(act, &QAction::triggered,
|
||||||
this, [this, p_master]() {
|
this, [this, p_master]() {
|
||||||
@ -1271,8 +1286,44 @@ QAction *NotebookNodeExplorer::createAction(Action p_act, QObject *p_parent, boo
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Action::Edit:
|
||||||
|
Q_FALLTHROUGH();
|
||||||
|
case Action::Read:
|
||||||
|
{
|
||||||
|
const bool isEdit = p_act == Action::Edit;
|
||||||
|
act = new QAction(isEdit ? tr("&Edit") : tr("&Read"), p_parent);
|
||||||
|
connect(act, &QAction::triggered,
|
||||||
|
this, [this, p_master, isEdit]() {
|
||||||
|
// Support nodes and external nodes.
|
||||||
|
// Do nothing for folders.
|
||||||
|
auto selectedNodes = p_master ? getMasterSelectedNodesAndExternalNodes() : getSlaveSelectedNodesAndExternalNodes();
|
||||||
|
for (const auto &externalNode : selectedNodes.second) {
|
||||||
|
if (!externalNode->isFolder()) {
|
||||||
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_mode = isEdit ? ViewWindowMode::Edit : ViewWindowMode::Read;
|
||||||
|
paras->m_forceMode = true;
|
||||||
|
emit fileActivated(externalNode->fetchAbsolutePath(), paras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &node : selectedNodes.first) {
|
||||||
|
if (checkInvalidNode(node)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node->hasContent()) {
|
||||||
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_mode = isEdit ? ViewWindowMode::Edit : ViewWindowMode::Read;
|
||||||
|
paras->m_forceMode = true;
|
||||||
|
emit nodeActivated(node, paras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Action::ExpandAll:
|
case Action::ExpandAll:
|
||||||
act = new QAction(tr("&Expand All\t*"), p_parent);
|
act = new QAction(tr("E&xpand All\t*"), p_parent);
|
||||||
connect(act, &QAction::triggered,
|
connect(act, &QAction::triggered,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
auto item = m_masterExplorer->currentItem();
|
auto item = m_masterExplorer->currentItem();
|
||||||
|
@ -160,6 +160,8 @@ namespace vnotex
|
|||||||
ReloadIndex,
|
ReloadIndex,
|
||||||
ImportToConfig,
|
ImportToConfig,
|
||||||
Open,
|
Open,
|
||||||
|
Edit,
|
||||||
|
Read,
|
||||||
ExpandAll,
|
ExpandAll,
|
||||||
PinToQuickAccess,
|
PinToQuickAccess,
|
||||||
Tag
|
Tag
|
||||||
|
Loading…
x
Reference in New Issue
Block a user