Commit b94162c1 authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg

Allow view-controlling keys in read-only mode

Summary:
Allow to use scrolling (Shift+Up/Down/PgUp/PgDown/Home/End) and a key
for showing URL hints when the view is in read-only mode.

Test Plan:
* Prepare
  * Turn on scrollback
  * Set at least one modifier key for "Show URL hints" (edit profile → advanced)
  * Generate a few screens of text in Konsole
  * Display some URL (e.g. `echo 'www.kde.org'`)
  * Display current time every second: `while sleep 1; do printf '\r%s' "$(date)"; done`
  * Turn on read-only mode
* Patch tests
  * Scroll the view with Shift+Up/Down/PgUp/PgDown/Home/End - the view should scroll
  * Hold down URL hint key - the URL should be underlined with square and a digit on the left
  * Press <URL-hint-key>+1 - the URL should open in a web browser
* Regressions tests
  * Press different keys (including Ctrl+C, Ctrl+Z, etc; skip those mapped to Konsole actions) - nothing in terminal should happen
  * Press Ctrl+S - the time should not stop updating

Reviewers: #konsole, hindenburg

Reviewed By: #konsole, hindenburg

Subscribers: hindenburg, #konsole

Tags: #konsole

Differential Revision: https://phabricator.kde.org/D11668

(cherry picked from commit 6635190c)
parent fefd2e56
...@@ -1578,7 +1578,11 @@ void SessionController::updateReadOnlyActionStates() ...@@ -1578,7 +1578,11 @@ void SessionController::updateReadOnlyActionStates()
bool SessionController::isReadOnly() const bool SessionController::isReadOnly() const
{ {
return _session->isReadOnly(); if (!_session.isNull()) {
return _session->isReadOnly();
} else {
return false;
}
} }
void SessionController::sessionTitleChanged() void SessionController::sessionTitleChanged()
......
...@@ -3421,12 +3421,6 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m ...@@ -3421,12 +3421,6 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event) void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{ {
if (_readOnly) {
event->accept();
return;
}
if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) { if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) {
int hintSelected = event->key() - 0x31; int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) { if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) {
...@@ -3443,25 +3437,29 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event) ...@@ -3443,25 +3437,29 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
} }
} }
_screenWindow->screen()->setCurrentTerminalDisplay(this); if (!_readOnly) {
_screenWindow->screen()->setCurrentTerminalDisplay(this);
_actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't _actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't
// know where the current selection is. // know where the current selection is.
if (_allowBlinkingCursor) { if (_allowBlinkingCursor) {
_blinkCursorTimer->start(); _blinkCursorTimer->start();
if (_cursorBlinking) { if (_cursorBlinking) {
// if cursor is blinking(hidden), blink it again to show it // if cursor is blinking(hidden), blink it again to show it
blinkCursorEvent(); blinkCursorEvent();
}
Q_ASSERT(!_cursorBlinking);
} }
Q_ASSERT(!_cursorBlinking);
} }
emit keyPressedSignal(event); emit keyPressedSignal(event);
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()); if (!_readOnly) {
QAccessible::updateAccessibility(&textCursorEvent); QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX());
QAccessible::updateAccessibility(&textCursorEvent);
}
#endif #endif
event->accept(); event->accept();
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
// Konsole // Konsole
#include "KeyboardTranslator.h" #include "KeyboardTranslator.h"
#include "SessionController.h"
#include "TerminalDisplay.h" #include "TerminalDisplay.h"
using Konsole::Vt102Emulation; using Konsole::Vt102Emulation;
...@@ -1042,6 +1043,9 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) ...@@ -1042,6 +1043,9 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
const Qt::KeyboardModifiers modifiers = event->modifiers(); const Qt::KeyboardModifiers modifiers = event->modifiers();
KeyboardTranslator::States states = KeyboardTranslator::NoState; KeyboardTranslator::States states = KeyboardTranslator::NoState;
TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
const bool isReadOnly = currentView->sessionController()->isReadOnly();
// get current states // get current states
if (getMode(MODE_NewLine)) { if (getMode(MODE_NewLine)) {
states |= KeyboardTranslator::NewLineState; states |= KeyboardTranslator::NewLineState;
...@@ -1059,16 +1063,18 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) ...@@ -1059,16 +1063,18 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
states |= KeyboardTranslator::ApplicationKeypadState; states |= KeyboardTranslator::ApplicationKeypadState;
} }
// check flow control state if (!isReadOnly) {
if ((modifiers &Qt::ControlModifier) != 0u) { // check flow control state
switch (event->key()) { if ((modifiers &Qt::ControlModifier) != 0u) {
case Qt::Key_S: switch (event->key()) {
emit flowControlKeyPressed(true); case Qt::Key_S:
break; emit flowControlKeyPressed(true);
case Qt::Key_Q: break;
case Qt::Key_C: // cancel flow control case Qt::Key_Q:
emit flowControlKeyPressed(false); case Qt::Key_C: // cancel flow control
break; emit flowControlKeyPressed(false);
break;
}
} }
} }
...@@ -1104,8 +1110,6 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) ...@@ -1104,8 +1110,6 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
if ( entry.command() != KeyboardTranslator::NoCommand ) if ( entry.command() != KeyboardTranslator::NoCommand )
{ {
TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
if ((entry.command() & KeyboardTranslator::EraseCommand) != 0) { if ((entry.command() & KeyboardTranslator::EraseCommand) != 0) {
textToSend += eraseChar(); textToSend += eraseChar();
} else if ((entry.command() & KeyboardTranslator::ScrollPageUpCommand) != 0) { } else if ((entry.command() & KeyboardTranslator::ScrollPageUpCommand) != 0) {
...@@ -1128,8 +1132,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event) ...@@ -1128,8 +1132,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
textToSend += _codec->fromUnicode(event->text()); textToSend += _codec->fromUnicode(event->text());
} }
emit sendData(textToSend); if (!isReadOnly) {
} else { emit sendData(textToSend);
}
} else if (!isReadOnly) {
// print an error message to the terminal if no key translator has been // print an error message to the terminal if no key translator has been
// set // set
QString translatorError = i18n("No keyboard translator available. " QString translatorError = i18n("No keyboard translator available. "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment