From 36ada6f2676865110a826924818412b634db93b9 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 7 Jan 2007 16:43:38 +0000 Subject: [PATCH] Correctly enable/disable all paste lfuns git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16576 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Clipboard.h | 2 ++ src/frontends/Selection.h | 6 ++++++ src/frontends/qt4/GuiClipboard.C | 6 ++++++ src/frontends/qt4/GuiClipboard.h | 1 + src/frontends/qt4/GuiSelection.C | 13 ++++++++++++- src/frontends/qt4/GuiSelection.h | 10 ++++++++++ src/text3.C | 33 +++++++++++++++++--------------- 7 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/frontends/Clipboard.h b/src/frontends/Clipboard.h index 817b78144c..5ebde162da 100644 --- a/src/frontends/Clipboard.h +++ b/src/frontends/Clipboard.h @@ -43,6 +43,8 @@ public: /// state of clipboard. /// \retval true if the system clipboard has been set within LyX. virtual bool isInternal() const = 0; + /// Is the clipboard empty? + virtual bool empty() const = 0; }; } // namespace frontend diff --git a/src/frontends/Selection.h b/src/frontends/Selection.h index 6c7e782982..53f587ddbe 100644 --- a/src/frontends/Selection.h +++ b/src/frontends/Selection.h @@ -57,6 +57,12 @@ public: * from the kernel and push it to X with this method. */ virtual void put(docstring const &) = 0; + /** + * Is the X selection empty? + * This reports only the state of the internal selection on systems + * that don't have a real selection. + */ + virtual bool empty() const = 0; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiClipboard.C b/src/frontends/qt4/GuiClipboard.C index fe45d65691..235a72986c 100644 --- a/src/frontends/qt4/GuiClipboard.C +++ b/src/frontends/qt4/GuiClipboard.C @@ -56,5 +56,11 @@ bool GuiClipboard::isInternal() const return qApp->clipboard()->ownsClipboard(); } + +bool GuiClipboard::empty() const +{ + return qApp->clipboard()->text(QClipboard::Clipboard).isEmpty(); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h index 74fac3b7f7..efc705a33d 100644 --- a/src/frontends/qt4/GuiClipboard.h +++ b/src/frontends/qt4/GuiClipboard.h @@ -33,6 +33,7 @@ public: docstring const get() const; void put(docstring const & str); bool isInternal() const; + bool empty() const; //@} }; diff --git a/src/frontends/qt4/GuiSelection.C b/src/frontends/qt4/GuiSelection.C index 3c8df3b634..50f9045c7d 100644 --- a/src/frontends/qt4/GuiSelection.C +++ b/src/frontends/qt4/GuiSelection.C @@ -32,8 +32,10 @@ namespace frontend { void GuiSelection::haveSelection(bool own) { - if (!qApp->clipboard()->supportsSelection()) + if (!qApp->clipboard()->supportsSelection()) { + empty_ = !own; return; + } // Tell qt that we have a selection by setting a dummy selection. // We don't use the interface provided by Qt for setting the @@ -76,5 +78,14 @@ void GuiSelection::put(docstring const & str) QClipboard::Selection); } + +bool GuiSelection::empty() const +{ + if (!qApp->clipboard()->supportsSelection()) + return empty_; + + return qApp->clipboard()->text(QClipboard::Selection).isEmpty(); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiSelection.h b/src/frontends/qt4/GuiSelection.h index ed6210f713..860c3d16aa 100644 --- a/src/frontends/qt4/GuiSelection.h +++ b/src/frontends/qt4/GuiSelection.h @@ -25,6 +25,7 @@ namespace frontend { class GuiSelection: public Selection { public: + GuiSelection() : empty_(true) {} virtual ~GuiSelection() {} /** Selection overloaded methods @@ -33,7 +34,16 @@ public: void haveSelection(bool own); docstring const get() const; void put(docstring const & str); + bool empty() const; //@} +private: + /** + * Is the selection empty? + * Only used on systems that don't support a real selection to + * reflect the status of the internal selection of LyX. + * This is needed to emulate the X selection as far as possible. + */ + bool empty_; }; } // namespace frontend diff --git a/src/text3.C b/src/text3.C index 2e595fadb8..1212fcd1a4 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1736,23 +1736,28 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, break; case LFUN_PASTE: - // FIXME: This is not correct, but the correct code below is - // expensive - enable = cap::numberOfSelections() > 0 || - !theClipboard().isInternal(); -#if 0 if (cmd.argument().empty()) { if (theClipboard().isInternal()) enable = cap::numberOfSelections() > 0; else - enable = !theClipboard().get().empty(); - } else if (isStrUnsignedInt(to_utf8(cmd.argument()))) { - int n = convert(to_utf8(cmd.argument())); - enable = cap::numberOfSelections() > n; - } else - // unknown argument - enable = false; -#endif + enable = !theClipboard().empty(); + } else { + string const arg = to_utf8(cmd.argument()); + if (isStrUnsignedInt(arg)) { + unsigned int n = convert(arg); + enable = cap::numberOfSelections() > n; + } else + // unknown argument + enable = false; + } + break; + + case LFUN_CLIPBOARD_PASTE: + enable = !theClipboard().empty(); + break; + + case LFUN_PRIMARY_SELECTION_PASTE: + enable = !theSelection().empty(); break; case LFUN_PARAGRAPH_MOVE_UP: @@ -1825,8 +1830,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_SERVER_GET_FONT: case LFUN_SERVER_GET_LAYOUT: case LFUN_LAYOUT: - case LFUN_CLIPBOARD_PASTE: - case LFUN_PRIMARY_SELECTION_PASTE: case LFUN_DATE_INSERT: case LFUN_SELF_INSERT: case LFUN_LINE_INSERT: -- 2.39.2