From 467fb1edcbc53081de348251cef490ed5002fa3b Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Tue, 5 Apr 2011 11:11:20 -0400 Subject: [PATCH] Restore 'Close Tab' on the tab context menu and the close tabbar button. These 2 options were disabled due to they messed up the menu texts after the fix for bko 185466. The close method via dbus has been disabled as it causes menu issues. Most of patch to fix 'Close Tab' by Albert Astals Cid aacid@kde.org BUG: 267896 CCBUG: 185466 FIXED-IN: 4.6.3 --- src/Session.h | 3 ++- src/ViewContainer.cpp | 21 +++++++-------------- src/ViewContainer.h | 2 +- src/ViewManager.cpp | 13 +++++++++++++ src/ViewManager.h | 2 ++ 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Session.h b/src/Session.h index def9f92e..6f16fe91 100644 --- a/src/Session.h +++ b/src/Session.h @@ -376,7 +376,8 @@ public slots: * then the terminal connection (the pty) is closed and Konsole waits for the * process to exit. */ - Q_SCRIPTABLE void close(); + //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466 + void close(); /** * Changes the session title or other customizable aspects of the terminal diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp index 7df7add4..2e65f315 100644 --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -443,13 +443,11 @@ TabbedViewContainer::TabbedViewContainer(NavigationPosition position , QObject* _closeTabButton->setIcon(KIcon("tab-close")); _closeTabButton->adjustSize(); _closeTabButton->setHidden(true); - _closeTabButton->setEnabled(false); connect( _tabBar , SIGNAL(currentChanged(int)) , this , SLOT(currentTabChanged(int)) ); connect( _tabBar , SIGNAL(tabDoubleClicked(int)) , this , SLOT(tabDoubleClicked(int)) ); connect( _tabBar , SIGNAL(newTabRequest()) , this , SIGNAL(newViewRequest()) ); connect( _tabBar , SIGNAL(wheelDelta(int)) , this , SLOT(wheelScrolled(int)) ); - connect( _tabBar , SIGNAL(tabCloseRequested(int)) , this , SLOT(closeTab(int)) ); connect( _tabBar , SIGNAL(initiateDrag(int)) , this , SLOT(startTabDrag(int)) ); connect( _tabBar, SIGNAL(contextMenu(int, const QPoint&)), this, SLOT(openTabContextMenu(int, const QPoint&)) ); @@ -496,9 +494,9 @@ TabbedViewContainer::TabbedViewContainer(NavigationPosition position , QObject* i18nc("@action:inmenu", "&Rename Tab..."), this, SLOT(tabContextMenuRenameTab())); -// _contextPopupMenu->addAction(KIcon("tab-close"), -// i18nc("@action:inmenu", "&Close Tab"), this, -// SLOT(tabContextMenuCloseTab())); + _contextPopupMenu->addAction(KIcon("tab-close"), + i18nc("@action:inmenu", "&Close Tab"), this, + SLOT(tabContextMenuCloseTab())); } void TabbedViewContainer::setNewViewMenu(QMenu* menu) @@ -521,16 +519,10 @@ void TabbedViewContainer::closeCurrentTab() { if (_stackWidget->currentIndex() != -1) { - closeTab(_stackWidget->currentIndex()); + emit closeTab(this, _stackWidget->widget(_stackWidget->currentIndex())); } } -void TabbedViewContainer::closeTab(int tab) -{ - Q_ASSERT(tab >= 0 && tab < _stackWidget->count()); - - if (viewProperties(_stackWidget->widget(tab))->confirmClose()) - removeView(_stackWidget->widget(tab)); -} + void TabbedViewContainer::setTabBarVisible(bool visible) { _tabBar->setVisible(visible); @@ -655,7 +647,8 @@ void TabbedViewContainer::openTabContextMenu(int index, const QPoint& pos) void TabbedViewContainer::tabContextMenuCloseTab() { - closeTab(_contextMenuTabIndex); + _tabBar->setCurrentIndex(_contextMenuTabIndex);// Required for this to work + emit closeTab(this, _stackWidget->widget(_contextMenuTabIndex)); } void TabbedViewContainer::tabContextMenuDetachTab() diff --git a/src/ViewContainer.h b/src/ViewContainer.h index da7d5985..aa512f8d 100644 --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -427,7 +427,6 @@ private slots: void updateIcon(ViewProperties* item); void updateActivity(ViewProperties* item); void currentTabChanged(int index); - void closeTab(int index); void closeCurrentTab(); void wheelScrolled(int delta); @@ -440,6 +439,7 @@ private slots: signals: void detachTab(ViewContainer * self, QWidget * activeView); + void closeTab(ViewContainer * self, QWidget * activeView); private: void dynamicTabBarVisibility(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 54d11c41..89d019e3 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -639,6 +639,11 @@ ViewContainer* ViewManager::createContainer(const Profile::Ptr info) this, SLOT(detachView(ViewContainer*, QWidget*)) ); + connect(container, + SIGNAL(closeTab(ViewContainer*, QWidget*)), + this, + SLOT(closeTabFromContainer(ViewContainer*, QWidget*))); + } break; case NoNavigation: @@ -1090,5 +1095,13 @@ void ViewManager::moveSessionRight() this->moveActiveViewRight(); } +void ViewManager::closeTabFromContainer(ViewContainer *container, QWidget *tab) +{ + SessionController *controller = dynamic_cast(container->viewProperties(tab)); + Q_ASSERT(controller); + if (controller && controller->confirmClose()) + controller->session()->close(); +} + #include "ViewManager.moc" diff --git a/src/ViewManager.h b/src/ViewManager.h index 05f5370c..538dfec9 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -314,6 +314,8 @@ private slots: void detachView(ViewContainer* container, QWidget* view); + void closeTabFromContainer(ViewContainer *container, QWidget *view); + private: void createView(Session* session, ViewContainer* container, int index); const ColorScheme* colorSchemeForProfile(const Profile::Ptr profile) const;