mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
UniversalEntry: add more shortcuts
- Ctrl+R to go to parent item in tree widget; - Ctrl+T to expand or collapse an tree item;
This commit is contained in:
parent
7de9eab039
commit
e844bf5e40
@ -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)
|
||||
{
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
|
||||
virtual void selectNextItem(bool p_forward) Q_DECL_OVERRIDE;
|
||||
|
||||
virtual void selectParentItem();
|
||||
|
||||
void setFitContent(bool p_enabled);
|
||||
|
||||
protected:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user