]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / buffer.C
index 21240a0bea95f15d6212d15603d29f9503336314..91d57fa612c2cdcf3d6cd030f6c079148adfc8b5 100644 (file)
@@ -41,7 +41,6 @@
 #include "output.h"
 #include "output_docbook.h"
 #include "output_latex.h"
-#include "output_linuxdoc.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
@@ -56,9 +55,9 @@
 #include "insets/insetinclude.h"
 #include "insets/insettext.h"
 
-#include "mathed/math_macrotemplate.h"
-#include "mathed/math_macrotable.h"
-#include "mathed/math_support.h"
+#include "mathed/MathMacroTemplate.h"
+#include "mathed/MathMacroTable.h"
+#include "mathed/MathSupport.h"
 
 #include "frontends/Alert.h"
 
@@ -79,6 +78,7 @@ namespace io = boost::iostreams;
 #include "support/convert.h"
 
 #include <boost/bind.hpp>
+#include <boost/filesystem/exception.hpp>
 #include <boost/filesystem/operations.hpp>
 
 #if defined (HAVE_UTIME_H)
@@ -93,6 +93,7 @@ namespace io = boost::iostreams;
 #include <fstream>
 
 
+using lyx::docstring;
 using lyx::pos_type;
 using lyx::pit_type;
 
@@ -112,7 +113,6 @@ using lyx::support::makeDisplayPath;
 using lyx::support::makeLatexName;
 using lyx::support::onlyFilename;
 using lyx::support::onlyPath;
-using lyx::support::Path;
 using lyx::support::quoteName;
 using lyx::support::removeAutosaveFile;
 using lyx::support::rename;
@@ -231,7 +231,8 @@ Buffer::~Buffer()
 
        if (!temppath().empty() && !destroyDir(temppath())) {
                Alert::warning(_("Could not remove temporary directory"),
-                       bformat(_("Could not remove the temporary directory %1$s"), temppath()));
+                       bformat(_("Could not remove the temporary directory %1$s"),
+                       lyx::from_utf8(temppath())));
        }
 
        // Remove any previewed LaTeX snippets associated with this buffer.
@@ -389,8 +390,8 @@ namespace {
 void unknownClass(string const & unknown)
 {
        Alert::warning(_("Unknown document class"),
-               bformat(_("Using the default document class, because the "
-                       "class %1$s is unknown."), unknown));
+                      bformat(_("Using the default document class, because the "
+                                             "class %1$s is unknown."), lyx::from_utf8(unknown)));
 }
 
 } // anon
@@ -444,17 +445,17 @@ int Buffer::readHeader(LyXLex & lex)
                                unknownClass(unknown);
                        } else {
                                ++unknown_tokens;
-                               string const s = bformat(_("Unknown token: "
-                                                          "%1$s %2$s\n"),
-                                                        token,
-                                                        lex.getString());
+                               docstring const s = bformat(_("Unknown token: "
+                                                                       "%1$s %2$s\n"),
+                                                        lyx::from_utf8(token),
+                                                        lyx::from_utf8(lex.getString()));
                                errorList.push_back(ErrorItem(_("Document header error"),
                                        s, -1, 0, 0));
                        }
                }
        }
        if (begin_header_line) {
-               string const s = _("\\begin_header is missing");
+               docstring const s = _("\\begin_header is missing");
                errorList.push_back(ErrorItem(_("Document header error"),
                        s, -1, 0, 0));
        }
@@ -474,7 +475,7 @@ bool Buffer::readDocument(LyXLex & lex)
        lex.next();
        string const token = lex.getString();
        if (token != "\\begin_document") {
-               string const s = _("\\begin_document is missing");
+               docstring const s = _("\\begin_document is missing");
                errorList.push_back(ErrorItem(_("Document header error"),
                        s, -1, 0, 0));
        }
@@ -486,8 +487,8 @@ bool Buffer::readDocument(LyXLex & lex)
        if (!params().getLyXTextClass().load(filePath())) {
                string theclass = params().getLyXTextClass().name();
                Alert::error(_("Can't load document class"), bformat(
-                                    "Using the default document class, because the "
-                                    " class %1$s could not be loaded.", theclass));
+                       _("Using the default document class, because the "
+                                    " class %1$s could not be loaded."), lyx::from_utf8(theclass)));
                params().textclass = 0;
        }
 
