From 4668bd581a3dd484dd105201f57316eea7fe6240 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 26 Sep 2017 21:30:35 +0800 Subject: [PATCH] double click on a tab to close it Add configuration double_click_close_tab. --- src/resources/vnote.ini | 3 +++ src/vconfigmanager.cpp | 3 +++ src/vconfigmanager.h | 10 ++++++++++ src/veditwindow.cpp | 11 +++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 70c080b8..9907d03d 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -122,6 +122,9 @@ confirm_images_clean_up=true ; Confirm before reloading folder from disk confirm_reload_folder=true +; Whether double click on a tab to close it +double_click_close_tab=true + [web] ; Location and configuration for Mathjax mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 32c06aec..a085f820 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -219,6 +219,9 @@ void VConfigManager::initialize() m_mathjaxJavascript = getConfigFromSettings("web", "mathjax_javascript").toString(); + + m_doubleClickCloseTab = getConfigFromSettings("global", + "double_click_close_tab").toBool(); } void VConfigManager::readPredefinedColorsFromSettings() diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 88a943d6..a767c956 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -281,6 +281,8 @@ public: const QString &getMathjaxJavascript() const; + bool getDoubleClickCloseTab() const; + // Return the configured key sequence of @p_operation. // Return empty if there is no corresponding config. QString getShortcutKeySequence(const QString &p_operation) const; @@ -567,6 +569,9 @@ private: // Location and configuration for Mathjax. QString m_mathjaxJavascript; + // Whether double click on a tab to close it. + bool m_doubleClickCloseTab; + // The name of the config file in each directory, obsolete. // Use c_dirConfigFile instead. static const QString c_obsoleteDirConfigFile; @@ -1488,4 +1493,9 @@ inline const QString &VConfigManager::getMathjaxJavascript() const return m_mathjaxJavascript; } +inline bool VConfigManager::getDoubleClickCloseTab() const +{ + return m_doubleClickCloseTab; +} + #endif // VCONFIGMANAGER_H diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index 2f692013..857a2606 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -11,8 +11,10 @@ #include "vmdtab.h" #include "vhtmltab.h" #include "vfilelist.h" +#include "vconfigmanager.h" extern VNote *g_vnote; +extern VConfigManager *g_config; VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) : QTabWidget(parent), vnote(vnote), m_editArea(editArea), @@ -38,6 +40,14 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) this, &VEditWindow::closeTab); connect(this, &VEditWindow::tabBarClicked, this, &VEditWindow::handleTabbarClicked); + + connect(this, &VEditWindow::tabBarDoubleClicked, + this, [this](int p_index) { + if (p_index != -1 && g_config->getDoubleClickCloseTab()) { + closeTab(p_index); + } + }); + connect(this, &VEditWindow::currentChanged, this, &VEditWindow::handleCurrentIndexChanged); connect(this, &VEditWindow::customContextMenuRequested, @@ -548,6 +558,7 @@ void VEditWindow::handleCurrentIndexChanged(int p_index) if (wid && (wid == m_curTabWidget)) { return; } + m_lastTabWidget = m_curTabWidget; m_curTabWidget = wid; }