Browse Source

Settings: add item to config single click's behavior in notes list

Le Tan 7 years ago
parent
commit
f733ce45db
5 changed files with 58 additions and 4 deletions
  1. 26 0
      src/dialog/vsettingsdialog.cpp
  2. 6 0
      src/dialog/vsettingsdialog.h
  3. 3 2
      src/resources/vnote.ini
  4. 11 0
      src/vconfigmanager.h
  5. 12 2
      src/vfilelist.cpp

+ 26 - 0
src/dialog/vsettingsdialog.cpp

@@ -657,9 +657,15 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
     attachmentFolderLayout->addWidget(m_customAttachmentFolder);
     attachmentFolderLayout->addWidget(m_attachmentFolderEdit);
 
+    // Single click open.
+    m_singleClickOpen = new QCheckBox(tr("Single click to open a note in current tab"), this);
+    m_singleClickOpen->setToolTip(tr("Single click a note in the notes list to open it in current tab, "
+                                     "double click to open it in a new tab"));
+
     QFormLayout *noteLayout = new QFormLayout();
     noteLayout->addRow(imageFolderLayout);
     noteLayout->addRow(attachmentFolderLayout);
+    noteLayout->addRow(m_singleClickOpen);
     m_noteBox->setLayout(noteLayout);
 
     // External File.
@@ -706,6 +712,10 @@ bool VNoteManagementTab::loadConfiguration()
         return false;
     }
 
+    if (!loadSingleClickOpen()) {
+        return false;
+    }
+
     return true;
 }
 
@@ -723,6 +733,10 @@ bool VNoteManagementTab::saveConfiguration()
         return false;
     }
 
+    if (!saveSingleClickOpen()) {
+        return false;
+    }
+
     return true;
 }
 
@@ -825,6 +839,18 @@ void VNoteManagementTab::customImageFolderExtChanged(int p_state)
     }
 }
 
+bool VNoteManagementTab::loadSingleClickOpen()
+{
+    m_singleClickOpen->setChecked(g_config->getSingleClickClosePreviousTab());
+    return true;
+}
+
+bool VNoteManagementTab::saveSingleClickOpen()
+{
+    g_config->setSingleClickClosePreviousTab(m_singleClickOpen->isChecked());
+    return true;
+}
+
 VMarkdownTab::VMarkdownTab(QWidget *p_parent)
     : QWidget(p_parent)
 {

+ 6 - 0
src/dialog/vsettingsdialog.h

@@ -117,6 +117,9 @@ private:
     bool loadAttachmentFolder();
     bool saveAttachmentFolder();
 
+    bool loadSingleClickOpen();
+    bool saveSingleClickOpen();
+
     QGroupBox *m_noteBox;
     QGroupBox *m_externalBox;
 
@@ -131,6 +134,9 @@ private:
     // Attachment folder.
     QCheckBox *m_customAttachmentFolder;
     VLineEdit *m_attachmentFolderEdit;
+
+    // Single click to open note in current tab.
+    QCheckBox *m_singleClickOpen;
 };
 
 class VMarkdownTab : public QWidget

+ 3 - 2
src/resources/vnote.ini

@@ -35,7 +35,8 @@ language=System
 markdown_converter=2
 
 enable_mermaid=false
-enable_mathjax=false
+
+enable_mathjax=true
 
 ; Enable flowchart.js
 enable_flowchart=false
@@ -191,7 +192,7 @@ close_before_external_editor=true
 custom_colors=White:#FFFFFF,LightGrey:#EEEEEE
 
 ; Single click to open a file then close previous tab
-single_click_close_previous_tab=true
+single_click_close_previous_tab=false
 
 ; Whether enable auto wildcard match in simple search like list and tree widgets
 enable_wildcard_in_simple_search=true

+ 11 - 0
src/vconfigmanager.h

@@ -438,6 +438,7 @@ public:
     void setMenuBarChecked(bool p_checked);
 
     bool getSingleClickClosePreviousTab() const;
+    void setSingleClickClosePreviousTab(bool p_enabled);
 
     bool getEnableWildCardInSimpleSearch() const;
 
@@ -2063,6 +2064,16 @@ inline bool VConfigManager::getSingleClickClosePreviousTab() const
     return m_singleClickClosePreviousTab;
 }
 
+inline void VConfigManager::setSingleClickClosePreviousTab(bool p_enabled)
+{
+    if (m_singleClickClosePreviousTab == p_enabled) {
+        return;
+    }
+
+    m_singleClickClosePreviousTab = p_enabled;
+    setConfigToSettings("global", "single_click_close_previous_tab", m_singleClickClosePreviousTab);
+}
+
 inline bool VConfigManager::getEnableWildCardInSimpleSearch() const
 {
     return getConfigFromSettings("global",

+ 12 - 2
src/vfilelist.cpp

@@ -935,11 +935,15 @@ void VFileList::pasteFiles(VDirectory *p_destDir,
 
 void VFileList::keyPressEvent(QKeyEvent *p_event)
 {
-    if (p_event->key() == Qt::Key_Return) {
+    switch (p_event->key()) {
+    case Qt::Key_Enter:
+    case Qt::Key_Return:
+    {
         QListWidgetItem *item = fileList->currentItem();
         if (item) {
             VFile *fileToClose = NULL;
-            if (!(p_event->modifiers() & Qt::ControlModifier)) {
+            if (!(p_event->modifiers() & Qt::ControlModifier)
+                && g_config->getSingleClickClosePreviousTab()) {
                 VFile *file = getVFile(item);
                 Q_ASSERT(file);
                 if (!editArea->isFileOpened(file)) {
@@ -956,6 +960,12 @@ void VFileList::keyPressEvent(QKeyEvent *p_event)
                 editArea->closeFile(fileToClose, false);
             }
         }
+
+        break;
+    }
+
+    default:
+        break;
     }
 
     QWidget::keyPressEvent(p_event);