@@ -504,13 +505,13 @@ bool Buffer::readDocument(LyXLex & lex)
 // needed to insert the selection
 void Buffer::insertStringAsLines(ParagraphList & pars,
        pit_type & pit, pos_type & pos,
-       LyXFont const & fn, string const & str, bool autobreakrows)
+       LyXFont const & fn, docstring const & str, bool autobreakrows)
 {
        LyXFont font = fn;
 
        // insert the string, don't insert doublespace
        bool space_inserted = true;
-       for (string::const_iterator cit = str.begin();
+       for (docstring::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                Paragraph & par = pars[pit];
                if (*cit == '\n') {
@@ -541,9 +542,11 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
                                }
                                space_inserted = true;
                        }
+/* FIXME: not needed anymore?
                } else if (!isPrintable(*cit)) {
                        // Ignore unprintables
                        continue;
+*/
                } else {
                        // just insert the character
                        par.insertChar(pos, *cit, font);
@@ -567,14 +570,15 @@ bool Buffer::readFile(string const & filename)
        paragraphs().clear();
        LyXLex lex(0, 0);
        lex.setFile(filename);
-       bool ret = readFile(lex, filename);
+       if (!readFile(lex, filename))
+               return false;
 
        // After we have read a file, we must ensure that the buffer
        // language is set and used in the gui.
        // If you know of a better place to put this, please tell me. (Lgb)
        updateDocLang(params().language);
 
-       return ret;
+       return true;
 }
 
 
@@ -596,7 +600,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 
        if (!lex.isOK()) {
                Alert::error(_("Document could not be read"),
-                            bformat(_("%1$s could not be read."), filename));
+                            bformat(_("%1$s could not be read."), lyx::from_utf8(filename)));
                return false;
        }
 
@@ -605,7 +609,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 
        if (!lex.isOK()) {
                Alert::error(_("Document could not be read"),
-                            bformat(_("%1$s could not be read."), filename));
+                            bformat(_("%1$s could not be read."), lyx::from_utf8(filename)));
                return false;
        }
 
@@ -615,7 +619,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s is not a LyX document."),
-                                      filename));
+                                      lyx::from_utf8(filename)));
                return false;
        }
 
@@ -637,8 +641,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                                     bformat(_("%1$s is from an earlier"
                                              " version of LyX, but a temporary"
                                              " file for converting it could"
-                                             " not be created."),
-                                             filename));
+                                                           " not be created."),
+                                             lyx::from_utf8(filename)));
                        return false;
                }
                string const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
@@ -647,8 +651,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                                     bformat(_("%1$s is from an earlier"
                                               " version of LyX, but the"
                                               " conversion script lyx2lyx"
-                                              " could not be found."),
-                                              filename));
+                                                           " could not be found."),
+                                              lyx::from_utf8(filename)));
                        return false;
                }
                ostringstream command;
@@ -667,8 +671,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
                        Alert::error(_("Conversion script failed"),
                                     bformat(_("%1$s is from an earlier version"
                                              " of LyX, but the lyx2lyx script"
-                                             " failed to convert it."),
-                                             filename));
+                                                           " failed to convert it."),
+                                             lyx::from_utf8(filename)));
                        return false;
                } else {
                        bool const ret = readFile(tmpfile);
@@ -681,8 +685,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
        if (readDocument(lex)) {
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s ended unexpectedly, which means"
-                                      " that it is probably corrupted."),
-                                      filename));
+                                                   " that it is probably corrupted."),
+                                      lyx::from_utf8(filename)));
        }
 
        //lyxerr << "removing " << MacroTable::localMacros().size()
@@ -712,14 +716,16 @@ bool Buffer::save() const
                // good enough. (Lgb)
                // But to use this we need fs::copy_file to actually do a copy,
                // even when the target file exists. (Lgb)
-               if (fs::exists(fileName()) && fs::is_writable(fs::path(fileName()).branch_path())) {
-                 //try {
+               try {
                    fs::copy_file(fileName(), s, false);
-                   //}
-                   //catch (fs::filesystem_error const & fe) {
-                   //lyxerr << "LyX was not able to make backup copy. Beware.\n"
-                   //     << fe.what() << endl;
-                   //}
+               }
+               catch (fs::filesystem_error const & fe) {
+                       Alert::error(_("Backup failure"),
+                                    bformat(_("LyX was not able to make a backup copy in %1$s.\n"
+                                                           "Please check if the directory exists and is writeable."),
+                                         lyx::from_utf8(fs::path(s).branch_path().native_directory_string())));
+                       lyxerr[Debug::DEBUG] << "Fs error: "
+                                            << fe.what() << endl;
                }
        }
 
@@ -957,12 +963,6 @@ bool Buffer::isLatex() const
 }
 
 
