Uwe Stöhr wrote:
> > Is it possible to convert between pageref and pagebackref?
>
> It is, this is the third issue. Simply deleting information in lyx2lyx is 
> not an option. I changed it now so that pagebackref is converted to 
> backref=page, otherwise this would be a dataloss.
>
> > to me hyperref support is a new feature and there is no correct way how 
> to
> > put it back into 1.5.
>
> But this already works. 

nope.

the conversion 1.5 -> 1.6 doesn't work wrt hyperref and it will be almost
impossible to get it right, which was one of the three reasons i objected the 
whole
idea of 1.6 -> 1.5 conversion. any user of 1.6 pdfsupport who will exchange 
docs 
between 1.6 and 1.5 is bound to encounter strange bugs because of this.

the second reason was that the lyx2lyx code complexity will grow and will be
error-prone of which is one example below.

>Nevertheless we should at least take care of 
> existing LyX documents created with LyX 1.6svn (beta or RC). Therefore 
> deleting is no option in lyx2lyx.

i finally didn't commit because i think the proposed lyx2lyx routines
are currently wrong. it will need more care if we want the data-saving version.

for example convert_backref_options doesn't care about the case \pdf_backref 
true
which is now to be translated as section, moreover it can coincide with already 
passed
\pdf_backref page.
there will be similar problems in revert part of routine.

attached is the current patch with some small additions in non ly2lyx parts.
pavel
Index: development/FORMAT
===================================================================
--- development/FORMAT  (revision 26876)
+++ development/FORMAT  (working copy)
@@ -1,6 +1,10 @@
 LyX file-format changes
 -----------------------
 
+2008-10-12 Pavel Sanda <[EMAIL PROTECTED]>
+       * Format incremented to 344: sanitize backreference settings
+         for hyperref (fix bug 5340).
+
 2008-10-12 JĂźrgen SpitzmĂźller <[EMAIL PROTECTED]>
        * Format incremented to 343: new param \use_default_options
          (fix bug 2114).
Index: src/frontends/qt4/GuiDocument.cpp
===================================================================
--- src/frontends/qt4/GuiDocument.cpp   (revision 26876)
+++ src/frontends/qt4/GuiDocument.cpp   (working copy)
@@ -134,6 +134,18 @@
 };
 
 
+char const * backref_opts[] =
+{
+       "false", "section", "slide", "page", ""
+};
+
+
+char const * backref_opts_gui[] =
+{
+       N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
+};
+
+
 vector<pair<string, QString> > pagestyles;
 
 
@@ -989,17 +1001,18 @@
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
-       connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
+       connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
-       connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
        connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
 
