mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Rationalize the handling of makeTextClass().
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22388 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
80e98c5b71
commit
9a7cd29f5b
@ -517,6 +517,8 @@ int Buffer::readHeader(Lexer & lex)
|
|||||||
errorList.push_back(ErrorItem(_("Document header error"),
|
errorList.push_back(ErrorItem(_("Document header error"),
|
||||||
s, -1, 0, 0));
|
s, -1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params().makeTextClass();
|
||||||
|
|
||||||
return unknown_tokens;
|
return unknown_tokens;
|
||||||
}
|
}
|
||||||
@ -542,14 +544,6 @@ bool Buffer::readDocument(Lexer & lex)
|
|||||||
BOOST_ASSERT(paragraphs().empty());
|
BOOST_ASSERT(paragraphs().empty());
|
||||||
|
|
||||||
readHeader(lex);
|
readHeader(lex);
|
||||||
TextClass const & baseClass = textclasslist[params().getBaseClass()];
|
|
||||||
if (!baseClass.load(filePath())) {
|
|
||||||
string theclass = baseClass.name();
|
|
||||||
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().setBaseClass(defaultTextclass());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params().outputChanges) {
|
if (params().outputChanges) {
|
||||||
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
||||||
|
@ -314,6 +314,7 @@ BufferParams::BufferParams()
|
|||||||
: pimpl_(new Impl)
|
: pimpl_(new Impl)
|
||||||
{
|
{
|
||||||
setBaseClass(defaultTextclass());
|
setBaseClass(defaultTextclass());
|
||||||
|
makeTextClass();
|
||||||
paragraph_separation = PARSEP_INDENT;
|
paragraph_separation = PARSEP_INDENT;
|
||||||
quotes_language = InsetQuotes::EnglishQ;
|
quotes_language = InsetQuotes::EnglishQ;
|
||||||
fontsize = "default";
|
fontsize = "default";
|
||||||
@ -497,7 +498,6 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
|
|||||||
readPreamble(lex);
|
readPreamble(lex);
|
||||||
} else if (token == "\\begin_modules") {
|
} else if (token == "\\begin_modules") {
|
||||||
readModules(lex);
|
readModules(lex);
|
||||||
makeTextClass();
|
|
||||||
} else if (token == "\\options") {
|
} else if (token == "\\options") {
|
||||||
lex.eatLine();
|
lex.eatLine();
|
||||||
options = lex.getString();
|
options = lex.getString();
|
||||||
@ -1363,24 +1363,16 @@ void BufferParams::setTextClass(TextClassPtr tc) {
|
|||||||
|
|
||||||
bool BufferParams::setBaseClass(textclass_type tc)
|
bool BufferParams::setBaseClass(textclass_type tc)
|
||||||
{
|
{
|
||||||
bool retVal = true;
|
if (textclasslist[tc].load()) {
|
||||||
if (textclasslist[tc].load())
|
|
||||||
baseClass_ = tc;
|
baseClass_ = tc;
|
||||||
else {
|
return true;
|
||||||
docstring s =
|
|
||||||
bformat(_("The document class %1$s could not be loaded."),
|
|
||||||
from_utf8(textclasslist[tc].name()));
|
|
||||||
frontend::Alert::error(_("Could not load class"), s);
|
|
||||||
retVal = false;
|
|
||||||
}
|
}
|
||||||
makeTextClass();
|
|
||||||
return retVal;
|
docstring s =
|
||||||
}
|
bformat(_("The document class %1$s could not be loaded."),
|
||||||
|
from_utf8(textclasslist[tc].name()));
|
||||||
|
frontend::Alert::error(_("Could not load class"), s);
|
||||||
void BufferParams::setJustBaseClass(textclass_type tc)
|
return false;
|
||||||
{
|
|
||||||
baseClass_ = tc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1393,6 +1385,7 @@ textclass_type BufferParams::getBaseClass() const
|
|||||||
void BufferParams::makeTextClass()
|
void BufferParams::makeTextClass()
|
||||||
{
|
{
|
||||||
textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
|
textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
|
||||||
|
|
||||||
//FIXME It might be worth loading the children's modules here,
|
//FIXME It might be worth loading the children's modules here,
|
||||||
//just as we load their bibliographies and such, instead of just
|
//just as we load their bibliographies and such, instead of just
|
||||||
//doing a check in InsetInclude.
|
//doing a check in InsetInclude.
|
||||||
@ -1432,7 +1425,7 @@ vector<string> const & BufferParams::getModules() const {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BufferParams::addLayoutModule(string modName, bool makeClass) {
|
bool BufferParams::addLayoutModule(string modName) {
|
||||||
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
||||||
LayoutModuleList::const_iterator end = layoutModules_.end();
|
LayoutModuleList::const_iterator end = layoutModules_.end();
|
||||||
for (; it != end; it++) {
|
for (; it != end; it++) {
|
||||||
@ -1442,27 +1435,23 @@ bool BufferParams::addLayoutModule(string modName, bool makeClass) {
|
|||||||
if (it != layoutModules_.end())
|
if (it != layoutModules_.end())
|
||||||
return false;
|
return false;
|
||||||
layoutModules_.push_back(modName);
|
layoutModules_.push_back(modName);
|
||||||
if (makeClass)
|
|
||||||
makeTextClass();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is not currently used but may prove useful
|
||||||
bool BufferParams::addLayoutModules(vector<string>modNames)
|
bool BufferParams::addLayoutModules(vector<string>modNames)
|
||||||
{
|
{
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
vector<string>::const_iterator it = modNames.begin();
|
vector<string>::const_iterator it = modNames.begin();
|
||||||
vector<string>::const_iterator end = modNames.end();
|
vector<string>::const_iterator end = modNames.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
retval &= addLayoutModule(*it, false);
|
retval &= addLayoutModule(*it);
|
||||||
makeTextClass();
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void BufferParams::clearLayoutModules() {
|
void BufferParams::clearLayoutModules() {
|
||||||
layoutModules_.clear();
|
layoutModules_.clear();
|
||||||
makeTextClass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,24 +108,19 @@ public:
|
|||||||
std::string fontsize;
|
std::string fontsize;
|
||||||
///Get the LyX TextClass (that is, the layout file) this document is using.
|
///Get the LyX TextClass (that is, the layout file) this document is using.
|
||||||
textclass_type getBaseClass() const;
|
textclass_type getBaseClass() const;
|
||||||
///Set the LyX TextClass (that is, the layout file) this document is using.
|
/// Set the LyX TextClass (that is, the layout file) this document is using.
|
||||||
///NOTE This also calls makeTextClass(), to update the local
|
/// NOTE: This does not call makeTextClass() to update the local TextClass.
|
||||||
///TextClass.
|
/// That needs to be done manually.
|
||||||
bool setBaseClass(textclass_type);
|
bool setBaseClass(textclass_type);
|
||||||
///Returns the TextClass currently in use: the BaseClass as modified
|
/// Adds the module information to the baseClass information to
|
||||||
///by modules.
|
/// create our local TextClass.
|
||||||
|
void makeTextClass();
|
||||||
|
/// Returns the TextClass currently in use: the BaseClass as modified
|
||||||
|
/// by modules.
|
||||||
TextClass const & getTextClass() const;
|
TextClass const & getTextClass() const;
|
||||||
///Returns a pointer to the TextClass currently in use: the BaseClass
|
/// Returns a pointer to the TextClass currently in use: the BaseClass
|
||||||
///as modified by modules. (See \file TextClassPtr.h for the typedef.)
|
/// as modified by modules. (See \file TextClassPtr.h for the typedef.)
|
||||||
TextClassPtr getTextClassPtr() const;
|
TextClassPtr getTextClassPtr() 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.
|
/// This bypasses the baseClass and sets the textClass directly.
|
||||||
/// Should be called with care and would be better not being here,
|
/// Should be called with care and would be better not being here,
|
||||||
/// but it seems to be needed by CutAndPaste::putClipboard().
|
/// but it seems to be needed by CutAndPaste::putClipboard().
|
||||||
@ -134,10 +129,15 @@ public:
|
|||||||
std::vector<std::string> const & getModules() const;
|
std::vector<std::string> const & getModules() const;
|
||||||
/// Add a module to the list of modules in use.
|
/// Add a module to the list of modules in use.
|
||||||
/// Returns true if module was successfully added.
|
/// Returns true if module was successfully added.
|
||||||
bool addLayoutModule(std::string modName, bool makeClass = true);
|
/// The makeClass variable signals whether to call makeTextClass. This
|
||||||
/// Add a list of modules.
|
/// need not be done if we know this isn't the final time through, or if
|
||||||
/// Returns true if all modules were successfully added.
|
/// the BufferParams do not represent the parameters for an actual buffer
|
||||||
bool addLayoutModules(std::vector<std::string>modNames);
|
/// (as in GuiDocument).
|
||||||
|
bool addLayoutModule(std::string modName);
|
||||||
|
// Add a list of modules.
|
||||||
|
// Returns true if all modules were successfully added.
|
||||||
|
// Currently unused.
|
||||||
|
// bool addLayoutModules(std::vector<std::string>modNames);
|
||||||
/// Clear the list
|
/// Clear the list
|
||||||
void clearLayoutModules();
|
void clearLayoutModules();
|
||||||
|
|
||||||
@ -314,11 +314,7 @@ private:
|
|||||||
void readBulletsLaTeX(Lexer &);
|
void readBulletsLaTeX(Lexer &);
|
||||||
///
|
///
|
||||||
void readModules(Lexer &);
|
void readModules(Lexer &);
|
||||||
/// Adds the module information to the baseClass information to
|
|
||||||
/// create our local TextClass.
|
|
||||||
void makeTextClass();
|
|
||||||
|
|
||||||
|
|
||||||
/// for use with natbib
|
/// for use with natbib
|
||||||
biblio::CiteEngine cite_engine_;
|
biblio::CiteEngine cite_engine_;
|
||||||
/// the base TextClass associated with the document
|
/// the base TextClass associated with the document
|
||||||
|
@ -1659,6 +1659,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
||||||
view()->cursor().recordUndoFullDocument();
|
view()->cursor().recordUndoFullDocument();
|
||||||
buffer->params().clearLayoutModules();
|
buffer->params().clearLayoutModules();
|
||||||
|
buffer->params().makeTextClass();
|
||||||
updateLayout(oldClass, buffer);
|
updateLayout(oldClass, buffer);
|
||||||
updateFlags = Update::Force | Update::FitCursor;
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
@ -1670,6 +1671,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
||||||
view()->cursor().recordUndoFullDocument();
|
view()->cursor().recordUndoFullDocument();
|
||||||
buffer->params().addLayoutModule(argument);
|
buffer->params().addLayoutModule(argument);
|
||||||
|
buffer->params().makeTextClass();
|
||||||
updateLayout(oldClass, buffer);
|
updateLayout(oldClass, buffer);
|
||||||
updateFlags = Update::Force | Update::FitCursor;
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
@ -1698,6 +1700,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
TextClassPtr oldClass = buffer->params().getTextClassPtr();
|
||||||
view()->cursor().recordUndoFullDocument();
|
view()->cursor().recordUndoFullDocument();
|
||||||
buffer->params().setBaseClass(new_class);
|
buffer->params().setBaseClass(new_class);
|
||||||
|
buffer->params().makeTextClass();
|
||||||
updateLayout(oldClass, buffer);
|
updateLayout(oldClass, buffer);
|
||||||
updateFlags = Update::Force | Update::FitCursor;
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
@ -1710,6 +1713,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
textclass_type const tc = buffer->params().getBaseClass();
|
textclass_type const tc = buffer->params().getBaseClass();
|
||||||
textclasslist.reset(tc);
|
textclasslist.reset(tc);
|
||||||
buffer->params().setBaseClass(tc);
|
buffer->params().setBaseClass(tc);
|
||||||
|
buffer->params().makeTextClass();
|
||||||
updateLayout(oldClass, buffer);
|
updateLayout(oldClass, buffer);
|
||||||
updateFlags = Update::Force | Update::FitCursor;
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
|
@ -913,7 +913,7 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel)
|
|||||||
void GuiDocument::classChanged()
|
void GuiDocument::classChanged()
|
||||||
{
|
{
|
||||||
textclass_type const tc = latexModule->classCO->currentIndex();
|
textclass_type const tc = latexModule->classCO->currentIndex();
|
||||||
bp_.setJustBaseClass(tc);
|
bp_.setBaseClass(tc);
|
||||||
if (lyxrc.auto_reset_options)
|
if (lyxrc.auto_reset_options)
|
||||||
bp_.useClassDefaults();
|
bp_.useClassDefaults();
|
||||||
updateContents();
|
updateContents();
|
||||||
@ -1097,13 +1097,15 @@ void GuiDocument::apply(BufferParams & params)
|
|||||||
params.graphicsDriver =
|
params.graphicsDriver =
|
||||||
tex_graphics[latexModule->psdriverCO->currentIndex()];
|
tex_graphics[latexModule->psdriverCO->currentIndex()];
|
||||||
|
|
||||||
|
// text layout
|
||||||
|
params.setBaseClass(latexModule->classCO->currentIndex());
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
params.clearLayoutModules();
|
params.clearLayoutModules();
|
||||||
QStringList const selMods = selectedModel()->stringList();
|
QStringList const selMods = selectedModel()->stringList();
|
||||||
for (int i = 0; i != selMods.size(); ++i)
|
for (int i = 0; i != selMods.size(); ++i)
|
||||||
params.addLayoutModule(lyx::fromqstr(selMods[i]));
|
params.addLayoutModule(lyx::fromqstr(selMods[i]));
|
||||||
|
|
||||||
|
|
||||||
if (mathsModule->amsautoCB->isChecked()) {
|
if (mathsModule->amsautoCB->isChecked()) {
|
||||||
params.use_amsmath = BufferParams::package_auto;
|
params.use_amsmath = BufferParams::package_auto;
|
||||||
} else {
|
} else {
|
||||||
@ -1122,9 +1124,6 @@ void GuiDocument::apply(BufferParams & params)
|
|||||||
params.use_esint = BufferParams::package_off;
|
params.use_esint = BufferParams::package_off;
|
||||||
}
|
}
|
||||||
|
|
||||||
// text layout
|
|
||||||
params.setJustBaseClass(latexModule->classCO->currentIndex());
|
|
||||||
|
|
||||||
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
|
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
|
||||||
params.pagestyle = "default";
|
params.pagestyle = "default";
|
||||||
else {
|
else {
|
||||||
@ -1639,7 +1638,7 @@ void GuiDocument::updateContents()
|
|||||||
|
|
||||||
void GuiDocument::useClassDefaults()
|
void GuiDocument::useClassDefaults()
|
||||||
{
|
{
|
||||||
bp_.setJustBaseClass(latexModule->classCO->currentIndex());
|
bp_.setBaseClass(latexModule->classCO->currentIndex());
|
||||||
bp_.useClassDefaults();
|
bp_.useClassDefaults();
|
||||||
updateContents();
|
updateContents();
|
||||||
}
|
}
|
||||||
@ -1742,8 +1741,6 @@ void GuiDocument::dispatchParams()
|
|||||||
|
|
||||||
// Apply the BufferParams. Note that this will set the base class
|
// Apply the BufferParams. Note that this will set the base class
|
||||||
// and then update the buffer's layout.
|
// and then update the buffer's layout.
|
||||||
//FIXME Could this be done last? Then, I think, we'd get the automatic
|
|
||||||
//update mentioned in the next FIXME...
|
|
||||||
dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
|
dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
|
||||||
|
|
||||||
// Generate the colours requested by each new branch.
|
// Generate the colours requested by each new branch.
|
||||||
|
Loading…
Reference in New Issue
Block a user