NavigationMode: add m_isSecondKey member

This commit is contained in:
Le Tan 2018-11-22 20:31:56 +08:00
parent 28eb48cc2e
commit 72dcb181cc
12 changed files with 22 additions and 40 deletions

View File

@ -286,11 +286,9 @@ void VCart::showNavigation()
bool VCart::handleKeyNavigation(int p_key, bool &p_succeed) bool VCart::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
setupUI(); setupUI();
return VNavigationMode::handleKeyNavigation(m_itemList, return VNavigationMode::handleKeyNavigation(m_itemList,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -1111,9 +1111,7 @@ void VDirectoryTree::showNavigation()
bool VDirectoryTree::handleKeyNavigation(int p_key, bool &p_succeed) bool VDirectoryTree::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
return VNavigationMode::handleKeyNavigation(this, return VNavigationMode::handleKeyNavigation(this,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -820,12 +820,11 @@ void VEditArea::hideNavigation()
bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed) bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
bool ret = false; bool ret = false;
p_succeed = false; p_succeed = false;
QChar keyChar = VUtils::keyToChar(p_key); QChar keyChar = VUtils::keyToChar(p_key);
if (secondKey && !keyChar.isNull()) { if (m_isSecondKey && !keyChar.isNull()) {
secondKey = false; m_isSecondKey = false;
p_succeed = true; p_succeed = true;
auto it = m_keyMap.find(keyChar); auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) { if (it != m_keyMap.end()) {
@ -838,7 +837,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
if (m_keyMap.isEmpty()) { if (m_keyMap.isEmpty()) {
p_succeed = true; p_succeed = true;
} else { } else {
secondKey = true; m_isSecondKey = true;
} }
ret = true; ret = true;
} }

View File

@ -1130,8 +1130,7 @@ void VFileList::showNavigation()
bool VFileList::handleKeyNavigation(int p_key, bool &p_succeed) bool VFileList::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false; return VNavigationMode::handleKeyNavigation(fileList, p_key, p_succeed);
return VNavigationMode::handleKeyNavigation(fileList, secondKey, p_key, p_succeed);
} }
int VFileList::getNewMagic() int VFileList::getNewMagic()

View File

@ -482,11 +482,9 @@ void VHistoryList::showNavigation()
bool VHistoryList::handleKeyNavigation(int p_key, bool &p_succeed) bool VHistoryList::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
setupUI(); setupUI();
return VNavigationMode::handleKeyNavigation(m_itemList, return VNavigationMode::handleKeyNavigation(m_itemList,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -13,6 +13,7 @@
extern VNote *g_vnote; extern VNote *g_vnote;
VNavigationMode::VNavigationMode() VNavigationMode::VNavigationMode()
: m_isSecondKey(false)
{ {
} }
@ -118,15 +119,14 @@ QList<QTreeWidgetItem *> VNavigationMode::getVisibleItems(const QTreeWidget *p_w
} }
bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget, bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget,
bool &p_secondKey,
int p_key, int p_key,
bool &p_succeed) bool &p_succeed)
{ {
bool ret = false; bool ret = false;
p_succeed = false; p_succeed = false;
QChar keyChar = VUtils::keyToChar(p_key); QChar keyChar = VUtils::keyToChar(p_key);
if (p_secondKey && !keyChar.isNull()) { if (m_isSecondKey && !keyChar.isNull()) {
p_secondKey = false; m_isSecondKey = false;
p_succeed = true; p_succeed = true;
auto it = m_keyMap.find(keyChar); auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) { if (it != m_keyMap.end()) {
@ -141,7 +141,7 @@ bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget,
if (m_keyMap.isEmpty()) { if (m_keyMap.isEmpty()) {
p_succeed = true; p_succeed = true;
} else { } else {
p_secondKey = true; m_isSecondKey = true;
} }
ret = true; ret = true;
@ -175,6 +175,8 @@ void VNavigationMode::showNavigation(QTreeWidget *p_widget)
void VNavigationMode::clearNavigation() void VNavigationMode::clearNavigation()
{ {
m_isSecondKey = false;
m_keyMap.clear(); m_keyMap.clear();
for (auto label : m_naviLabels) { for (auto label : m_naviLabels) {
delete label; delete label;
@ -184,15 +186,14 @@ void VNavigationMode::clearNavigation()
} }
bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget, bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget,
bool &p_secondKey,
int p_key, int p_key,
bool &p_succeed) bool &p_succeed)
{ {
bool ret = false; bool ret = false;
p_succeed = false; p_succeed = false;
QChar keyChar = VUtils::keyToChar(p_key); QChar keyChar = VUtils::keyToChar(p_key);
if (p_secondKey && !keyChar.isNull()) { if (m_isSecondKey && !keyChar.isNull()) {
p_secondKey = false; m_isSecondKey = false;
p_succeed = true; p_succeed = true;
auto it = m_keyMap.find(keyChar); auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) { if (it != m_keyMap.end()) {
@ -206,7 +207,7 @@ bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget,
if (m_keyMap.isEmpty()) { if (m_keyMap.isEmpty()) {
p_succeed = true; p_succeed = true;
} else { } else {
p_secondKey = true; m_isSecondKey = true;
} }
ret = true; ret = true;

View File

@ -38,12 +38,10 @@ protected:
void showNavigation(QTreeWidget *p_widget); void showNavigation(QTreeWidget *p_widget);
bool handleKeyNavigation(QListWidget *p_widget, bool handleKeyNavigation(QListWidget *p_widget,
bool &p_secondKey,
int p_key, int p_key,
bool &p_succeed); bool &p_succeed);
bool handleKeyNavigation(QTreeWidget *p_widget, bool handleKeyNavigation(QTreeWidget *p_widget,
bool &p_secondKey,
int p_key, int p_key,
bool &p_succeed); bool &p_succeed);
@ -52,6 +50,8 @@ protected:
// Map second key to item. // Map second key to item.
QMap<QChar, void *> m_keyMap; QMap<QChar, void *> m_keyMap;
bool m_isSecondKey;
QVector<QLabel *> m_naviLabels; QVector<QLabel *> m_naviLabels;
private: private:
@ -79,10 +79,7 @@ public:
bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE
{ {
static bool secondKey = false;
return VNavigationMode::handleKeyNavigation(m_widget, return VNavigationMode::handleKeyNavigation(m_widget,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -338,13 +338,11 @@ void VOutline::showNavigation()
bool VOutline::handleKeyNavigation(int p_key, bool &p_succeed) bool VOutline::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
bool ret = VNavigationMode::handleKeyNavigation(m_tree, bool ret = VNavigationMode::handleKeyNavigation(m_tree,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
if (ret && p_succeed && !secondKey) { if (ret && p_succeed && !m_isSecondKey) {
g_mainWin->focusEditArea(); g_mainWin->focusEditArea();
} }

View File

@ -582,11 +582,9 @@ void VSearcher::showNavigation()
bool VSearcher::handleKeyNavigation(int p_key, bool &p_succeed) bool VSearcher::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
setupUI(); setupUI();
return VNavigationMode::handleKeyNavigation(m_results, return VNavigationMode::handleKeyNavigation(m_results,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -481,11 +481,9 @@ void VSnippetList::showNavigation()
bool VSnippetList::handleKeyNavigation(int p_key, bool &p_succeed) bool VSnippetList::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
setupUI(); setupUI();
return VNavigationMode::handleKeyNavigation(m_snippetList, return VNavigationMode::handleKeyNavigation(m_snippetList,
secondKey,
p_key, p_key,
p_succeed); p_succeed);
} }

View File

@ -253,12 +253,11 @@ void VTagPanel::showNavigation()
bool VTagPanel::handleKeyNavigation(int p_key, bool &p_succeed) bool VTagPanel::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
bool ret = false; bool ret = false;
p_succeed = false; p_succeed = false;
QChar keyChar = VUtils::keyToChar(p_key); QChar keyChar = VUtils::keyToChar(p_key);
if (secondKey && !keyChar.isNull()) { if (m_isSecondKey && !keyChar.isNull()) {
secondKey = false; m_isSecondKey = false;
p_succeed = true; p_succeed = true;
auto it = m_keyMap.find(keyChar); auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) { if (it != m_keyMap.end()) {
@ -280,7 +279,7 @@ bool VTagPanel::handleKeyNavigation(int p_key, bool &p_succeed)
if (m_keyMap.isEmpty()) { if (m_keyMap.isEmpty()) {
p_succeed = true; p_succeed = true;
} else { } else {
secondKey = true; m_isSecondKey = true;
} }
ret = true; ret = true;

View File

@ -170,12 +170,11 @@ void VToolBox::showNavigation()
bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed) bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed)
{ {
static bool secondKey = false;
bool ret = false; bool ret = false;
p_succeed = false; p_succeed = false;
QChar keyChar = VUtils::keyToChar(p_key); QChar keyChar = VUtils::keyToChar(p_key);
if (secondKey && !keyChar.isNull()) { if (m_isSecondKey && !keyChar.isNull()) {
secondKey = false; m_isSecondKey = false;
p_succeed = true; p_succeed = true;
auto it = m_keyMap.find(keyChar); auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) { if (it != m_keyMap.end()) {
@ -189,7 +188,7 @@ bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed)
if (m_keyMap.isEmpty()) { if (m_keyMap.isEmpty()) {
p_succeed = true; p_succeed = true;
} else { } else {
secondKey = true; m_isSecondKey = true;
} }
ret = true; ret = true;