From e844bf5e401c258c7b3aa781d5d6f6914bf9a334 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 31 Mar 2018 21:07:55 +0800 Subject: [PATCH] UniversalEntry: add more shortcuts - Ctrl+R to go to parent item in tree widget; - Ctrl+T to expand or collapse an tree item; --- src/iuniversalentry.h | 16 +++++++++++++++- src/voutlineue.cpp | 30 +++++++++++++++++++++++++----- src/voutlineue.h | 4 +++- src/vsearchue.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/vsearchue.h | 4 ++++ src/vtreewidget.cpp | 11 +++++++++++ src/vtreewidget.h | 2 ++ src/vuniversalentry.cpp | 28 +++++++++++++++++++++++++++- 8 files changed, 125 insertions(+), 8 deletions(-) diff --git a/src/iuniversalentry.h b/src/iuniversalentry.h index e4a848b4..9798974d 100644 --- a/src/iuniversalentry.h +++ b/src/iuniversalentry.h @@ -54,11 +54,25 @@ public: // Select next item. virtual void selectNextItem(int p_id, bool p_forward) = 0; + // Select parent item. + virtual void selectParentItem(int p_id) + { + Q_UNUSED(p_id); + } + // Activate current item. virtual void activate(int p_id) = 0; // Ask the UE to stop asynchronously. - virtual void askToStop(int p_id) = 0; + virtual void askToStop(int p_id) + { + Q_UNUSED(p_id); + } + + virtual void toggleItemExpanded(int p_id) + { + Q_UNUSED(p_id); + } void setWidgetParent(QWidget *p_parent) { diff --git a/src/voutlineue.cpp b/src/voutlineue.cpp index 3310ebc0..c360d7a3 100644 --- a/src/voutlineue.cpp +++ b/src/voutlineue.cpp @@ -89,6 +89,12 @@ void VOutlineUE::processCommand(int p_id, const QString &p_cmd) if (tab) { const VTableOfContent &outline = tab->getOutline(); VOutline::updateTreeFromOutline(m_treeWidget, outline); + + // expandAll() has some bugs with the first item. Fix it. + if (m_treeWidget->topLevelItemCount() > 0) { + m_treeWidget->topLevelItem(0)->setExpanded(true); + } + m_treeWidget->expandAll(); const VHeaderPointer &header = tab->getCurrentHeader(); @@ -194,11 +200,6 @@ void VOutlineUE::activate(int p_id) } } -void VOutlineUE::askToStop(int p_id) -{ - Q_UNUSED(p_id); -} - void VOutlineUE::activateItem(QListWidgetItem *p_item) { if (!p_item) { @@ -232,3 +233,22 @@ void VOutlineUE::activateItem(QTreeWidgetItem *p_item, int p_col) g_mainWin->getEditArea()->scrollToHeader(hp); } } + +void VOutlineUE::selectParentItem(int p_id) +{ + Q_UNUSED(p_id); + if (m_listOutline) { + m_treeWidget->selectParentItem(); + } +} + +void VOutlineUE::toggleItemExpanded(int p_id) +{ + Q_UNUSED(p_id); + if (m_listOutline) { + QTreeWidgetItem *item = m_treeWidget->currentItem(); + if (item) { + item->setExpanded(!item->isExpanded()); + } + } +} diff --git a/src/voutlineue.h b/src/voutlineue.h index ca5df845..dba3de78 100644 --- a/src/voutlineue.h +++ b/src/voutlineue.h @@ -29,9 +29,11 @@ public: void selectNextItem(int p_id, bool p_forward) Q_DECL_OVERRIDE; + void selectParentItem(int p_id) Q_DECL_OVERRIDE; + void activate(int p_id) Q_DECL_OVERRIDE; - void askToStop(int p_id) Q_DECL_OVERRIDE; + void toggleItemExpanded(int p_id) Q_DECL_OVERRIDE; protected: void init() Q_DECL_OVERRIDE; diff --git a/src/vsearchue.cpp b/src/vsearchue.cpp index ed0ad298..f61d13a8 100644 --- a/src/vsearchue.cpp +++ b/src/vsearchue.cpp @@ -891,3 +891,41 @@ void VSearchUE::askToStop(int p_id) m_search->stop(); } } + +void VSearchUE::selectParentItem(int p_id) +{ + switch (p_id) { + case ID::Content_Note_AllNotebook: + case ID::Content_Note_CurrentNotebook: + case ID::Content_Note_CurrentFolder: + case ID::Content_Note_Buffer: + case ID::Outline_Note_Buffer: + m_treeWidget->selectParentItem(); + break; + + default: + break; + } +} + +void VSearchUE::toggleItemExpanded(int p_id) +{ + switch (p_id) { + case ID::Content_Note_AllNotebook: + case ID::Content_Note_CurrentNotebook: + case ID::Content_Note_CurrentFolder: + case ID::Content_Note_Buffer: + case ID::Outline_Note_Buffer: + { + QTreeWidgetItem *item = m_treeWidget->currentItem(); + if (item) { + item->setExpanded(!item->isExpanded()); + } + + break; + } + + default: + break; + } +} diff --git a/src/vsearchue.h b/src/vsearchue.h index ec3ecb78..3c5d113e 100644 --- a/src/vsearchue.h +++ b/src/vsearchue.h @@ -69,10 +69,14 @@ public: void selectNextItem(int p_id, bool p_forward) Q_DECL_OVERRIDE; + void selectParentItem(int p_id) Q_DECL_OVERRIDE; + void activate(int p_id) Q_DECL_OVERRIDE; void askToStop(int p_id) Q_DECL_OVERRIDE; + void toggleItemExpanded(int p_id) Q_DECL_OVERRIDE; + protected: void init() Q_DECL_OVERRIDE; diff --git a/src/vtreewidget.cpp b/src/vtreewidget.cpp index 3690c72d..aec84fe1 100644 --- a/src/vtreewidget.cpp +++ b/src/vtreewidget.cpp @@ -324,3 +324,14 @@ QTreeWidgetItem *VTreeWidget::nextItem(QTreeWidgetItem *p_item, bool p_forward) return nItem; } + +void VTreeWidget::selectParentItem() +{ + QTreeWidgetItem *item = currentItem(); + if (item) { + QTreeWidgetItem *pitem = item->parent(); + if (pitem) { + setCurrentItem(pitem); + } + } +} diff --git a/src/vtreewidget.h b/src/vtreewidget.h index 2972cfcc..72a95a3b 100644 --- a/src/vtreewidget.h +++ b/src/vtreewidget.h @@ -39,6 +39,8 @@ public: virtual void selectNextItem(bool p_forward) Q_DECL_OVERRIDE; + virtual void selectParentItem(); + void setFitContent(bool p_enabled); protected: diff --git a/src/vuniversalentry.cpp b/src/vuniversalentry.cpp index d55653ff..5c27ce7e 100644 --- a/src/vuniversalentry.cpp +++ b/src/vuniversalentry.cpp @@ -311,8 +311,9 @@ void VUniversalEntry::keyPressEvent(QKeyEvent *p_event) m_cmdTimer->stop(); m_cmdEdit->setText(cmd.left(1)); processCommand(); - return; } + + return; } break; @@ -324,6 +325,31 @@ void VUniversalEntry::keyPressEvent(QKeyEvent *p_event) if (m_lastEntry) { m_lastEntry->m_entry->askToStop(m_lastEntry->m_id); } + + return; + } + + break; + + case Qt::Key_R: + if (VUtils::isControlModifierForVim(modifiers)) { + // Ctrl+R to go up a level. + if (m_lastEntry) { + m_lastEntry->m_entry->selectParentItem(m_lastEntry->m_id); + } + + return; + } + + break; + + case Qt::Key_T: + if (VUtils::isControlModifierForVim(modifiers)) { + // Ctrl+T to expand or collapse an item. + if (m_lastEntry) { + m_lastEntry->m_entry->toggleItemExpanded(m_lastEntry->m_id); + } + return; }