FileName const bname(
addName(path, onlyFileName(
changeExtension(filename,
- formats.extension(bufferFormat()) + ".out"))));
+ formats.extension(params().bufferFormat()) + ".out"))));
// Also consider the master buffer log file
FileName masterfname = fname;
}
-bool Buffer::isLatex() const
-{
- return params().documentClass().outputType() == LATEX;
-}
-
-
-bool Buffer::isLiterate() const
-{
- return params().documentClass().outputType() == LITERATE;
-}
-
-
-bool Buffer::isDocBook() const
-{
- return params().documentClass().outputType() == DOCBOOK;
-}
-
-
void Buffer::makeDocBookFile(FileName const & fname,
OutputParams const & runparams,
bool const body_only) const
}
-bool Buffer::isExportableFormat(string const & format) const
-{
- typedef vector<Format const *> Formats;
- Formats formats;
- formats = exportableFormats(true);
- Formats::const_iterator fit = formats.begin();
- Formats::const_iterator end = formats.end();
- for (; fit != end ; ++fit) {
- if ((*fit)->name() == format)
- return true;
- }
- return false;
-}
-
-
bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
{
if (isInternal()) {
case LFUN_BUFFER_EXPORT: {
docstring const arg = cmd.argument();
- enable = arg == "custom" || isExportable(to_utf8(arg));
+ enable = arg == "custom" || params().isExportable(to_utf8(arg));
if (!enable)
flag.message(bformat(
_("Don't know how to export to format: %1$s"), arg));
}
case LFUN_BUFFER_CHKTEX:
- enable = isLatex() && !lyxrc.chktex_command.empty();
+ enable = params().isLatex() && !lyxrc.chktex_command.empty();
break;
case LFUN_BUILD_PROGRAM:
- enable = isExportable("program");
+ enable = params().isExportable("program");
break;
case LFUN_BRANCH_ACTIVATE:
{
OutputParams runparams(¶ms().encoding());
runparams.nice = true;
- runparams.flavor = getOutputFlavor(format);
+ runparams.flavor = params().getOutputFlavor(format);
runparams.linelen = lyxrc.plaintext_linelen;
// No side effect of file copying and image conversion
runparams.dryrun = true;
d->texrow.reset();
d->texrow.newline();
d->texrow.newline();
- if (isDocBook())
+ if (params().isDocBook())
writeDocBookSource(os, absFileName(), runparams, false);
else if (runparams.flavor == OutputParams::HTML)
writeLyXHTMLSource(os, runparams, false);
texrow.newline();
texrow.newline();
// output paragraphs
- if (isDocBook())
+ if (params().isDocBook())
docbookParagraphs(text(), *this, os, runparams);
else if (runparams.flavor == OutputParams::HTML) {
XHTMLStream xs(os);
}
-string Buffer::bufferFormat() const
-{
- string format = params().documentClass().outputFormat();
- if (format == "latex") {
- if (params().useNonTeXFonts)
- return "xetex";
- if (params().encoding().package() == Encoding::japanese)
- return "platex";
- }
- return format;
-}
-
-
-string Buffer::getDefaultOutputFormat() const
-{
- if (!params().default_output_format.empty()
- && params().default_output_format != "default")
- return params().default_output_format;
- if (isDocBook()
- || params().useNonTeXFonts
- || params().encoding().package() == Encoding::japanese) {
- vector<Format const *> const formats = exportableFormats(true);
- if (formats.empty())
- return string();
- // return the first we find
- return formats.front()->name();
- }
- return lyxrc.default_view_format;
-}
-
-
-OutputParams::FLAVOR Buffer::getOutputFlavor(string const format) const
-{
- string const dformat = (format.empty() || format == "default") ?
- getDefaultOutputFormat() : format;
- DefaultFlavorCache::const_iterator it =
- default_flavors_.find(dformat);
-
- if (it != default_flavors_.end())
- return it->second;
-
- OutputParams::FLAVOR result = OutputParams::LATEX;
-
- if (dformat == "xhtml")
- result = OutputParams::HTML;
- else {
- // Try to determine flavor of default output format
- vector<string> backs = backends();
- if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
- // Get shortest path to format
- Graph::EdgePath path;
- for (vector<string>::const_iterator it = backs.begin();
- it != backs.end(); ++it) {
- Graph::EdgePath p = theConverters().getPath(*it, dformat);
- if (!p.empty() && (path.empty() || p.size() < path.size())) {
- path = p;
- }
- }
- if (!path.empty())
- result = theConverters().getFlavor(path);
- }
- }
- // cache this flavor
- default_flavors_[dformat] = result;
- return result;
-}
-
-
namespace {
// helper class, to guarantee this gets reset properly
class MarkAsExporting {
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.plaintext_linelen;
runparams.includeall = includeall;
- vector<string> backs = backends();
+ vector<string> backs = params().backends();
Converters converters = theConverters();
if (find(backs.begin(), backs.end(), format) == backs.end()) {
// Get shortest path to format
} else if (backend_format == "lyx")
writeFile(FileName(filename));
// Docbook backend
- else if (isDocBook()) {
+ else if (params().isDocBook()) {
runparams.nice = !put_in_tempdir;
makeDocBookFile(FileName(filename), runparams);
}
}
string const error_type = (format == "program")
- ? "Build" : bufferFormat();
+ ? "Build" : params().bufferFormat();
ErrorList & error_list = d->errorLists[error_type];
string const ext = formats.extension(format);
FileName const tmp_result_file(changeExtension(filename, ext));
// FIXME: There is a possibility of concurrent access to texrow
// here from the main GUI thread that should be securized.
d->cloned_buffer_->d->texrow = d->texrow;
- string const error_type = bufferFormat();
+ string const error_type = params().bufferFormat();
d->cloned_buffer_->d->errorLists[error_type] = d->errorLists[error_type];
}
}
-bool Buffer::isExportable(string const & format) const
-{
- vector<string> backs = backends();
- for (vector<string>::const_iterator it = backs.begin();
- it != backs.end(); ++it)
- if (theConverters().isReachable(*it, format))
- return true;
- return false;
-}
-
-
-vector<Format const *> Buffer::exportableFormats(bool only_viewable) const
-{
- vector<string> const backs = backends();
- set<string> excludes;
- if (params().useNonTeXFonts) {
- excludes.insert("latex");
- excludes.insert("pdflatex");
- }
- vector<Format const *> result =
- theConverters().getReachable(backs[0], only_viewable, true, excludes);
- for (vector<string>::const_iterator it = backs.begin() + 1;
- it != backs.end(); ++it) {
- vector<Format const *> r =
- theConverters().getReachable(*it, only_viewable, false, excludes);
- result.insert(result.end(), r.begin(), r.end());
- }
- return result;
-}
-
-
-vector<string> Buffer::backends() const
-{
- vector<string> v;
- v.push_back(bufferFormat());
- // FIXME: Don't hardcode format names here, but use a flag
- if (v.back() == "latex") {
- v.push_back("pdflatex");
- v.push_back("luatex");
- v.push_back("xetex");
- } else if (v.back() == "xetex")
- v.push_back("luatex");
- v.push_back("xhtml");
- v.push_back("text");
- v.push_back("lyx");
- return v;
-}
-
-
Buffer::ReadStatus Buffer::extractFromVC()
{
bool const found = LyXVC::file_not_found_hook(d->filename);
/// Set buffer read-only flag
void setReadonly(bool flag = true);
- /// returns \c true if the buffer contains a LaTeX document
- bool isLatex() const;
- /// returns \c true if the buffer contains a DocBook document
- bool isDocBook() const;
- /// returns \c true if the buffer contains a Wed document
- bool isLiterate() const;
-
/** Validate a buffer for LaTeX.
This validates the buffer, and returns a struct for use by
#makeLaTeX# and others. Its main use is to figure out what
- /// return the format of the buffer on a string
- std::string bufferFormat() const;
- /// return the default output format of the current backend
- std::string getDefaultOutputFormat() const;
- /// return the output flavor of \p format or the default
- OutputParams::FLAVOR getOutputFlavor(
- std::string const format = std::string()) const;
-
///
bool doExport(std::string const & format, bool put_in_tempdir,
bool includeall, std::string & result_file) const;
bool includeall = false) const;
///
bool preview(std::string const & format, bool includeall = false) const;
- ///
- bool isExportable(std::string const & format) const;
- ///
- std::vector<Format const *> exportableFormats(bool only_viewable) const;
- ///
- bool isExportableFormat(std::string const & format) const;
/// mark the buffer as busy exporting something, or not
void setExportStatus(bool e) const;
///
/// Change name of buffer. Updates "read-only" flag.
void setFileName(support::FileName const & fname);
///
- std::vector<std::string> backends() const;
- /// A cache for the default flavors
- typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
- ///
- mutable DefaultFlavorCache default_flavors_;
- ///
void getLanguages(std::set<Language const *> &) const;
/// Checks whether any of the referenced bibfiles have changed since the
/// last time we loaded the cache. Note that this does NOT update the
#include "Bullet.h"
#include "Color.h"
#include "ColorSet.h"
+#include "Converter.h"
#include "Encoding.h"
#include "HSpace.h"
#include "IndicesList.h"
}
+string BufferParams::bufferFormat() const
+{
+ string format = documentClass().outputFormat();
+ if (format == "latex") {
+ if (useNonTeXFonts)
+ return "xetex";
+ if (encoding().package() == Encoding::japanese)
+ return "platex";
+ }
+ return format;
+}
+
+
+bool BufferParams::isExportable(string const & format) const
+{
+ vector<string> backs = backends();
+ for (vector<string>::const_iterator it = backs.begin();
+ it != backs.end(); ++it)
+ if (theConverters().isReachable(*it, format))
+ return true;
+ return false;
+}
+
+
+vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
+{
+ vector<string> const backs = backends();
+ set<string> excludes;
+ if (useNonTeXFonts) {
+ excludes.insert("latex");
+ excludes.insert("pdflatex");
+ }
+ vector<Format const *> result =
+ theConverters().getReachable(backs[0], only_viewable, true, excludes);
+ for (vector<string>::const_iterator it = backs.begin() + 1;
+ it != backs.end(); ++it) {
+ vector<Format const *> r =
+ theConverters().getReachable(*it, only_viewable, false, excludes);
+ result.insert(result.end(), r.begin(), r.end());
+ }
+ return result;
+}
+
+
+bool BufferParams::isExportableFormat(string const & format) const
+{
+ typedef vector<Format const *> Formats;
+ Formats formats;
+ formats = exportableFormats(true);
+ Formats::const_iterator fit = formats.begin();
+ Formats::const_iterator end = formats.end();
+ for (; fit != end ; ++fit) {
+ if ((*fit)->name() == format)
+ return true;
+ }
+ return false;
+}
+
+
+vector<string> BufferParams::backends() const
+{
+ vector<string> v;
+ v.push_back(bufferFormat());
+ // FIXME: Don't hardcode format names here, but use a flag
+ if (v.back() == "latex") {
+ v.push_back("pdflatex");
+ v.push_back("luatex");
+ v.push_back("xetex");
+ } else if (v.back() == "xetex")
+ v.push_back("luatex");
+ v.push_back("xhtml");
+ v.push_back("text");
+ v.push_back("lyx");
+ return v;
+}
+
+
+OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
+{
+ string const dformat = (format.empty() || format == "default") ?
+ getDefaultOutputFormat() : format;
+ DefaultFlavorCache::const_iterator it =
+ default_flavors_.find(dformat);
+
+ if (it != default_flavors_.end())
+ return it->second;
+
+ OutputParams::FLAVOR result = OutputParams::LATEX;
+
+ if (dformat == "xhtml")
+ result = OutputParams::HTML;
+ else {
+ // Try to determine flavor of default output format
+ vector<string> backs = backends();
+ if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
+ // Get shortest path to format
+ Graph::EdgePath path;
+ for (vector<string>::const_iterator it = backs.begin();
+ it != backs.end(); ++it) {
+ Graph::EdgePath p = theConverters().getPath(*it, dformat);
+ if (!p.empty() && (path.empty() || p.size() < path.size())) {
+ path = p;
+ }
+ }
+ if (!path.empty())
+ result = theConverters().getFlavor(path);
+ }
+ }
+ // cache this flavor
+ default_flavors_[dformat] = result;
+ return result;
+}
+
+
+string BufferParams::getDefaultOutputFormat() const
+{
+ if (!default_output_format.empty()
+ && default_output_format != "default")
+ return default_output_format;
+ if (isDocBook()
+ || useNonTeXFonts
+ || encoding().package() == Encoding::japanese) {
+ vector<Format const *> const formats = exportableFormats(true);
+ if (formats.empty())
+ return string();
+ // return the first we find
+ return formats.front()->name();
+ }
+ return lyxrc.default_view_format;
+}
+
Font const BufferParams::getFont() const
{
FontInfo f = documentClass().defaultfont();
}
+bool BufferParams::isLatex() const
+{
+ return documentClass().outputType() == LATEX;
+}
+
+
+bool BufferParams::isLiterate() const
+{
+ return documentClass().outputType() == LITERATE;
+}
+
+
+bool BufferParams::isDocBook() const
+{
+ return documentClass().outputType() == DOCBOOK;
+}
+
+
void BufferParams::readPreamble(Lexer & lex)
{
if (lex.getString() != "\\begin_preamble")
#define BUFFERPARAMS_H
#include "Citation.h"
+#include "Format.h"
#include "LayoutModuleList.h"
+#include "OutputParams.h"
#include "paper.h"
#include "insets/InsetQuotes.h"
#include "support/copied_ptr.h"
#include <map>
+#include <vector>
namespace lyx {
/// Clear the removed module list
void clearRemovedModules() { removed_modules_.clear(); }
+ /// returns \c true if the buffer contains a LaTeX document
+ bool isLatex() const;
+ /// returns \c true if the buffer contains a DocBook document
+ bool isDocBook() const;
+ /// returns \c true if the buffer contains a Wed document
+ bool isLiterate() const;
+
+ /// return the format of the buffer on a string
+ std::string bufferFormat() const;
+ /// return the default output format of the current backend
+ std::string getDefaultOutputFormat() const;
+ /// return the output flavor of \p format or the default
+ OutputParams::FLAVOR getOutputFlavor(
+ std::string const format = std::string()) const;
+ ///
+ bool isExportable(std::string const & format) const;
+ ///
+ std::vector<Format const *> exportableFormats(bool only_viewable) const;
+ ///
+ bool isExportableFormat(std::string const & format) const;
+ ///
+ std::vector<std::string> backends() const;
+
/// List of included children (for includeonly)
std::list<std::string> const & getIncludedChildren() const
{ return included_children_; }
void readRemovedModules(Lexer &);
///
void readIncludeonly(Lexer &);
+ /// A cache for the default flavors
+ typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
+ ///
+ mutable DefaultFlavorCache default_flavors_;
/// for use with natbib
CiteEngine cite_engine_;
///
runparams.flavor = getFlavor(edgepath);
if (buffer) {
- runparams.use_japanese = buffer->bufferFormat() == "platex";
+ runparams.use_japanese = buffer->params().bufferFormat() == "platex";
runparams.use_indices = buffer->params().use_indices;
runparams.bibtex_command = (buffer->params().bibtex_command == "default") ?
string() : buffer->params().bibtex_command;
#include "qt_helpers.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "BufferView.h"
#include "Cursor.h"
#include "FuncRequest.h"
KernelDocType Dialog::docType() const
{
- if (buffer().isLatex())
+ if (buffer().params().isLatex())
return LATEX;
- if (buffer().isLiterate())
+ if (buffer().params().isLiterate())
return LITERATE;
return DOCBOOK;
if (!bufferview())
return;
// make a copy in order to consider unapplied changes
- Buffer * tmpbuf = buffer().clone();
- tmpbuf->params().useNonTeXFonts =
- fontModule->osFontsCB->isChecked();
- int idx = latexModule->classCO->currentIndex();
+ BufferParams param_copy = buffer().params();
+ param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
+ int const idx = latexModule->classCO->currentIndex();
if (idx >= 0) {
string const classname = classes_model_.getIDString(idx);
- tmpbuf->params().setBaseClass(classname);
- tmpbuf->params().makeDocumentClass();
+ param_copy.setBaseClass(classname);
+ param_copy.makeDocumentClass();
}
outputModule->defaultFormatCO->blockSignals(true);
outputModule->defaultFormatCO->clear();
outputModule->defaultFormatCO->addItem(qt_("Default"),
QVariant(QString("default")));
typedef vector<Format const *> Formats;
- Formats formats = tmpbuf->exportableFormats(true);
+ Formats formats = param_copy.exportableFormats(true);
Formats::const_iterator cit = formats.begin();
Formats::const_iterator end = formats.end();
for (; cit != end; ++cit)
outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
QVariant(toqstr((*cit)->name())));
outputModule->defaultFormatCO->blockSignals(false);
- // delete the copy
- delete tmpbuf;
}
#include "qt_helpers.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "Format.h"
#include "FuncRequest.h"
void GuiSendTo::updateContents()
{
- all_formats_ = buffer().exportableFormats(false);
+ all_formats_ = buffer().params().exportableFormats(false);
// Save the current selection if any
Format const * current_format = 0;
}
string format = to_utf8(cmd.argument());
if (cmd.argument().empty())
- format = doc_buffer->getDefaultOutputFormat();
- enable = doc_buffer->isExportableFormat(format);
+ format = doc_buffer->params().getDefaultOutputFormat();
+ enable = doc_buffer->params().isExportableFormat(format);
break;
}
|| name == "progress"
|| name == "compare";
else if (name == "print")
- enable = doc_buffer->isExportable("dvi")
+ enable = doc_buffer->params().isExportable("dvi")
&& lyxrc.print_command != "none";
else if (name == "character" || name == "symbols") {
if (!buf || buf->isReadonly())
string format = argument;
if (format.empty())
- format = used_buffer->getDefaultOutputFormat();
+ format = used_buffer->params().getDefaultOutputFormat();
#if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
if (!msg.empty()) {
used_buffer->clone(),
format);
setPreviewFuture(f);
- last_export_format = used_buffer->bufferFormat();
+ last_export_format = used_buffer->params().bufferFormat();
(void) syncFunc;
(void) previewFunc;
// We are asynchronous, so we don't know here anything about the success
#include "LaTeXHighlighter.h"
#include "qt_helpers.h"
-#include "BufferView.h"
#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
#include "Cursor.h"
#include "Format.h"
#include "Paragraph.h"
outputFormatCO->addItem(qt_("Default"),
QVariant(QString("default")));
typedef vector<Format const *> Formats;
- Formats formats = bv_->buffer().exportableFormats(true);
+ Formats formats = bv_->buffer().params().exportableFormats(true);
Formats::const_iterator cit = formats.begin();
Formats::const_iterator end = formats.end();
for (; cit != end; ++cit)
action = LFUN_BUFFER_IMPORT;
break;
case MenuItem::ViewFormats:
- formats = buf->exportableFormats(true);
+ formats = buf->params().exportableFormats(true);
action = LFUN_BUFFER_VIEW;
break;
case MenuItem::UpdateFormats:
- formats = buf->exportableFormats(true);
+ formats = buf->params().exportableFormats(true);
action = LFUN_BUFFER_UPDATE;
break;
default:
- formats = buf->exportableFormats(false);
+ formats = buf->params().exportableFormats(false);
action = LFUN_BUFFER_EXPORT;
}
sort(formats.begin(), formats.end(), &compareFormat);
break;
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
- if ((*fit)->name() == buf->getDefaultOutputFormat()) {
+ if ((*fit)->name() == buf->params().getDefaultOutputFormat()) {
docstring lbl = (kind == MenuItem::ViewFormats ?
bformat(_("View [%1$s]|V"), qstring_to_ucs4(label))
: bformat(_("Update [%1$s]|U"), qstring_to_ucs4(label)));
PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
: parent_(p), buffer_(b)
{
- if (b.bufferFormat() == "lilypond-book")
+ if (b.params().bufferFormat() == "lilypond-book")
pconverter_ = setConverter("lyxpreview-lytex");
else if (b.params().encoding().package() == Encoding::japanese)
pconverter_ = setConverter("lyxpreview-platex");
tmp->markDepClean(masterBuffer->temppath());
// Don't assume the child's format is latex
- string const inc_format = tmp->bufferFormat();
+ string const inc_format = tmp->params().bufferFormat();
FileName const tmpwritefile(changeExtension(writefile.absFileName(),
formats.extension(inc_format)));
}
label += ref;
- if (!buffer().isLatex() && !getParam("name").empty()) {
+ if (!buffer().params().isLatex() && !getParam("name").empty()) {
label += "||";
label += getParam("name");
}
LYXERR(Debug::FIND, " with cur.lastpost=" << cur.lastpos() << ", cur.lastrow="
<< cur.lastrow() << ", cur.lastcol=" << cur.lastcol());
Buffer const & buf = *cur.buffer();
- LASSERT(buf.isLatex(), /* */);
+ LASSERT(buf.params().isLatex(), /* */);
TexRow texrow;
odocstringstream ods;