From 787d54c808046696b9cd5fe584830a74d80f4200 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 30 Nov 2016 23:38:29 +0800 Subject: [PATCH] update tab list menu dynamically when menu show up Signed-off-by: Le Tan --- src/veditwindow.cpp | 7 ++----- src/veditwindow.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index f6dd07d8..5bd0297a 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -61,6 +61,8 @@ void VEditWindow::setupCornerWidget() QMenu *leftMenu = new QMenu(this); leftBtn->setMenu(leftMenu); setCornerWidget(leftBtn, Qt::TopLeftCorner); + connect(leftMenu, &QMenu::aboutToShow, + this, &VEditWindow::updateTabListMenu); } void VEditWindow::splitWindow() @@ -143,7 +145,6 @@ bool VEditWindow::closeFile(const VFile *p_file, bool p_forced) if (ok) { removeEditTab(idx); } - updateTabListMenu(); return ok; } @@ -167,7 +168,6 @@ bool VEditWindow::closeAllFiles(bool p_forced) break; } } - updateTabListMenu(); if (ret) { emit requestRemoveSplit(this); } @@ -187,7 +187,6 @@ int VEditWindow::openFileInTab(VFile *p_file, OpenFileMode p_mode) this, &VEditWindow::handleTabStatusChanged); int idx = appendEditTab(p_file, editor); - updateTabListMenu(); return idx; } @@ -210,7 +209,6 @@ bool VEditWindow::handleTabCloseRequest(int index) if (ok) { removeEditTab(index); } - updateTabListMenu(); noticeStatus(currentIndex()); // User clicks the close button. We should make this window // to be current window. @@ -431,6 +429,5 @@ void VEditWindow::updateFileInfo(const VFile *p_file) int idx = findTabByFile(p_file); if (idx > -1) { noticeStatus(idx); - updateTabListMenu(); } } diff --git a/src/veditwindow.h b/src/veditwindow.h index 39e779f5..eef52462 100644 --- a/src/veditwindow.h +++ b/src/veditwindow.h @@ -59,6 +59,7 @@ private slots: void handleOutlineChanged(const VToc &p_toc); void handleCurHeaderChanged(const VAnchor &p_anchor); void handleTabStatusChanged(); + void updateTabListMenu(); private: void setupCornerWidget(); @@ -68,7 +69,6 @@ private: int openFileInTab(VFile *p_file, OpenFileMode p_mode); inline VEditTab *getTab(int tabIndex) const; void noticeTabStatus(int p_index); - void updateTabListMenu(); void noticeStatus(int index); inline QString generateTooltip(const VFile *p_file) const; inline QString generateTabText(const QString &p_name, bool p_modified) const;