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