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)
|
void TerminalPane::openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters)
|
||||||
{
|
{
|
||||||
showPage(0);
|
showPage(0);
|
||||||
m_tabWidget->setCurrentIndex(
|
auto terminalWidget = new TerminalWidget(m_tabWidget, parameters);
|
||||||
m_tabWidget->addTab(new TerminalWidget(m_tabWidget, parameters), Tr::tr("Terminal")));
|
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminalWidget, Tr::tr("Terminal")));
|
||||||
|
setupTerminalWidget(terminalWidget);
|
||||||
|
|
||||||
m_tabWidget->currentWidget()->setFocus();
|
m_tabWidget->currentWidget()->setFocus();
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@ void TerminalPane::addTerminal(TerminalWidget *terminal, const QString &title)
|
|||||||
{
|
{
|
||||||
showPage(0);
|
showPage(0);
|
||||||
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminal, title));
|
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminal, title));
|
||||||
|
setupTerminalWidget(terminal);
|
||||||
|
|
||||||
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
@@ -106,7 +108,10 @@ QWidget *TerminalPane::outputWidget(QWidget *parent)
|
|||||||
removeTab(index);
|
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;
|
return m_tabWidget;
|
||||||
@@ -127,6 +132,24 @@ void TerminalPane::removeTab(int index)
|
|||||||
emit navigateStateUpdate();
|
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
|
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
||||||
{
|
{
|
||||||
return {m_newTerminalButton, m_closeTerminalButton};
|
return {m_newTerminalButton, m_closeTerminalButton};
|
||||||
|
@@ -43,6 +43,7 @@ private:
|
|||||||
TerminalWidget *currentTerminal() const;
|
TerminalWidget *currentTerminal() const;
|
||||||
|
|
||||||
void removeTab(int index);
|
void removeTab(int index);
|
||||||
|
void setupTerminalWidget(TerminalWidget *terminal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_tabWidget{nullptr};
|
QTabWidget *m_tabWidget{nullptr};
|
||||||
|
@@ -162,6 +162,10 @@ void TerminalWidget::setupPty()
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(m_process.get(), &QtcProcess::started, this, [this] {
|
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();
|
applySizeChange();
|
||||||
emit started(m_process->processId());
|
emit started(m_process->processId());
|
||||||
});
|
});
|
||||||
@@ -463,6 +467,11 @@ void TerminalWidget::setSelection(const std::optional<Selection> &selection)
|
|||||||
m_selection = selection;
|
m_selection = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TerminalWidget::shellName() const
|
||||||
|
{
|
||||||
|
return m_shellName;
|
||||||
|
}
|
||||||
|
|
||||||
const VTermScreenCell *TerminalWidget::fetchCell(int x, int y) const
|
const VTermScreenCell *TerminalWidget::fetchCell(int x, int y) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(y >= 0, return nullptr);
|
QTC_ASSERT(y >= 0, return nullptr);
|
||||||
|
@@ -52,6 +52,8 @@ public:
|
|||||||
QPoint end;
|
QPoint end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QString shellName() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void started(qint64 pid);
|
void started(qint64 pid);
|
||||||
|
|
||||||
@@ -119,6 +121,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::unique_ptr<Utils::QtcProcess> m_process;
|
std::unique_ptr<Utils::QtcProcess> m_process;
|
||||||
|
|
||||||
|
QString m_shellName;
|
||||||
|
|
||||||
std::unique_ptr<VTerm, void (*)(VTerm *)> m_vterm;
|
std::unique_ptr<VTerm, void (*)(VTerm *)> m_vterm;
|
||||||
VTermScreen *m_vtermScreen;
|
VTermScreen *m_vtermScreen;
|
||||||
QSize m_vtermSize;
|
QSize m_vtermSize;
|
||||||
|
Reference in New Issue
Block a user