Commit c695c9b2 authored by Christian Schärf's avatar Christian Schärf Committed by Tomaz Canabrava
Browse files

Move connecting and disconnecting TerminalDisplays into separate function to...

Move connecting and disconnecting TerminalDisplays into separate function to avoid code duplication.
parent 343d8595
......@@ -431,7 +431,7 @@ QHash<TerminalDisplay*, Session*> ViewManager::forgetAll(ViewSplitter* splitter)
Session* ViewManager::forgetTerminal(TerminalDisplay* terminal)
{
disconnect(terminal, &TerminalDisplay::requestToggleExpansion, nullptr, nullptr);
unregisterTerminal(terminal);
removeController(terminal->sessionController());
auto session = _sessionMap.take(terminal);
......@@ -636,11 +636,10 @@ void ViewManager::attachView(TerminalDisplay *terminal, Session *session)
Qt::UniqueConnection);
// Disconnect from the other viewcontainer.
disconnect(terminal, &TerminalDisplay::requestToggleExpansion, nullptr, nullptr);
unregisterTerminal(terminal);
// reconnect on this container.
connect(terminal, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal, Qt::UniqueConnection);
registerTerminal(terminal);
_sessionMap[terminal] = session;
createController(session, terminal);
......@@ -790,8 +789,7 @@ TerminalDisplay *ViewManager::createTerminalDisplay(Session *session)
{
auto display = new TerminalDisplay(nullptr);
display->setRandomSeed(session->sessionId() | (qApp->applicationPid() << 10));
connect(display, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal);
registerTerminal(display);
return display;
}
......@@ -1160,3 +1158,17 @@ void ViewManager::updateTerminalDisplayHistory(TerminalDisplay* terminalDisplay,
}
}
}
void ViewManager::registerTerminal(TerminalDisplay *terminal)
{
connect(terminal, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal, Qt::UniqueConnection);
connect(terminal, &TerminalDisplay::requestMoveToNewTab,
_viewContainer, &TabbedViewContainer::moveToNewTab, Qt::UniqueConnection);
}
void ViewManager::unregisterTerminal(TerminalDisplay *terminal)
{
disconnect(terminal, &TerminalDisplay::requestToggleExpansion, nullptr, nullptr);
disconnect(terminal, &TerminalDisplay::requestMoveToNewTab, nullptr, nullptr);
}
......@@ -419,6 +419,9 @@ private:
void activateLastUsedView(bool reverse);
void registerTerminal(TerminalDisplay *terminal);
void unregisterTerminal(TerminalDisplay *terminal);
private:
QPointer<TabbedViewContainer> _viewContainer;
QPointer<SessionController> _pluggedController;
......
......@@ -263,6 +263,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
_scrollBar->setCursor(Qt::ArrowCursor);
_headerBar->setCursor(Qt::ArrowCursor);
connect(_headerBar, &TerminalHeaderBar::requestToggleExpansion, this, &Konsole::TerminalDisplay::requestToggleExpansion);
connect(_headerBar, &TerminalHeaderBar::requestMoveToNewTab, this, [this]{requestMoveToNewTab(this);});
connect(_scrollBar, &QScrollBar::sliderMoved, this, &Konsole::TerminalDisplay::viewScrolledByUser);
// setup timers for blinking text
......
......@@ -455,6 +455,8 @@ public Q_SLOTS:
Q_SIGNALS:
void requestToggleExpansion();
void requestMoveToNewTab(TerminalDisplay* display);
/**
* Emitted when the user presses a key whilst the terminal widget has focus.
*/
......
......@@ -84,6 +84,18 @@ TerminalHeaderBar::TerminalHeaderBar(QWidget *parent)
m_boxLayout->addWidget(m_toggleExpandedMode);
// Move to new tab button
m_moveToNewTab = new QToolButton(this);
m_moveToNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
m_moveToNewTab->setAutoRaise(true);
m_moveToNewTab->setToolTip(i18nc("@info:tooltip", "Move terminal to new tab"));
connect(m_moveToNewTab, &QToolButton::clicked,
this, &TerminalHeaderBar::requestMoveToNewTab);
m_boxLayout->addWidget(m_moveToNewTab);
// Close button
m_closeBtn = new QToolButton(this);
......
......@@ -47,6 +47,7 @@ protected:
Q_SIGNALS:
void requestToggleExpansion();
void requestMoveToNewTab();
private:
QBoxLayout *m_boxLayout;
......@@ -58,6 +59,7 @@ private:
QLabel *m_statusIconActivity;
QLabel *m_statusIconBell;
QToolButton *m_closeBtn;
QToolButton *m_moveToNewTab;
QToolButton *m_toggleExpandedMode;
bool m_terminalIsFocused;
QPoint m_startDrag;
......
......@@ -702,3 +702,7 @@ void TabbedViewContainer::setNavigationBehavior(int behavior)
{
_newTabBehavior = static_cast<NewTabBehavior>(behavior);
}
void TabbedViewContainer::moveToNewTab(TerminalDisplay* display) {
addView(display);
}
......@@ -153,6 +153,8 @@ public:
void setNavigationBehavior(int behavior);
void terminalDisplayDropped(TerminalDisplay* terminalDisplay);
void moveToNewTab(TerminalDisplay* display);
QSize sizeHint() const override;
Q_SIGNALS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment