X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiSelection.cpp;h=362da4aba54d1c9c074c19ca974aa6fd3fdc3721;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=d12ee008294d97bcbcef3e1c18097ec3e18f649e;hpb=8a393b1f46e680206085259e2ef7ae717c9563ab;p=lyx.git diff --git a/src/frontends/qt4/GuiSelection.cpp b/src/frontends/qt4/GuiSelection.cpp index d12ee00829..362da4aba5 100644 --- a/src/frontends/qt4/GuiSelection.cpp +++ b/src/frontends/qt4/GuiSelection.cpp @@ -15,8 +15,8 @@ #include "GuiSelection.h" #include "qt_helpers.h" -#include "support/debug.h" +#include "support/debug.h" #include "support/lstrings.h" #include @@ -27,17 +27,13 @@ namespace lyx { namespace frontend { -using support::internalLineEnding; -using support::externalLineEnding; - GuiSelection::GuiSelection() - : selection_supported_(qApp->clipboard()->supportsSelection()) + : schedule_check_(true), + selection_supported_(qApp->clipboard()->supportsSelection()) { - connect(qApp->clipboard(), SIGNAL(dataChanged()), + connect(qApp->clipboard(), SIGNAL(selectionChanged()), this, SLOT(on_dataChanged())); - // initialize clipboard status. - on_dataChanged(); } @@ -55,6 +51,7 @@ void GuiSelection::haveSelection(bool own) // an application actually requests it. // This way calling Selection::have() is cheap and we can do it as // often as we want. + //LYXERR(Debug::SELECTION, "GuiSelection: setting dummy selection"); if (own) qApp->clipboard()->setText(QString(), QClipboard::Selection); // We don't need to do anything if own = false, as this case is @@ -71,27 +68,27 @@ docstring const GuiSelection::get() const { QString const str = qApp->clipboard()->text(QClipboard::Selection) .normalized(QString::NormalizationForm_C); - LYXERR(Debug::ACTION, "GuiSelection::get: " << fromqstr(str)); + LYXERR(Debug::SELECTION, "GuiSelection::get: " << str); if (str.isNull()) return docstring(); - return internalLineEnding(qstring_to_ucs4(str)); + return internalLineEnding(str); } void GuiSelection::put(docstring const & str) { - LYXERR(Debug::ACTION, "GuiSelection::put: " << to_utf8(str)); + LYXERR(Debug::SELECTION, "GuiSelection::put: " << to_utf8(str)); - qApp->clipboard()->setText(toqstr(externalLineEnding(str)), + qApp->clipboard()->setText(externalLineEnding(str), QClipboard::Selection); } void GuiSelection::on_dataChanged() { - text_selection_empty_ = qApp->clipboard()-> - text(QClipboard::Selection).isEmpty(); + schedule_check_ = true; + LYXERR(Debug::SELECTION, "GuiSelection::on_dataChanged"); } @@ -100,12 +97,20 @@ bool GuiSelection::empty() const if (!selection_supported_) return true; - LYXERR(Debug::ACTION, "GuiSelection::empty: " << text_selection_empty_); - - return text_selection_empty_; + // Cache which is to speed up selection-status read + // (4 calls when open Edit menu). + static bool text_selection_empty; + if (schedule_check_) { + text_selection_empty = qApp->clipboard()-> + text(QClipboard::Selection).isEmpty(); + schedule_check_ = false; + } + + LYXERR(Debug::SELECTION, "GuiSelection::filled: " << !text_selection_empty); + return text_selection_empty; } } // namespace frontend } // namespace lyx -#include "GuiSelection_moc.cpp" +#include "moc_GuiSelection.cpp"