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