On Wed, Dec 12, 2007 at 12:04:14AM +0100, Pavel Sanda wrote: > > > >> reasons why > > > >> we dont ask directly > > > >> qApp->clipboard()->text(QClipboard::Selection).isEmpty() ? > > > > > > > > The only reason was speed issue. > > > > > > what about to call this whenever middle button is clicked ? > > > > Might work. Otoh we get the signal delivered anyway... > > i really dont understand what 'speed issues' were the reason. > i was not able to get a single call of empty() function while > editing. i get its call only when i go to the edit menu (ok, > here 4 calls for menu items).
Thinks tend to change, and I am pretty sure this was once called once per keystroke. > anyway i made the patch which preserves the caching and adds > recalculating of cache in case LFUN_PRIMARY_SELECTION_PASTE > is called (eg middle button shot). > > this solves the bug 4403 for me (Helge, can you confirm it ?) > it would also solve the bug 4394 if you want to backport it > to 1.5. > > i will commit this to trunk later INO (if no objections;) > pavel > diff --git a/src/Text3.cpp b/src/Text3.cpp > index fa9fa8d..775bec0 100644 > --- a/src/Text3.cpp > +++ b/src/Text3.cpp > @@ -2027,7 +2027,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & > cmd, > break; > > case LFUN_PRIMARY_SELECTION_PASTE: > - enable = cur.selection() || !theSelection().empty(); > + enable = cur.selection() || !theSelection().empty(false); I don't like single boolean arguments, especially since a lot of our _setters_ look the same. This code can't be understood without reading Selection.h. Can't we have two different functions with meaningful names? > case LFUN_PARAGRAPH_MOVE_UP: > diff --git a/src/frontends/Selection.h b/src/frontends/Selection.h > index ac902ff..4144ddb 100644 > --- a/src/frontends/Selection.h > +++ b/src/frontends/Selection.h > @@ -61,8 +61,11 @@ public: > * Is the X selection empty? > * This does always return true on systems that don't have a real > * selection. > + * For performance reasons cache is used under the hood, which produced > + * problems of middle-button pasting on some systems. Thats where > + * useCache=false helps. > */ > - virtual bool empty() const = 0; > + virtual bool empty(bool useCache=true) = 0; > }; > > } // namespace frontend > diff --git a/src/frontends/qt4/GuiSelection.cpp > b/src/frontends/qt4/GuiSelection.cpp > index d12ee00..fa440b2 100644 > --- a/src/frontends/qt4/GuiSelection.cpp > +++ b/src/frontends/qt4/GuiSelection.cpp > @@ -95,11 +95,13 @@ void GuiSelection::on_dataChanged() > } > > > -bool GuiSelection::empty() const > +bool GuiSelection::empty(bool useCache) > { > if (!selection_supported_) > return true; > > + if (!useCache) on_dataChanged(); > + > LYXERR(Debug::ACTION, "GuiSelection::empty: " << text_selection_empty_); > > return text_selection_empty_; > diff --git a/src/frontends/qt4/GuiSelection.h > b/src/frontends/qt4/GuiSelection.h > index c7f2096..fa32d6d 100644 > --- a/src/frontends/qt4/GuiSelection.h > +++ b/src/frontends/qt4/GuiSelection.h > @@ -37,7 +37,7 @@ public: > void haveSelection(bool own); > docstring const get() const; > void put(docstring const & str); > - bool empty() const; > + bool empty(bool useCache=true); > //@} Formatting around '=' and in the single-line 'if' is off. Andre'