TexRow.h
Text.h
TextClass.h
+ TextClass_ptr.h
TextClassList.h
TextMetrics.h
Thesaurus.h
#include "ParIterator.h"
#include "sgml.h"
#include "TexRow.h"
+#include "TextClassList.h"
#include "TexStream.h"
#include "TocBackend.h"
#include "Undo.h"
params().headsep.erase();
params().footskip.erase();
params().listings_params.clear();
+
for (int i = 0; i < 4; ++i) {
params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
params().temp_bullet(i) = ITEMIZE_DEFAULTS[i];
Alert::error(_("Can't load document class"), bformat(
_("Using the default document class, because the "
"class %1$s could not be loaded."), from_utf8(theclass)));
- params().textclass = 0;
+ params().setBaseClass(defaultTextclass());
}
if (params().outputChanges) {
#include "Author.h"
#include "BranchList.h"
+#include "buffer_funcs.h"
#include "Bullet.h"
#include "debug.h"
#include "Encoding.h"
}
-textclass_type defaultTextclass()
-{
- // Initialize textclass to point to article. if `first' is
- // true in the returned pair, then `second' is the textclass
- // number; if it is false, second is 0. In both cases, second
- // is what we want.
- return textclasslist.numberOfClass("article").second;
-}
-
} // anon namespace
BufferParams::BufferParams()
- : textclass(defaultTextclass()), pimpl_(new Impl)
+ : pimpl_(new Impl)
{
+ setBaseClass(defaultTextclass());
paragraph_separation = PARSEP_INDENT;
quotes_language = InsetQuotes::EnglishQ;
fontsize = "default";
pair<bool, lyx::textclass_type> pp =
textclasslist.numberOfClass(classname);
if (pp.first) {
- textclass = pp.second;
+ setBaseClass(pp.second);
} else {
// if text class does not exist, try to load it from filepath
pp = textclasslist.addTextClass(classname, filepath);
if (pp.first) {
- textclass = pp.second;
+ setBaseClass(pp.second);
} else {
- textclass = defaultTextclass();
+ setBaseClass(defaultTextclass());
return classname;
}
}
- // FIXME: isTeXClassAvailable will try to load the layout file, but will
- // fail because of the lack of path info. Warnings will be given although
- // the layout file will be correctly loaded later.
if (!getTextClass().isTeXClassAvailable()) {
docstring const msg =
bformat(_("The layout file requested by this document,\n"
// Prints out the buffer info into the .lyx file given by file
// the textclass
- os << "\\textclass " << textclasslist[textclass].name() << '\n';
+ os << "\\textclass " << textclasslist[baseClass_].name() << '\n';
// then the preamble
if (!preamble.empty()) {
void BufferParams::useClassDefaults()
{
- TextClass const & tclass = textclasslist[textclass];
+ TextClass const & tclass = textclasslist[baseClass_];
sides = tclass.sides();
columns = tclass.columns();
bool BufferParams::hasClassDefaults() const
{
- TextClass const & tclass = textclasslist[textclass];
+ TextClass const & tclass = textclasslist[baseClass_];
return (sides == tclass.sides()
&& columns == tclass.columns()
TextClass const & BufferParams::getTextClass() const
{
- return textclasslist[textclass];
+ return *textClass_;
+}
+
+
+TextClass_ptr BufferParams::getTextClass_ptr() const {
+ return textClass_;
+}
+
+
+void BufferParams::setTextClass(TextClass_ptr tc) {
+ textClass_ = tc;
+}
+
+
+void BufferParams::setBaseClass(textclass_type tc)
+{
+ baseClass_ = tc;
+ makeTextClass();
+}
+
+
+void BufferParams::setJustBaseClass(textclass_type tc)
+{
+ baseClass_ = tc;
+}
+
+
+textclass_type BufferParams::getBaseClass() const
+{
+ return baseClass_;
+}
+
+
+void BufferParams::makeTextClass()
+{
+ textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
}
#include "BiblioInfo.h"
#include "TextClass.h"
+#include "TextClass_ptr.h"
#include "paper.h"
#include "insets/InsetQuotes.h"
#include "support/copied_ptr.h"
+#include "support/FileName.h"
#include "support/types.h"
#include "frontends/controllers/frontend_helpers.h"
#include <vector>
-
namespace lyx {
class AuthorList;
class VSpace;
class Language;
-
/** Buffer parameters.
- * This class contains all the parameters for this a buffer uses. Some
+ * This class contains all the parameters for this buffer's use. Some
* work needs to be done on this class to make it nice. Now everything
* is in public.
*/
///
void setDefSkip(VSpace const & vs);
- /** Wether paragraphs are separated by using a indent like in
+ /** Whether paragraphs are separated by using a indent like in
* articles or by using a little skip like in letters.
*/
PARSEP paragraph_separation;
InsetQuotes::quote_times quotes_times;
///
std::string fontsize;
- ///
- textclass_type textclass;
- ///
+ ///Get the LyX TextClass (that is, the layout file) this document is using.
+ textclass_type getBaseClass() const;
+ ///Set the LyX TextClass (that is, the layout file) this document is using.
+ ///NOTE This also calls makeTextClass(), to update the local
+ ///TextClass.
+ void setBaseClass(textclass_type);
+ ///Returns the TextClass currently in use: the BaseClass as modified
+ ///by modules.
TextClass const & getTextClass() const;
+ ///Returns a pointer to the TextClass currently in use: the BaseClass
+ ///as modified by modules. (See \file TextClass_ptr.h for the typedef.)
+ TextClass_ptr getTextClass_ptr() const;
+ ///Set the LyX TextClass---layout file---this document is using.
+ ///This does NOT call makeTextClass() and so should be used with
+ ///care. This is most likely not what you want if you are operating on
+ ///BufferParams that are actually associatd with a Buffer. If, on the
+ ///other hand, you are using a temporary set of BufferParams---say, in
+ ///a controller, it may well be, since in that case the local TextClass
+ ///has nothing to do.
+ void setJustBaseClass(textclass_type);
+ /// This bypasses the baseClass and sets the textClass directly.
+ /// Should be called with care and would be better not being here,
+ /// but it seems to be needed by CutAndPaste::putClipboard().
+ void setTextClass(TextClass_ptr);
/// returns the main font for the buffer (document)
Font const getFont() const;
/// \param index should lie in the range 0 <= \c index <= 3.
Bullet & user_defined_bullet(size_type index);
Bullet const & user_defined_bullet(size_type index) const;
- ///
- void readPreamble(Lexer &);
- ///
- void readLanguage(Lexer &);
- ///
- void readGraphicsDriver(Lexer &);
- ///
- void readBullets(Lexer &);
- ///
- void readBulletsLaTeX(Lexer &);
/// Whether to load a package such as amsmath or esint.
/// The enum values must not be changed (file format!)
void setCiteEngine(biblio::CiteEngine const);
private:
+ ///
+ void readPreamble(Lexer &);
+ ///
+ void readLanguage(Lexer &);
+ ///
+ void readGraphicsDriver(Lexer &);
+ ///
+ void readBullets(Lexer &);
+ ///
+ void readBulletsLaTeX(Lexer &);
+ /// create our local TextClass.
+ void makeTextClass();
+
+
+ /// for use with natbib
+ biblio::CiteEngine cite_engine_;
+ /// the base TextClass associated with the document
+ textclass_type baseClass_;
+ /// the possibly modular TextClass actually in use
+ TextClass_ptr textClass_;
+
/** Use the Pimpl idiom to hide those member variables that would otherwise
* drag in other header files.
*/
};
support::copied_ptr<Impl, MemoryTraits> pimpl_;
- ///
- biblio::CiteEngine cite_engine_;
};
} // namespace lyx
el = buf.errorList("Parse");
recordUndo(cursor_);
cap::pasteParagraphList(cursor_, buf.paragraphs(),
- buf.params().textclass, el);
+ buf.params().getTextClass_ptr(), el);
res = _("Document %1$s inserted.");
} else
res = _("Could not insert document %1$s");
#include "LyXFunc.h"
#include "LyXRC.h"
#include "Text.h"
+#include "TextClass_ptr.h"
#include "TextClassList.h"
#include "Paragraph.h"
#include "paragraph_funcs.h"
typedef std::pair<pit_type, int> PitPosPair;
-typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
+typedef limited_stack<pair<ParagraphList, TextClass_ptr> > CutStack;
CutStack theCuts(10);
// persistent selection, cleared until the next selection
pair<PitPosPair, pit_type>
pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
- textclass_type textclass, ErrorList & errorlist)
+ TextClass_ptr textclass, ErrorList & errorlist)
{
Buffer const & buffer = cur.buffer();
pit_type pit = cur.pit();
// Make a copy of the CaP paragraphs.
ParagraphList insertion = parlist;
- textclass_type const tc = buffer.params().textclass;
+ TextClass_ptr const tc = buffer.params().getTextClass_ptr();
// Now remove all out of the pars which is NOT allowed in the
// new environment and set also another font if that is required.
}
-void putClipboard(ParagraphList const & paragraphs, textclass_type textclass,
+void putClipboard(ParagraphList const & paragraphs, TextClass_ptr textclass,
docstring const & plaintext)
{
// For some strange reason gcc 3.2 and 3.3 do not accept
Buffer buffer("", false);
buffer.setUnnamed(true);
buffer.paragraphs() = paragraphs;
- buffer.params().textclass = textclass;
+ buffer.params().setTextClass(textclass);
std::ostringstream lyx;
if (buffer.write(lyx))
theClipboard().put(lyx.str(), plaintext);
void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
pit_type startpit, pit_type endpit,
- int start, int end, textclass_type tc, CutStack & cutstack)
+ int start, int end, TextClass_ptr tc, CutStack & cutstack)
{
BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
}
-void switchBetweenClasses(textclass_type c1, textclass_type c2,
- InsetText & in, ErrorList & errorlist)
+void switchBetweenClasses(TextClass_ptr const & c1,
+ TextClass_ptr const & c2, InsetText & in, ErrorList & errorlist)
{
errorlist.clear();
BOOST_ASSERT(!in.paragraphs().empty());
if (c1 == c2)
return;
-
- TextClass const & tclass1 = textclasslist[c1];
- TextClass const & tclass2 = textclasslist[c2];
+
+ TextClass const & tclass1 = *c1;
+ TextClass const & tclass2 = *c2;
// layouts
ParIterator end = par_iterator_end(in);
text->paragraphs(),
begpit, endpit,
cur.selBegin().pos(), endpos,
- bp.textclass, theCuts);
+ bp.getTextClass_ptr(), theCuts);
// Stuff what we got on the clipboard.
// Even if there is no selection.
putClipboard(theCuts[0].first, theCuts[0].second,
++pos;
copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
- pos, cur.selEnd().pos(), cur.buffer().params().textclass, cutstack);
+ pos, cur.selEnd().pos(),
+ cur.buffer().params().getTextClass_ptr(), cutstack);
dirtyTabularStack(false);
}
par.layout(bp.getTextClass().defaultLayout());
par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
pars.push_back(par);
- cutstack.push(make_pair(pars, bp.textclass));
+ cutstack.push(make_pair(pars, bp.getTextClass_ptr()));
}
}
par.layout(bp.getTextClass().defaultLayout());
par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
pars.push_back(par);
- theCuts.push(make_pair(pars, bp.textclass));
+ theCuts.push(make_pair(pars, bp.getTextClass_ptr()));
} else
copySelectionToStack(cur, theCuts);
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- textclass_type textclass, ErrorList & errorList)
+ TextClass_ptr textclass, ErrorList & errorList)
{
if (cur.inTexted()) {
Text * text = cur.text();
if (buffer.readString(lyx)) {
recordUndo(cur);
pasteParagraphList(cur, buffer.paragraphs(),
- buffer.params().textclass, errorList);
+ buffer.params().getTextClass_ptr(), errorList);
cur.setSelection();
return;
}
#define CUTANDPASTE_H
#include "support/docstring.h"
+#include "TextClass_ptr.h"
#include <vector>
/// Paste the paragraph list \p parlist at the position given by \p cur.
/// Does not handle undo. Does only work in text, not mathed.
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- textclass_type textclass, ErrorList & errorList);
+ TextClass_ptr textclass, ErrorList & errorList);
/** Needed to switch between different classes. This works
* for a list of paragraphs beginning with the specified par.
* It changes layouts and character styles.
*/
-void switchBetweenClasses(textclass_type c1, textclass_type c2,
- InsetText & in, ErrorList &);
+void switchBetweenClasses(TextClass_ptr const & c1,
+ TextClass_ptr const & c2, InsetText & in, ErrorList &);
/// Get the current selection as a string. Does not change the selection.
/// Does only work if the whole selection is in mathed.
textclass_type const tc = tc_pair.second;
if (!textclasslist[tc].load()) {
- docstring s = bformat(_("The document could not be converted\n"
- "into the document class %1$s."),
+ docstring s = bformat(_("The document class %1$s."
+ "could not be loaded."),
from_utf8(textclasslist[tc].name()));
- Alert::error(_("Could not change class"), s);
+ Alert::error(_("Could not load class"), s);
}
}
BOOST_ASSERT(lyx_view_);
Buffer * buffer = lyx_view_->buffer();
- textclass_type const old_class =
- buffer->params().textclass;
-
loadTextclass(argument);
std::pair<bool, textclass_type> const tc_pair =
if (!tc_pair.first)
break;
+ textclass_type const old_class = buffer->params().getBaseClass();
textclass_type const new_class = tc_pair.second;
+
if (old_class == new_class)
// nothing to do
break;
lyx_view_->message(_("Converting document to new document class..."));
recordUndoFullDocument(view());
- buffer->params().textclass = new_class;
+ //Save the old, possibly modular, layout for use in conversion.
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+ buffer->params().setBaseClass(new_class);
+
StableDocIterator backcur(view()->cursor());
ErrorList & el = buffer->errorList("Class Switch");
cap::switchBetweenClasses(
- old_class, new_class,
+ oldClass, buffer->params().getTextClass_ptr(),
static_cast<InsetText &>(buffer->inset()), el);
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
Text3.cpp \
TextClass.cpp \
TextClass.h \
+ TextClass_ptr.h \
TextClassList.cpp \
TextClassList.h \
TextMetrics.cpp \
b.getLanguage());
}
- pasteParagraphList(cur, plist, b.params().textclass,
+ pasteParagraphList(cur, plist, b.params().getTextClass_ptr(),
b.errorList("Paste"));
// restore position
cur.pit() = std::min(cur.lastpit(), spit);
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file TextClass_ptr.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef TEXTCLASS_PTR_H
+#define TEXTCLASS_PTR_H
+
+#include <boost/shared_ptr.hpp>
+
+namespace lyx {
+
+class TextClass;
+
+/** Shared pointer for possibly modular layout. Needed so that paste,
+ * for example, will still be able to retain the pointer, even when
+ * the buffer itself is closed.
+ */
+typedef boost::shared_ptr<TextClass> TextClass_ptr;
+
+}
+#endif
#include "LaTeX.h"
#include "LyX.h"
#include "TextClass.h"
+#include "TextClassList.h"
#include "Paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphList.h"
}
}
+textclass_type defaultTextclass()
+{
+ // We want to return the article class. if `first' is
+ // true in the returned pair, then `second' is the textclass
+ // number; if it is false, second is 0. In both cases, second
+ // is what we want.
+ return textclasslist.numberOfClass("article").second;
+}
+
void loadChildDocuments(Buffer const & buf)
{
if (use_gui && buf.getMasterBuffer() == &buf)
updateLabels(buf);
}
-
} // namespace lyx
///
void checkBufferStructure(Buffer &, ParIterator const &);
+///
+textclass_type defaultTextclass();
+
///
void loadChildDocuments(Buffer const & buffer);
}
// Update the layout display
- if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
+ if (toolbars_->updateLayoutList(buffer()->params().getTextClass_ptr())) {
current_layout = buffer()->params().getTextClass().defaultLayoutName();
}
Toolbars::Toolbars(LyXView & owner)
: owner_(owner),
layout_(0),
- last_textclass_(-1)
+ last_textclass_(TextClass_ptr())
{}
#define TurnOnFlag(x) flags |= ToolbarInfo::x
}
-bool Toolbars::updateLayoutList(int textclass)
+bool Toolbars::updateLayoutList(TextClass_ptr textclass)
{
// update the layout display
if (last_textclass_ != textclass) {
void Toolbars::clearLayoutList()
{
- last_textclass_ = -1;
+ last_textclass_ = TextClass_ptr();
if (layout_)
layout_->clear();
}
#ifndef TOOLBARS_H
#define TOOLBARS_H
+#include "TextClass_ptr.h"
#include "ToolbarBackend.h"
#include "Session.h"
/** Populate the layout combox - returns whether we did a full
* update or not
*/
- bool updateLayoutList(int textclass);
+ bool updateLayoutList(TextClass_ptr textclass);
/// Drop down the layout list.
void openLayoutList();
ToolbarsMap toolbars_;
/// The last textclass layout list in the layout choice selector
- int last_textclass_;
+ TextClass_ptr last_textclass_;
// load flags with saved values
void initFlags(ToolbarInfo & tbinfo);
TextClass const & ControlDocument::textClass() const
{
- return textclasslist[bp_->textclass];
+ return textclasslist[bp_->getBaseClass()];
}
// Set the document class.
textclass_type const old_class =
- kernel().buffer().params().textclass;
- textclass_type const new_class = bp_->textclass;
+ kernel().buffer().params().getBaseClass();
+ textclass_type const new_class = bp_->getBaseClass();
if (new_class != old_class) {
string const name = textclasslist[new_class].name();
kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
textclass_type const tc = latexModule->classCO->currentIndex();
if (form_->controller().loadTextclass(tc)) {
- params.textclass = tc;
+ params.setJustBaseClass(tc);
if (lyxrc.auto_reset_options)
params.useClassDefaults();
form_->update_contents();
} else {
- latexModule->classCO->setCurrentIndex(params.textclass);
+ latexModule->classCO->setCurrentIndex(params.getBaseClass());
}
}
}
// text layout
- params.textclass =
- latexModule->classCO->currentIndex();
+ params.setJustBaseClass(latexModule->classCO->currentIndex());
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
params.pagestyle = "default";
}
// text layout
- latexModule->classCO->setCurrentIndex(params.textclass);
+ latexModule->classCO->setCurrentIndex(params.getBaseClass());
updatePagestyle(form_->controller().textClass().opt_pagestyle(),
params.pagestyle);
{
BufferParams & params = controller().params();
- ///\todo verify the use of below with lyx-devel:
- params.textclass = dialog_->latexModule->classCO->currentIndex();
+ params.setJustBaseClass(dialog_->latexModule->classCO->currentIndex());
params.useClassDefaults();
update_contents();
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
- if (tmp->params().textclass != m_buffer->params().textclass) {
+ if (tmp->params().getBaseClass() != m_buffer->params().getBaseClass()) {
// FIXME UNICODE
docstring text = bformat(_("Included file `%1$s'\n"
"has textclass `%2$s'\n"