forked from qt-creator/qt-creator
Terminal: Axivion warning fixes
Change-Id: Iae048d53c64c2c42fa14e425b5de11e0bf1a59d3 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -32,9 +32,8 @@ using namespace Utils::Terminal;
|
|||||||
|
|
||||||
TerminalPane::TerminalPane(QObject *parent)
|
TerminalPane::TerminalPane(QObject *parent)
|
||||||
: Core::IOutputPane(parent)
|
: Core::IOutputPane(parent)
|
||||||
, m_tabWidget(new QTabWidget)
|
|
||||||
{
|
{
|
||||||
setupContext("Terminal.Pane", m_tabWidget);
|
setupContext("Terminal.Pane", &m_tabWidget);
|
||||||
setZoomButtonsEnabled(true);
|
setZoomButtonsEnabled(true);
|
||||||
|
|
||||||
TerminalCommands::instance().init(Core::Context("Terminal.Pane"));
|
TerminalCommands::instance().init(Core::Context("Terminal.Pane"));
|
||||||
@@ -66,13 +65,13 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
closeTerminal.setToolTip(Tr::tr("Close the current Terminal."));
|
closeTerminal.setToolTip(Tr::tr("Close the current Terminal."));
|
||||||
|
|
||||||
connect(&closeTerminal, &QAction::triggered, this, [this] {
|
connect(&closeTerminal, &QAction::triggered, this, [this] {
|
||||||
removeTab(m_tabWidget->currentIndex());
|
removeTab(m_tabWidget.currentIndex());
|
||||||
});
|
});
|
||||||
|
|
||||||
m_newTerminalButton = new QToolButton();
|
m_newTerminalButton = new QToolButton();
|
||||||
|
|
||||||
QMenu *shellMenu = new QMenu(m_newTerminalButton);
|
QMenu *shellMenu = new QMenu(m_newTerminalButton);
|
||||||
Internal::ShellModel *shellModel = new Internal::ShellModel(shellMenu);
|
const Internal::ShellModel *shellModel = new Internal::ShellModel(shellMenu);
|
||||||
connect(shellMenu, &QMenu::aboutToShow, shellMenu, [shellMenu, shellModel, pane = this] {
|
connect(shellMenu, &QMenu::aboutToShow, shellMenu, [shellMenu, shellModel, pane = this] {
|
||||||
shellMenu->clear();
|
shellMenu->clear();
|
||||||
|
|
||||||
@@ -129,10 +128,12 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
TerminalCommands::openSettingsAction()->trigger();
|
TerminalCommands::openSettingsAction()->trigger();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto updateEscButton = [this] {
|
const auto updateEscButton = [this] {
|
||||||
m_escSettingButton->setChecked(TerminalSettings::instance().sendEscapeToTerminal.value());
|
m_escSettingButton->setChecked(TerminalSettings::instance().sendEscapeToTerminal.value());
|
||||||
static QString escKey = QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText);
|
static const QString escKey
|
||||||
static QString shiftEsc = QKeySequence(QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape))
|
= QKeySequence(Qt::Key_Escape).toString(QKeySequence::NativeText);
|
||||||
|
static const QString shiftEsc = QKeySequence(
|
||||||
|
QKeyCombination(Qt::ShiftModifier, Qt::Key_Escape))
|
||||||
.toString(QKeySequence::NativeText);
|
.toString(QKeySequence::NativeText);
|
||||||
if (TerminalSettings::instance().sendEscapeToTerminal.value()) {
|
if (TerminalSettings::instance().sendEscapeToTerminal.value()) {
|
||||||
m_escSettingButton->setText(escKey);
|
m_escSettingButton->setText(escKey);
|
||||||
@@ -157,14 +158,11 @@ TerminalPane::TerminalPane(QObject *parent)
|
|||||||
connect(&TerminalSettings::instance(), &TerminalSettings::applied, this, updateEscButton);
|
connect(&TerminalSettings::instance(), &TerminalSettings::applied, this, updateEscButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalPane::~TerminalPane()
|
TerminalPane::~TerminalPane() {}
|
||||||
{
|
|
||||||
delete m_tabWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::optional<FilePath> startupProjectDirectory()
|
static std::optional<FilePath> startupProjectDirectory()
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject();
|
const ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject();
|
||||||
if (!project)
|
if (!project)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
@@ -187,11 +185,11 @@ void TerminalPane::openTerminal(const OpenTerminalParameters ¶meters)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto terminalWidget = new TerminalWidget(m_tabWidget, parametersCopy);
|
const auto terminalWidget = new TerminalWidget(&m_tabWidget, parametersCopy);
|
||||||
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminalWidget, Tr::tr("Terminal")));
|
m_tabWidget.setCurrentIndex(m_tabWidget.addTab(terminalWidget, Tr::tr("Terminal")));
|
||||||
setupTerminalWidget(terminalWidget);
|
setupTerminalWidget(terminalWidget);
|
||||||
|
|
||||||
m_tabWidget->currentWidget()->setFocus();
|
m_tabWidget.currentWidget()->setFocus();
|
||||||
|
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
}
|
}
|
||||||
@@ -200,7 +198,7 @@ void TerminalPane::addTerminal(TerminalWidget *terminal, const QString &title)
|
|||||||
{
|
{
|
||||||
if (!m_isVisible)
|
if (!m_isVisible)
|
||||||
emit showPage(IOutputPane::ModeSwitch);
|
emit showPage(IOutputPane::ModeSwitch);
|
||||||
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminal, title));
|
m_tabWidget.setCurrentIndex(m_tabWidget.addTab(terminal, title));
|
||||||
setupTerminalWidget(terminal);
|
setupTerminalWidget(terminal);
|
||||||
|
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
@@ -210,17 +208,16 @@ void TerminalPane::ensureVisible(TerminalWidget *terminal)
|
|||||||
{
|
{
|
||||||
if (!m_isVisible)
|
if (!m_isVisible)
|
||||||
emit showPage(IOutputPane::ModeSwitch);
|
emit showPage(IOutputPane::ModeSwitch);
|
||||||
m_tabWidget->setCurrentWidget(terminal);
|
m_tabWidget.setCurrentWidget(terminal);
|
||||||
terminal->setFocus();
|
terminal->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalWidget *TerminalPane::stoppedTerminalWithId(const Id &identifier) const
|
TerminalWidget *TerminalPane::stoppedTerminalWithId(Id identifier) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_tabWidget, return nullptr);
|
for (int i = 0; i < m_tabWidget.count(); ++i) {
|
||||||
|
const auto terminal = qobject_cast<TerminalWidget *>(m_tabWidget.widget(i));
|
||||||
for (int i = 0; i < m_tabWidget->count(); ++i) {
|
if (terminal && terminal->processState() == QProcess::NotRunning
|
||||||
auto terminal = qobject_cast<TerminalWidget *>(m_tabWidget->widget(i));
|
&& terminal->identifier() == identifier)
|
||||||
if (terminal->processState() == QProcess::NotRunning && terminal->identifier() == identifier)
|
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,39 +228,38 @@ QWidget *TerminalPane::outputWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
if (!m_widgetInitialized) {
|
if (!m_widgetInitialized) {
|
||||||
m_widgetInitialized = true;
|
m_widgetInitialized = true;
|
||||||
m_tabWidget->setTabBarAutoHide(false);
|
m_tabWidget.setTabBarAutoHide(false);
|
||||||
m_tabWidget->setDocumentMode(true);
|
m_tabWidget.setDocumentMode(true);
|
||||||
m_tabWidget->setTabsClosable(true);
|
m_tabWidget.setTabsClosable(true);
|
||||||
m_tabWidget->setMovable(true);
|
m_tabWidget.setMovable(true);
|
||||||
|
|
||||||
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, [this](int index) {
|
connect(&m_tabWidget, &QTabWidget::tabCloseRequested, this, [this](int index) {
|
||||||
removeTab(index);
|
removeTab(index);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_tabWidget, &QTabWidget::currentChanged, this, [this](int index) {
|
connect(&m_tabWidget, &QTabWidget::currentChanged, this, [this](int index) {
|
||||||
if (auto widget = m_tabWidget->widget(index))
|
if (auto widget = m_tabWidget.widget(index))
|
||||||
widget->setFocus();
|
widget->setFocus();
|
||||||
else
|
else
|
||||||
emit hidePage();
|
emit hidePage();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto terminalWidget = new TerminalWidget(parent);
|
const auto terminalWidget = new TerminalWidget(parent);
|
||||||
m_tabWidget->addTab(terminalWidget, Tr::tr("Terminal"));
|
m_tabWidget.addTab(terminalWidget, Tr::tr("Terminal"));
|
||||||
setupTerminalWidget(terminalWidget);
|
setupTerminalWidget(terminalWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_tabWidget;
|
return &m_tabWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalWidget *TerminalPane::currentTerminal() const
|
TerminalWidget *TerminalPane::currentTerminal() const
|
||||||
{
|
{
|
||||||
QWidget *activeWidget = m_tabWidget->currentWidget();
|
return static_cast<TerminalWidget *>(m_tabWidget.currentWidget());
|
||||||
return static_cast<TerminalWidget *>(activeWidget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalPane::removeTab(int index)
|
void TerminalPane::removeTab(int index)
|
||||||
{
|
{
|
||||||
delete m_tabWidget->widget(index);
|
delete m_tabWidget.widget(index);
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,8 +268,8 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal)
|
|||||||
if (!terminal)
|
if (!terminal)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto setTabText = [this](TerminalWidget *terminal) {
|
const auto setTabText = [this, terminal]() {
|
||||||
auto index = m_tabWidget->indexOf(terminal);
|
const int index = m_tabWidget.indexOf(terminal);
|
||||||
const FilePath cwd = terminal->cwd();
|
const FilePath cwd = terminal->cwd();
|
||||||
|
|
||||||
const QString exe = terminal->currentCommand().isEmpty()
|
const QString exe = terminal->currentCommand().isEmpty()
|
||||||
@@ -281,25 +277,17 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal)
|
|||||||
: terminal->currentCommand().executable().fileName();
|
: terminal->currentCommand().executable().fileName();
|
||||||
|
|
||||||
if (cwd.isEmpty())
|
if (cwd.isEmpty())
|
||||||
m_tabWidget->setTabText(index, exe);
|
m_tabWidget.setTabText(index, exe);
|
||||||
else
|
else
|
||||||
m_tabWidget->setTabText(index, exe + " - " + cwd.fileName());
|
m_tabWidget.setTabText(index, exe + " - " + cwd.fileName());
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(terminal, &TerminalWidget::started, this, [setTabText, terminal](qint64 /*pid*/) {
|
connect(terminal, &TerminalWidget::started, this, setTabText);
|
||||||
setTabText(terminal);
|
connect(terminal, &TerminalWidget::cwdChanged, this, setTabText);
|
||||||
});
|
connect(terminal, &TerminalWidget::commandChanged, this, setTabText);
|
||||||
|
|
||||||
connect(terminal, &TerminalWidget::cwdChanged, this, [setTabText, terminal]() {
|
|
||||||
setTabText(terminal);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(terminal, &TerminalWidget::commandChanged, this, [setTabText, terminal]() {
|
|
||||||
setTabText(terminal);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!terminal->shellName().isEmpty())
|
if (!terminal->shellName().isEmpty())
|
||||||
setTabText(terminal);
|
setTabText();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
||||||
@@ -334,7 +322,7 @@ void TerminalPane::visibilityChanged(bool visible)
|
|||||||
|
|
||||||
m_isVisible = visible;
|
m_isVisible = visible;
|
||||||
|
|
||||||
if (visible && m_tabWidget && m_tabWidget->count() == 0)
|
if (visible && m_tabWidget.count() == 0)
|
||||||
openTerminal({});
|
openTerminal({});
|
||||||
|
|
||||||
IOutputPane::visibilityChanged(visible);
|
IOutputPane::visibilityChanged(visible);
|
||||||
@@ -366,31 +354,31 @@ bool TerminalPane::canNavigate() const
|
|||||||
|
|
||||||
bool TerminalPane::canNext() const
|
bool TerminalPane::canNext() const
|
||||||
{
|
{
|
||||||
return m_tabWidget->count() > 1;
|
return m_tabWidget.count() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TerminalPane::canPrevious() const
|
bool TerminalPane::canPrevious() const
|
||||||
{
|
{
|
||||||
return m_tabWidget->count() > 1;
|
return m_tabWidget.count() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalPane::goToNext()
|
void TerminalPane::goToNext()
|
||||||
{
|
{
|
||||||
int nextIndex = m_tabWidget->currentIndex() + 1;
|
int nextIndex = m_tabWidget.currentIndex() + 1;
|
||||||
if (nextIndex >= m_tabWidget->count())
|
if (nextIndex >= m_tabWidget.count())
|
||||||
nextIndex = 0;
|
nextIndex = 0;
|
||||||
|
|
||||||
m_tabWidget->setCurrentIndex(nextIndex);
|
m_tabWidget.setCurrentIndex(nextIndex);
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalPane::goToPrev()
|
void TerminalPane::goToPrev()
|
||||||
{
|
{
|
||||||
int prevIndex = m_tabWidget->currentIndex() - 1;
|
int prevIndex = m_tabWidget.currentIndex() - 1;
|
||||||
if (prevIndex < 0)
|
if (prevIndex < 0)
|
||||||
prevIndex = m_tabWidget->count() - 1;
|
prevIndex = m_tabWidget.count() - 1;
|
||||||
|
|
||||||
m_tabWidget->setCurrentIndex(prevIndex);
|
m_tabWidget.setCurrentIndex(prevIndex);
|
||||||
emit navigateStateUpdate();
|
emit navigateStateUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public:
|
|||||||
void openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters);
|
void openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters);
|
||||||
void addTerminal(TerminalWidget *terminal, const QString &title);
|
void addTerminal(TerminalWidget *terminal, const QString &title);
|
||||||
|
|
||||||
TerminalWidget *stoppedTerminalWithId(const Utils::Id &identifier) const;
|
TerminalWidget *stoppedTerminalWithId(Utils::Id identifier) const;
|
||||||
|
|
||||||
void ensureVisible(TerminalWidget *terminal);
|
void ensureVisible(TerminalWidget *terminal);
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ private:
|
|||||||
void setupTerminalWidget(TerminalWidget *terminal);
|
void setupTerminalWidget(TerminalWidget *terminal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_tabWidget{nullptr};
|
QTabWidget m_tabWidget;
|
||||||
|
|
||||||
QToolButton *m_newTerminalButton{nullptr};
|
QToolButton *m_newTerminalButton{nullptr};
|
||||||
QToolButton *m_closeTerminalButton{nullptr};
|
QToolButton *m_closeTerminalButton{nullptr};
|
||||||
|
|||||||
Reference in New Issue
Block a user