mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
move Vim option from menu to settings
This commit is contained in:
parent
4fbe2d87b7
commit
4db6c1cc7b
@ -548,6 +548,21 @@ VReadEditTab::VReadEditTab(QWidget *p_parent)
|
||||
connect(m_autoSave, &QCheckBox::stateChanged,
|
||||
this, &VReadEditTab::showTipsAboutAutoSave);
|
||||
|
||||
// Key mode.
|
||||
m_keyModeCB = VUtils::getComboBox();
|
||||
m_keyModeCB->setToolTip(tr("Choose the key mode in editor"));
|
||||
m_keyModeCB->addItem(tr("Normal"), (int)KeyMode::Normal);
|
||||
m_keyModeCB->addItem(tr("Vim"), (int)KeyMode::Vim);
|
||||
connect(m_keyModeCB, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, [this](int p_index) {
|
||||
int mode = m_keyModeCB->itemData(p_index).toInt();
|
||||
m_smartIM->setVisible(mode == (int)KeyMode::Vim);
|
||||
});
|
||||
|
||||
// Smart IM in Vim.
|
||||
m_smartIM = new QCheckBox(tr("Smart input method in Vim mode"));
|
||||
m_smartIM->setToolTip(tr("Disable input method when leaving Insert mode in Vim mode"));
|
||||
|
||||
// Editor zoom delta.
|
||||
m_editorZoomDeltaSpin = new QSpinBox();
|
||||
m_editorZoomDeltaSpin->setToolTip(tr("Set the zoom delta of the editor font"));
|
||||
@ -563,9 +578,14 @@ VReadEditTab::VReadEditTab(QWidget *p_parent)
|
||||
QFormLayout *editLayout = new QFormLayout();
|
||||
editLayout->addRow(m_swapFile);
|
||||
editLayout->addRow(m_autoSave);
|
||||
editLayout->addRow(tr("Key mode:"), m_keyModeCB);
|
||||
editLayout->addWidget(m_smartIM);
|
||||
editLayout->addRow(tr("Editor zoom delta:"), m_editorZoomDeltaSpin);
|
||||
m_editBox->setLayout(editLayout);
|
||||
|
||||
m_smartIM->hide();
|
||||
m_keyModeCB->setCurrentIndex(0);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout();
|
||||
mainLayout->addWidget(m_readBox);
|
||||
mainLayout->addWidget(m_editBox);
|
||||
@ -606,6 +626,10 @@ bool VReadEditTab::loadConfiguration()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loadKeyMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -631,6 +655,10 @@ bool VReadEditTab::saveConfiguration()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!saveKeyMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -712,6 +740,20 @@ bool VReadEditTab::saveAutoSave()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VReadEditTab::loadKeyMode()
|
||||
{
|
||||
m_keyModeCB->setCurrentIndex(m_keyModeCB->findData((int)g_config->getKeyMode()));
|
||||
m_smartIM->setChecked(g_config->getEnableSmartImInVimMode());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VReadEditTab::saveKeyMode()
|
||||
{
|
||||
g_config->setKeyMode((KeyMode)m_keyModeCB->currentData().toInt());
|
||||
g_config->setEnableSmartImInVimMode(m_smartIM->isChecked());
|
||||
return true;
|
||||
}
|
||||
|
||||
VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
|
||||
: QWidget(p_parent)
|
||||
{
|
||||
|
@ -91,6 +91,9 @@ private:
|
||||
|
||||
void showTipsAboutAutoSave();
|
||||
|
||||
bool loadKeyMode();
|
||||
bool saveKeyMode();
|
||||
|
||||
bool loadFlashAnchor();
|
||||
bool saveFlashAnchor();
|
||||
|
||||
@ -110,6 +113,12 @@ private:
|
||||
// Auto save.
|
||||
QCheckBox *m_autoSave;
|
||||
|
||||
// Key mode.
|
||||
QComboBox *m_keyModeCB;
|
||||
|
||||
// Smart IM in Vim mode.
|
||||
QCheckBox *m_smartIM;
|
||||
|
||||
// Editor zoom delta.
|
||||
QSpinBox *m_editorZoomDeltaSpin;
|
||||
|
||||
|
@ -84,12 +84,6 @@ attachment_folder=_v_attachments
|
||||
; Enable trailing space highlight
|
||||
enable_trailing_space_highlight=true
|
||||
|
||||
; Enable Vim mode in edit mode
|
||||
enable_vim_mode=false
|
||||
|
||||
; Enable smart input method in Vim mode (disable IM in non-Insert modes)
|
||||
enable_smart_im_in_vim_mode=true
|
||||
|
||||
; Display an area besides the editor area to show line number
|
||||
; 0 - None, 1 - Absolute, 2 - Relative, 3 - CodeBlock
|
||||
editor_line_number=1
|
||||
@ -258,6 +252,13 @@ auto_list=true
|
||||
; Auto add block quote marker
|
||||
auto_quote=true
|
||||
|
||||
; 0 - normal mode
|
||||
; 1 - Vim mode
|
||||
key_mode=0
|
||||
|
||||
; Enable smart input method in Vim mode (disable IM in non-Insert modes)
|
||||
enable_smart_im_in_vim_mode=true
|
||||
|
||||
[export]
|
||||
; Path of the wkhtmltopdf tool
|
||||
wkhtmltopdf=wkhtmltopdf
|
||||
|
@ -93,12 +93,6 @@ void VConfigManager::initialize()
|
||||
m_highlightSelectedWord = getConfigFromSettings("global", "highlight_selected_word").toBool();
|
||||
m_highlightSearchedWord = getConfigFromSettings("global", "highlight_searched_word").toBool();
|
||||
|
||||
m_autoIndent = getConfigFromSettings("editor", "auto_indent").toBool();
|
||||
|
||||
m_autoList = getConfigFromSettings("editor", "auto_list").toBool();
|
||||
|
||||
m_autoQuote = getConfigFromSettings("editor", "auto_quote").toBool();
|
||||
|
||||
readCustomColors();
|
||||
|
||||
curBackgroundColor = getConfigFromSettings("global", "current_background_color").toString();
|
||||
@ -165,12 +159,6 @@ void VConfigManager::initialize()
|
||||
m_enableTrailingSpaceHighlight = getConfigFromSettings("global",
|
||||
"enable_trailing_space_highlight").toBool();
|
||||
|
||||
m_enableVimMode = getConfigFromSettings("global",
|
||||
"enable_vim_mode").toBool();
|
||||
|
||||
m_enableSmartImInVimMode = getConfigFromSettings("global",
|
||||
"enable_smart_im_in_vim_mode").toBool();
|
||||
|
||||
m_editorLineNumber = getConfigFromSettings("global",
|
||||
"editor_line_number").toInt();
|
||||
|
||||
@ -319,6 +307,26 @@ void VConfigManager::initialize()
|
||||
|
||||
m_maxNumOfTagLabels = getConfigFromSettings("global",
|
||||
"max_num_of_tag_labels").toInt();
|
||||
|
||||
initEditorConfigs();
|
||||
}
|
||||
|
||||
void VConfigManager::initEditorConfigs()
|
||||
{
|
||||
m_autoIndent = getConfigFromSettings("editor", "auto_indent").toBool();
|
||||
|
||||
m_autoList = getConfigFromSettings("editor", "auto_list").toBool();
|
||||
|
||||
m_autoQuote = getConfigFromSettings("editor", "auto_quote").toBool();
|
||||
|
||||
int keyMode = getConfigFromSettings("editor", "key_mode").toInt();
|
||||
if (keyMode < 0 || keyMode >= (int)KeyMode::Invalid) {
|
||||
keyMode = 0;
|
||||
}
|
||||
m_keyMode = (KeyMode)keyMode;
|
||||
|
||||
m_enableSmartImInVimMode = getConfigFromSettings("editor",
|
||||
"enable_smart_im_in_vim_mode").toBool();
|
||||
}
|
||||
|
||||
void VConfigManager::initSettings()
|
||||
|
@ -52,6 +52,14 @@ enum class HeadingSequenceType
|
||||
Invalid
|
||||
};
|
||||
|
||||
// Editor key mode.
|
||||
enum class KeyMode
|
||||
{
|
||||
Normal = 0,
|
||||
Vim,
|
||||
Invalid
|
||||
};
|
||||
|
||||
|
||||
class VConfigManager : public QObject
|
||||
{
|
||||
@ -60,6 +68,8 @@ public:
|
||||
|
||||
void initialize();
|
||||
|
||||
void initEditorConfigs();
|
||||
|
||||
// Read config from the directory config json file into a QJsonObject.
|
||||
// @path is the directory containing the config json file.
|
||||
static QJsonObject readDirectoryConfig(const QString &path);
|
||||
@ -298,8 +308,10 @@ public:
|
||||
bool getEnableTrailingSpaceHighlight() const;
|
||||
void setEnableTrailingSapceHighlight(bool p_enabled);
|
||||
|
||||
KeyMode getKeyMode() const;
|
||||
void setKeyMode(KeyMode p_mode);
|
||||
|
||||
bool getEnableVimMode() const;
|
||||
void setEnableVimMode(bool p_enabled);
|
||||
|
||||
bool getEnableSmartImInVimMode() const;
|
||||
void setEnableSmartImInVimMode(bool p_enabled);
|
||||
@ -768,8 +780,8 @@ private:
|
||||
// Enable trailing-space highlight.
|
||||
bool m_enableTrailingSpaceHighlight;
|
||||
|
||||
// Enable Vim mode.
|
||||
bool m_enableVimMode;
|
||||
// Editor key mode.
|
||||
KeyMode m_keyMode;
|
||||
|
||||
// Enable smart input method in Vim mode.
|
||||
bool m_enableSmartImInVimMode;
|
||||
@ -1761,20 +1773,24 @@ inline void VConfigManager::setEnableTrailingSapceHighlight(bool p_enabled)
|
||||
m_enableTrailingSpaceHighlight);
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getEnableVimMode() const
|
||||
inline KeyMode VConfigManager::getKeyMode() const
|
||||
{
|
||||
return m_enableVimMode;
|
||||
return m_keyMode;
|
||||
}
|
||||
|
||||
inline void VConfigManager::setEnableVimMode(bool p_enabled)
|
||||
inline void VConfigManager::setKeyMode(KeyMode p_mode)
|
||||
{
|
||||
if (m_enableVimMode == p_enabled) {
|
||||
if (m_keyMode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_enableVimMode = p_enabled;
|
||||
setConfigToSettings("global", "enable_vim_mode",
|
||||
m_enableVimMode);
|
||||
m_keyMode = p_mode;
|
||||
setConfigToSettings("editor", "key_mode", (int)m_keyMode);
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getEnableVimMode() const
|
||||
{
|
||||
return m_keyMode == KeyMode::Vim;
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getEnableSmartImInVimMode() const
|
||||
@ -1789,7 +1805,7 @@ inline void VConfigManager::setEnableSmartImInVimMode(bool p_enabled)
|
||||
}
|
||||
|
||||
m_enableSmartImInVimMode = p_enabled;
|
||||
setConfigToSettings("global", "enable_smart_im_in_vim_mode",
|
||||
setConfigToSettings("editor", "enable_smart_im_in_vim_mode",
|
||||
m_enableSmartImInVimMode);
|
||||
}
|
||||
|
||||
|
@ -1200,22 +1200,6 @@ void VMainWindow::initEditMenu()
|
||||
connect(autoListAct, &QAction::triggered,
|
||||
this, &VMainWindow::changeAutoList);
|
||||
|
||||
// Vim Mode.
|
||||
QAction *vimAct = new QAction(tr("Vim Mode"), this);
|
||||
vimAct->setToolTip(tr("Enable Vim mode for editing (re-open current tabs to make it work)"));
|
||||
vimAct->setCheckable(true);
|
||||
connect(vimAct, &QAction::triggered,
|
||||
this, &VMainWindow::changeVimMode);
|
||||
|
||||
// Smart input method in Vim mode.
|
||||
QAction *smartImAct = new QAction(tr("Smart Input Method In Vim Mode"), this);
|
||||
smartImAct->setToolTip(tr("Disable input method when leaving Insert mode in Vim mode"));
|
||||
smartImAct->setCheckable(true);
|
||||
connect(smartImAct, &QAction::triggered,
|
||||
this, [this](bool p_checked){
|
||||
g_config->setEnableSmartImInVimMode(p_checked);
|
||||
});
|
||||
|
||||
// Highlight current cursor line.
|
||||
QAction *cursorLineAct = new QAction(tr("Highlight Cursor Line"), this);
|
||||
cursorLineAct->setToolTip(tr("Highlight current cursor line"));
|
||||
@ -1296,12 +1280,6 @@ void VMainWindow::initEditMenu()
|
||||
}
|
||||
Q_ASSERT(!(autoListAct->isChecked() && !m_autoIndentAct->isChecked()));
|
||||
|
||||
editMenu->addAction(vimAct);
|
||||
vimAct->setChecked(g_config->getEnableVimMode());
|
||||
|
||||
editMenu->addAction(smartImAct);
|
||||
smartImAct->setChecked(g_config->getEnableSmartImInVimMode());
|
||||
|
||||
editMenu->addSeparator();
|
||||
|
||||
initEditorStyleMenu(editMenu);
|
||||
@ -2409,11 +2387,6 @@ void VMainWindow::changeAutoList(bool p_checked)
|
||||
}
|
||||
}
|
||||
|
||||
void VMainWindow::changeVimMode(bool p_checked)
|
||||
{
|
||||
g_config->setEnableVimMode(p_checked);
|
||||
}
|
||||
|
||||
void VMainWindow::enableCodeBlockHighlight(bool p_checked)
|
||||
{
|
||||
g_config->setEnableCodeBlockHighlight(p_checked);
|
||||
|
@ -162,7 +162,6 @@ private slots:
|
||||
void enableMathjax(bool p_checked);
|
||||
void changeAutoIndent(bool p_checked);
|
||||
void changeAutoList(bool p_checked);
|
||||
void changeVimMode(bool p_checked);
|
||||
void enableCodeBlockHighlight(bool p_checked);
|
||||
void enableImagePreview(bool p_checked);
|
||||
void enableImagePreviewConstraint(bool p_checked);
|
||||
|
Loading…
x
Reference in New Issue
Block a user