forked from qt-creator/qt-creator
Terminal: use shell name as terminal tab name
This way cmd, bash, powershell are more descriptive than "Terminal" Change-Id: I19310f423cd4188ecc48580a30ed414833a15aee Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -74,8 +74,9 @@ TerminalPane::TerminalPane(QObject *parent)
|
||||
void TerminalPane::openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters)
|
||||
{
|
||||
showPage(0);
|
||||
m_tabWidget->setCurrentIndex(
|
||||
m_tabWidget->addTab(new TerminalWidget(m_tabWidget, parameters), Tr::tr("Terminal")));
|
||||
auto terminalWidget = new TerminalWidget(m_tabWidget, parameters);
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminalWidget, Tr::tr("Terminal")));
|
||||
setupTerminalWidget(terminalWidget);
|
||||
|
||||
m_tabWidget->currentWidget()->setFocus();
|
||||
|
||||
@@ -87,6 +88,7 @@ void TerminalPane::addTerminal(TerminalWidget *terminal, const QString &title)
|
||||
{
|
||||
showPage(0);
|
||||
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminal, title));
|
||||
setupTerminalWidget(terminal);
|
||||
|
||||
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
||||
emit navigateStateUpdate();
|
||||
@@ -106,7 +108,10 @@ QWidget *TerminalPane::outputWidget(QWidget *parent)
|
||||
removeTab(index);
|
||||
});
|
||||
|
||||
m_tabWidget->addTab(new TerminalWidget(parent), Tr::tr("Terminal"));
|
||||
auto terminalWidget = new TerminalWidget(parent);
|
||||
m_tabWidget->addTab(terminalWidget, Tr::tr("Terminal"));
|
||||
setupTerminalWidget(terminalWidget);
|
||||
|
||||
}
|
||||
|
||||
return m_tabWidget;
|
||||
@@ -127,6 +132,24 @@ void TerminalPane::removeTab(int index)
|
||||
emit navigateStateUpdate();
|
||||
}
|
||||
|
||||
void TerminalPane::setupTerminalWidget(TerminalWidget *terminal)
|
||||
{
|
||||
if (!terminal)
|
||||
return;
|
||||
|
||||
auto setTabText = [this](TerminalWidget * terminal) {
|
||||
auto index = m_tabWidget->indexOf(terminal);
|
||||
m_tabWidget->setTabText(index, terminal->shellName());
|
||||
};
|
||||
|
||||
connect(terminal, &TerminalWidget::started, [setTabText, terminal](qint64 /*pid*/) {
|
||||
setTabText(terminal);
|
||||
});
|
||||
|
||||
if (!terminal->shellName().isEmpty())
|
||||
setTabText(terminal);
|
||||
}
|
||||
|
||||
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
||||
{
|
||||
return {m_newTerminalButton, m_closeTerminalButton};
|
||||
|
@@ -43,6 +43,7 @@ private:
|
||||
TerminalWidget *currentTerminal() const;
|
||||
|
||||
void removeTab(int index);
|
||||
void setupTerminalWidget(TerminalWidget *terminal);
|
||||
|
||||
private:
|
||||
QTabWidget *m_tabWidget{nullptr};
|
||||
|
@@ -162,6 +162,10 @@ void TerminalWidget::setupPty()
|
||||
});
|
||||
|
||||
connect(m_process.get(), &QtcProcess::started, this, [this] {
|
||||
m_shellName = m_process->commandLine().executable().fileName();
|
||||
if (HostOsInfo::isWindowsHost() && m_shellName.endsWith(QTC_WIN_EXE_SUFFIX))
|
||||
m_shellName.chop(QStringLiteral(QTC_WIN_EXE_SUFFIX).size());
|
||||
|
||||
applySizeChange();
|
||||
emit started(m_process->processId());
|
||||
});
|
||||
@@ -463,6 +467,11 @@ void TerminalWidget::setSelection(const std::optional<Selection> &selection)
|
||||
m_selection = selection;
|
||||
}
|
||||
|
||||
QString TerminalWidget::shellName() const
|
||||
{
|
||||
return m_shellName;
|
||||
}
|
||||
|
||||
const VTermScreenCell *TerminalWidget::fetchCell(int x, int y) const
|
||||
{
|
||||
QTC_ASSERT(y >= 0, return nullptr);
|
||||
|
@@ -52,6 +52,8 @@ public:
|
||||
QPoint end;
|
||||
};
|
||||
|
||||
QString shellName() const;
|
||||
|
||||
signals:
|
||||
void started(qint64 pid);
|
||||
|
||||
@@ -119,6 +121,8 @@ protected:
|
||||
private:
|
||||
std::unique_ptr<Utils::QtcProcess> m_process;
|
||||
|
||||
QString m_shellName;
|
||||
|
||||
std::unique_ptr<VTerm, void (*)(VTerm *)> m_vterm;
|
||||
VTermScreen *m_vtermScreen;
|
||||
QSize m_vtermSize;
|
||||
|
Reference in New Issue
Block a user