Browse Source

add config enable_smart_table to control whether format tables automatically

Le Tan 6 years ago
parent
commit
e06ce87710
5 changed files with 43 additions and 1 deletions
  1. 3 0
      src/resources/vnote.ini
  2. 2 0
      src/vconfigmanager.cpp
  3. 21 0
      src/vconfigmanager.h
  4. 11 0
      src/vmainwindow.cpp
  5. 6 1
      src/vtablehelper.cpp

+ 3 - 0
src/resources/vnote.ini

@@ -324,6 +324,9 @@ auto_scroll_cursor_line=1
 ; Editor font family to override the value set by the style
 editor_font_family=
 
+; Whether enable smart table
+enable_smart_table=true
+
 [export]
 ; Path of the wkhtmltopdf tool
 wkhtmltopdf=wkhtmltopdf

+ 2 - 0
src/vconfigmanager.cpp

@@ -371,6 +371,8 @@ void VConfigManager::initEditorConfigs()
     m_autoScrollCursorLine = getConfigFromSettings(section, "auto_scroll_cursor_line").toInt();
 
     m_editorFontFamily = getConfigFromSettings(section, "editor_font_family").toString();
+
+    m_enableSmartTable = getConfigFromSettings(section, "enable_smart_table").toBool();
 }
 
 void VConfigManager::initMarkdownConfigs()

+ 21 - 0
src/vconfigmanager.h

@@ -628,6 +628,9 @@ public:
     bool getPrependDotInRelativePath() const;
     void setPrependDotInRelativePath(bool p_enabled);
 
+    bool getEnableSmartTable() const;
+    void setEnableSmartTable(bool p_enabled);
+
 private:
     void initEditorConfigs();
 
@@ -1112,6 +1115,9 @@ private:
     // Whether prepend a dot in the relative path of images and attachments.
     bool m_prependDotInRelativePath;
 
+    // Whether enable smart table.
+    bool m_enableSmartTable;
+
     // The name of the config file in each directory.
     static const QString c_dirConfigFile;
 
@@ -2898,4 +2904,19 @@ inline void VConfigManager::setPrependDotInRelativePath(bool p_enabled)
     m_prependDotInRelativePath = p_enabled;
     setConfigToSettings("markdown", "prepend_dot_in_relative_path", m_prependDotInRelativePath);
 }
+
+inline bool VConfigManager::getEnableSmartTable() const
+{
+    return m_enableSmartTable;
+}
+
+inline void VConfigManager::setEnableSmartTable(bool p_enabled)
+{
+    if (m_enableSmartTable == p_enabled) {
+        return;
+    }
+
+    m_enableSmartTable = p_enabled;
+    setConfigToSettings("editor", "enable_smart_table", m_enableSmartTable);
+}
 #endif // VCONFIGMANAGER_H

+ 11 - 0
src/vmainwindow.cpp

@@ -1322,6 +1322,17 @@ void VMainWindow::initEditMenu()
     tabAct->setChecked(g_config->getEnableTabHighlight());
 
     initAutoScrollCursorLineMenu(editMenu);
+
+    // Smart table.
+    QAction *smartTableAct = new QAction(tr("Smart Table"), this);
+    smartTableAct->setToolTip(tr("Format table automatically"));
+    smartTableAct->setCheckable(true);
+    connect(smartTableAct, &QAction::triggered,
+            this, [](bool p_checked) {
+                g_config->setEnableSmartTable(p_checked);
+            });
+    editMenu->addAction(smartTableAct);
+    smartTableAct->setChecked(g_config->getEnableSmartTable());
 }
 
 void VMainWindow::initDockWindows()

+ 6 - 1
src/vtablehelper.cpp

@@ -1,6 +1,9 @@
 #include "vtablehelper.h"
 
 #include "veditor.h"
+#include "vconfigmanager.h"
+
+extern VConfigManager *g_config;
 
 VTableHelper::VTableHelper(VEditor *p_editor, QObject *p_parent)
     : QObject(p_parent),
@@ -10,7 +13,9 @@ VTableHelper::VTableHelper(VEditor *p_editor, QObject *p_parent)
 
 void VTableHelper::updateTableBlocks(const QVector<VTableBlock> &p_blocks)
 {
-    if (m_editor->isReadOnlyW() || !m_editor->isModified()) {
+    if (m_editor->isReadOnlyW() ||
+        !m_editor->isModified() ||
+        !g_config->getEnableSmartTable()) {
         return;
     }