From 609878cf005b2c3b30f19a67a61e70361de9219f Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Tue, 29 Jul 2008 01:51:20 +0000 Subject: [PATCH] Towards bug http://bugzilla.lyx.org/show_bug.cgi?id=4830 (selection issues on more LyX instances) This fixes for me the worst cases. Still some selection problem appear from time to time and it will be tricky to get this completely right since the performance 'hacks' our code uses. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25950 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Selection.h | 2 +- src/frontends/qt4/GuiSelection.cpp | 12 +++++++----- src/frontends/qt4/GuiSelection.h | 12 +++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) 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_; };