-bool Buffer::isLinuxDoc() const
-{
-       return params().getLyXTextClass().outputType() == LINUXDOC;
-}
-
-
 bool Buffer::isLiterate() const
 {
        return params().getLyXTextClass().outputType() == LITERATE;
@@ -975,83 +975,6 @@ bool Buffer::isDocBook() const
 }
 
 
-bool Buffer::isSGML() const
-{
-       LyXTextClass const & tclass = params().getLyXTextClass();
-
-       return tclass.outputType() == LINUXDOC ||
-              tclass.outputType() == DOCBOOK;
-}
-
-
-void Buffer::makeLinuxDocFile(string const & fname,
-                             OutputParams const & runparams,
-                             bool const body_only)
-{
-       lyxerr[Debug::LATEX] << "makeLinuxDocFile..." << endl;
-
-       ofstream ofs;
-       if (!openFileWrite(ofs, fname))
-               return;
-
-       writeLinuxDocSource(ofs, fname, runparams, body_only);
-
-       ofs.close();
-       if (ofs.fail())
-               lyxerr << "File '" << fname << "' was not closed properly." << endl;
-}
-
-
-void Buffer::writeLinuxDocSource(ostream &os, string const & fname,
-                             OutputParams const & runparams,
-                             bool const body_only)
-{
-       LaTeXFeatures features(*this, params(), runparams);
-       validate(features);
-
-       texrow().reset();
-
-       LyXTextClass const & tclass = params().getLyXTextClass();
-
-       string const & top_element = tclass.latexname();
-
-       if (!body_only) {
-               os << tclass.class_header();
-
-               string preamble = params().preamble;
-               string const name = runparams.nice ? changeExtension(pimpl_->filename, ".sgml")
-                        : fname;
-               preamble += features.getIncludedFiles(name);
-               preamble += features.getLyXSGMLEntities();
-
-               if (!preamble.empty()) {
-                       os << " [ " << preamble << " ]";
-               }
-               os << ">\n\n";
-
-               if (params().options.empty())
-                       sgml::openTag(os, top_element);
-               else {
-                       string top = top_element;
-                       top += ' ';
-                       top += params().options;
-                       sgml::openTag(os, top);
-               }
-       }
-
-       os << "<!-- LyX "  << lyx_version
-           << " created this file. For more info see http://www.lyx.org/"
-           << " -->\n";
-
-       linuxdocParagraphs(*this, paragraphs(), os, runparams);
-
-       if (!body_only) {
-               os << "\n\n";
-               sgml::closeTag(os, top_element);
-       }
-}
-
-
 void Buffer::makeDocBookFile(string const & fname,
                              OutputParams const & runparams,
                              bool const body_only)
@@ -1152,7 +1075,7 @@ int Buffer::runChktex()
        string const path = temppath();
        string const org_path = filePath();
 
-       Path p(path); // path to LaTeX file
+       lyx::support::Path p(path); // path to LaTeX file
        message(_("Running chktex..."));
 
        // Generate the LaTeX file if neccessary
@@ -1355,7 +1278,7 @@ bool Buffer::dispatch(FuncRequest const & func, bool * result)
 
        switch (func.action) {
                case LFUN_BUFFER_EXPORT: {
-                       bool const tmp = Exporter::Export(this, func.argument, false);
+                       bool const tmp = Exporter::Export(this, lyx::to_utf8(func.argument()), false);
                        if (result)
                                *result = tmp;
                        break;
@@ -1462,7 +1385,7 @@ Language const * Buffer::getLanguage() const
 }
 
 
-string const Buffer::B_(string const & l10n) const
+docstring const Buffer::B_(string const & l10n) const
 {
        if (pimpl_->messages.get()) {
                return pimpl_->messages->get(l10n);
@@ -1676,11 +1599,9 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type
 
        if (full_source) {
                os << "% Preview source code\n\n";
-               if (isLatex()) 
+               if (isLatex())
                        writeLaTeXSource(os, filePath(), runparams, true, true);
-               else if (isLinuxDoc())
-                       writeLinuxDocSource(os, fileName(), runparams, false);
-               else 
+               else
                        writeDocBookSource(os, fileName(), runparams, false);
        } else {
                runparams.par_begin = par_begin;
@@ -1693,9 +1614,7 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type
                if (isLatex()) {
                        texrow().reset();
                        latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
-               } else if (isLinuxDoc())
-                       linuxdocParagraphs(*this, paragraphs(), os, runparams);
-               else // DocBook
+               } else // DocBook
                        docbookParagraphs(paragraphs(), *this, os, runparams);
        }
 }