Commit 9129523e authored by Victor Yacovlev's avatar Victor Yacovlev

GUI: implemented context menu paste action for Input terminal

parent a224d118
......@@ -800,52 +800,52 @@ p, li { white-space: pre-wrap; }
<context>
<name>Terminal::OneSession</name>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="272"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="277"/>
<source>&gt;&gt; %1:%2:%3 - %4 - Process started</source>
<translation>&gt;&gt; %1:%2:%3 - %4 - Начало выполнения</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="282"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="287"/>
<source>&gt;&gt; %1:%2:%3 - %4 - Process finished</source>
<translation>&gt;&gt; %1:%2:%3 - %4 - Выполнение завершено</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="334"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="339"/>
<source>INPUT </source>
<translation>ВВОД </translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="341"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="346"/>
<source>string</source>
<translation>лит</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="343"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="348"/>
<source>integer</source>
<translation>цел</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="345"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="350"/>
<source>real</source>
<translation>вещ</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="347"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="352"/>
<source>charect</source>
<translation>сим</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="349"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="354"/>
<source>boolean</source>
<translation>лог</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="504"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="509"/>
<source>Not a &apos;%1&apos; value</source>
<translation>Это не значение типа %1</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="540"/>
<location filename="../../../src/plugins/coregui/terminal_onesession.cpp" line="545"/>
<source>RUNTIME ERROR: %1</source>
<translation>ОШИБКА ВЫПОЛНЕНИЯ: %1</translation>
</message>
......@@ -853,10 +853,15 @@ p, li { white-space: pre-wrap; }
<context>
<name>Terminal::Plane</name>
<message>
<location filename="../../../src/plugins/coregui/terminal_plane.cpp" line="21"/>
<location filename="../../../src/plugins/coregui/terminal_plane.cpp" line="22"/>
<source>Copy to clipboard</source>
<translation>Копировать</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/terminal_plane.cpp" line="26"/>
<source>Paste from clipboard</source>
<translation>Вставить</translation>
</message>
</context>
<context>
<name>Terminal::Term</name>
......
......@@ -208,6 +208,11 @@ bool OneSession::hasSelectedText() const
return false;
}
bool OneSession::isEditable() const
{
return inputCursorPosition_ != -1;
}
QString OneSession::selectedText() const
{
QString result;
......
......@@ -35,6 +35,7 @@ public:
int widthInChars(int realWidth) const;
bool hasSelectedText() const;
QString selectedText() const;
bool isEditable() const;
public slots:
void output(const QString & text);
void input(const QString & format);
......
......@@ -15,6 +15,7 @@ Plane::Plane(Term *parent)
, inputPosition_(0)
, selectedSession_(nullptr)
, actionCopyToClipboard_(new QAction(this))
, actionPasteFromClipboard_(new QAction(this))
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
......@@ -22,6 +23,10 @@ Plane::Plane(Term *parent)
connect(actionCopyToClipboard_, SIGNAL(triggered()),
this, SLOT(copyToClipboard()));
actionPasteFromClipboard_->setText(tr("Paste from clipboard"));
connect(actionPasteFromClipboard_, SIGNAL(triggered()),
this, SLOT(pasteFromClipboard()));
}
void Plane::keyPressEvent(QKeyEvent *e)
......@@ -173,12 +178,19 @@ void Plane::contextMenuEvent(QContextMenuEvent * event)
foreach (const OneSession * s, terminal_->sessions_) {
canCopyToClipboard = canCopyToClipboard || s->hasSelectedText();
}
bool hasAnyAction = canCopyToClipboard;
const QClipboard * clipboard = QApplication::clipboard();
bool canPasteFromClipboard = inputMode_ &&
clipboard->text().length()>0;
bool hasAnyAction =
canCopyToClipboard ||
canPasteFromClipboard;
if (hasAnyAction) {
QMenu * menu = new QMenu(this);
if (canCopyToClipboard)
menu->addAction(actionCopyToClipboard_);
if (canPasteFromClipboard)
menu->addAction(actionPasteFromClipboard_);
menu->exec(mapToGlobal(event->pos()));
}
}
......@@ -193,6 +205,16 @@ void Plane::copyToClipboard()
clipboard->setText(text);
}
void Plane::pasteFromClipboard()
{
const QClipboard * clipboard = QApplication::clipboard();
const QString text = clipboard->text().replace("\n", " ");
inputText_ += text;
inputPosition_ += text.length();
emit inputTextChanged(inputText_);
emit inputCursorPositionChanged(inputPosition_);
}
void Plane::updateScrollBars()
{
QPoint prevOffset = offset();
......
......@@ -42,6 +42,7 @@ protected:
private slots:
void copyToClipboard();
void pasteFromClipboard();
private:
OneSession* sessionByPos(const QPoint & pos) const;
......@@ -53,6 +54,7 @@ private:
OneSession* selectedSession_;
QPoint mousePressPosition_;
QAction * actionCopyToClipboard_;
QAction * actionPasteFromClipboard_;
};
} // namespace Terminal
......
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