Introduce namespace lyx::external.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7843 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-10-01 10:16:00 +00:00
parent 10289e0dbb
commit 27f298812d
11 changed files with 131 additions and 86 deletions

View File

@ -1,3 +1,8 @@
2003-10-01 Angus Leeming <leeming@lyx.org>
* ControlExternal.[Ch]: changes due to the introduction of
namespace lyx::external.
2003-09-25 Angus Leeming <leeming@lyx.org>
* ControlExternal.C (getTemplatePtr): simplify, due to change in

View File

@ -20,6 +20,8 @@
#include "insets/ExternalTemplate.h"
namespace external = lyx::external;
using std::vector;
@ -79,9 +81,9 @@ vector<string> const ControlExternal::getTemplates() const
{
vector<string> result;
ExternalTemplateManager::Templates::const_iterator i1, i2;
i1 = ExternalTemplateManager::get().getTemplates().begin();
i2 = ExternalTemplateManager::get().getTemplates().end();
external::TemplateManager::Templates::const_iterator i1, i2;
i1 = external::TemplateManager::get().getTemplates().begin();
i2 = external::TemplateManager::get().getTemplates().end();
for (; i1 != i2; ++i1) {
result.push_back(i1->second.lyxName);
@ -92,9 +94,9 @@ vector<string> const ControlExternal::getTemplates() const
int ControlExternal::getTemplateNumber(string const & name) const
{
ExternalTemplateManager::Templates::const_iterator i1, i2;
i1 = ExternalTemplateManager::get().getTemplates().begin();
i2 = ExternalTemplateManager::get().getTemplates().end();
external::TemplateManager::Templates::const_iterator i1, i2;
i1 = external::TemplateManager::get().getTemplates().begin();
i2 = external::TemplateManager::get().getTemplates().end();
for (int i = 0; i1 != i2; ++i1, ++i) {
if (i1->second.lyxName == name)
return i;
@ -106,10 +108,10 @@ int ControlExternal::getTemplateNumber(string const & name) const
}
ExternalTemplate ControlExternal::getTemplate(int i) const
external::Template ControlExternal::getTemplate(int i) const
{
ExternalTemplateManager::Templates::const_iterator i1
= ExternalTemplateManager::get().getTemplates().begin();
external::TemplateManager::Templates::const_iterator i1
= external::TemplateManager::get().getTemplates().begin();
std::advance(i1, i);
@ -119,9 +121,10 @@ ExternalTemplate ControlExternal::getTemplate(int i) const
namespace {
ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
external::Template const * getTemplatePtr(InsetExternal::Params const & params)
{
ExternalTemplateManager const & etm = ExternalTemplateManager::get();
external::TemplateManager const & etm =
external::TemplateManager::get();
return etm.getTemplateByName(params.templatename());
}
@ -136,7 +139,7 @@ string const ControlExternal::Browse(string const & input) const
/// Determine the template file extension
string pattern = "*";
ExternalTemplate const * const et_ptr = getTemplatePtr(params());
external::Template const * const et_ptr = getTemplatePtr(params());
if (et_ptr)
pattern = et_ptr->fileRegExp;

View File

@ -20,7 +20,11 @@
#include <boost/scoped_ptr.hpp>
class ExternalTemplate;
namespace lyx {
namespace external {
class Template;
} // namespace external
} // namespace lyx
class ControlExternal : public Dialog::Controller {
@ -48,7 +52,7 @@ public:
///
int getTemplateNumber(string const &) const;
///
ExternalTemplate getTemplate(int) const;
lyx::external::Template getTemplate(int) const;
///
string const Browse(string const &) const;
private:

View File

@ -1,3 +1,8 @@
2003-10-01 Angus Leeming <leeming@lyx.org>
* QExternal.C (helpText): changes due to the introduction of
namespace lyx::external.
2003-09-29 Lars Gullik Bjønnes <larsbj@gullik.net>
* several .C files: add debug.h at top to avoid compilation

View File

@ -94,7 +94,7 @@ void QExternal::update_contents()
string const QExternal::helpText() const
{
ExternalTemplate templ =
lyx::external::Template templ =
controller().getTemplate(dialog_->externalCO->currentItem());
return templ.helpText;
}

View File

@ -1,3 +1,8 @@
2003-10-01 Angus Leeming <leeming@lyx.org>
* FormExternal.C (updateComboChange): changes due to the
introduction of namespace lyx::external.
2003-09-29 Angus Leeming <leeming@lyx.org>
* FormGraphics.C: remove incorrect comment.

View File

@ -180,7 +180,7 @@ ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
void FormExternal::updateComboChange()
{
int const choice = fl_get_choice(dialog_->choice_template) - 1;
ExternalTemplate templ = controller().getTemplate(choice);
lyx::external::Template templ = controller().getTemplate(choice);
// Update the help text
string const txt = formatted(templ.helpText,

View File

@ -1,3 +1,10 @@
2003-10-01 Angus Leeming <leeming@lyx.org>
* ExternalTemplace.[Ch]: introduce namespace lyx::external.
* insetexternal.[Ch]: changes due to the introduction of
namespace lyx::external.
2003-09-30 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch] (Params::read, write): new member functions.

View File

@ -33,18 +33,20 @@ using std::ostream;
using std::vector;
// We have to have dummy default commands for security reasons!
namespace lyx {
namespace external {
ExternalTemplate::ExternalTemplate()
// We have to have dummy default commands for security reasons!
Template::Template()
: inputFormat("*")
{}
ExternalTemplate::FormatTemplate::FormatTemplate()
Template::Format::Format()
{}
ExternalTemplateManager::ExternalTemplateManager()
TemplateManager::TemplateManager()
{
readTemplates(support::user_lyxdir());
if (lyxerr.debugging(Debug::EXTERNAL)) {
@ -57,7 +59,7 @@ ExternalTemplateManager::ExternalTemplateManager()
class dumpPreambleDef {
public:
typedef ExternalTemplateManager::PreambleDefs::value_type value_type;
typedef TemplateManager::PreambleDefs::value_type value_type;
dumpPreambleDef(ostream & o) : ost(o) {}
@ -74,12 +76,12 @@ private:
class dumpTemplate {
public:
typedef ExternalTemplateManager::Templates::value_type value_type;
typedef TemplateManager::Templates::value_type value_type;
dumpTemplate(ostream & o) : ost(o) {}
void operator()(value_type const & vt) {
ExternalTemplate const & et = vt.second;
Template const & et = vt.second;
ost << "Template " << et.lyxName << '\n'
<< "\tGuiName " << et.guiName << '\n'
@ -101,12 +103,12 @@ private:
class dumpFormat {
public:
typedef ExternalTemplate::Formats::value_type value_type;
typedef Template::Formats::value_type value_type;
dumpFormat(ostream & o) : ost(o) {}
void operator()(value_type const & vt) const{
ExternalTemplate::FormatTemplate const & ft = vt.second;
Template::Format const & ft = vt.second;
ost << "\tFormat " << vt.first << '\n'
<< "\t\tProduct " << ft.product << '\n'
<< "\t\tUpdateFormat " << ft.updateFormat << '\n'
@ -126,47 +128,47 @@ private:
};
void ExternalTemplate::dumpFormats(ostream & os) const
void Template::dumpFormats(ostream & os) const
{
for_each(formats.begin(), formats.end(), dumpFormat(os));
}
void ExternalTemplateManager::dumpPreambleDefs(ostream & os) const
void TemplateManager::dumpPreambleDefs(ostream & os) const
{
for_each(preambledefs.begin(), preambledefs.end(), dumpPreambleDef(os));
}
void ExternalTemplateManager::dumpTemplates(ostream & os) const
void TemplateManager::dumpTemplates(ostream & os) const
{
for_each(templates.begin(), templates.end(), dumpTemplate(os));
}
ExternalTemplateManager & ExternalTemplateManager::get()
TemplateManager & TemplateManager::get()
{
static ExternalTemplateManager externalTemplateManager;
static TemplateManager externalTemplateManager;
return externalTemplateManager;
}
ExternalTemplateManager::Templates &
ExternalTemplateManager::getTemplates()
TemplateManager::Templates &
TemplateManager::getTemplates()
{
return templates;
}
ExternalTemplateManager::Templates const &
ExternalTemplateManager::getTemplates() const
TemplateManager::Templates const &
TemplateManager::getTemplates() const
{
return templates;
}
ExternalTemplate const *
ExternalTemplateManager::getTemplateByName(string const & name) const
Template const *
TemplateManager::getTemplateByName(string const & name) const
{
Templates::const_iterator it = templates.find(name);
return (it == templates.end()) ? 0 : &it->second;
@ -174,7 +176,7 @@ ExternalTemplateManager::getTemplateByName(string const & name) const
string const
ExternalTemplateManager::getPreambleDefByName(string const & name) const
TemplateManager::getPreambleDefByName(string const & name) const
{
string const trimmed_name = support::trim(name);
if (trimmed_name.empty())
@ -188,7 +190,7 @@ ExternalTemplateManager::getPreambleDefByName(string const & name) const
}
void ExternalTemplateManager::readTemplates(string const & path)
void TemplateManager::readTemplates(string const & path)
{
support::Path p(path);
@ -210,7 +212,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
string filename = support::LibFileSearch("", "external_templates");
if (filename.empty() || !lex.setFile(filename)) {
lex.printError("ExternalTemplateManager::readTemplates: "
lex.printError("external::TemplateManager::readTemplates: "
"No template file");
return;
}
@ -230,7 +232,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
case TM_TEMPLATE: {
lex.next();
string const name = lex.getString();
ExternalTemplate & tmp = templates[name];
Template & tmp = templates[name];
tmp.lyxName = name;
tmp.readTemplate(lex);
}
@ -248,7 +250,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
}
void ExternalTemplate::readTemplate(LyXLex & lex)
void Template::readTemplate(LyXLex & lex)
{
enum TemplateOptionTags {
TO_GUINAME = 1,
@ -314,7 +316,7 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
return;
default:
lex.printError("ExternalTemplate::readTemplate: "
lex.printError("external::Template::readTemplate: "
"Wrong tag: $$Token");
BOOST_ASSERT(false);
break;
@ -323,7 +325,7 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
}
void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
void Template::Format::readFormat(LyXLex & lex)
{
enum FormatTags {
FO_PRODUCT = 1,
@ -377,3 +379,6 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
}
}
}
} // namespace external
} // namespace lyx

View File

@ -12,6 +12,7 @@
#ifndef EXTERNALTEMPLATE_H
#define EXTERNALTEMPLATE_H
#include <boost/function.hpp>
#include <boost/utility.hpp>
#include "support/std_string.h"
#include <iosfwd>
@ -20,9 +21,18 @@
class LyXLex;
namespace lyx {
namespace external {
///
struct ExternalTemplate {
struct Template {
/// We have to have default commands for safety reasons!
Template();
///
void readTemplate(LyXLex &);
///
void dumpFormats(std::ostream &) const;
/// What is the name of this template in the LyX format?
string lyxName;
/// What will the button in the GUI say?
@ -30,8 +40,8 @@ struct ExternalTemplate {
/// A short help text
string helpText;
/** The format of the input file. Can be "*", in which case we try and
ascertain the format from the contents of the file.
*/
* ascertain the format from the contents of the file.
*/
string inputFormat;
/// A file extension regular expression for the file browser
string fileRegExp;
@ -39,8 +49,14 @@ struct ExternalTemplate {
string editCommand;
/// Should we do automatic production of the output?
bool automaticProduction;
/// This is the information needed to support a specific output format
struct FormatTemplate {
struct Format {
/// This constructor has to default a command for safety reasons!
Format();
///
void readFormat(LyXLex &);
/// The text that should be inserted into the exported file
string product;
/// The filename of the resulting file
@ -51,50 +67,39 @@ struct ExternalTemplate {
string requirement;
/// A collection of preamble snippets identified by name.
std::vector<string> preambleNames;
///
void readFormat(LyXLex &);
/// This constructor has to default a command for safety reasons!
FormatTemplate();
};
///
void readTemplate(LyXLex &);
///
typedef std::map<string, FormatTemplate> Formats;
typedef std::map<string, Format> Formats;
///
Formats formats;
///
void dumpFormats(std::ostream &) const;
/// We have to have default commands for safety reasons!
ExternalTemplate();
};
/**
A singleton class that manages the external inset templates
*/
class ExternalTemplateManager : boost::noncopyable {
class TemplateManager : boost::noncopyable {
public:
/// Map from the LyX name of the template to the template structure
typedef std::map<string, ExternalTemplate> Templates;
typedef std::map<string, Template> Templates;
/** Map from the LyX name of the preamble definition to the preamble
* definition itself.
*/
typedef std::map<string, string> PreambleDefs;
static ExternalTemplateManager & get();
static TemplateManager & get();
Templates & getTemplates();
Templates const & getTemplates() const;
/** return the template by LyX name.
* If it isn't found, return 0.
*/
ExternalTemplate const * getTemplateByName(string const & name) const;
Template const * getTemplateByName(string const & name) const;
/** return the preamble definition by LyX name.
* If it isn't found, return an empty string.
*/
string const getPreambleDefByName(string const & name) const;
private:
ExternalTemplateManager();
TemplateManager();
void readTemplates(string const & path);
void dumpTemplates(std::ostream &) const;
void dumpPreambleDefs(std::ostream &) const;
@ -103,4 +108,7 @@ private:
PreambleDefs preambledefs;
};
#endif
} // namespace external
} // namespace lyx
#endif // EXTERNALTEMPLATE_H

View File

@ -41,6 +41,7 @@
#include <boost/bind.hpp>
namespace support = lyx::support;
namespace external = lyx::external;
using std::endl;
@ -72,16 +73,18 @@ string const doSubstitution(InsetExternal::Params const & params,
void editExternal(InsetExternal::Params const & params, Buffer const & buffer);
ExternalTemplate const * getTemplatePtr(string const & name)
external::Template const * getTemplatePtr(string const & name)
{
ExternalTemplateManager const & etm = ExternalTemplateManager::get();
external::TemplateManager const & etm =
external::TemplateManager::get();
return etm.getTemplateByName(name);
}
ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
external::Template const * getTemplatePtr(InsetExternal::Params const & params)
{
ExternalTemplateManager const & etm = ExternalTemplateManager::get();
external::TemplateManager const & etm =
external::TemplateManager::get();
return etm.getTemplateByName(params.templatename());
}
@ -348,7 +351,7 @@ lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams)
string const getScreenLabel(InsetExternal::Params const & params,
Buffer const & buffer)
{
ExternalTemplate const * const ptr = getTemplatePtr(params);
external::Template const * const ptr = getTemplatePtr(params);
if (!ptr)
return support::bformat(_("External template %1$s is not installed"),
params.templatename());
@ -417,12 +420,12 @@ int InsetExternal::write(string const & format,
Buffer const & buf, ostream & os,
bool external_in_tmpdir) const
{
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
external::Template const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return 0;
ExternalTemplate const & et = *et_ptr;
external::Template const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit =
external::Template::Formats::const_iterator cit =
et.formats.find(format);
if (cit == et.formats.end()) {
lyxerr[Debug::EXTERNAL]
@ -452,12 +455,12 @@ int InsetExternal::latex(Buffer const & buf, ostream & os,
// If the template has specified a PDFLaTeX output, then we try and
// use that.
if (runparams.flavor == LatexRunParams::PDFLATEX) {
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
external::Template const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return 0;
ExternalTemplate const & et = *et_ptr;
external::Template const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit =
external::Template::Formats::const_iterator cit =
et.formats.find("PDFLaTeX");
if (cit != et.formats.end())
return write("PDFLaTeX", buf, os, external_in_tmpdir);
@ -487,19 +490,19 @@ int InsetExternal::docbook(Buffer const & buf, ostream & os, bool) const
void InsetExternal::validate(LaTeXFeatures & features) const
{
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
external::Template const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
external::Template const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit = et.formats.find("LaTeX");
external::Template::Formats::const_iterator cit = et.formats.find("LaTeX");
if (cit == et.formats.end())
return;
if (!cit->second.requirement.empty())
features.require(cit->second.requirement);
ExternalTemplateManager & etm = ExternalTemplateManager::get();
external::TemplateManager & etm = external::TemplateManager::get();
vector<string>::const_iterator it = cit->second.preambleNames.begin();
vector<string>::const_iterator end = cit->second.preambleNames.end();
@ -515,20 +518,20 @@ void InsetExternal::updateExternal(string const & format,
Buffer const & buf,
bool external_in_tmpdir) const
{
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
external::Template const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
external::Template const & et = *et_ptr;
if (!et.automaticProduction)
return;
ExternalTemplate::Formats::const_iterator cit =
external::Template::Formats::const_iterator cit =
et.formats.find(format);
if (cit == et.formats.end())
return;
ExternalTemplate::FormatTemplate const & outputFormat = cit->second;
external::Template::Format const & outputFormat = cit->second;
if (outputFormat.updateResult.empty())
return;
@ -636,10 +639,10 @@ string const doSubstitution(InsetExternal::Params const & params,
void editExternal(InsetExternal::Params const & params, Buffer const & buffer)
{
ExternalTemplate const * const et_ptr = getTemplatePtr(params);
external::Template const * const et_ptr = getTemplatePtr(params);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
external::Template const & et = *et_ptr;
if (et.editCommand.empty())
return;