Terminal: Add select all action

Fixes: QTCREATORBUG-29922
Change-Id: I565f2f9f570610e1bb7f528cd874a0dd9c47dbe8
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2023-11-27 07:13:24 +01:00
parent cdee6e263d
commit 2da12ddc60
5 changed files with 17 additions and 0 deletions

View File

@@ -324,6 +324,11 @@ void TerminalView::clearSelection()
//d->m_surface->sendKey(Qt::Key_Escape);
}
void TerminalView::selectAll()
{
setSelection(Selection{0, d->m_surface->fullSize().width() * d->m_surface->fullSize().height()});
}
void TerminalView::zoomIn()
{
QFont f = font();

View File

@@ -75,6 +75,7 @@ public:
std::optional<Selection> selection() const;
void clearSelection();
void selectAll();
void zoomIn();
void zoomOut();

View File

@@ -16,5 +16,6 @@ constexpr char MOVECURSORWORDLEFT[] = "Terminal.MoveCursorWordLeft";
constexpr char MOVECURSORWORDRIGHT[] = "Terminal.MoveCursorWordRight";
constexpr char CLEAR_TERMINAL[] = "Terminal.ClearTerminal";
constexpr char TOGGLE_KEYBOARD_LOCK[] = "Terminal.ToggleKeyboardLock";
constexpr char SELECTALL[] = "Terminal.SelectAll";
} // namespace Terminal::Constants

View File

@@ -278,11 +278,13 @@ void TerminalWidget::setupActions()
m_clearSelection = registerAction(Constants::CLEARSELECTION, m_context);
m_moveCursorWordLeft = registerAction(Constants::MOVECURSORWORDLEFT, m_context);
m_moveCursorWordRight = registerAction(Constants::MOVECURSORWORDRIGHT, m_context);
m_selectAll = registerAction(Constants::SELECTALL, m_context);
connect(m_copy.get(), &QAction::triggered, this, &TerminalWidget::copyToClipboard);
connect(m_paste.get(), &QAction::triggered, this, &TerminalWidget::pasteFromClipboard);
connect(m_close.get(), &QAction::triggered, this, &TerminalWidget::closeTerminal);
connect(m_clearTerminal.get(), &QAction::triggered, this, &TerminalWidget::clearContents);
connect(m_selectAll.get(), &QAction::triggered, this, &TerminalWidget::selectAll);
connect(m_clearSelection.get(), &QAction::triggered, this, &TerminalWidget::clearSelection);
connect(m_moveCursorWordLeft.get(),
&QAction::triggered,
@@ -503,6 +505,7 @@ void TerminalWidget::contextMenuRequested(const QPoint &pos)
contextMenu->addAction(ActionManager::command(Constants::COPY)->action());
contextMenu->addAction(ActionManager::command(Constants::PASTE)->action());
contextMenu->addAction(ActionManager::command(Constants::SELECTALL)->action());
contextMenu->addSeparator();
contextMenu->addAction(ActionManager::command(Constants::CLEAR_TERMINAL)->action());
contextMenu->addSeparator();
@@ -612,6 +615,7 @@ void TerminalWidget::initActions()
static QAction paste;
static QAction clearSelection;
static QAction clearTerminal;
static QAction selectAll;
static QAction moveCursorWordLeft;
static QAction moveCursorWordRight;
static QAction close;
@@ -620,24 +624,29 @@ void TerminalWidget::initActions()
paste.setText(Tr::tr("Paste"));
clearSelection.setText(Tr::tr("Clear Selection"));
clearTerminal.setText(Tr::tr("Clear Terminal"));
selectAll.setText(Tr::tr("Select All"));
moveCursorWordLeft.setText(Tr::tr("Move Cursor Word Left"));
moveCursorWordRight.setText(Tr::tr("Move Cursor Word Right"));
close.setText(Tr::tr("Close Terminal"));
auto copyCmd = ActionManager::registerAction(&copy, Constants::COPY, context);
auto pasteCmd = ActionManager::registerAction(&paste, Constants::PASTE, context);
auto selectAllCmd = ActionManager::registerAction(&selectAll, Constants::SELECTALL, context);
if (HostOsInfo::isMacHost()) {
copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+C")));
pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+V")));
selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+A")));
} else if (HostOsInfo::isLinuxHost()) {
copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+C")));
pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+V")));
selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+A")));
} else if (HostOsInfo::isWindowsHost()) {
copyCmd->setDefaultKeySequences(
{QKeySequence(QLatin1String("Ctrl+C")), QKeySequence(QLatin1String("Ctrl+Shift+C"))});
pasteCmd->setDefaultKeySequences(
{QKeySequence(QLatin1String("Ctrl+V")), QKeySequence(QLatin1String("Ctrl+Shift+V"))});
selectAllCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+A")));
}
ActionManager::registerAction(&clearSelection, Constants::CLEARSELECTION, context);

View File

@@ -105,6 +105,7 @@ private:
RegisteredAction m_paste;
RegisteredAction m_clearSelection;
RegisteredAction m_clearTerminal;
RegisteredAction m_selectAll;
RegisteredAction m_moveCursorWordLeft;
RegisteredAction m_moveCursorWordRight;
RegisteredAction m_close;