mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support custom mode to open a note by config note_open_mode
This commit is contained in:
parent
d2ef9608fc
commit
f050d7d814
@ -234,8 +234,18 @@ VReadEditTab::VReadEditTab(QWidget *p_parent)
|
||||
zoomFactorLayout->addWidget(m_customWebZoom);
|
||||
zoomFactorLayout->addWidget(m_webZoomFactorSpin);
|
||||
|
||||
// Default note open mode.
|
||||
m_openModeCombo = new QComboBox();
|
||||
m_openModeCombo->setToolTip(tr("Default mode to open a note"));
|
||||
m_openModeCombo->addItem(tr("Read Mode"), (int)OpenFileMode::Read);
|
||||
m_openModeCombo->addItem(tr("Edit Mode"), (int)OpenFileMode::Edit);
|
||||
|
||||
QLabel *openModeLabel = new QLabel(tr("Note open mode:"));
|
||||
openModeLabel->setToolTip(m_openModeCombo->toolTip());
|
||||
|
||||
QFormLayout *readLayout = new QFormLayout();
|
||||
readLayout->addRow(zoomFactorLayout);
|
||||
readLayout->addRow(openModeLabel, m_openModeCombo);
|
||||
|
||||
m_readBox->setLayout(readLayout);
|
||||
|
||||
@ -251,6 +261,11 @@ bool VReadEditTab::loadConfiguration()
|
||||
if (!loadWebZoomFactor()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loadOpenMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -259,6 +274,11 @@ bool VReadEditTab::saveConfiguration()
|
||||
if (!saveWebZoomFactor()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!saveOpenMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -295,6 +315,29 @@ void VReadEditTab::customWebZoomChanged(int p_state)
|
||||
m_webZoomFactorSpin->setEnabled(p_state == Qt::Checked);
|
||||
}
|
||||
|
||||
bool VReadEditTab::loadOpenMode()
|
||||
{
|
||||
int mode = (int)g_config->getNoteOpenMode();
|
||||
bool found = false;
|
||||
for (int i = 0; i < m_openModeCombo->count(); ++i) {
|
||||
if (m_openModeCombo->itemData(i).toInt() == mode) {
|
||||
m_openModeCombo->setCurrentIndex(i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Q_ASSERT(found);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VReadEditTab::saveOpenMode()
|
||||
{
|
||||
int mode = m_openModeCombo->currentData().toInt();
|
||||
g_config->setNoteOpenMode((OpenFileMode)mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
|
||||
: QWidget(p_parent)
|
||||
{
|
||||
|
@ -52,12 +52,18 @@ public:
|
||||
QCheckBox *m_customWebZoom;
|
||||
QDoubleSpinBox *m_webZoomFactorSpin;
|
||||
|
||||
// Default note open mode for markdown.
|
||||
QComboBox *m_openModeCombo;
|
||||
|
||||
private slots:
|
||||
void customWebZoomChanged(int p_state);
|
||||
|
||||
private:
|
||||
bool loadWebZoomFactor();
|
||||
bool saveWebZoomFactor();
|
||||
|
||||
bool loadOpenMode();
|
||||
bool saveOpenMode();
|
||||
};
|
||||
|
||||
class VNoteManagementTab : public QWidget
|
||||
|
@ -79,6 +79,10 @@ line_distance_height=3
|
||||
; Whether insert the note name as a title when creating a new note
|
||||
insert_title_from_note_name=true
|
||||
|
||||
; Default open mode when opening a note
|
||||
; 0 - Read, 1 - Edit
|
||||
note_open_mode=0
|
||||
|
||||
[session]
|
||||
tools_dock_checked=true
|
||||
|
||||
|
@ -166,6 +166,14 @@ void VConfigManager::initialize()
|
||||
|
||||
m_insertTitleFromNoteName = getConfigFromSettings("global",
|
||||
"insert_title_from_note_name").toBool();
|
||||
|
||||
int openMode = getConfigFromSettings("global",
|
||||
"note_open_mode").toInt();
|
||||
if (openMode == 1) {
|
||||
m_noteOpenMode = OpenFileMode::Edit;
|
||||
} else {
|
||||
m_noteOpenMode = OpenFileMode::Read;
|
||||
}
|
||||
}
|
||||
|
||||
void VConfigManager::readPredefinedColorsFromSettings()
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "vnotebook.h"
|
||||
#include "hgmarkdownhighlighter.h"
|
||||
#include "vmarkdownconverter.h"
|
||||
#include "vconstants.h"
|
||||
|
||||
class QJsonObject;
|
||||
class QString;
|
||||
@ -228,6 +229,9 @@ public:
|
||||
bool getInsertTitleFromNoteName() const;
|
||||
void setInsertTitleFromNoteName(bool p_enabled);
|
||||
|
||||
OpenFileMode getNoteOpenMode() const;
|
||||
void setNoteOpenMode(OpenFileMode p_mode);
|
||||
|
||||
// Return the configured key sequence of @p_operation.
|
||||
// Return empty if there is no corresponding config.
|
||||
QString getShortcutKeySequence(const QString &p_operation) const;
|
||||
@ -462,6 +466,9 @@ private:
|
||||
// Whether insert the note name as a title when creating a new note.
|
||||
bool m_insertTitleFromNoteName;
|
||||
|
||||
// Default mode when opening a note.
|
||||
OpenFileMode m_noteOpenMode;
|
||||
|
||||
// The name of the config file in each directory, obsolete.
|
||||
// Use c_dirConfigFile instead.
|
||||
static const QString c_obsoleteDirConfigFile;
|
||||
@ -1181,4 +1188,20 @@ inline void VConfigManager::setInsertTitleFromNoteName(bool p_enabled)
|
||||
m_insertTitleFromNoteName);
|
||||
}
|
||||
|
||||
inline OpenFileMode VConfigManager::getNoteOpenMode() const
|
||||
{
|
||||
return m_noteOpenMode;
|
||||
}
|
||||
|
||||
inline void VConfigManager::setNoteOpenMode(OpenFileMode p_mode)
|
||||
{
|
||||
if (m_noteOpenMode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_noteOpenMode = p_mode;
|
||||
setConfigToSettings("global", "note_open_mode",
|
||||
m_noteOpenMode == OpenFileMode::Read ? 0 : 1);
|
||||
}
|
||||
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
@ -456,7 +456,7 @@ void VFileList::handleItemClicked(QListWidgetItem *currentItem)
|
||||
|
||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||
fileList->update();
|
||||
emit fileClicked(getVFile(currentItem), OpenFileMode::Read);
|
||||
emit fileClicked(getVFile(currentItem), g_config->getNoteOpenMode());
|
||||
}
|
||||
|
||||
bool VFileList::importFile(const QString &p_srcFilePath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user