]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
* In the process of fixing the math background color bug, this commit transfer backgr...
[lyx.git] / src / insets / insetinclude.C
index 36d745ffaab50d50390a14dbced97131035e6018..213cb3ad63077f1715306de8678f06299e3db5c8 100644 (file)
@@ -271,7 +271,7 @@ void InsetInclude::read(Buffer const &, LyXLex & lex)
 void InsetInclude::read(LyXLex & lex)
 {
        if (lex.isOK()) {
-               lex.next();
+               lex.eatLine();
                string const command = lex.getString();
                params_.scanCommand(command);
        }
@@ -369,7 +369,7 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
 
 
 int InsetInclude::latex(Buffer const & buffer, odocstream & os,
-                       OutputParams const & runparams) const
+                        OutputParams const & runparams) const
 {
        string incfile(to_utf8(params_["filename"]));
 
@@ -383,8 +383,9 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
        // if incfile is relative, make it relative to the master
        // buffer directory.
        if (!absolutePath(incfile)) {
-               incfile = makeRelPath(included_file.absFilename(),
-                                     m_buffer->filePath());
+               // FIXME UNICODE
+               incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
+                                             from_utf8(m_buffer->filePath())));
        }
 
        // write it to a file (so far the complete file)
@@ -395,9 +396,9 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
        if (!runparams.nice)
                incfile = mangled;
-       lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
-       lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
-       lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+       LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
+       LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
+       LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
 
        if (runparams.inComment || runparams.dryrun)
                // Don't try to load or copy the file
@@ -426,9 +427,13 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 // argument. Should we set it to string(), or should makeLaTeXFile
 // make use of it somehow? (JMarc 20031002)
 #endif
+               // The included file might be written in a different encoding
+               Encoding const * const oldEnc = runparams.encoding;
+               runparams.encoding = &tmp->params().encoding();
                tmp->makeLaTeXFile(writefile,
                                   onlyPath(masterFilename(buffer)),
                                   runparams, false);
+               runparams.encoding = oldEnc;
        } else {
                // Copy the file to the temp dir, so that .aux files etc.
                // are not created in the original dir. Files included by
@@ -439,7 +444,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
                if (checksum_in != checksum_out) {
                        if (!copy(included_file, writefile)) {
                                // FIXME UNICODE
-                               lyxerr[Debug::LATEX]
+                               LYXERR(Debug::LATEX)
                                        << to_utf8(bformat(_("Could not copy the file\n%1$s\n"
                                                                  "into the temporary directory."),
                                                   from_utf8(included_file.absFilename())))
@@ -491,22 +496,26 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 
 
 int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
-                       OutputParams const &) const
+                            OutputParams const &) const
 {
        if (isVerbatim(params_)) {
+               os << '[' << getScreenLabel(buffer) << '\n';
                // FIXME: We don't know the encoding of the file
-               docstring const str = from_utf8(
-                       getFileContents(includedFilename(buffer, params_)));
+               docstring const str =
+                    from_utf8(getFileContents(includedFilename(buffer, params_)));
                os << str;
-               // Return how many newlines we issued.
-               return int(lyx::count(str.begin(), str.end(), '\n'));
+               os << "\n]";
+               return PLAINTEXT_NEWLINE + 1; // one char on a separate line
+       } else {
+               docstring const str = '[' + getScreenLabel(buffer) + ']';
+               os << str;
+               return str.size();
        }
-       return 0;
 }
 
 
 int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
-                         OutputParams const & runparams) const
+                          OutputParams const & runparams) const
 {
        string incfile = to_utf8(params_["filename"]);
 
@@ -529,9 +538,9 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
                if (!runparams.nice)
                        incfile = mangled;
 
-               lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
-               lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
-               lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+               LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
+               LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
+               LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
 
                tmp->makeDocBookFile(writefile, runparams, true);
        }
@@ -735,7 +744,9 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
 docstring const latex_string(InsetInclude const & inset, Buffer const & buffer)
 {
        odocstringstream os;
-       OutputParams runparams;
+       // We don't need to set runparams.encoding since this will be done
+       // by latex() anyway.
+       OutputParams runparams(0);
        runparams.flavor = OutputParams::LATEX;
        inset.latex(buffer, os, runparams);