aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2020-02-28 11:02:01 +0100
committerMiodrag Milanovic <mmicko@gmail.com>2020-02-28 11:02:01 +0100
commit6566b5da734b8d7592d262523243a62b722d06b0 (patch)
tree287c3082fb8caea97630175b9a0d6223803ed112 /gui
parent7e54d2c3054be47c6ed336ec66162d790213bf10 (diff)
downloadnextpnr-6566b5da734b8d7592d262523243a62b722d06b0.tar.gz
nextpnr-6566b5da734b8d7592d262523243a62b722d06b0.tar.bz2
nextpnr-6566b5da734b8d7592d262523243a62b722d06b0.zip
Add support for pasting multiline code to python
Diffstat (limited to 'gui')
-rw-r--r--gui/line_editor.cc30
-rw-r--r--gui/line_editor.h1
2 files changed, 25 insertions, 6 deletions
diff --git a/gui/line_editor.cc b/gui/line_editor.cc
index b25f4031..3e1000dc 100644
--- a/gui/line_editor.cc
+++ b/gui/line_editor.cc
@@ -19,6 +19,8 @@
*/
#include "line_editor.h"
+#include <QApplication>
+#include <QClipboard>
#include <QKeyEvent>
#include <QToolTip>
#include "ColumnFormatter.h"
@@ -43,8 +45,19 @@ LineEditor::LineEditor(ParseHelper *helper, QWidget *parent) : QLineEdit(parent)
void LineEditor::keyPressEvent(QKeyEvent *ev)
{
-
- if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
+ if (ev->matches(QKeySequence::Paste)) {
+ QString clipboard = QApplication::clipboard()->text();
+ if (clipboard.isEmpty())
+ return;
+ if (clipboard.contains('\n')) {
+ QStringList clipboard_lines = clipboard.split('\n');
+ for (int i = 0; i < clipboard_lines.size(); i++) {
+ addLineToHistory(clipboard_lines[i]);
+ Q_EMIT textLineInserted(clipboard_lines[i]);
+ }
+ return;
+ }
+ } else if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
QToolTip::hideText();
if (lines.empty())
return;
@@ -79,13 +92,18 @@ bool LineEditor::focusNextPrevChild(bool next) { return false; }
void LineEditor::textInserted()
{
- if (lines.empty() || lines.back() != text())
- lines += text();
+ addLineToHistory(text());
+ clear();
+ Q_EMIT textLineInserted(lines.back());
+}
+
+void LineEditor::addLineToHistory(QString line)
+{
+ if (lines.empty() || lines.back() != line)
+ lines += line;
if (lines.size() > 100)
lines.removeFirst();
index = lines.size();
- clear();
- Q_EMIT textLineInserted(lines.back());
}
void LineEditor::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); }
diff --git a/gui/line_editor.h b/gui/line_editor.h
index a779072f..05a6cf1c 100644
--- a/gui/line_editor.h
+++ b/gui/line_editor.h
@@ -47,6 +47,7 @@ class LineEditor : public QLineEdit
void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
void autocomplete();
+ void addLineToHistory(QString line);
private:
int index;