From 72dcb181cc321a8864e797377300286f3a066d3e Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 22 Nov 2018 20:31:56 +0800 Subject: [PATCH] NavigationMode: add m_isSecondKey member --- src/vcart.cpp | 2 -- src/vdirectorytree.cpp | 2 -- src/veditarea.cpp | 7 +++---- src/vfilelist.cpp | 3 +-- src/vhistorylist.cpp | 2 -- src/vnavigationmode.cpp | 17 +++++++++-------- src/vnavigationmode.h | 7 ++----- src/voutline.cpp | 4 +--- src/vsearcher.cpp | 2 -- src/vsnippetlist.cpp | 2 -- src/vtagpanel.cpp | 7 +++---- src/vtoolbox.cpp | 7 +++---- 12 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/vcart.cpp b/src/vcart.cpp index b6553943..2067ee74 100644 --- a/src/vcart.cpp +++ b/src/vcart.cpp @@ -286,11 +286,9 @@ void VCart::showNavigation() bool VCart::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; setupUI(); return VNavigationMode::handleKeyNavigation(m_itemList, - secondKey, p_key, p_succeed); } diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp index 23a4eb1c..0071880a 100644 --- a/src/vdirectorytree.cpp +++ b/src/vdirectorytree.cpp @@ -1111,9 +1111,7 @@ void VDirectoryTree::showNavigation() bool VDirectoryTree::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; return VNavigationMode::handleKeyNavigation(this, - secondKey, p_key, p_succeed); } diff --git a/src/veditarea.cpp b/src/veditarea.cpp index 54119b56..9ad1864e 100644 --- a/src/veditarea.cpp +++ b/src/veditarea.cpp @@ -820,12 +820,11 @@ void VEditArea::hideNavigation() bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; bool ret = false; p_succeed = false; QChar keyChar = VUtils::keyToChar(p_key); - if (secondKey && !keyChar.isNull()) { - secondKey = false; + if (m_isSecondKey && !keyChar.isNull()) { + m_isSecondKey = false; p_succeed = true; auto it = m_keyMap.find(keyChar); if (it != m_keyMap.end()) { @@ -838,7 +837,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed) if (m_keyMap.isEmpty()) { p_succeed = true; } else { - secondKey = true; + m_isSecondKey = true; } ret = true; } diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index f3d4d81a..bd9742a5 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -1130,8 +1130,7 @@ void VFileList::showNavigation() bool VFileList::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; - return VNavigationMode::handleKeyNavigation(fileList, secondKey, p_key, p_succeed); + return VNavigationMode::handleKeyNavigation(fileList, p_key, p_succeed); } int VFileList::getNewMagic() diff --git a/src/vhistorylist.cpp b/src/vhistorylist.cpp index df155292..d93e7447 100644 --- a/src/vhistorylist.cpp +++ b/src/vhistorylist.cpp @@ -482,11 +482,9 @@ void VHistoryList::showNavigation() bool VHistoryList::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; setupUI(); return VNavigationMode::handleKeyNavigation(m_itemList, - secondKey, p_key, p_succeed); } diff --git a/src/vnavigationmode.cpp b/src/vnavigationmode.cpp index a6764554..86dca465 100644 --- a/src/vnavigationmode.cpp +++ b/src/vnavigationmode.cpp @@ -13,6 +13,7 @@ extern VNote *g_vnote; VNavigationMode::VNavigationMode() + : m_isSecondKey(false) { } @@ -118,15 +119,14 @@ QList VNavigationMode::getVisibleItems(const QTreeWidget *p_w } bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget, - bool &p_secondKey, int p_key, bool &p_succeed) { bool ret = false; p_succeed = false; QChar keyChar = VUtils::keyToChar(p_key); - if (p_secondKey && !keyChar.isNull()) { - p_secondKey = false; + if (m_isSecondKey && !keyChar.isNull()) { + m_isSecondKey = false; p_succeed = true; auto it = m_keyMap.find(keyChar); if (it != m_keyMap.end()) { @@ -141,7 +141,7 @@ bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget, if (m_keyMap.isEmpty()) { p_succeed = true; } else { - p_secondKey = true; + m_isSecondKey = true; } ret = true; @@ -175,6 +175,8 @@ void VNavigationMode::showNavigation(QTreeWidget *p_widget) void VNavigationMode::clearNavigation() { + m_isSecondKey = false; + m_keyMap.clear(); for (auto label : m_naviLabels) { delete label; @@ -184,15 +186,14 @@ void VNavigationMode::clearNavigation() } bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget, - bool &p_secondKey, int p_key, bool &p_succeed) { bool ret = false; p_succeed = false; QChar keyChar = VUtils::keyToChar(p_key); - if (p_secondKey && !keyChar.isNull()) { - p_secondKey = false; + if (m_isSecondKey && !keyChar.isNull()) { + m_isSecondKey = false; p_succeed = true; auto it = m_keyMap.find(keyChar); if (it != m_keyMap.end()) { @@ -206,7 +207,7 @@ bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget, if (m_keyMap.isEmpty()) { p_succeed = true; } else { - p_secondKey = true; + m_isSecondKey = true; } ret = true; diff --git a/src/vnavigationmode.h b/src/vnavigationmode.h index 06c82da5..d23c87cb 100644 --- a/src/vnavigationmode.h +++ b/src/vnavigationmode.h @@ -38,12 +38,10 @@ protected: void showNavigation(QTreeWidget *p_widget); bool handleKeyNavigation(QListWidget *p_widget, - bool &p_secondKey, int p_key, bool &p_succeed); bool handleKeyNavigation(QTreeWidget *p_widget, - bool &p_secondKey, int p_key, bool &p_succeed); @@ -52,6 +50,8 @@ protected: // Map second key to item. QMap m_keyMap; + bool m_isSecondKey; + QVector m_naviLabels; private: @@ -79,10 +79,7 @@ public: bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE { - static bool secondKey = false; - return VNavigationMode::handleKeyNavigation(m_widget, - secondKey, p_key, p_succeed); } diff --git a/src/voutline.cpp b/src/voutline.cpp index 2d61c442..75918b8f 100644 --- a/src/voutline.cpp +++ b/src/voutline.cpp @@ -338,13 +338,11 @@ void VOutline::showNavigation() bool VOutline::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; bool ret = VNavigationMode::handleKeyNavigation(m_tree, - secondKey, p_key, p_succeed); - if (ret && p_succeed && !secondKey) { + if (ret && p_succeed && !m_isSecondKey) { g_mainWin->focusEditArea(); } diff --git a/src/vsearcher.cpp b/src/vsearcher.cpp index d81ca7b4..3fa5891b 100644 --- a/src/vsearcher.cpp +++ b/src/vsearcher.cpp @@ -582,11 +582,9 @@ void VSearcher::showNavigation() bool VSearcher::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; setupUI(); return VNavigationMode::handleKeyNavigation(m_results, - secondKey, p_key, p_succeed); } diff --git a/src/vsnippetlist.cpp b/src/vsnippetlist.cpp index ec09e4d9..1db6a11a 100644 --- a/src/vsnippetlist.cpp +++ b/src/vsnippetlist.cpp @@ -481,11 +481,9 @@ void VSnippetList::showNavigation() bool VSnippetList::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; setupUI(); return VNavigationMode::handleKeyNavigation(m_snippetList, - secondKey, p_key, p_succeed); } diff --git a/src/vtagpanel.cpp b/src/vtagpanel.cpp index b59065c1..55c045d4 100644 --- a/src/vtagpanel.cpp +++ b/src/vtagpanel.cpp @@ -253,12 +253,11 @@ void VTagPanel::showNavigation() bool VTagPanel::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; bool ret = false; p_succeed = false; QChar keyChar = VUtils::keyToChar(p_key); - if (secondKey && !keyChar.isNull()) { - secondKey = false; + if (m_isSecondKey && !keyChar.isNull()) { + m_isSecondKey = false; p_succeed = true; auto it = m_keyMap.find(keyChar); if (it != m_keyMap.end()) { @@ -280,7 +279,7 @@ bool VTagPanel::handleKeyNavigation(int p_key, bool &p_succeed) if (m_keyMap.isEmpty()) { p_succeed = true; } else { - secondKey = true; + m_isSecondKey = true; } ret = true; diff --git a/src/vtoolbox.cpp b/src/vtoolbox.cpp index 59df5991..cf8d75db 100644 --- a/src/vtoolbox.cpp +++ b/src/vtoolbox.cpp @@ -170,12 +170,11 @@ void VToolBox::showNavigation() bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed) { - static bool secondKey = false; bool ret = false; p_succeed = false; QChar keyChar = VUtils::keyToChar(p_key); - if (secondKey && !keyChar.isNull()) { - secondKey = false; + if (m_isSecondKey && !keyChar.isNull()) { + m_isSecondKey = false; p_succeed = true; auto it = m_keyMap.find(keyChar); if (it != m_keyMap.end()) { @@ -189,7 +188,7 @@ bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed) if (m_keyMap.isEmpty()) { p_succeed = true; } else { - secondKey = true; + m_isSecondKey = true; } ret = true;