diff --git a/src/frontends/Selection.h b/src/frontends/Selection.h index ac902ffc1e..fb835e7ffb 100644 --- a/src/frontends/Selection.h +++ b/src/frontends/Selection.h @@ -62,7 +62,7 @@ public: * This does always return true on systems that don't have a real * selection. */ - virtual bool empty() const = 0; + virtual bool empty() = 0; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiSelection.cpp b/src/frontends/qt4/GuiSelection.cpp index f483a3b1b2..0f6fb88ac5 100644 --- a/src/frontends/qt4/GuiSelection.cpp +++ b/src/frontends/qt4/GuiSelection.cpp @@ -91,19 +91,21 @@ void GuiSelection::put(docstring const & str) void GuiSelection::on_dataChanged() { - text_selection_empty_ = qApp->clipboard()-> - text(QClipboard::Selection).isEmpty(); - LYXERR(Debug::SELECTION, "GuiSelection::on_dataChanged::filled: " << !text_selection_empty_); + schedule_check_ = true; + LYXERR(Debug::SELECTION, "GuiSelection::on_dataChanged"); } -bool GuiSelection::empty() const +bool GuiSelection::empty() { if (!selection_supported_) return true; - LYXERR(Debug::SELECTION, "GuiSelection::filled: " << !text_selection_empty_); + if (schedule_check_) + text_selection_empty_ = qApp->clipboard()-> + text(QClipboard::Selection).isEmpty(); + LYXERR(Debug::SELECTION, "GuiSelection::filled: " << !text_selection_empty_); return text_selection_empty_; } diff --git a/src/frontends/qt4/GuiSelection.h b/src/frontends/qt4/GuiSelection.h index c7f2096aa8..f76dc2642c 100644 --- a/src/frontends/qt4/GuiSelection.h +++ b/src/frontends/qt4/GuiSelection.h @@ -37,14 +37,24 @@ public: void haveSelection(bool own); docstring const get() const; void put(docstring const & str); - bool empty() const; + bool empty(); //@} private Q_SLOTS: void on_dataChanged(); private: + // Cache which is to speed up selection-status read + // (4 calls when openi Edit menu). bool text_selection_empty_; + // Direct call clipboard()->text(QClipboard::Selection) inside onDataChanged causes + // selection to be obtained. Now imagine the some LyX instance A, when making selection - + // each change triggers onDataChange in all others instances for each mouse + // or keyboard move. This in turn causes many calls of requestSelection in A + // which interferes with the selecting itself. As a result middle button pasting + // for more instances don't work and debugging is a hell. So we just schedule + // obtaining of selection on the time empty() is actually called. + bool schedule_check_; bool const selection_supported_; };