mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 05:40:59 +00:00
The remaining External Template clean-up patch ;-)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7666 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bf053299a6
commit
e9c209c298
@ -1,3 +1,8 @@
|
||||
2003-09-04 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* external_templates: add a new PreambleDef section and use it in the
|
||||
XFig template.
|
||||
|
||||
2003-09-04 Johnathan Burchill <jkerrb@shaw.ca>
|
||||
|
||||
* external_templates: add some clever LaTeX to the XFIG template so that
|
||||
|
@ -1,5 +1,17 @@
|
||||
# Basic External Templates for LyX
|
||||
|
||||
PreambleDef XFigInput
|
||||
%% This inputs the file if it exists, else prints a warning
|
||||
%% encased in an fbox.
|
||||
\def\stripprefix#1>{}
|
||||
\newcommand*{\xfiginput}[1]{%
|
||||
\edef\tempfilename{#1}%
|
||||
\InputIfFileExists{#1}{}{%
|
||||
\fbox{Could not find
|
||||
\ttfamily\expandafter\stripprefix\meaning\tempfilename
|
||||
!}}}
|
||||
PreambleDefEnd
|
||||
|
||||
Template XFig
|
||||
GuiName "[XFig: $$Basename]"
|
||||
HelpText
|
||||
@ -15,34 +27,14 @@ Template XFig
|
||||
UpdateFormat pstex
|
||||
UpdateResult "$$Basename.pstex_t"
|
||||
Requirement "graphicx"
|
||||
Preamble
|
||||
%% This inputs the file if it exists, else prints a warning
|
||||
%% encased in an fbox.
|
||||
\def\stripprefix#1>{}
|
||||
\newcommand*{\xfiginput}[1]{%
|
||||
\edef\tempfilename{#1}%
|
||||
\InputIfFileExists{#1}{}{%
|
||||
\fbox{Could not find
|
||||
\ttfamily\expandafter\stripprefix\meaning\tempfilename
|
||||
!}}}
|
||||
PreambleEnd
|
||||
Preamble XFigInput
|
||||
FormatEnd
|
||||
Format PDFLaTeX
|
||||
Product "\\xfiginput{$$Basename.pdftex_t}"
|
||||
UpdateFormat pdftex
|
||||
UpdateResult "$$Basename.pdftex_t"
|
||||
Requirement "graphicx"
|
||||
Preamble
|
||||
%% This inputs the file if it exists, else prints a warning
|
||||
%% encased in an fbox.
|
||||
\def\stripprefix#1>{}
|
||||
\newcommand*{\xfiginput}[1]{%
|
||||
\edef\tempfilename{#1}%
|
||||
\InputIfFileExists{#1}{}{%
|
||||
\fbox{Could not find
|
||||
\ttfamily\expandafter\stripprefix\meaning\tempfilename
|
||||
!}}}
|
||||
PreambleEnd
|
||||
Preamble XFigInput
|
||||
FormatEnd
|
||||
Format Ascii
|
||||
Product "$$Contents(\"$$Basename.asc\")"
|
||||
|
@ -1,3 +1,10 @@
|
||||
2003-09-04 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* LaTeXFeatures.C (getMacros): move the output of the preamble_snippets
|
||||
here (from getPackages).
|
||||
|
||||
* debug.[Ch]: add a new EXTERNAL tag.
|
||||
|
||||
2003-09-04 Lars Gullik Bjønnes <larsbj@lyx.org>
|
||||
|
||||
* text2.C (cursorEnd): simplify
|
||||
|
@ -302,12 +302,6 @@ string const LaTeXFeatures::getPackages() const
|
||||
packages << "]{natbib}\n";
|
||||
}
|
||||
|
||||
FeaturesList::const_iterator pit = preamble_snippets.begin();
|
||||
FeaturesList::const_iterator pend = preamble_snippets.end();
|
||||
for (; pit != pend; ++pit) {
|
||||
packages << *pit << '\n';
|
||||
}
|
||||
|
||||
return STRCONV(packages.str());
|
||||
}
|
||||
|
||||
@ -316,6 +310,14 @@ string const LaTeXFeatures::getMacros() const
|
||||
{
|
||||
ostringstream macros;
|
||||
|
||||
if (!preamble_snippets.empty())
|
||||
macros << '\n';
|
||||
FeaturesList::const_iterator pit = preamble_snippets.begin();
|
||||
FeaturesList::const_iterator pend = preamble_snippets.end();
|
||||
for (; pit != pend; ++pit) {
|
||||
macros << *pit << '\n';
|
||||
}
|
||||
|
||||
if (isRequired("LyX"))
|
||||
macros << lyx_def << '\n';
|
||||
|
||||
|
@ -19,13 +19,15 @@
|
||||
using std::ostream;
|
||||
|
||||
|
||||
Box::Box()
|
||||
: x1(0), x2(0), y1(0), y2(0)
|
||||
{}
|
||||
|
||||
|
||||
Box::Box(int x1_, int x2_, int y1_, int y2_)
|
||||
: x1(x1_), x2(x2_), y1(y1_), y2(y2_)
|
||||
{}
|
||||
|
||||
Box::Box()
|
||||
: x1(0), x2(0), y1(0), y2(0)
|
||||
{}
|
||||
|
||||
bool Box::contains(int x, int y)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ error_item errorTags[] = {
|
||||
{ Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
|
||||
{ Debug::GRAPHICS, "graphics", N_("Graphics conversion and loading")},
|
||||
{ Debug::CHANGES, "changes", N_("Change tracking")},
|
||||
{ Debug::EXTERNAL, "external", N_("External template/inset messages")},
|
||||
{ Debug::ANY, "any", N_("All debugging messages")}
|
||||
};
|
||||
|
||||
@ -72,7 +73,7 @@ Debug::type const Debug::ANY = Debug::type(
|
||||
Debug::MATHED | Debug::FONT | Debug::TCLASS | Debug::LYXVC |
|
||||
Debug::LYXSERVER | Debug::ROFF | Debug::ACTION | Debug::LYXLEX |
|
||||
Debug::DEPEND | Debug::INSETS | Debug::FILES | Debug::WORKAREA |
|
||||
Debug::INSETTEXT | Debug::GRAPHICS | Debug::CHANGES);
|
||||
Debug::INSETTEXT | Debug::GRAPHICS | Debug::CHANGES | Debug::EXTERNAL);
|
||||
|
||||
|
||||
Debug::type Debug::value(string const & val)
|
||||
|
@ -71,7 +71,9 @@ struct Debug {
|
||||
///
|
||||
GRAPHICS = (1 << 21),
|
||||
/// change tracking
|
||||
CHANGES = (1 << 22)
|
||||
CHANGES = (1 << 22),
|
||||
///
|
||||
EXTERNAL = (1 << 23)
|
||||
};
|
||||
///
|
||||
static type const ANY;
|
||||
|
@ -10,6 +10,16 @@
|
||||
up the dialogs. Cursor has to be in front of the inset (i.e.
|
||||
start of row) for this to function.
|
||||
|
||||
2003-09-04 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ExternalTemplate.[Ch]: store the preamble snippets in a separate
|
||||
structure outside of the Format struct. Format::preambleName refers to
|
||||
an item in the map of all preamble snippets.
|
||||
Make use of the new Debug::EXTERNAL flag.
|
||||
|
||||
* insetexternal.C: make use of the new Debug::EXTERNAL flag.
|
||||
(validate): Small change due to the changed storage of preamble snippets.
|
||||
|
||||
2003-09-04 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetgraphics.C: #include "support/os.h"
|
||||
|
@ -17,11 +17,12 @@
|
||||
#include "support/path.h"
|
||||
#include "support/LAssert.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/path_defines.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace lyx::support;
|
||||
namespace support = lyx::support;
|
||||
|
||||
using std::endl;
|
||||
using std::ostream;
|
||||
@ -41,28 +42,50 @@ ExternalTemplate::FormatTemplate::FormatTemplate()
|
||||
ExternalTemplateManager::ExternalTemplateManager()
|
||||
{
|
||||
// gimp gnuchess gnuplot ical netscape tetris xpaint
|
||||
readTemplates(user_lyxdir());
|
||||
if (lyxerr.debugging())
|
||||
dumpTemplates();
|
||||
readTemplates(support::user_lyxdir());
|
||||
if (lyxerr.debugging(Debug::EXTERNAL)) {
|
||||
dumpPreambleDefs(lyxerr);
|
||||
lyxerr << '\n';
|
||||
dumpTemplates(lyxerr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class dumpPreambleDef {
|
||||
public:
|
||||
typedef ExternalTemplateManager::PreambleDefs::value_type value_type;
|
||||
|
||||
dumpPreambleDef(ostream & o) : ost(o) {}
|
||||
|
||||
void operator()(value_type const & vt) {
|
||||
ost << "PreambleDef " << vt.first << '\n'
|
||||
<< vt.second
|
||||
<< "PreambleDefEnd" << endl;
|
||||
}
|
||||
|
||||
private:
|
||||
ostream & ost;
|
||||
};
|
||||
|
||||
|
||||
class dumpTemplate {
|
||||
public:
|
||||
dumpTemplate(ostream & o)
|
||||
: ost(o) {}
|
||||
void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
|
||||
typedef ExternalTemplateManager::Templates::value_type value_type;
|
||||
|
||||
dumpTemplate(ostream & o) : ost(o) {}
|
||||
|
||||
void operator()(value_type const & vt) {
|
||||
ExternalTemplate const & et = vt.second;
|
||||
|
||||
ost << "Template " << et.lyxName << "\n"
|
||||
<< "\tGuiName " << et.guiName << "\n"
|
||||
ost << "Template " << et.lyxName << '\n'
|
||||
<< "\tGuiName " << et.guiName << '\n'
|
||||
<< "\tHelpText\n"
|
||||
<< et.helpText
|
||||
<< "\tHelpTextEnd\n"
|
||||
<< "\tInputFormat " << et.inputFormat << "\n"
|
||||
<< "\tFileFilter " << et.fileRegExp << "\n"
|
||||
<< "\tEditCommand " << et.editCommand << "\n"
|
||||
<< "\tAutomaticProduction " << et.automaticProduction << "\n";
|
||||
<< "\tInputFormat " << et.inputFormat << '\n'
|
||||
<< "\tFileFilter " << et.fileRegExp << '\n'
|
||||
<< "\tEditCommand " << et.editCommand << '\n'
|
||||
<< "\tAutomaticProduction " << et.automaticProduction << '\n';
|
||||
et.dumpFormats(ost);
|
||||
ost << "TemplateEnd" << endl;
|
||||
|
||||
@ -74,18 +97,18 @@ private:
|
||||
|
||||
class dumpFormat {
|
||||
public:
|
||||
dumpFormat(ostream & o)
|
||||
: ost(o) {}
|
||||
void operator()(ExternalTemplate::Formats::value_type const & vt) const{
|
||||
typedef ExternalTemplate::Formats::value_type value_type;
|
||||
|
||||
dumpFormat(ostream & o) : ost(o) {}
|
||||
|
||||
void operator()(value_type const & vt) const{
|
||||
ExternalTemplate::FormatTemplate const & ft = vt.second;
|
||||
ost << "\tFormat " << vt.first << "\n"
|
||||
<< "\t\tProduct " << ft.product << "\n"
|
||||
<< "\t\tUpdateFormat " << ft.updateFormat << "\n"
|
||||
<< "\t\tUpdateResult " << ft.updateResult << "\n"
|
||||
<< "\t\tRequirement " << ft.requirement << "\n"
|
||||
<< "\t\tPreamble\n"
|
||||
<< ft.preamble
|
||||
<< "\t\tPreambleEnd\n"
|
||||
ost << "\tFormat " << vt.first << '\n'
|
||||
<< "\t\tProduct " << ft.product << '\n'
|
||||
<< "\t\tUpdateFormat " << ft.updateFormat << '\n'
|
||||
<< "\t\tUpdateResult " << ft.updateResult << '\n'
|
||||
<< "\t\tRequirement " << ft.requirement << '\n'
|
||||
<< "\t\tPreamble " << ft.preambleName << '\n'
|
||||
<< "\tFormatEnd\n";
|
||||
}
|
||||
private:
|
||||
@ -99,9 +122,15 @@ void ExternalTemplate::dumpFormats(ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
void ExternalTemplateManager::dumpTemplates() const
|
||||
void ExternalTemplateManager::dumpPreambleDefs(ostream & os) const
|
||||
{
|
||||
for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
|
||||
for_each(preambledefs.begin(), preambledefs.end(), dumpPreambleDef(os));
|
||||
}
|
||||
|
||||
|
||||
void ExternalTemplateManager::dumpTemplates(ostream & os) const
|
||||
{
|
||||
for_each(templates.begin(), templates.end(), dumpTemplate(os));
|
||||
}
|
||||
|
||||
|
||||
@ -132,48 +161,76 @@ ExternalTemplate const & ExternalTemplateManager::getTemplateByName(string const
|
||||
}
|
||||
|
||||
|
||||
string const
|
||||
ExternalTemplateManager::getPreambleDefByName(string const & name) const
|
||||
{
|
||||
string const trimmed_name = support::trim(name);
|
||||
if (trimmed_name.empty())
|
||||
return string();
|
||||
|
||||
PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
|
||||
if (it == preambledefs.end())
|
||||
return string();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void ExternalTemplateManager::readTemplates(string const & path)
|
||||
{
|
||||
Path p(path);
|
||||
support::Path p(path);
|
||||
|
||||
enum TemplateTags {
|
||||
TM_TEMPLATE = 1,
|
||||
TM_END
|
||||
TM_PREAMBLEDEF = 1,
|
||||
TM_PREAMBLEDEF_END,
|
||||
TM_TEMPLATE,
|
||||
TM_TEMPLATE_END
|
||||
};
|
||||
|
||||
keyword_item templatetags[] = {
|
||||
{ "preambledef", TM_PREAMBLEDEF },
|
||||
{ "preambledefend", TM_PREAMBLEDEF_END },
|
||||
{ "template", TM_TEMPLATE },
|
||||
{ "templateend", TM_END }
|
||||
{ "templateend", TM_TEMPLATE_END }
|
||||
};
|
||||
|
||||
string filename = LibFileSearch("", "external_templates");
|
||||
if (filename.empty()) {
|
||||
lyxerr << "ExternalTemplateManager::readTemplates: "
|
||||
"No template file" << endl;
|
||||
LyXLex lex(templatetags, TM_TEMPLATE_END);
|
||||
|
||||
string filename = support::LibFileSearch("", "external_templates");
|
||||
if (filename.empty() || !lex.setFile(filename)) {
|
||||
lex.printError("ExternalTemplateManager::readTemplates: "
|
||||
"No template file");
|
||||
return;
|
||||
}
|
||||
|
||||
LyXLex lex(templatetags, TM_END);
|
||||
if (!lex.setFile(filename)) {
|
||||
lyxerr << "ExternalTemplateManager::readTemplates: "
|
||||
"No template file" << endl;
|
||||
return;
|
||||
}
|
||||
char const * const preamble_end_tag =
|
||||
templatetags[TM_PREAMBLEDEF_END-1].tag;
|
||||
|
||||
while (lex.isOK()) {
|
||||
switch (lex.lex()) {
|
||||
case TM_PREAMBLEDEF: {
|
||||
lex.next();
|
||||
string const name = lex.getString();
|
||||
preambledefs[name] = lex.getLongString(preamble_end_tag);
|
||||
}
|
||||
break;
|
||||
|
||||
case TM_TEMPLATE: {
|
||||
lex.next();
|
||||
string const temp = lex.getString();
|
||||
ExternalTemplate & tmp = templates[temp];
|
||||
tmp.lyxName = temp;
|
||||
string const name = lex.getString();
|
||||
ExternalTemplate & tmp = templates[name];
|
||||
tmp.lyxName = name;
|
||||
tmp.readTemplate(lex);
|
||||
}
|
||||
break;
|
||||
|
||||
case TM_END:
|
||||
case TM_TEMPLATE_END:
|
||||
lex.printError("Warning: End outside Template.");
|
||||
break;
|
||||
|
||||
case TM_PREAMBLEDEF_END:
|
||||
lex.printError("Warning: End outside PreambleDef.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -247,7 +304,7 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
|
||||
default:
|
||||
lex.printError("ExternalTemplate::readTemplate: "
|
||||
"Wrong tag: $$Token");
|
||||
Assert(false);
|
||||
support::Assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -299,12 +356,11 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
|
||||
break;
|
||||
|
||||
case FO_PREAMBLE:
|
||||
preamble = lex.getLongString("preambleend");
|
||||
lex.next(true);
|
||||
preambleName = lex.getString();
|
||||
break;
|
||||
|
||||
case FO_END:
|
||||
if (lyxerr.debugging())
|
||||
lex.printError("FormatEnd");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ struct ExternalTemplate {
|
||||
string updateFormat;
|
||||
/// What features does this external inset require?
|
||||
string requirement;
|
||||
/// What should be inserted into the preamble
|
||||
string preamble;
|
||||
/// Identify the preamble snippet using \c preambleName.
|
||||
string preambleName;
|
||||
///
|
||||
void readFormat(LyXLex &);
|
||||
/// This constructor has to default a command for safety reasons!
|
||||
@ -76,17 +76,25 @@ class ExternalTemplateManager : boost::noncopyable {
|
||||
public:
|
||||
/// Map from the LyX name of the template to the template structure
|
||||
typedef std::map<string, ExternalTemplate> Templates;
|
||||
/** Map from the LyX name of the preamble definition to the preamble
|
||||
* definition itself.
|
||||
*/
|
||||
typedef std::map<string, string> PreambleDefs;
|
||||
|
||||
static ExternalTemplateManager & get();
|
||||
Templates & getTemplates();
|
||||
Templates const & getTemplates() const;
|
||||
/// return the template by LyX name
|
||||
ExternalTemplate const & getTemplateByName(string const & name);
|
||||
string const getPreambleDefByName(string const & name) const;
|
||||
private:
|
||||
ExternalTemplateManager();
|
||||
void readTemplates(string const & path);
|
||||
void dumpTemplates() const;
|
||||
void dumpTemplates(std::ostream &) const;
|
||||
void dumpPreambleDefs(std::ostream &) const;
|
||||
|
||||
Templates templates;
|
||||
PreambleDefs preambledefs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -367,12 +367,13 @@ void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
|
||||
// Replace the inset's store
|
||||
setParams(params, buffer);
|
||||
|
||||
lyxerr[Debug::INFO] << "InsetExternal::Read: "
|
||||
<< "template: '" << params_.templatename
|
||||
<< "' filename: '" << params_.filename.absFilename()
|
||||
<< "' display: '" << params_.display
|
||||
<< "' scale: '" << params_.lyxscale
|
||||
<< '\'' << endl;
|
||||
lyxerr[Debug::EXTERNAL]
|
||||
<< "InsetExternal::Read: "
|
||||
<< "template: '" << params_.templatename
|
||||
<< "' filename: '" << params_.filename.absFilename()
|
||||
<< "' display: '" << params_.display
|
||||
<< "' scale: '" << params_.lyxscale
|
||||
<< '\'' << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -388,9 +389,10 @@ int InsetExternal::write(string const & format,
|
||||
ExternalTemplate::Formats::const_iterator cit =
|
||||
et.formats.find(format);
|
||||
if (cit == et.formats.end()) {
|
||||
lyxerr << "External template format '" << format
|
||||
<< "' not specified in template "
|
||||
<< params_.templatename << endl;
|
||||
lyxerr[Debug::EXTERNAL]
|
||||
<< "External template format '" << format
|
||||
<< "' not specified in template "
|
||||
<< params_.templatename << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -454,18 +456,17 @@ void InsetExternal::validate(LaTeXFeatures & features) const
|
||||
return;
|
||||
ExternalTemplate const & et = *et_ptr;
|
||||
|
||||
ExternalTemplate::Formats::const_iterator cit =
|
||||
et.formats.find("LaTeX");
|
||||
|
||||
ExternalTemplate::Formats::const_iterator cit = et.formats.find("LaTeX");
|
||||
if (cit == et.formats.end())
|
||||
return;
|
||||
|
||||
if (!cit->second.requirement.empty()) {
|
||||
if (!cit->second.requirement.empty())
|
||||
features.require(cit->second.requirement);
|
||||
}
|
||||
if (!cit->second.preamble.empty()) {
|
||||
features.addExternalPreamble(cit->second.preamble);
|
||||
}
|
||||
|
||||
ExternalTemplateManager & etm = ExternalTemplateManager::get();
|
||||
string const preamble = etm.getPreambleDefByName(cit->second.preambleName);
|
||||
if (!preamble.empty())
|
||||
features.addExternalPreamble(preamble);
|
||||
}
|
||||
|
||||
|
||||
@ -511,9 +512,10 @@ void InsetExternal::updateExternal(string const & format,
|
||||
return;
|
||||
|
||||
if (!converters.isReachable(from_format, to_format)) {
|
||||
lyxerr << "InsetExternal::updateExternal. "
|
||||
"Unable to convert from "
|
||||
<< from_format << " to " << to_format << endl;
|
||||
lyxerr[Debug::EXTERNAL]
|
||||
<< "InsetExternal::updateExternal. "
|
||||
<< "Unable to convert from "
|
||||
<< from_format << " to " << to_format << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -605,7 +607,7 @@ void editExternal(InsetExternal::Params const & params, Buffer const & buffer)
|
||||
|
||||
support::Path p(buffer.filePath());
|
||||
support::Forkedcall call;
|
||||
if (lyxerr.debugging()) {
|
||||
if (lyxerr.debugging(Debug::EXTERNAL)) {
|
||||
lyxerr << "Executing '" << command << "' in '"
|
||||
<< buffer.filePath() << '\'' << endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user