/// 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
* 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
return qApp->clipboard()->ownsClipboard();
}
+
+bool GuiClipboard::empty() const
+{
+ return qApp->clipboard()->text(QClipboard::Clipboard).isEmpty();
+}
+
} // namespace frontend
} // namespace lyx
docstring const get() const;
void put(docstring const & str);
bool isInternal() const;
+ bool empty() const;
//@}
};
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
QClipboard::Selection);
}
+
+bool GuiSelection::empty() const
+{
+ if (!qApp->clipboard()->supportsSelection())
+ return empty_;
+
+ return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
+}
+
} // namespace frontend
} // namespace lyx
class GuiSelection: public Selection
{
public:
+ GuiSelection() : empty_(true) {}
virtual ~GuiSelection() {}
/** Selection overloaded methods
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
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:
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: