mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-09 18:52:46 +00:00
Support for removing "default" modules.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25917 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c08f8291f9
commit
163d827729
@ -115,7 +115,7 @@ namespace os = support::os;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
int const LYX_FORMAT = 338; //Uwe: support for polytonic Greek
|
int const LYX_FORMAT = 339; //rgh: removed modules
|
||||||
|
|
||||||
typedef map<string, bool> DepClean;
|
typedef map<string, bool> DepClean;
|
||||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||||
@ -471,6 +471,7 @@ int Buffer::readHeader(Lexer & lex)
|
|||||||
params().fontsCJK.erase();
|
params().fontsCJK.erase();
|
||||||
params().listings_params.clear();
|
params().listings_params.clear();
|
||||||
params().clearLayoutModules();
|
params().clearLayoutModules();
|
||||||
|
params().clearRemovedModules();
|
||||||
params().pdfoptions().clear();
|
params().pdfoptions().clear();
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
@ -487,6 +487,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
|||||||
readLocalLayout(lex);
|
readLocalLayout(lex);
|
||||||
} else if (token == "\\begin_modules") {
|
} else if (token == "\\begin_modules") {
|
||||||
readModules(lex);
|
readModules(lex);
|
||||||
|
} else if (token == "\\begin_removed_modules") {
|
||||||
|
readRemovedModules(lex);
|
||||||
} else if (token == "\\options") {
|
} else if (token == "\\options") {
|
||||||
lex.eatLine();
|
lex.eatLine();
|
||||||
options = lex.getString();
|
options = lex.getString();
|
||||||
@ -692,11 +694,22 @@ void BufferParams::writeFile(ostream & os) const
|
|||||||
os << "\\master " << master << '\n';
|
os << "\\master " << master << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
//the modules
|
// removed modules
|
||||||
|
if (!removedModules_.empty()) {
|
||||||
|
os << "\\begin_removed_modules" << '\n';
|
||||||
|
set<string>::const_iterator it = removedModules_.begin();
|
||||||
|
set<string>::const_iterator en = removedModules_.end();
|
||||||
|
for (; it != en; it++)
|
||||||
|
os << *it << '\n';
|
||||||
|
os << "\\end_removed_modules" << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// the modules
|
||||||
if (!layoutModules_.empty()) {
|
if (!layoutModules_.empty()) {
|
||||||
os << "\\begin_modules" << '\n';
|
os << "\\begin_modules" << '\n';
|
||||||
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
||||||
for (; it != layoutModules_.end(); it++)
|
LayoutModuleList::const_iterator en = layoutModules_.end();
|
||||||
|
for (; it != en; it++)
|
||||||
os << *it << '\n';
|
os << *it << '\n';
|
||||||
os << "\\end_modules" << '\n';
|
os << "\\end_modules" << '\n';
|
||||||
}
|
}
|
||||||
@ -1445,33 +1458,44 @@ bool BufferParams::setBaseClass(string const & classname)
|
|||||||
set<string>::const_iterator men = mods.end();
|
set<string>::const_iterator men = mods.end();
|
||||||
for (; mit != men; mit++) {
|
for (; mit != men; mit++) {
|
||||||
string const & modName = *mit;
|
string const & modName = *mit;
|
||||||
LayoutModuleList::const_iterator const fit =
|
// see if we're already in use
|
||||||
find(layoutModules_.begin(), layoutModules_.end(), modName);
|
if (find(layoutModules_.begin(), layoutModules_.end(), modName) !=
|
||||||
if (fit == layoutModules_.end()) {
|
layoutModules_.end()) {
|
||||||
// We need to make sure there's no module chosen that excludes this one
|
LYXERR(Debug::TCLASS, "Default module `" << modName <<
|
||||||
LayoutModuleList::const_iterator lit = layoutModules_.begin();
|
"' not added because already used.");
|
||||||
LayoutModuleList::const_iterator len = layoutModules_.end();
|
continue;
|
||||||
bool foundit = false;
|
}
|
||||||
// so iterate over the selected modules...
|
// make sure the user hasn't removed it
|
||||||
for (; lit != len; lit++) {
|
if (find(removedModules_.begin(), removedModules_.end(), modName) !=
|
||||||
LyXModule * lm = moduleList[*lit];
|
removedModules_.end()) {
|
||||||
if (!lm)
|
LYXERR(Debug::TCLASS, "Default module `" << modName <<
|
||||||
continue;
|
"' not added because removed by user.");
|
||||||
vector<string> const & exc = lm->getExcludedModules();
|
continue;
|
||||||
// ...and see if one of them excludes us.
|
}
|
||||||
if (find(exc.begin(), exc.end(), modName) != exc.end()) {
|
// Now we want to check the list of selected modules to see if any of them
|
||||||
foundit = true;
|
// exclude this one.
|
||||||
LYXERR(Debug::TCLASS, "Default module `" << modName <<
|
bool foundit = false;
|
||||||
"' not added because excluded by loaded module `" <<
|
// so iterate over the selected modules...
|
||||||
*lit << "'.");
|
LayoutModuleList::const_iterator lit = layoutModules_.begin();
|
||||||
break;
|
LayoutModuleList::const_iterator len = layoutModules_.end();
|
||||||
}
|
for (; lit != len; lit++) {
|
||||||
}
|
LyXModule * lm = moduleList[*lit];
|
||||||
if (!foundit) {
|
if (!lm)
|
||||||
LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
|
continue;
|
||||||
layoutModules_.push_back(modName);
|
vector<string> const & exc = lm->getExcludedModules();
|
||||||
|
// ...and see if this one excludes us.
|
||||||
|
if (find(exc.begin(), exc.end(), modName) != exc.end()) {
|
||||||
|
foundit = true;
|
||||||
|
LYXERR(Debug::TCLASS, "Default module `" << modName <<
|
||||||
|
"' not added because excluded by loaded module `" <<
|
||||||
|
*lit << "'.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!foundit) {
|
||||||
|
LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
|
||||||
|
layoutModules_.push_back(modName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1541,13 +1565,6 @@ void BufferParams::makeDocumentClass()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<string> const & BufferParams::getModules() const
|
|
||||||
{
|
|
||||||
return layoutModules_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BufferParams::addLayoutModule(string const & modName)
|
bool BufferParams::addLayoutModule(string const & modName)
|
||||||
{
|
{
|
||||||
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
LayoutModuleList::const_iterator it = layoutModules_.begin();
|
||||||
@ -1560,12 +1577,6 @@ bool BufferParams::addLayoutModule(string const & modName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BufferParams::clearLayoutModules()
|
|
||||||
{
|
|
||||||
layoutModules_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Font const BufferParams::getFont() const
|
Font const BufferParams::getFont() const
|
||||||
{
|
{
|
||||||
FontInfo f = documentClass().defaultfont();
|
FontInfo f = documentClass().defaultfont();
|
||||||
@ -1693,6 +1704,37 @@ void BufferParams::readModules(Lexer & lex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BufferParams::readRemovedModules(Lexer & lex)
|
||||||
|
{
|
||||||
|
if (!lex.eatLine()) {
|
||||||
|
lyxerr << "Error (BufferParams::readRemovedModules):"
|
||||||
|
"Unexpected end of input." << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
string mod = lex.getString();
|
||||||
|
if (mod == "\\end_removed_modules")
|
||||||
|
break;
|
||||||
|
removedModules_.insert(mod);
|
||||||
|
lex.eatLine();
|
||||||
|
}
|
||||||
|
// now we want to remove any removed modules that were previously
|
||||||
|
// added. normally, that will be because default modules were added in
|
||||||
|
// setBaseClass(), which gets called when \textclass is read at the
|
||||||
|
// start of the read.
|
||||||
|
set<string>::const_iterator rit = removedModules_.begin();
|
||||||
|
set<string>::const_iterator const ren = removedModules_.end();
|
||||||
|
for (; rit != ren; rit++) {
|
||||||
|
LayoutModuleList::iterator const mit = layoutModules_.begin();
|
||||||
|
LayoutModuleList::iterator const men = layoutModules_.end();
|
||||||
|
LayoutModuleList::iterator found = find(mit, men, *rit);
|
||||||
|
if (found == men)
|
||||||
|
continue;
|
||||||
|
layoutModules_.erase(found);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string BufferParams::paperSizeName(PapersizePurpose purpose) const
|
string BufferParams::paperSizeName(PapersizePurpose purpose) const
|
||||||
{
|
{
|
||||||
char real_papersize = papersize;
|
char real_papersize = papersize;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "support/copied_ptr.h"
|
#include "support/copied_ptr.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -51,6 +52,8 @@ class VSpace;
|
|||||||
*/
|
*/
|
||||||
class BufferParams {
|
class BufferParams {
|
||||||
public:
|
public:
|
||||||
|
///
|
||||||
|
typedef std::vector<std::string> LayoutModuleList;
|
||||||
///
|
///
|
||||||
enum ParagraphSeparation {
|
enum ParagraphSeparation {
|
||||||
///
|
///
|
||||||
@ -124,7 +127,11 @@ public:
|
|||||||
/// but it seems to be needed by CutAndPaste::putClipboard().
|
/// but it seems to be needed by CutAndPaste::putClipboard().
|
||||||
void setDocumentClass(DocumentClass const * const);
|
void setDocumentClass(DocumentClass const * const);
|
||||||
/// List of modules in use
|
/// List of modules in use
|
||||||
std::vector<std::string> const & getModules() const;
|
LayoutModuleList const & getModules() const { return layoutModules_; }
|
||||||
|
/// List of default modules the user has removed
|
||||||
|
std::set<std::string> const & getRemovedModules() const
|
||||||
|
{ return removedModules_; }
|
||||||
|
///
|
||||||
/// 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.
|
||||||
/// The makeClass variable signals whether to call makeDocumentClass. This
|
/// The makeClass variable signals whether to call makeDocumentClass. This
|
||||||
@ -132,8 +139,13 @@ public:
|
|||||||
/// the BufferParams do not represent the parameters for an actual buffer
|
/// the BufferParams do not represent the parameters for an actual buffer
|
||||||
/// (as in GuiDocument).
|
/// (as in GuiDocument).
|
||||||
bool addLayoutModule(std::string const & modName);
|
bool addLayoutModule(std::string const & modName);
|
||||||
|
///
|
||||||
|
void addRemovedModule(std::string const & modName)
|
||||||
|
{ removedModules_.insert(modName); }
|
||||||
/// Clear the list
|
/// Clear the list
|
||||||
void clearLayoutModules();
|
void clearLayoutModules() { layoutModules_.clear(); }
|
||||||
|
/// Clear the removed module list
|
||||||
|
void clearRemovedModules() { removedModules_.clear(); }
|
||||||
|
|
||||||
/// returns the main font for the buffer (document)
|
/// returns the main font for the buffer (document)
|
||||||
Font const getFont() const;
|
Font const getFont() const;
|
||||||
@ -327,15 +339,18 @@ private:
|
|||||||
void readBulletsLaTeX(Lexer &);
|
void readBulletsLaTeX(Lexer &);
|
||||||
///
|
///
|
||||||
void readModules(Lexer &);
|
void readModules(Lexer &);
|
||||||
|
///
|
||||||
|
void readRemovedModules(Lexer &);
|
||||||
|
|
||||||
/// for use with natbib
|
/// for use with natbib
|
||||||
CiteEngine cite_engine_;
|
CiteEngine cite_engine_;
|
||||||
///
|
///
|
||||||
DocumentClass * doc_class_;
|
DocumentClass * doc_class_;
|
||||||
///
|
///
|
||||||
typedef std::vector<std::string> LayoutModuleList;
|
|
||||||
///
|
|
||||||
LayoutModuleList layoutModules_;
|
LayoutModuleList layoutModules_;
|
||||||
|
/// this is for modules that are required by the document class but that
|
||||||
|
/// the user has chosen not to use
|
||||||
|
std::set<std::string> removedModules_;
|
||||||
|
|
||||||
/** Use the Pimpl idiom to hide those member variables that would otherwise
|
/** Use the Pimpl idiom to hide those member variables that would otherwise
|
||||||
* drag in other header files.
|
* drag in other header files.
|
||||||
|
@ -1565,6 +1565,27 @@ void GuiDocument::apply(BufferParams & params)
|
|||||||
vector<string> selModList;
|
vector<string> selModList;
|
||||||
for (int i = 0; i < srows; ++i)
|
for (int i = 0; i < srows; ++i)
|
||||||
params.addLayoutModule(modules_sel_model_.getIDString(i));
|
params.addLayoutModule(modules_sel_model_.getIDString(i));
|
||||||
|
// update the list of removed modules
|
||||||
|
params.clearRemovedModules();
|
||||||
|
set<string> const & reqmods = params.baseClass()->defaultModules();
|
||||||
|
set<string>::const_iterator rit = reqmods.begin();
|
||||||
|
set<string>::const_iterator ren = reqmods.end();
|
||||||
|
// check each of the required modules
|
||||||
|
for (; rit != ren; rit++) {
|
||||||
|
vector<string>::const_iterator mit = params.getModules().begin();
|
||||||
|
vector<string>::const_iterator men = params.getModules().end();
|
||||||
|
bool found = false;
|
||||||
|
for (; mit != men; mit++) {
|
||||||
|
if (*rit == *mit) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
// the module isn't present so must have been removed by the user
|
||||||
|
params.addRemovedModule(*rit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mathsModule->amsautoCB->isChecked()) {
|
if (mathsModule->amsautoCB->isChecked()) {
|
||||||
params.use_amsmath = BufferParams::package_auto;
|
params.use_amsmath = BufferParams::package_auto;
|
||||||
|
Loading…
Reference in New Issue
Block a user