No, not that one either. Here's one that actually does work.

The issue about converting labels is still there. I'll deal with that.

Thanks for all the testing.

rh

Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 33790)
+++ src/Buffer.cpp	(working copy)
@@ -126,7 +126,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 378; // ps: rev insetinfo
+int const LYX_FORMAT = 379; // rgh: refstyle
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Index: src/insets/InsetRef.cpp
===================================================================
--- src/insets/InsetRef.cpp	(revision 33790)
+++ src/insets/InsetRef.cpp	(working copy)
@@ -24,6 +24,7 @@
 #include "sgml.h"
 #include "TocBackend.h"
 
+#include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -51,7 +52,7 @@
 		|| s == "pageref"
 		|| s == "vref" 
 		|| s == "vpageref"
-		|| s == "prettyref"
+		|| s == "refstyle"
 		|| s == "eqref";
 }
 
@@ -74,6 +75,25 @@
 	// in docbook. So we construct new params, without it, and use that.
 	InsetCommandParams p(REF_CODE, getCmdName());
 	p["reference"] = getParam("reference");
+	string const cmd = p.getCmdName();
+	if (cmd != "refstyle") {
+		os << p.getCommand(runparams);
+		return 0;
+	}
+	// refstyle isn't really a command. rather, it signals that
+	// we need to create the command needed.
+	docstring prefix;
+	docstring const rest = split(p["reference"], prefix, ':');
+	// if rest is empty, then there's no ":", so we'll treat
+	// it simply as a normal reference.
+	if (rest.empty()) {
+		LYXERR0("Couldn't determine reference type for label `" << 
+				prefix << "'");
+		p.setCmdName("ref");
+	} else {
+		p.setCmdName(to_utf8(prefix) + "ref");
+		p["reference"] = rest;
+	}
 	os << p.getCommand(runparams);
 	return 0;
 }
@@ -208,8 +228,8 @@
 {
 	if (getCmdName() == "vref" || getCmdName() == "vpageref")
 		features.require("varioref");
-	else if (getCmdName() == "prettyref")
-		features.require("prettyref");
+	else if (getCmdName() == "refstyle")
+		features.require("refstyle");
 	else if (getCmdName() == "eqref")
 		features.require("amsmath");
 }
@@ -221,7 +241,7 @@
 	{ "pageref",   N_("Page Number"),           N_("Page: ")},
 	{ "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
 	{ "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
-	{ "prettyref", N_("PrettyRef"),             N_("FrmtRef: ")},
+	{ "refstyle",  N_("RefStyle"),              N_("RefStyle: ")},
 	{ "", "", "" }
 };
 
Index: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp	(revision 33790)
+++ src/LaTeXFeatures.cpp	(working copy)
@@ -510,7 +510,7 @@
 	"pifont",
 	// subfig is handled in BufferParams.cpp
 	"varioref",
-	"prettyref",
+	"refstyle",
 	/*For a successful cooperation of the `wrapfig' package with the
 	  `float' package you should load the `wrapfig' package *after*
 	  the `float' package. See the caption package documentation
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp	(revision 33790)
+++ src/LyXAction.cpp	(working copy)
@@ -2305,7 +2305,7 @@
                pageref -- <page> \n
                vpageref -- on <page> \n
                vref -- <reference> on <page> \n
-               prettyref -- Formatted reference
+               refstyle -- Formatted reference
  * \endvar
  */
 		{ LFUN_INSET_INSERT, "inset-insert", Noop, Edit },
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py	(revision 33790)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -602,6 +602,41 @@
         i = i + 1
 
 
+def convert_prettyref(document):
+    " Converts prettyref commands to refstyle commands "
+    re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset ref", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: No end of InsetRef")
+            i += 1
+            continue
+        k = find_token(document.body, "LatexCommand prettyref", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        document.body[k] = "LatexCommand refstyle"
+        k = find_token(document.body, "reference", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        m = re_ref.match(document.body[k])
+        if m:
+            # Note: We could switch from ":" to something else here, though
+            # that would mean doing a lot of \newref somewhere.
+            prefix = m.group(1)
+            suffix = m.group(2)
+            if prefix == "cha":
+                prefix = "chap"
+            elif prefix == "par":
+                prefix = "part"
+            document.body[k] = "reference + " \"" + prefix + ":" + suffix + "\""
+        i = j + 1
+
 def convert_splitindex(document):
     " Converts index and printindex insets to splitindex-aware format "
     i = 0
@@ -1242,10 +1277,12 @@
            [375, []],
            [376, []],
            [377, []],
-           [378, []]
+           [378, []],
+           [379, [convert_prettyref]]
           ]
 
-revert =  [[377, []],
+revert =  [#[378, [revert_refstyle]]
+           [377, []],
            [376, [revert_multirow]],
            [375, [revert_includeall]],
            [374, [revert_includeonly]],
Index: lib/symbols
===================================================================
--- lib/symbols	(revision 33790)
+++ lib/symbols	(working copy)
@@ -131,7 +131,7 @@
 
 # references
 pageref           ref         none
-prettyref         ref         none
+refstyle          ref         none
 ref               ref         none
 vpageref          ref         none
 vref              ref         none
Index: lib/ui/stdcontext.inc
===================================================================
--- lib/ui/stdcontext.inc	(revision 33790)
+++ lib/ui/stdcontext.inc	(working copy)
@@ -90,7 +90,7 @@
 		Item "<Page>|P" "inset-modify changetype pageref"
 		Item "On Page <Page>|O" "inset-modify changetype vpageref"
 		Item "<Reference> on Page <Page>|f" "inset-modify changetype vref"
-		Item "Formatted Reference|t" "inset-modify changetype prettyref"
+		Item "Formatted Reference|t" "inset-modify changetype refstyle"
 		Separator
 		Item "Settings...|S" "inset-settings"
 	End
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx	(revision 33790)
+++ lib/chkconfig.ltx	(working copy)
@@ -265,8 +265,8 @@
 \TestPackage{nomencl}
 \TestPackage{pdfcolmk}
 \TestPackage{pdfpages}
-\TestPackage{prettyref}
 \TestPackage{preview}
+\TestPackage{refstyle}
 \TestPackage{rotating}
 \TestPackage{rotfloat}
 \TestPackage{setspace}

Reply via email to