commit f07771a43b78102cf7f39c581a9588b0af47e3a3
Author: Juergen Spitzmueller <[email protected]>
Date:   Tue Apr 8 06:51:14 2025 +0200

    Make xr also work with label-copy-as-ref
---
 lib/doc/UserGuide.lyx        | 13 ++++++++++++-
 lib/doc/de/UserGuide.lyx     | 10 ++++++++++
 src/insets/InsetLabel.cpp    |  1 +
 src/insets/InsetRef.cpp      | 35 +++++++++++++++++++++++++++++++++++
 src/insets/InsetRef.h        |  2 ++
 src/mathed/InsetMathHull.cpp |  1 +
 6 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx
index 1627430135..fd49f84f92 100644
--- a/lib/doc/UserGuide.lyx
+++ b/lib/doc/UserGuide.lyx
@@ -32679,7 +32679,7 @@ To insert such a reference,
  From the document
 \change_inserted -584632292 1743956042
  in which
-\change_inserted -712698321 1743947698
+\change_inserted -712698321 1744087522
  the reference should be inserted,
  open the cross-references dialog as explained in the previous section.
  Assure that 
@@ -32708,6 +32708,17 @@ In:
 
 \begin_layout Standard
 
+\change_inserted -712698321 1744087587
+Alternatively,
+ you can also use the 
+\family sans
+Copy as Reference
+\family default
+ context menu function to copy the label from the external document as 
described in the previous section.
+\end_layout
+
+\begin_layout Standard
+
 \change_inserted -712698321 1743947906
 There is one caveat,
  though:
diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx
index c257a9e358..f17b07152d 100644
--- a/lib/doc/de/UserGuide.lyx
+++ b/lib/doc/de/UserGuide.lyx
@@ -31362,6 +31362,16 @@ In:
  Wählen Sie die gewünschte und fügen Sie sie hinzu.
 \end_layout
 
+\begin_layout Standard
+Alternativ können Sie – wie im vorhergehenden Abschnitt beschrieben – auch die 
Funktion 
+\family sans
+Als Querverweis kopieren
+\family default
+ aus dem Kontextmenü verwenden,
+ um eine Marke aus einem externen Dokument zu kopieren und sie dann als 
Querverweis einzufügen.
+ 
+\end_layout
+
 \begin_layout Standard
 Beachten Sie aber folgendes:
  Da \SpecialChar LaTeX
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index bfb12e462a..9bc371d341 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -302,6 +302,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_LABEL_COPY_AS_REFERENCE: {
                InsetCommandParams p(REF_CODE, "ref");
                p["reference"] = getParam("name");
+               p["filenames"] = getParam("name") + "@" + 
from_utf8(buffer().absFileName());
                cap::clearSelection();
                cap::copyInset(cur, new InsetRef(buffer_, p), getParam("name"));
                break;
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index e15c54196e..811c8916a9 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -815,6 +815,7 @@ void InsetRef::updateBuffer(ParIterator const & it, 
UpdateType, bool const /*del
        // not be in the label cache yet.)
        broken_ = false;
        setBroken(broken_);
+       cleanUpExternalFileNames();
 }
 
 
@@ -1057,4 +1058,38 @@ FileName InsetRef::getExternalFileName(docstring const & 
inlabel) const
 }
 
 
+void InsetRef::cleanUpExternalFileNames()
+{
+       // remove file names from document and relatives
+       // and make all paths relative
+       if (params()["filenames"].empty())
+               return;
+       vector<string> incFileNames = 
getVectorFromString(ltrim(to_utf8(params()["filenames"])));
+       vector<string> cleanedFN;
+       ListOfBuffers const children = 
buffer().masterBuffer()->getDescendants();
+       for (auto const & ifn : incFileNames) {
+               string label;
+               string const incFileName = split(ifn, label, '@');
+               FileName fn =
+                       support::makeAbsPath(incFileName,
+                                            
support::onlyPath(buffer().absFileName()));
+               if (fn.exists()) {
+                       if (buffer().fileName() == fn)
+                               continue;
+                       bool is_family = false;
+                       for (auto const * b : children) {
+                               if (b->fileName() == fn) {
+                                       is_family = true;
+                                       break;
+                               }
+                       }
+                       if (!is_family)
+                               cleanedFN.push_back(label + "@" + 
to_utf8(fn.relPath(buffer().filePath())));
+               } else
+                       cleanedFN.push_back(label + "@" + 
to_utf8(fn.relPath(buffer().filePath())));
+       }
+       setParam("filenames", from_utf8(getStringFromVector(cleanedFN)));
+}
+
+
 } // namespace lyx
diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h
index f122f6ad37..b97608d313 100644
--- a/src/insets/InsetRef.h
+++ b/src/insets/InsetRef.h
@@ -134,6 +134,8 @@ private:
        ///
        support::FileName getExternalFileName(docstring const & label) const;
        ///
+       void cleanUpExternalFileNames();
+       ///
        std::vector<docstring> getLabels() const { return 
support::getVectorFromString(getParam("reference")); }
        ///
        bool isBroken(docstring const & label, bool const preset = false) const;
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 04d48151f8..a0f22f5674 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -1987,6 +1987,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest 
& cmd)
 
                InsetCommandParams p(REF_CODE, "ref");
                p["reference"] = label(row);
+               p["filenames"] = label(row) + "@" + 
from_utf8(buffer().absFileName());
                cap::clearSelection();
                cap::copyInset(cur, new InsetRef(buffer_, p), label(row));
                break;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to