diff options
| -rw-r--r-- | gui/line_editor.cc | 30 | ||||
| -rw-r--r-- | gui/line_editor.h | 1 | 
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; | 
