Author: rgheck
Date: Wed Jun  1 15:18:08 2011
New Revision: 38915
URL: http://www.lyx.org/trac/changeset/38915

Log:
Fix bug #7540. Patch based upon one added to bug report by Max Funk.

Basically, patch adds routine that calcuates relative paths to parent
rather than child directories.

Modified:
   lyx-devel/trunk/src/frontends/qt4/GuiBibtex.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiCompare.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiExternal.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiGraphics.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiPrint.cpp
   lyx-devel/trunk/src/frontends/qt4/qt_helpers.h

Modified: lyx-devel/trunk/src/frontends/qt4/GuiBibtex.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiBibtex.cpp     Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiBibtex.cpp     Wed Jun  1 15:18:08 
2011        (r38915)
@@ -435,7 +435,7 @@
        QString const label1 = qt_("Documents|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("BibTeX Databases (*.bib)"));
-       return browseRelFile(in_name, bufferFilePath(),
+       return browseRelToParent(in_name, bufferFilePath(),
                qt_("Select a BibTeX database to add"), filter, false, label1, 
dir1);
 }
 
@@ -445,7 +445,7 @@
        QString const label1 = qt_("Documents|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("BibTeX Styles (*.bst)"));
-       return browseRelFile(in_name, bufferFilePath(),
+       return browseRelToParent(in_name, bufferFilePath(),
                qt_("Select a BibTeX style"), filter, false, label1, dir1);
 }
 

Modified: lyx-devel/trunk/src/frontends/qt4/GuiCompare.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiCompare.cpp    Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiCompare.cpp    Wed Jun  1 15:18:08 
2011        (r38915)
@@ -158,11 +158,11 @@
        QString filename;
        if (lyxview().documentBufferView()) {
                QString path = bufferFilePath();
-               filename = browseRelFile(in_name, path, title, filters, false, 
+               filename = browseRelToParent(in_name, path, title, filters, 
false,
                        qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
        } else {
                QString path = toqstr(lyxrc.document_path);
-               QString rel_filename = browseRelFile(in_name, path, title, 
filters, false, 
+               QString rel_filename = browseRelToParent(in_name, path, title, 
filters, false,
                        qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                filename = makeAbsPath(rel_filename, path);
        }

Modified: lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp   Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp   Wed Jun  1 15:18:08 
2011        (r38915)
@@ -1817,7 +1817,7 @@
        QString const label1 = qt_("Layouts|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
        QStringList const filter(qt_("LyX Layout (*.layout)"));
-       QString file = browseRelFile(QString(), bufferFilePath(),
+       QString file = browseRelToParent(QString(), bufferFilePath(),
                qt_("Local layout file"), filter, false,
                label1, dir1);
 
@@ -1873,7 +1873,7 @@
        QString const old = latexModule->childDocLE->text();
        QString const docpath = 
toqstr(support::onlyPath(buffer().absFileName()));
        QStringList const filter(qt_("LyX Files (*.lyx)"));
-       QString file = browseRelFile(old, docpath, title, filter, false,
+       QString file = browseRelToSub(old, docpath, title, filter, false,
                qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
 
        if (!file.isEmpty())

Modified: lyx-devel/trunk/src/frontends/qt4/GuiExternal.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiExternal.cpp   Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiExternal.cpp   Wed Jun  1 15:18:08 
2011        (r38915)
@@ -639,7 +639,7 @@
        QString const label1 = qt_("Documents|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
 
-       return browseRelFile(input, bufpath, title, filter, false, label1, 
dir1);
+       return browseRelToParent(input, bufpath, title, filter, false, label1, 
dir1);
 }
 
 

Modified: lyx-devel/trunk/src/frontends/qt4/GuiGraphics.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiGraphics.cpp   Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiGraphics.cpp   Wed Jun  1 15:18:08 
2011        (r38915)
@@ -793,7 +793,7 @@
        if (!clip.isDirectory())
                clipdir = addName(package().system_support().absFileName(), 
"clipart");
 
-       return browseRelFile(in_name, bufferFilePath(),
+       return browseRelToParent(in_name, bufferFilePath(),
                title, fileFilters(QString()), false, 
                qt_("Clipart|#C#c"), toqstr(clipdir),
                qt_("Documents|#o#O"), toqstr(lyxrc.document_path));

Modified: lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp    Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp    Wed Jun  1 15:18:08 
2011        (r38915)
@@ -328,7 +328,7 @@
 
        QString const docpath = 
toqstr(support::onlyPath(buffer().absFileName()));
 
-       return browseRelFile(in_name, docpath, title, filters, false, 
+       return browseRelToParent(in_name, docpath, title, filters, false,
                qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
 }
 

Modified: lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp      Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp      Wed Jun  1 15:18:08 
2011        (r38915)
@@ -90,7 +90,7 @@
 /** Launch a file dialog and return the chosen file.
        filename: a suggested filename.
        title: the title of the dialog.
-       pattern: *.ps etc.
+       filters: *.ps etc.
        dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
 */
 QString browseFile(QString const & filename,
@@ -194,19 +194,18 @@
 } // namespace frontend
 
 
-QString browseRelFile(QString const & filename, QString const & refpath,
+QString browseRelToParent(QString const & filename, QString const & relpath,
        QString const & title, QStringList const & filters, bool save,
        QString const & label1, QString const & dir1,
        QString const & label2, QString const & dir2)
 {
-       QString const fname = makeAbsPath(filename, refpath);
-
+       QString const fname = makeAbsPath(filename, relpath);
 
        QString const outname =
                frontend::browseFile(fname, title, filters, save, label1, dir1, 
label2, dir2);
 
        QString const reloutname =
-               toqstr(makeRelPath(qstring_to_ucs4(outname), 
qstring_to_ucs4(refpath)));
+               toqstr(makeRelPath(qstring_to_ucs4(outname), 
qstring_to_ucs4(relpath)));
 
        if (reloutname.startsWith("../"))
                return outname;
@@ -215,6 +214,29 @@
 }
 
 
+QString browseRelToSub(QString const & filename, QString const & relpath,
+       QString const & title, QStringList const & filters, bool save,
+       QString const & label1, QString const & dir1,
+       QString const & label2, QString const & dir2)
+{
+       QString const fname = makeAbsPath(filename, relpath);
+
+       QString const outname =
+               frontend::browseFile(fname, title, filters, save, label1, dir1, 
label2, dir2);
+
+       QString const reloutname =
+               toqstr(makeRelPath(qstring_to_ucs4(outname), 
qstring_to_ucs4(relpath)));
+
+       QString testname = reloutname;
+       testname.remove(QRegExp("^(\\.\\./)+"));
+       
+       if (testname.contains("/"))
+               return outname;
+       else
+               return reloutname;
+}
+
+
 
 /////////////////////////////////////////////////////////////////////
 //

Modified: lyx-devel/trunk/src/frontends/qt4/GuiPrint.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiPrint.cpp      Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/GuiPrint.cpp      Wed Jun  1 15:18:08 
2011        (r38915)
@@ -84,7 +84,7 @@
 void GuiPrint::browseClicked()
 {
        QString file =
-               browseRelFile(QString(), bufferFilePath(), qt_("Print to file"),
+               browseRelToParent(QString(), bufferFilePath(), qt_("Print to 
file"),
                             QStringList(qt_("PostScript files (*.ps)")), true);
        if (!file.isEmpty()) {
                fileED->setText(file);

Modified: lyx-devel/trunk/src/frontends/qt4/qt_helpers.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/qt_helpers.h      Wed Jun  1 15:14:28 
2011        (r38914)
+++ lyx-devel/trunk/src/frontends/qt4/qt_helpers.h      Wed Jun  1 15:18:08 
2011        (r38915)
@@ -84,14 +84,29 @@
 support::FileName imageLibFileSearch(QString & dir, QString const & name,
                                     QString const & ext = QString());
 
-/** Wrapper around browseFile which tries to provide a filename
-       relative to relpath.  If the relative path is of the form "foo.txt"
-       or "bar/foo.txt", then it is returned as relative. OTOH, if it is
-       of the form "../baz/foo.txt", an absolute path is returned. This is
-       intended to be useful for insets which encapsulate files/
+/** Wrappers around browseFile which try to provide a filename
+       relative to relpath.
+
+\param title: title for dialog
+       
+\param filters: *.ps, etc
+
+\param save: whether to save dialog info (current path, etc) for next use.
+
+The \param labelN and \param dirN arguments provide for extra buttons 
+in the dialog (e.g., "Templates" and a path to that directory).
+
+The difference between the functions concerns when we think we have a 
+relative path. 
+
+In \c browseRelToParent, we return a relative path only if it IS NOT of 
+       the form "../../foo.txt".
+
+In \c browseRelToSub, we return a relative path only if it IS of the
+ form "../../foo.txt".
 */
-QString browseRelFile(QString const & filename,
-       QString const & refpath,
+QString browseRelToParent(QString const & filename,
+       QString const & relpath,
        QString const & title,
        QStringList const & filters,
        bool save = false,
@@ -100,6 +115,15 @@
        QString const & label2 = QString(),
        QString const & dir2 = QString());
 
+QString browseRelToSub(QString const & filename,
+       QString const & relpath,
+       QString const & title,
+       QStringList const & filters,
+       bool save = false,
+       QString const & label1 = QString(),
+       QString const & dir1 = QString(),
+       QString const & label2 = QString(),
+       QString const & dir2 = QString());
 
 /** Build filelists of all availabe bst/cls/sty-files. Done through
 *  kpsewhich and an external script, saved in *Files.lst.

Reply via email to