]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbibtex.C
changelogs
[lyx.git] / src / insets / insetbibtex.C
index feec01537bd4d7ca777faa1cd8630126e68beec3..73ca790e50296ee3b8f9153b26cc62cb960ae606 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <fstream>
 
+using lyx::support::AbsolutePath;
 using lyx::support::ascii_lowercase;
 using lyx::support::ChangeExtension;
 using lyx::support::contains;
@@ -36,6 +37,7 @@ using lyx::support::findtexfile;
 using lyx::support::IsFileReadable;
 using lyx::support::ltrim;
 using lyx::support::MakeAbsPath;
+using lyx::support::MakeRelPath;
 using lyx::support::Path;
 using lyx::support::prefixIs;
 using lyx::support::rtrim;
@@ -60,13 +62,13 @@ InsetBibtex::InsetBibtex(InsetCommandParams const & p)
 {}
 
 
-std::auto_ptr<InsetBase> InsetBibtex::clone() const
+std::auto_ptr<InsetBase> InsetBibtex::doClone() const
 {
        return std::auto_ptr<InsetBase>(new InsetBibtex(*this));
 }
 
 
-void InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void InsetBibtex::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
@@ -79,7 +81,7 @@ void InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        default:
-               InsetCommand::priv_dispatch(cur, cmd);
+               InsetCommand::doDispatch(cur, cmd);
                break;
        }
 }
@@ -91,6 +93,23 @@ string const InsetBibtex::getScreenLabel(Buffer const &) const
 }
 
 
+namespace {
+
+string normalize_name(Buffer const & buffer, OutputParams const & runparams,
+                     string const & name, string const & ext)
+{
+       string const fname = MakeAbsPath(name, buffer.filePath());
+       if (AbsolutePath(name) || !IsFileReadable(fname + ext))
+               return name;
+       else if (!runparams.nice)
+               return fname;
+       else
+               return MakeRelPath(fname, buffer.getMasterBuffer()->filePath());
+}
+
+}
+
+
 int InsetBibtex::latex(Buffer const & buffer, ostream & os,
                       OutputParams const & runparams) const
 {
@@ -113,11 +132,8 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
        // have a comma-separated list of bibliographies
        string db_out;
        while (!adb.empty()) {
-               if (!runparams.nice &&
-                   IsFileReadable(MakeAbsPath(adb, buffer.filePath())+".bib"))
-                        adb = os::external_path(MakeAbsPath(adb,
-                               buffer.filePath()));
-               db_out += adb;
+               db_out += os::external_path(normalize_name(buffer, runparams,
+                                                          adb, ".bib"));
                db_out += ',';
                db_in = split(db_in, adb,',');
        }
@@ -136,13 +152,11 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
        // line count
        int i = 0;
 
-       if (!runparams.nice
-           && IsFileReadable(MakeAbsPath(style, buffer.filePath()) + ".bst")) {
-               style = MakeAbsPath(style, buffer.filePath());
-       }
-
        if (!style.empty()) {
-               os << "\\bibliographystyle{" << style << "}\n";
+               os << "\\bibliographystyle{"
+                  << os::external_path(normalize_name(buffer, runparams,
+                                                      style, ".bst"))
+                  << "}\n";
                i += 1;
        }