[LyX/master] Extend 0768b232583
Juergen Spitzmueller <[email protected]>
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 32c6040934bea712a342a1e3d629a2a02b27acc4 Author: Juergen Spitzmueller <[email protected]> Date: Fri Aug 14 08:28:31 2026 +0200 Extend 0768b232583 Also support copy html and copy docbook --- lib/RELEASE-NOTES | 7 ++++--- src/BufferView.cpp | 18 +++++++++++++----- src/Cursor.cpp | 8 ++++---- src/Cursor.h | 2 +- src/CutAndPaste.cpp | 4 ++-- src/CutAndPaste.h | 2 +- src/LyXAction.cpp | 3 ++- src/Paragraph.cpp | 15 +++++++++++++++ src/Paragraph.h | 4 +++- src/insets/InsetTabular.cpp | 27 +++++++++++++++++++++++---- src/insets/InsetTabular.h | 2 +- 11 files changed, 69 insertions(+), 23 deletions(-) diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES index c5af4f3bb4..a8145e1c37 100644 --- a/lib/RELEASE-NOTES +++ b/lib/RELEASE-NOTES @@ -65,9 +65,10 @@ - The function language now accepts an additional "local" argument which ensures the language switch is an inline one (e.g. \foreignlanguage). -- The function copy now accepts an optional argument "latex" which will cause - LyX to copy the selection in its LaTeX representation to the external clipboard. - The argument "plain" is equal to the default (copy as plain text string). +- The function copy now accepts an optional argument which will cause + LyX to copy the selection in a special representation to the external clipboard. + Supported values are "latex", "docbook", and "xhtml", as well as "plain" which + is equal to the default (copy as plain text string). - The function paste now has a second optional argument "force" that will enforce conversion with the first argument "latex" or "html" even if the pasted string diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 8a57cf0e49..ed1ace664d 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1422,7 +1422,8 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) case LFUN_COPY: { string const arg = cmd.getArg(0); - if (!arg.empty() && arg != "latex" && arg != "plain") { + if (!arg.empty() && arg != "latex" && arg != "plain" + && arg != "html" && arg != "docbook") { flag.setEnabled(false); break; } @@ -2677,7 +2678,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_COPY: { - bool const latex = cmd.getArg(0) == "latex"; // With multi-cell table content, we pass down to the inset if (cur.inTexted() && cur.selection() && cur.selectionBegin().idx() != cur.selectionEnd().idx()) { @@ -2685,9 +2685,17 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) dispatched = dr.dispatched(); break; } - cap::copySelection(cur, latex); - if (latex) - cur.message(_("Copy as LaTeX")); + string const type = cmd.getArg(0); + int option = AS_STR_NONE; + if (type == "latex") + option = AS_STR_LATEX; + else if (type == "html") + option = AS_STR_XHTML; + else if (type == "docbook") + option = AS_STR_DOCBOOK; + cap::copySelection(cur, option); + if (!type.empty()) + cur.message(bformat(_("Copy to Format: %1$s"), from_ascii(type))); else cur.message(_("Copy")); break; diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 09bd78c7ca..7c7f0d9cbf 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -341,7 +341,7 @@ docstring parbreak(CursorData const * cur) docstring CursorData::selectionAsString(bool const with_label, bool const skipdelete, - bool const latex) const + int const option) const { if (!selection()) return docstring(); @@ -361,9 +361,9 @@ docstring CursorData::selectionAsString(bool const with_label, bool const skipde seq_label = AS_STR_INSETS | AS_STR_SKIPDELETE; } - if (latex) { - label |= AS_STR_LATEX; - seq_label |= AS_STR_LATEX; + if (option != AS_STR_NONE) { + label |= option; + seq_label |= option; } idx_type const startidx = selBegin().idx(); diff --git a/src/Cursor.h b/src/Cursor.h index 1307217338..e886843ff5 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -161,7 +161,7 @@ public: /// docstring selectionAsString(bool const with_label, bool const skipdelete = false, - bool const latex = false) const; + int const option = 0) const; /// get some interesting description of top position void info(odocstream & os, bool devel_mode) const; /// diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index e3b197d47a..8f6d9d7555 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -1045,9 +1045,9 @@ void cutSelectionToTemp(Cursor & cur, bool realcut) } -void copySelection(Cursor const & cur, bool const latex) +void copySelection(Cursor const & cur, int const option) { - copySelection(cur, cur.selectionAsString(true, true, latex)); + copySelection(cur, cur.selectionAsString(true, true, option)); } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index ba308b8927..db4edc08f6 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -71,7 +71,7 @@ void cutSelection(Cursor & cur, bool realcut = true); void cutSelectionToTemp(Cursor & cur, bool realcut = true); /// Push the current selection to the cut buffer and the system clipboard. -void copySelection(Cursor const & cur, bool const latex = false); +void copySelection(Cursor const & cur, int const option = 0); /// Like copySelection, but only put to temporary cut buffer void copySelectionToTemp(Cursor const & cur); /// diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 24a5f2b78d..5cd182d627 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1436,7 +1436,8 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_COPY * \li Action: Copies the current selection to the clipboard. * \li Syntax: copy [<type>] - * \li Params: <type>: type of copy, possible values: plain (= default), latex + * \li Params: <type>: type of copy, possible values: plain (= default), latex, + * html, docbook * \endvar */ { LFUN_COPY, "copy", ReadOnly, Edit }, diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index b73074bb27..8f616a5008 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -4600,6 +4600,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out { odocstringstream os; otexstream ots(os); + XMLStream xs(os); if (beg == 0 && options & AS_STR_LABEL @@ -4621,6 +4622,8 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out || (c == '\n' && (options & AS_STR_NEWLINES))) { if (options & AS_STR_LATEX) ots.put(c); + else if (options & AS_STR_XHTML || options & AS_STR_DOCBOOK) + xs << c; else os.put(c); } else if (c == META_INSET && (options & AS_STR_INSETS)) { @@ -4643,6 +4646,18 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out Font const font(inherit_font, buf.params().language); rp.local_font = &font; getInset(i)->latex(ots, rp); + } else if (c == META_INSET && (options & AS_STR_XHTML)) { + Buffer const & buf = getInset(i)->buffer(); + OutputParams rp(&buf.params().encoding()); + Font const font(inherit_font, buf.params().language); + rp.local_font = &font; + getInset(i)->xhtml(xs, rp); + } else if (c == META_INSET && (options & AS_STR_DOCBOOK)) { + Buffer const & buf = getInset(i)->buffer(); + OutputParams rp(&buf.params().encoding()); + Font const font(inherit_font, buf.params().language); + rp.local_font = &font; + getInset(i)->docbook(xs, rp); } else { getInset(i)->toString(os); } diff --git a/src/Paragraph.h b/src/Paragraph.h index a77b50bcee..83cb848243 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -130,7 +130,9 @@ enum AsStringParameter AS_STR_SKIPDELETE = 8, ///< Skip deleted text in change tracking. AS_STR_PLAINTEXT = 16, ///< Don't export formatting when descending into insets. AS_STR_MATHED = 32, ///< Use a format suitable for mathed (eg. for InsetRef). - AS_STR_LATEX = 64 ///< LaTeX output. + AS_STR_LATEX = 64, ///< LaTeX output. + AS_STR_XHTML = 128, ///< XHTML output. + AS_STR_DOCBOOK = 256 ///< DocBook output. }; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 65b333e06a..0ba8550502 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -5969,9 +5969,16 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_COPY: { - bool const latex = cmd.getArg(0) == "latex"; + string const type = cmd.getArg(0); + int option = AS_STR_NONE; + if (type == "latex") + option = AS_STR_LATEX; + else if (type == "html") + option = AS_STR_XHTML; + else if (type == "docbook") + option = AS_STR_DOCBOOK; if (cur.selIsMultiCell()) - copySelection(cur, latex); + copySelection(cur, option); else cell(cur.idx())->dispatch(cur, cmd); break; @@ -8129,7 +8136,7 @@ void InsetTabular::tabularFeatures(Cursor & cur, } -bool InsetTabular::copySelection(Cursor & cur, bool const latex) +bool InsetTabular::copySelection(Cursor & cur, int const type) { if (!cur.selection()) return false; @@ -8156,7 +8163,7 @@ bool InsetTabular::copySelection(Cursor & cur, bool const latex) paste_tabular->setBuffer(tabular.buffer()); - if (latex) { + if (type == AS_STR_LATEX) { otexstringstream ots; Buffer const & buf = paste_tabular->buffer(); OutputParams runparams(&buf.params().encoding()); @@ -8164,6 +8171,18 @@ bool InsetTabular::copySelection(Cursor & cur, bool const latex) runparams.local_font = &font; paste_tabular->latex(ots, runparams); cap::copySelection(cur, ots.str()); + } else if (type == AS_STR_XHTML || type == AS_STR_DOCBOOK) { + odocstringstream os; + XMLStream xs(os); + Buffer const & buf = paste_tabular->buffer(); + OutputParams runparams(&buf.params().encoding()); + Font const font(inherit_font, buf.params().language); + runparams.local_font = &font; + if (type == AS_STR_XHTML) + paste_tabular->xhtml(xs, runparams); + else + paste_tabular->docbook(xs, runparams); + cap::copySelection(cur, os.str()); } else { OutputParams const runparams(nullptr); odocstringstream os; diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 556ae2d250..6f4370a72d 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -1311,7 +1311,7 @@ private: /// int cellYPos(idx_type cell) const; /// - bool copySelection(Cursor & cur, bool const latex = false); + bool copySelection(Cursor & cur, int const type = AS_STR_NONE); /// bool pasteClipboard(Cursor & cur); /// -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs