2023-02-23 12:47:39 +01:00
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
#include "shellintegration.h"
|
2023-06-06 09:37:13 +02:00
|
|
|
#include "shortcutmap.h"
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-03-24 12:53:21 +01:00
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
|
2023-06-06 09:37:13 +02:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2023-07-17 13:51:56 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
2023-07-20 08:34:09 +02:00
|
|
|
#include <coreplugin/terminal/searchableterminal.h>
|
2023-05-23 07:15:42 +02:00
|
|
|
|
2023-03-06 12:25:26 +01:00
|
|
|
#include <utils/link.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2023-02-23 12:47:39 +01:00
|
|
|
#include <utils/terminalhooks.h>
|
|
|
|
|
|
2023-08-10 06:44:27 +02:00
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2023-02-23 12:47:39 +01:00
|
|
|
namespace Terminal {
|
|
|
|
|
|
2023-06-06 08:23:09 +02:00
|
|
|
using RegisteredAction = std::unique_ptr<QAction, std::function<void(QAction *)>>;
|
2023-05-23 07:15:42 +02:00
|
|
|
|
2023-07-20 08:34:09 +02:00
|
|
|
class TerminalWidget : public Core::SearchableTerminal
|
2023-02-23 12:47:39 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
TerminalWidget(QWidget *parent = nullptr,
|
|
|
|
|
const Utils::Terminal::OpenTerminalParameters &openParameters = {});
|
|
|
|
|
|
2023-05-23 07:15:42 +02:00
|
|
|
void closeTerminal();
|
|
|
|
|
|
2023-03-07 17:55:38 +01:00
|
|
|
void setShellName(const QString &shellName);
|
2023-03-02 16:59:03 +01:00
|
|
|
QString shellName() const;
|
2023-07-03 12:21:30 +03:00
|
|
|
QString title() const;
|
2023-03-02 16:59:03 +01:00
|
|
|
|
2023-03-10 13:55:17 +01:00
|
|
|
Utils::FilePath cwd() const;
|
|
|
|
|
Utils::CommandLine currentCommand() const;
|
2023-03-07 17:55:38 +01:00
|
|
|
std::optional<Utils::Id> identifier() const;
|
|
|
|
|
QProcess::ProcessState processState() const;
|
|
|
|
|
|
|
|
|
|
void restart(const Utils::Terminal::OpenTerminalParameters &openParameters);
|
2023-03-10 13:55:17 +01:00
|
|
|
|
2023-11-27 07:51:39 +01:00
|
|
|
static void initActions(QObject *parent);
|
2023-05-23 07:15:42 +02:00
|
|
|
|
2023-06-06 09:37:13 +02:00
|
|
|
void unlockGlobalAction(const Utils::Id &commandId);
|
2023-05-23 07:15:42 +02:00
|
|
|
|
2023-02-23 12:47:39 +01:00
|
|
|
signals:
|
|
|
|
|
void started(qint64 pid);
|
2023-10-25 13:16:16 +02:00
|
|
|
void finished(int exitCode);
|
2023-03-10 13:55:17 +01:00
|
|
|
void cwdChanged(const Utils::FilePath &cwd);
|
|
|
|
|
void commandChanged(const Utils::CommandLine &cmd);
|
2023-07-03 12:21:30 +03:00
|
|
|
void titleChanged();
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
protected:
|
2023-04-25 14:59:18 +02:00
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
2023-02-23 12:47:39 +01:00
|
|
|
void showEvent(QShowEvent *event) override;
|
2023-07-17 13:51:56 +02:00
|
|
|
void focusInEvent(QFocusEvent *event) override;
|
2023-02-23 12:47:39 +01:00
|
|
|
bool event(QEvent *event) override;
|
|
|
|
|
|
2023-03-01 10:48:05 +01:00
|
|
|
void onReadyRead(bool forceFlush);
|
2023-02-23 12:47:39 +01:00
|
|
|
void setupFont();
|
|
|
|
|
void setupPty();
|
|
|
|
|
void setupColors();
|
2023-03-02 15:21:50 +01:00
|
|
|
void setupActions();
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
void handleEscKey(QKeyEvent *event);
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
void surfaceChanged() override;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
void selectionChanged(const std::optional<Selection> &newSelection) override;
|
|
|
|
|
void linkActivated(const Link &link) override;
|
|
|
|
|
void contextMenuRequested(const QPoint &pos) override;
|
2023-03-03 17:18:56 +01:00
|
|
|
|
2023-07-30 14:49:56 +03:00
|
|
|
qint64 writeToPty(const QByteArray &data) override;
|
2023-07-17 13:51:56 +02:00
|
|
|
void resizePty(QSize newSize) override;
|
|
|
|
|
void setClipboard(const QString &text) override;
|
|
|
|
|
std::optional<TerminalView::Link> toLink(const QString &text) override;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-06-06 09:37:13 +02:00
|
|
|
void registerShortcut(Core::Command *command);
|
|
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
void updateCopyState();
|
|
|
|
|
|
2023-02-23 12:47:39 +01:00
|
|
|
private:
|
2023-05-23 07:15:42 +02:00
|
|
|
Core::Context m_context;
|
2023-05-03 16:00:22 +02:00
|
|
|
std::unique_ptr<Utils::Process> m_process;
|
2023-03-10 13:55:17 +01:00
|
|
|
std::unique_ptr<ShellIntegration> m_shellIntegration;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-03-02 16:59:03 +01:00
|
|
|
QString m_shellName;
|
2023-07-03 12:21:30 +03:00
|
|
|
QString m_title;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
2023-07-17 13:51:56 +02:00
|
|
|
Utils::Id m_identifier;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
Utils::Terminal::OpenTerminalParameters m_openParameters;
|
2023-03-01 10:48:05 +01:00
|
|
|
|
2023-03-10 13:55:17 +01:00
|
|
|
Utils::FilePath m_cwd;
|
|
|
|
|
Utils::CommandLine m_currentCommand;
|
2023-03-24 12:53:21 +01:00
|
|
|
|
2023-06-06 08:23:09 +02:00
|
|
|
RegisteredAction m_copy;
|
|
|
|
|
RegisteredAction m_paste;
|
|
|
|
|
RegisteredAction m_clearSelection;
|
|
|
|
|
RegisteredAction m_clearTerminal;
|
2023-11-27 07:13:24 +01:00
|
|
|
RegisteredAction m_selectAll;
|
2023-06-06 08:23:09 +02:00
|
|
|
RegisteredAction m_moveCursorWordLeft;
|
|
|
|
|
RegisteredAction m_moveCursorWordRight;
|
2023-05-23 07:15:42 +02:00
|
|
|
|
2023-06-06 09:37:13 +02:00
|
|
|
Internal::ShortcutMap m_shortcutMap;
|
2023-08-10 06:44:27 +02:00
|
|
|
|
2023-10-06 08:51:17 +02:00
|
|
|
std::unique_ptr<QFutureWatcher<Utils::expected_str<Utils::FilePath>>> m_findShellWatcher;
|
2023-02-23 12:47:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Terminal
|