+       for (int i = 0; backref_opts[i][0]; ++i)
+               pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
+
        // float
        floatModule = new FloatPlacement;
        connect(floatModule, SIGNAL(changed()),
@@ -1812,8 +1825,8 @@
        pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
        pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
        pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
-       pdf.backref = pdfSupportModule->backrefCB->isChecked();
-       pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
+       pdf.backref =
+               backref_opts[pdfSupportModule->backrefCO->currentIndex()];
        if (pdfSupportModule->fullscreenCB->isChecked())
                pdf.pagemode = pdf.pagemode_fullscreen;
        else
@@ -2145,8 +2158,11 @@
        pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
        pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
        pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
-       pdfSupportModule->backrefCB->setChecked(pdf.backref);
-       pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
+
+       n = findToken(backref_opts, pdf.backref);
+       if (n >= 0)
+               pdfSupportModule->backrefCO->setCurrentIndex(n);
+
        pdfSupportModule->fullscreenCB->setChecked
                (pdf.pagemode == pdf.pagemode_fullscreen);
 
Index: src/frontends/qt4/ui/PDFSupportUi.ui
===================================================================
--- src/frontends/qt4/ui/PDFSupportUi.ui        (revision 26876)
+++ src/frontends/qt4/ui/PDFSupportUi.ui        (working copy)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>420</width>
-    <height>411</height>
+    <width>437</width>
+    <height>400</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -64,7 +64,7 @@
             <property name="orientation" >
              <enum>Qt::Vertical</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>20</width>
               <height>40</height>
@@ -77,7 +77,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>181</width>
               <height>41</height>
@@ -87,12 +87,12 @@
           </item>
           <item row="1" column="0" >
            <layout class="QVBoxLayout" >
-            <property name="margin" >
-             <number>0</number>
-            </property>
             <property name="spacing" >
              <number>6</number>
             </property>
+            <property name="margin" >
+             <number>0</number>
+            </property>
             <item>
              <widget class="QCheckBox" name="pdfusetitleCB" >
               <property name="toolTip" >
@@ -200,7 +200,7 @@
             <property name="orientation" >
              <enum>Qt::Vertical</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>20</width>
               <height>40</height>
@@ -210,12 +210,12 @@
           </item>
           <item row="0" column="0" >
            <layout class="QVBoxLayout" >
-            <property name="margin" >
-             <number>0</number>
-            </property>
             <property name="spacing" >
              <number>6</number>
             </property>
+            <property name="margin" >
+             <number>0</number>
+            </property>
             <item>
              <widget class="QCheckBox" name="breaklinksCB" >
               <property name="toolTip" >
@@ -244,24 +244,20 @@
              </widget>
             </item>
             <item>
-             <widget class="QCheckBox" name="backrefCB" >
+             <widget class="QLabel" name="label" >
               <property name="toolTip" >
-               <string>Adds "backlink" text to the end of each item in the 
bibliography</string>
+               <string>Bibliographical backreferences</string>
               </property>
               <property name="text" >
-               <string>B&amp;ibliographical backreferences</string>
+               <string>B&amp;ackreferences:</string>
               </property>
+              <property name="buddy" >
+               <cstring>backrefCO</cstring>
+              </property>
              </widget>
             </item>
             <item>
-             <widget class="QCheckBox" name="pagebackrefCB" >
-              <property name="toolTip" >
-               <string>Adds "backlink" text to the end of each item in the 
bibliography</string>
-              </property>
-              <property name="text" >
-               <string>Backreference by pa&amp;ge number</string>
-              </property>
-             </widget>
+             <widget class="QComboBox" name="backrefCO" />
             </item>
            </layout>
           </item>
@@ -270,7 +266,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>151</width>
               <height>20</height>
@@ -321,12 +317,12 @@
              </item>
              <item row="2" column="0" >
               <layout class="QHBoxLayout" >
-               <property name="margin" >
-                <number>0</number>
-               </property>
                <property name="spacing" >
                 <number>6</number>
                </property>
+               <property name="margin" >
+                <number>0</number>
+               </property>
                <item>
                 <widget class="QLabel" name="bookmarksopenlevelLA" >
                  <property name="text" >
@@ -358,7 +354,7 @@
                <property name="orientation" >
                 <enum>Qt::Horizontal</enum>
                </property>
-               <property name="sizeHint" >
+               <property name="sizeHint" stdset="0" >
                 <size>
                  <width>40</width>
                  <height>20</height>
@@ -374,7 +370,7 @@
             <property name="orientation" >
              <enum>Qt::Vertical</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>20</width>
               <height>40</height>
@@ -410,9 +406,7 @@
          <item row="0" column="0" >
           <widget class="QLineEdit" name="optionsLE" >
            <property name="sizePolicy" >
-            <sizepolicy>
-             <hsizetype>7</hsizetype>
-             <vsizetype>0</vsizetype>
+            <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
@@ -433,7 +427,7 @@
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
        <width>402</width>
        <height>16</height>
Index: src/PDFOptions.cpp
===================================================================
--- src/PDFOptions.cpp  (revision 26876)
+++ src/PDFOptions.cpp  (working copy)
@@ -47,7 +47,6 @@
                && pdfborder == x.pdfborder
                && colorlinks == x.colorlinks
                && backref == x.backref
-               && pagebackref == x.pagebackref
                && pdfusetitle == x.pdfusetitle;
 }
 
@@ -76,8 +75,7 @@
        os << "\\pdf_breaklinks "  << convert<string>(breaklinks)  << '\n';
        os << "\\pdf_pdfborder "   << convert<string>(pdfborder)   << '\n';
        os << "\\pdf_colorlinks "  << convert<string>(colorlinks)  << '\n';
