Commit 274ebb98 authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Tomaz Canabrava
Browse files

Add keyboard shortcut for toggling display of semantic hints

parent 660b78f7
......@@ -61,10 +61,10 @@ public:
/** This enum describes semantic hints appearance
*/
enum SemanticHints {
SemanticHintsNever = 0,
SemanticHintsURL = 1,
SemanticHintsAlways = 2,
enum Hints {
HintsNever = 0,
HintsURL = 1,
HintsAlways = 2,
};
/** This enum describes the shapes used to draw the cursor in terminal
......
......@@ -288,6 +288,12 @@ void ViewManager::setupActions()
connect(action, &QAction::triggered, this, &ViewManager::semanticSetupBash);
_viewContainer->addAction(action);
action = new QAction(i18nc("@action Shortcut entry", "Toggle semantic hints display"), this);
collection->addAction(QStringLiteral("toggle-semantic-hints"), action);
collection->setDefaultShortcut(action, Qt::CTRL | Qt::ALT | Qt::Key_BracketLeft);
connect(action, &QAction::triggered, this, &ViewManager::toggleSemanticHints);
_viewContainer->addAction(action);
action = new QAction(this);
action->setText(i18nc("@action:inmenu", "Equal size to all views"));
collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::SHIFT | Qt::Key_Backslash);
......@@ -500,6 +506,22 @@ void ViewManager::semanticSetupBash()
QChar());
}
void ViewManager::toggleSemanticHints()
{
int currentSessionId = currentSession();
Q_ASSERT(currentSessionId >= 0);
Session *activeSession = SessionManager::instance()->idToSession(currentSessionId);
Q_ASSERT(activeSession);
auto profile = SessionManager::instance()->sessionProfile(activeSession);
profile->setProperty(Profile::SemanticHints, (profile->semanticHints() + 1) % 3);
auto activeTerminalDisplay = _viewContainer->activeViewSplitter()->activeTerminalDisplay();
const char *names[3] = {"Never", "Sometimes", "Always"};
activeTerminalDisplay->showNotification(i18n("Semantic hints ") + i18n(names[profile->semanticHints()]));
activeTerminalDisplay->update();
}
QHash<TerminalDisplay *, Session *> ViewManager::forgetAll(ViewSplitter *splitter)
{
splitter->setParent(nullptr);
......
......@@ -402,6 +402,8 @@ private Q_SLOTS:
void semanticSetupBash();
void toggleSemanticHints();
private:
Q_DISABLE_COPY(ViewManager)
......
......@@ -2867,7 +2867,6 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
_bidiLineLTR = profile->bidiLineLTR();
_bidiTableDirOverride = profile->bidiTableDirOverride();
_semanticUpDown = profile->semanticUpDown();
_semanticHints = profile->semanticHints();
_semanticInputClick = profile->semanticInputClick();
_trimLeadingSpaces = profile->property<bool>(Profile::TrimLeadingSpacesInSelectedText);
_trimTrailingSpaces = profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText);
......
......@@ -340,11 +340,6 @@ public:
return _semanticUpDown;
}
int semanticHints() const
{
return _semanticHints;
}
ColorSchemeWallpaper::Ptr wallpaper() const
{
return _wallpaper;
......@@ -790,7 +785,6 @@ private:
std::unique_ptr<KonsolePrintManager> _printManager;
int _semanticHints;
bool _semanticUpDown;
bool _semanticInputClick;
};
......
......@@ -66,12 +66,6 @@ static inline bool isLineCharString(const QString &string)
return LineBlockCharacters::isLegacyComputingSymbol(ucs4);
}
bool isInvertedRendition(const TerminalDisplay *display)
{
auto currentProfile = SessionManager::instance()->sessionProfile(display->session());
return currentProfile ? currentProfile->property<bool>(Profile::InvertSelectionColors) : false;
}
void TerminalPainter::drawContents(Character *image,
QPainter &paint,
const QRect &rect,
......@@ -81,7 +75,9 @@ void TerminalPainter::drawContents(Character *image,
QVector<LineProperty> lineProperties,
CharacterColor const *ulColorTable)
{
const bool invertedRendition = isInvertedRendition(m_parentDisplay);
auto currentProfile = SessionManager::instance()->sessionProfile(m_parentDisplay->session());
const bool invertedRendition = currentProfile ? currentProfile->property<bool>(Profile::InvertSelectionColors) : false;
const Enum::Hints semanticHints = currentProfile ? static_cast<Enum::Hints>(currentProfile->semanticHints()) : Enum::HintsNever;
QVector<uint> univec;
univec.reserve(m_parentDisplay->usedColumns());
......@@ -249,8 +245,7 @@ void TerminalPainter::drawContents(Character *image,
paint.setRenderHint(QPainter::Antialiasing, false);
paint.setWorldTransform(textScale.inverted(), true);
if ((lineProperty & LINE_PROMPT_START)
&& ((m_parentDisplay->semanticHints() == Enum::SemanticHintsURL && m_parentDisplay->filterChain()->showUrlHint())
|| m_parentDisplay->semanticHints() == Enum::SemanticHintsAlways)) {
&& ((semanticHints == Enum::HintsURL && m_parentDisplay->filterChain()->showUrlHint()) || semanticHints == Enum::HintsAlways)) {
QPen pen(m_parentDisplay->terminalColor()->foregroundColor());
paint.setPen(pen);
paint.drawLine(leftPadding, textY, m_parentDisplay->contentRect().right(), textY);
......
......@@ -489,9 +489,9 @@ void EditProfileDialog::setupGeneralPage(const Profile::Ptr &profile)
false, // preview
{
// buttons
{_generalUi->semanticHintsNever, Enum::SemanticHintsNever},
{_generalUi->semanticHintsURL, Enum::SemanticHintsURL},
{_generalUi->semanticHintsAlways, Enum::SemanticHintsAlways},
{_generalUi->semanticHintsNever, Enum::HintsNever},
{_generalUi->semanticHintsURL, Enum::HintsURL},
{_generalUi->semanticHintsAlways, Enum::HintsAlways},
},
};
setupButtonGroup(semanticHints, profile);
......
Supports Markdown
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