From b4ef40dfa1858374dc6f66953942e4263e480605 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 13 Jul 2018 17:46:02 +0200 Subject: [PATCH] Re enable close tabs, simplify code --- src/ViewContainer.cpp | 23 +++++++++++++++-------- src/ViewContainer.h | 5 +++-- src/ViewManager.cpp | 10 ---------- src/ViewManager.h | 2 -- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp index b05009cf5..93de0134b 100644 --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -61,9 +61,8 @@ TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWid emit newViewRequest(); }); - connect(tabBar(), &QTabBar::tabCloseRequested, this, [this](int idx) { - closeTab(this, widget(idx)); - }); + connect(tabBar(), &QTabBar::tabCloseRequested, + this, &TabbedViewContainer::closeTerminalTab); connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, &Konsole::TabbedViewContainer::tabDoubleClicked); @@ -88,11 +87,10 @@ TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWid // SLOT(tabContextMenuDetachTab())); #endif - _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), + auto editAction = _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18nc("@action:inmenu", "&Rename Tab..."), this, SLOT(tabContextMenuRenameTab())); - const auto contextPopupMenuActions = _contextPopupMenu->actions(); - contextPopupMenuActions.last()->setObjectName(QStringLiteral("edit-rename")); + editAction->setObjectName(QStringLiteral("edit-rename")); auto profileMenu = new QMenu(); auto profileList = new ProfileList(false, profileMenu); @@ -182,7 +180,10 @@ void TabbedViewContainer::addView(QWidget *view, ViewProperties *item, int index void TabbedViewContainer::viewDestroyed(QObject *view) { - QWidget *widget = qobject_cast(view); + auto widget = static_cast(view); + const auto idx = indexOf(widget); + + removeTab(idx); forgetView(widget); } @@ -236,7 +237,7 @@ QList TabbedViewContainer::widgetsForItem(ViewProperties *item) const void TabbedViewContainer::closeCurrentTab() { if (currentIndex() != -1) { - emit closeTab(this, widget(currentIndex())); + closeTerminalTab(currentIndex()); } } @@ -379,6 +380,12 @@ void TabbedViewContainer::updateIcon(ViewProperties *item) } } +void TabbedViewContainer::closeTerminalTab(int idx) { + auto currWidget = widget(idx); + auto controller = qobject_cast(_navigation[currWidget]); + controller->closeSession(); +} + ViewManager *TabbedViewContainer::connectedViewManager() { return _connectedViewManager; diff --git a/src/ViewContainer.h b/src/ViewContainer.h index 33f6f98d1..42b958c36 100644 --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -143,8 +143,6 @@ Q_SIGNALS: /** Requests creation of a new view, with the selected profile. */ void newViewRequest(Profile::Ptr); - void closeTab(TabbedViewContainer *tabbedViewContainer, QWidget *index); - /** * Emitted when the user requests to move a view from another container * into this container. If 'success' is set to true by a connected slot @@ -192,6 +190,9 @@ protected: */ void moveViewWidget(int fromIndex, int toIndex); + // close tabs and unregister + void closeTerminalTab(int index); + private Q_SLOTS: void viewDestroyed(QObject *view); void konsoleConfigChanged(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 2f9099027..ba1f49775 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -616,7 +616,6 @@ TabbedViewContainer *ViewManager::createContainer() auto *container = new TabbedViewContainer(this, _viewSplitter); //TODO: Fix Detaching. // connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); - connect(container, &TabbedViewContainer::closeTab, this, &ViewManager::closeTabFromContainer); // connect signals and slots connect(container, &Konsole::TabbedViewContainer::viewAdded, this, @@ -1100,12 +1099,3 @@ void ViewManager::moveSessionRight() { moveActiveViewRight(); } - -void ViewManager::closeTabFromContainer(TabbedViewContainer *container, QWidget *tab) -{ - SessionController *controller = qobject_cast(container->viewProperties(tab)); - Q_ASSERT(controller); - if (controller != nullptr) { - controller->closeSession(); - } -} diff --git a/src/ViewManager.h b/src/ViewManager.h index b217e9534..170de0327 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -348,8 +348,6 @@ private Q_SLOTS: void detachView(TabbedViewContainer *container, QWidget *view); - void closeTabFromContainer(TabbedViewContainer *container, QWidget *tab); - private: Q_DISABLE_COPY(ViewManager)