forked from qt-creator/qt-creator
Adds a new Terminal plugin that provides a Terminal pane inside Qt Creator. Fixes: QTCREATORBUG-8511 Change-Id: I7eacb3efa2463d7df9f383ae3fc33254fb9019a9 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
177 lines
4.3 KiB
C++
177 lines
4.3 KiB
C++
// Copyright (C) 2022 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
|
|
#include "terminalpane.h"
|
|
|
|
#include "terminaltr.h"
|
|
#include "terminalwidget.h"
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
#include <coreplugin/icontext.h>
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
namespace Terminal {
|
|
|
|
TerminalPane::TerminalPane(QObject *parent)
|
|
: Core::IOutputPane(parent)
|
|
{
|
|
Core::Context context("Terminal.Window");
|
|
|
|
m_newTerminal.setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
|
m_newTerminal.setToolTip(Tr::tr("Create a new Terminal."));
|
|
|
|
connect(&m_newTerminal, &QAction::triggered, this, [this] {
|
|
m_tabWidget->setCurrentIndex(
|
|
m_tabWidget->addTab(new TerminalWidget(m_tabWidget), Tr::tr("Terminal")));
|
|
|
|
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
|
emit navigateStateUpdate();
|
|
});
|
|
|
|
m_closeTerminal.setIcon(Utils::Icons::CLOSE_TOOLBAR.icon());
|
|
m_closeTerminal.setToolTip(Tr::tr("Close the current Terminal."));
|
|
m_closeTerminal.setEnabled(false);
|
|
|
|
connect(&m_closeTerminal, &QAction::triggered, this, [this] {
|
|
removeTab(m_tabWidget->currentIndex());
|
|
});
|
|
|
|
//Core::Command *cmd = Core::ActionManager::registerAction(m_newTerminal, Constants::STOP);
|
|
//cmd->setDescription(m_newTerminal->toolTip());
|
|
|
|
m_newTerminalButton = new QToolButton();
|
|
m_newTerminalButton->setDefaultAction(&m_newTerminal);
|
|
|
|
m_closeTerminalButton = new QToolButton();
|
|
m_closeTerminalButton->setDefaultAction(&m_closeTerminal);
|
|
}
|
|
|
|
void TerminalPane::openTerminal(const Utils::Terminal::OpenTerminalParameters ¶meters)
|
|
{
|
|
showPage(0);
|
|
m_tabWidget->setCurrentIndex(
|
|
m_tabWidget->addTab(new TerminalWidget(m_tabWidget, parameters), Tr::tr("Terminal")));
|
|
|
|
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
|
emit navigateStateUpdate();
|
|
}
|
|
|
|
void TerminalPane::addTerminal(TerminalWidget *terminal, const QString &title)
|
|
{
|
|
showPage(0);
|
|
m_tabWidget->setCurrentIndex(m_tabWidget->addTab(terminal, title));
|
|
|
|
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
|
emit navigateStateUpdate();
|
|
}
|
|
|
|
QWidget *TerminalPane::outputWidget(QWidget *parent)
|
|
{
|
|
if (!m_tabWidget) {
|
|
m_tabWidget = new QTabWidget(parent);
|
|
|
|
m_tabWidget->setTabBarAutoHide(true);
|
|
m_tabWidget->setDocumentMode(true);
|
|
m_tabWidget->setTabsClosable(true);
|
|
m_tabWidget->setMovable(true);
|
|
|
|
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, [this](int index) {
|
|
removeTab(index);
|
|
});
|
|
|
|
m_tabWidget->addTab(new TerminalWidget(parent), Tr::tr("Terminal"));
|
|
}
|
|
|
|
return m_tabWidget;
|
|
}
|
|
|
|
TerminalWidget *TerminalPane::currentTerminal() const
|
|
{
|
|
QWidget *activeWidget = m_tabWidget->currentWidget();
|
|
return static_cast<TerminalWidget *>(activeWidget);
|
|
}
|
|
|
|
void TerminalPane::removeTab(int index)
|
|
{
|
|
if (m_tabWidget->count() > 1)
|
|
delete m_tabWidget->widget(index);
|
|
|
|
m_closeTerminal.setEnabled(m_tabWidget->count() > 1);
|
|
emit navigateStateUpdate();
|
|
}
|
|
|
|
QList<QWidget *> TerminalPane::toolBarWidgets() const
|
|
{
|
|
return {m_newTerminalButton, m_closeTerminalButton};
|
|
}
|
|
|
|
QString TerminalPane::displayName() const
|
|
{
|
|
return Tr::tr("Terminal");
|
|
}
|
|
|
|
int TerminalPane::priorityInStatusBar() const
|
|
{
|
|
return 50;
|
|
}
|
|
|
|
void TerminalPane::clearContents()
|
|
{
|
|
if (const auto t = currentTerminal())
|
|
t->clearContents();
|
|
}
|
|
|
|
void TerminalPane::visibilityChanged(bool visible)
|
|
{
|
|
Q_UNUSED(visible);
|
|
}
|
|
|
|
void TerminalPane::setFocus()
|
|
{
|
|
if (const auto t = currentTerminal())
|
|
t->setFocus();
|
|
}
|
|
|
|
bool TerminalPane::hasFocus() const
|
|
{
|
|
if (const auto t = currentTerminal())
|
|
t->hasFocus();
|
|
|
|
return false;
|
|
}
|
|
|
|
bool TerminalPane::canFocus() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool TerminalPane::canNavigate() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool TerminalPane::canNext() const
|
|
{
|
|
return m_tabWidget->count() > 1 && m_tabWidget->currentIndex() < m_tabWidget->count() - 1;
|
|
}
|
|
|
|
bool TerminalPane::canPrevious() const
|
|
{
|
|
return m_tabWidget->count() > 1 && m_tabWidget->currentIndex() > 0;
|
|
}
|
|
|
|
void TerminalPane::goToNext()
|
|
{
|
|
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1);
|
|
emit navigateStateUpdate();
|
|
}
|
|
|
|
void TerminalPane::goToPrev()
|
|
{
|
|
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1);
|
|
emit navigateStateUpdate();
|
|
}
|
|
|
|
} // namespace Terminal
|