forked from qt-creator/qt-creator
Terminal: Create Terminal solution
Change-Id: If271fd23a84c49bbc25fcc3b9bc0939c7237d095 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -3,83 +3,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shellintegration.h"
|
||||
#include "shortcutmap.h"
|
||||
#include "terminalsearch.h"
|
||||
#include "terminalsurface.h"
|
||||
|
||||
#include <solutions/terminal/terminalview.h>
|
||||
|
||||
#include <aggregation/aggregate.h>
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <utils/link.h>
|
||||
#include <utils/process.h>
|
||||
#include <utils/terminalhooks.h>
|
||||
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QAction>
|
||||
#include <QTextLayout>
|
||||
#include <QTimer>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
namespace Terminal {
|
||||
|
||||
using RegisteredAction = std::unique_ptr<QAction, std::function<void(QAction *)>>;
|
||||
|
||||
class TerminalWidget : public QAbstractScrollArea
|
||||
class TerminalWidget : public TerminalSolution::TerminalView
|
||||
{
|
||||
friend class CellIterator;
|
||||
Q_OBJECT
|
||||
public:
|
||||
TerminalWidget(QWidget *parent = nullptr,
|
||||
const Utils::Terminal::OpenTerminalParameters &openParameters = {});
|
||||
|
||||
void setFont(const QFont &font);
|
||||
|
||||
void copyToClipboard();
|
||||
void pasteFromClipboard();
|
||||
void copyLinkToClipboard();
|
||||
|
||||
void clearSelection();
|
||||
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
|
||||
void moveCursorWordLeft();
|
||||
void moveCursorWordRight();
|
||||
|
||||
void clearContents();
|
||||
|
||||
void closeTerminal();
|
||||
|
||||
TerminalSearch *search() { return m_search.get(); }
|
||||
|
||||
struct Selection
|
||||
{
|
||||
int start;
|
||||
int end;
|
||||
bool final{false};
|
||||
|
||||
bool operator!=(const Selection &other) const
|
||||
{
|
||||
return start != other.start || end != other.end || final != other.final;
|
||||
}
|
||||
|
||||
bool operator==(const Selection &other) const { return !operator!=(other); }
|
||||
};
|
||||
|
||||
struct LinkSelection : public Selection
|
||||
{
|
||||
Utils::Link link;
|
||||
|
||||
bool operator!=(const LinkSelection &other) const
|
||||
{
|
||||
return link != other.link || Selection::operator!=(other);
|
||||
}
|
||||
};
|
||||
|
||||
void setShellName(const QString &shellName);
|
||||
QString shellName() const;
|
||||
QString title() const;
|
||||
@@ -102,142 +55,52 @@ signals:
|
||||
void titleChanged();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void focusInEvent(QFocusEvent *event) override;
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
void inputMethodEvent(QInputMethodEvent *event) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
void focusInEvent(QFocusEvent *event) override;
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
protected:
|
||||
void onReadyRead(bool forceFlush);
|
||||
void setupSurface();
|
||||
void setupFont();
|
||||
void setupPty();
|
||||
void setupColors();
|
||||
void setupActions();
|
||||
|
||||
void writeToPty(const QByteArray &data);
|
||||
void handleEscKey(QKeyEvent *event);
|
||||
|
||||
int paintCell(QPainter &p,
|
||||
const QRectF &cellRect,
|
||||
QPoint gridPos,
|
||||
const Internal::TerminalCell &cell,
|
||||
QFont &f,
|
||||
QList<SearchHit>::const_iterator &searchIt) const;
|
||||
void paintCells(QPainter &painter, QPaintEvent *event) const;
|
||||
void paintCursor(QPainter &painter) const;
|
||||
void paintPreedit(QPainter &painter) const;
|
||||
bool paintFindMatches(QPainter &painter,
|
||||
QList<SearchHit>::const_iterator &searchIt,
|
||||
const QRectF &cellRect,
|
||||
const QPoint gridPos) const;
|
||||
bool paintSelection(QPainter &painter, const QRectF &cellRect, const QPoint gridPos) const;
|
||||
void paintDebugSelection(QPainter &painter, const Selection &selection) const;
|
||||
void surfaceChanged() override;
|
||||
|
||||
qreal topMargin() const;
|
||||
void selectionChanged(const std::optional<Selection> &newSelection) override;
|
||||
void linkActivated(const Link &link) override;
|
||||
void contextMenuRequested(const QPoint &pos) override;
|
||||
|
||||
QPoint viewportToGlobal(QPoint p) const;
|
||||
QPoint globalToViewport(QPoint p) const;
|
||||
QPoint globalToGrid(QPointF p) const;
|
||||
QPointF gridToGlobal(QPoint p, bool bottom = false, bool right = false) const;
|
||||
QRect gridToViewport(QRect rect) const;
|
||||
QPoint toGridPos(QMouseEvent *event) const;
|
||||
void writeToPty(const QByteArray &data) override;
|
||||
void resizePty(QSize newSize) override;
|
||||
void setClipboard(const QString &text) override;
|
||||
std::optional<TerminalView::Link> toLink(const QString &text) override;
|
||||
|
||||
void updateViewport();
|
||||
void updateViewportRect(const QRect &rect);
|
||||
|
||||
int textLineFromPixel(int y) const;
|
||||
std::optional<int> textPosFromPoint(const QTextLayout &textLayout, QPoint p) const;
|
||||
|
||||
std::optional<QTextLayout::FormatRange> selectionToFormatRange(
|
||||
TerminalWidget::Selection selection, const QTextLayout &layout, int rowOffset) const;
|
||||
|
||||
bool checkLinkAt(const QPoint &pos);
|
||||
|
||||
struct TextAndOffsets
|
||||
{
|
||||
int start;
|
||||
int end;
|
||||
std::u32string text;
|
||||
};
|
||||
|
||||
TextAndOffsets textAt(const QPoint &pos) const;
|
||||
|
||||
void applySizeChange();
|
||||
void updateScrollBars();
|
||||
|
||||
void flushVTerm(bool force);
|
||||
|
||||
bool setSelection(const std::optional<Selection> &selection, bool scroll = true);
|
||||
QString textFromSelection() const;
|
||||
|
||||
void configBlinkTimer();
|
||||
|
||||
QColor toQColor(std::variant<int, QColor> color) const;
|
||||
|
||||
void updateCopyState();
|
||||
const QList<TerminalSolution::SearchHit> &searchHits() const override;
|
||||
|
||||
RegisteredAction registerAction(Utils::Id commandId, const Core::Context &context);
|
||||
void registerShortcut(Core::Command *command);
|
||||
|
||||
void updateCopyState();
|
||||
|
||||
private:
|
||||
Core::Context m_context;
|
||||
std::unique_ptr<Utils::Process> m_process;
|
||||
std::unique_ptr<Internal::TerminalSurface> m_surface;
|
||||
std::unique_ptr<ShellIntegration> m_shellIntegration;
|
||||
|
||||
QString m_shellName;
|
||||
Utils::Id m_identifier;
|
||||
|
||||
QFont m_font;
|
||||
QSizeF m_cellSize;
|
||||
|
||||
bool m_ignoreScroll{false};
|
||||
|
||||
QString m_preEditString;
|
||||
QString m_title;
|
||||
|
||||
std::optional<Selection> m_selection;
|
||||
std::optional<LinkSelection> m_linkSelection;
|
||||
TerminalSolution::SearchHit m_lastSelectedHit{};
|
||||
|
||||
struct
|
||||
{
|
||||
QPoint start;
|
||||
QPoint end;
|
||||
} m_activeMouseSelect;
|
||||
|
||||
QTimer m_flushDelayTimer;
|
||||
|
||||
QTimer m_scrollTimer;
|
||||
int m_scrollDirection{0};
|
||||
|
||||
std::array<QColor, 20> m_currentColors;
|
||||
Utils::Id m_identifier;
|
||||
|
||||
Utils::Terminal::OpenTerminalParameters m_openParameters;
|
||||
|
||||
std::chrono::system_clock::time_point m_lastFlush;
|
||||
std::chrono::system_clock::time_point m_lastDoubleClick;
|
||||
bool m_selectLineMode{false};
|
||||
|
||||
Internal::Cursor m_cursor;
|
||||
QTimer m_cursorBlinkTimer;
|
||||
bool m_cursorBlinkState{true};
|
||||
|
||||
Utils::FilePath m_cwd;
|
||||
Utils::CommandLine m_currentCommand;
|
||||
|
||||
@@ -245,7 +108,6 @@ private:
|
||||
TerminalSearchPtr m_search;
|
||||
|
||||
Aggregation::Aggregate *m_aggregate{nullptr};
|
||||
SearchHit m_lastSelectedHit{};
|
||||
|
||||
RegisteredAction m_copy;
|
||||
RegisteredAction m_paste;
|
||||
|
||||
Reference in New Issue
Block a user