]> git.lyx.org Git - lyx.git/commitdiff
Correctly enable/disable all paste lfuns
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 7 Jan 2007 16:43:38 +0000 (16:43 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 7 Jan 2007 16:43:38 +0000 (16:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16576 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/Clipboard.h
src/frontends/Selection.h
src/frontends/qt4/GuiClipboard.C
src/frontends/qt4/GuiClipboard.h
src/frontends/qt4/GuiSelection.C
src/frontends/qt4/GuiSelection.h
src/text3.C

index 817b78144c22ed4c79af9e530b559f03e9198a22..5ebde162daa695483134974e3bde1c4bf84765e5 100644 (file)
@@ -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
index 6c7e7829827cb1a4e0688e883f52f6b314500835..53f587ddbe3bb700d90c115853cec3b68bf6c420 100644 (file)
@@ -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
index fe45d656919201cfdb9ae103543fbd3e6b0e57a2..235a72986ced3f637abaf171a363ba3387d28dcd 100644 (file)
@@ -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
index 74fac3b7f78c5402b7469f13529583a496b66ffd..efc705a33d0b69939a0d5d8b2a2ec6680e2eeee5 100644 (file)
@@ -33,6 +33,7 @@ public:
        docstring const get() const;
        void put(docstring const & str);
        bool isInternal() const;
+       bool empty() const;
        //@}
 };
 
index 3c8df3b634012ecf8741d37b6c61c9e70ce91fee..50f9045c7d5c829e24eea4236cddaf3804be7bb0 100644 (file)
@@ -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
index ed6210f7133859525d799b5da98637a628227588..860c3d16aafb5a1821ed42a882099483bb1fc7ce 100644 (file)
@@ -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
index 2e595fadb85da2a8faf1220fbba20f3a588a9b9f..1212fcd1a4f574b0e67a59c7780ece349885785a 100644 (file)
@@ -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<unsigned int>(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<unsigned int>(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: