Skip to content

Commit

Permalink
Made DND text follow settings for newline trimming and multiline prom…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan authored Aug 26, 2022
1 parent 95ccd87 commit b53be2e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
56 changes: 39 additions & 17 deletions lib/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2735,22 +2735,7 @@ void TerminalDisplay::emitSelection(bool useXselection,bool appendReturn)
}

if (_confirmMultilinePaste && text.contains(QLatin1Char('\r'))) {
QMessageBox confirmation(this);
confirmation.setWindowTitle(tr("Paste multiline text"));
confirmation.setText(tr("Are you sure you want to paste this text?"));
confirmation.setDetailedText(text);
confirmation.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
// Click "Show details..." to show those by default
const auto buttons = confirmation.buttons();
for( QAbstractButton * btn : buttons ) {
if (confirmation.buttonRole(btn) == QMessageBox::ActionRole && btn->text() == QMessageBox::tr("Show Details...")) {
Q_EMIT btn->clicked();
break;
}
}
confirmation.setDefaultButton(QMessageBox::Yes);
confirmation.exec();
if (confirmation.standardButton(confirmation.clickedButton()) != QMessageBox::Yes) {
if (!multilineConfirmation(text)) {
return;
}
}
Expand Down Expand Up @@ -2798,6 +2783,29 @@ void TerminalDisplay::bracketText(QString& text) const
}
}

bool TerminalDisplay::multilineConfirmation(const QString& text)
{
QMessageBox confirmation(this);
confirmation.setWindowTitle(tr("Paste multiline text"));
confirmation.setText(tr("Are you sure you want to paste this text?"));
confirmation.setDetailedText(text);
confirmation.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
// Click "Show details..." to show those by default
const auto buttons = confirmation.buttons();
for( QAbstractButton * btn : buttons ) {
if (confirmation.buttonRole(btn) == QMessageBox::ActionRole && btn->text() == QMessageBox::tr("Show Details...")) {
Q_EMIT btn->clicked();
break;
}
}
confirmation.setDefaultButton(QMessageBox::Yes);
confirmation.exec();
if (confirmation.standardButton(confirmation.clickedButton()) != QMessageBox::Yes) {
return false;
}
return true;
}

void TerminalDisplay::setSelection(const QString& t)
{
if (QApplication::clipboard()->supportsSelection())
Expand Down Expand Up @@ -3209,9 +3217,23 @@ void TerminalDisplay::dropEvent(QDropEvent* event)
else
{
dropText = event->mimeData()->text();

dropText.replace(QLatin1String("\r\n"), QLatin1String("\n"));
dropText.replace(QLatin1Char('\n'), QLatin1Char('\r'));
if (_trimPastedTrailingNewlines)
{
dropText.replace(QRegularExpression(QStringLiteral("\\r+$")), QString());
}
if (_confirmMultilinePaste && dropText.contains(QLatin1Char('\r')))
{
if (!multilineConfirmation(dropText))
{
return;
}
}
}

emit sendStringToEmu(dropText.toLocal8Bit().constData());
emit sendStringToEmu(dropText.toLocal8Bit().constData());
}

void TerminalDisplay::doDrag()
Expand Down
3 changes: 3 additions & 0 deletions lib/TerminalDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ private slots:
// the left and right are ignored.
void scrollImage(int lines , const QRect& region);

// shows the multiline prompt
bool multilineConfirmation(const QString& text);

void calcGeometry();
void propagateSize();
void updateImageSize();
Expand Down

0 comments on commit b53be2e

Please sign in to comment.