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)
{
static bool secondKey = false;
setupUI();
return VNavigationMode::handleKeyNavigation(m_itemList,
secondKey,
p_key,
p_succeed);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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()

View File

@ -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);
}

View File

@ -13,6 +13,7 @@
extern VNote *g_vnote;
VNavigationMode::VNavigationMode()
: m_isSecondKey(false)
{
}
@ -118,15 +119,14 @@ QList<QTreeWidgetItem *> 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;

View File

@ -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<QChar, void *> m_keyMap;
bool m_isSecondKey;
QVector<QLabel *> 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);
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;