-       os << "\\pdf_backref "     << convert<string>(backref)     << '\n';
-       os << "\\pdf_pagebackref " << convert<string>(pagebackref) << '\n';
+       os << "\\pdf_backref "     << backref << '\n';
        os << "\\pdf_pdfusetitle " << convert<string>(pdfusetitle) << '\n';
        
        if (!pagemode.empty())
@@ -116,9 +114,7 @@
        opt += (pdfborder ?'0':'1');
        opt += "},";
 
-       opt += "backref="        + convert<string>(backref) + ',';
-       opt += "pagebackref="    + convert<string>(pagebackref) + ',';
-       opt += "\n ";
+       opt += "backref=" + backref + ',';
        opt += "colorlinks="     + convert<string>(colorlinks) + ',';
        if (!pagemode.empty())
                opt += "pdfpagemode=" + pagemode + ',';
@@ -194,8 +190,6 @@
                lex >> colorlinks;
        } else if (token == "\\pdf_backref") {
                lex >> backref;
-       } else if (token == "\\pdf_pagebackref") {
-               lex >> pagebackref;
        } else if (token == "\\pdf_pdfusetitle") {
                lex >> pdfusetitle;
        } else if (token == "\\pdf_pagemode") {
@@ -231,8 +225,7 @@
        breaklinks              = false;
        pdfborder               = false;
        colorlinks              = false;
-       backref                 = false;
-       pagebackref             = false;
+       backref                 = "false";
        pagemode.clear();
        quoted_options.clear();
        pdfusetitle             = true;  //in contrast with hyperref
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp      (revision 26876)
+++ src/Buffer.cpp      (working copy)
@@ -115,7 +115,9 @@
 
 namespace {
 
-int const LYX_FORMAT = 343;
+// Do not remove the comment below, so we get merge conflict in
+// in independent branches.
+int const LYX_FORMAT = 344;  // ps: backref
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Index: src/PDFOptions.h
===================================================================
--- src/PDFOptions.h    (revision 26876)
+++ src/PDFOptions.h    (working copy)
@@ -96,19 +96,15 @@
        bool colorlinks;
        /**
                * Adds backlink text to the end of each item in the 
bibliography,
-               * as a list of section numbers.
+               * as a list of section/slide/page numbers.
                * This can only work properly if there is a blank line after 
each
                * \bibitem.
-               * backref        boolean false
+               * backref   string  empty(="section"), "false", "section", 
"slide", "page"
+               *
+               * Internally we use false/section/slide/pages. See also bug 
5340.
                */
-       bool backref;
+       std::string backref;
        /**
-               * Adds backlink text to the end of each item in the 
bibliography,
-               * as a list of page numbers.
-               * pagebackref       boolean false
-               */
-       bool pagebackref;
-       /**
                * Determines how the file is opening in Acrobat;
                * the possibilities are None, UseThumbs (show thumbnails), 
UseOutlines
                * (show bookmarks), and FullScreen.
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py      (revision 26876)
+++ lib/lyx2lyx/lyx_1_6.py      (working copy)
@@ -2971,6 +2971,26 @@
     document.header.insert(i, '\\use_default_options false')
 
 
+def revert_backref_options(document):
+    ' Remove pageref additional options '
+    i = find_token(document.header, "\\pdf_backref page", 0)
+    if i != -1:
+        document.header[i] = "\\pdf_pagebackref true"
+        return
+    j = find_token(document.header, "\\pdf_backref", 0)
+    if j != -1:
+        del document.header[j]
+
+
+def convert_backref_options(document):
+    ' We have changed the option pagebackref to backref=true '
+    i = find_token(document.header, "\\pdf_pagebackref true", 0)
+    if i != -1:
+        document.header[i] = "\\pdf_backref page"
+    j = find_token(document.header, "\\pdf_pagebackref false", 0)
+    if j != -1:
+        del document.header[j]
+
 ##
 # Conversion hub
 #
@@ -3042,10 +3062,12 @@
            [340, [add_plain_layout]],
            [341, []],
            [342, []],
-           [343, [convert_default_options]]
+           [343, [convert_default_options]],
+           [344, [convert_backref_options]]
           ]
 
-revert =  [[342, [revert_default_options]],
+revert =  [[343, [revert_backref_options]],
+           [342, [revert_default_options]],
            [341, [revert_mongolian]],
            [340, [revert_tabulators, revert_tabsize]],
            [339, []],

Reply via email to