Enable the external inset to handle unknown templates gracefully.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7146 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-06-11 14:30:04 +00:00
parent 822efad779
commit 19e1271c83
10 changed files with 126 additions and 39 deletions

View File

@ -1,7 +1,12 @@
2003-06-11 Angus Leeming <leeming@lyx.org>
* ControlExternal.[Ch]: changes due to InsetExternal::Params no longer
storing the ExternalTemplate but its name.
2003-06-10 Angus Leeming <leeming@lyx.org>
* ControlExternal.C (editExternal): invokes new LFUN_EXTERNAL_EDIT rather
than generate a new inset itself.
* ControlExternal.C (editExternal): invokes new LFUN_EXTERNAL_EDIT
rather than generate a new inset itself.
2003-06-06 John Levon <levon@movementarian.org>

View File

@ -19,6 +19,8 @@
#include "helper_funcs.h"
#include "lyxrc.h"
#include "insets/ExternalTemplate.h"
#include "support/LAssert.h"
#include <vector>
@ -111,12 +113,26 @@ ExternalTemplate ControlExternal::getTemplate(int i) const
ExternalTemplateManager::Templates::const_iterator i1
= ExternalTemplateManager::get().getTemplates().begin();
std::advance(i1, i);
std::advance(i1, i);
return i1->second;
}
namespace {
ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
{
ExternalTemplateManager & etm = ExternalTemplateManager::get();
ExternalTemplate const & templ = etm.getTemplateByName(params.templatename);
if (templ.lyxName.empty())
return 0;
return &templ;
}
} // namespace anon
string const ControlExternal::Browse(string const & input) const
{
string const title = _("Select external file");
@ -124,10 +140,10 @@ string const ControlExternal::Browse(string const & input) const
string const bufpath = kernel().buffer()->filePath();
/// Determine the template file extension
ExternalTemplate const & et = params().templ;
string pattern = et.fileRegExp;
if (pattern.empty())
pattern = "*";
string pattern = "*";
ExternalTemplate const * const et_ptr = getTemplatePtr(params());
if (et_ptr)
pattern = et_ptr->fileRegExp;
// FIXME: a temporary hack until the FileDialog interface is updated
pattern += '|';

View File

@ -20,6 +20,9 @@
#include <boost/scoped_ptr.hpp>
class ExternalTemplate;
class ControlExternal : public Dialog::Controller {
public:
///

View File

@ -1,3 +1,8 @@
2003-06-11 Angus Leeming <leeming@lyx.org>
* QExternal.C: changes due to InsetExternal::Params no longer
storing the ExternalTemplate but its name.
2003-06-10 Angus Leeming <leeming@lyx.org>
* QDocument.C (apply): compilation fix after Lars' changes ;-)

View File

@ -13,6 +13,9 @@
#include "ControlExternal.h"
#include "qt_helpers.h"
#include "insets/ExternalTemplate.h"
#include "support/lstrings.h"
#include "support/tostr.h"
@ -63,7 +66,7 @@ void QExternal::update_contents()
dialog_->fileED->setText(toqstr(params.filename));
dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templ.lyxName));
dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templatename));
dialog_->externalTV->setText(toqstr(helpText()));
int item = 0;
@ -100,7 +103,8 @@ void QExternal::apply()
params.filename = fromqstr(dialog_->fileED->text());
params.templ = controller().getTemplate(dialog_->externalCO->currentItem());
params.templatename =
controller().getTemplate(dialog_->externalCO->currentItem()).lyxName;
switch (dialog_->showCB->currentItem()) {
case 0: params.display = grfx::DefaultDisplay; break;

View File

@ -1,3 +1,8 @@
2003-06-11 Angus Leeming <leeming@lyx.org>
* FormExternal.C: changes due to InsetExternal::Params no longer
storing the ExternalTemplate but its name.
2003-06-10 Lars Gullik Bjønnes <larsbj@lyx.org>
* XFormsView.C: remvoe current_view global variable.

View File

@ -24,6 +24,8 @@
#include "gettext.h"
#include "insets/ExternalTemplate.h"
#include "support/tostr.h"
#include "support/lstrings.h"
#include "lyx_forms.h"
@ -42,7 +44,7 @@ void FormExternal::apply()
params.filename = fl_get_input(dialog_->input_filename);
int const choice = fl_get_choice(dialog_->choice_template) - 1;
params.templ = controller().getTemplate(choice);
params.templatename = controller().getTemplate(choice).lyxName;
params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
if (params.lyxscale == 0)
@ -120,7 +122,7 @@ void FormExternal::update()
fl_set_input(dialog_->input_filename, params.filename.c_str());
int ID = controller().getTemplateNumber(params.templ.lyxName);
int ID = controller().getTemplateNumber(params.templatename);
if (ID < 0) ID = 0;
fl_set_choice(dialog_->choice_template, ID+1);

View File

@ -1,3 +1,14 @@
2003-06-11 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch]: InsetExternal::Params no longer stores the
ExternalTemplate but its name, templatename. This means that a file
containing a reference to an External Template not installed on the
current machine will be saved retaining this info rather than inserting
the first "valid" template from the list of templates.
As a by product, the visual statement that the Template is missing is
now very clear!
2003-06-10 Lars Gullik Bjønnes <larsbj@lyx.org>
* insettext.C (appendParagraphs): remove some commented code.

View File

@ -85,7 +85,6 @@ InsetExternal::InsetExternal()
: renderer_(new GraphicInset)
{
renderer_->connect(boost::bind(&InsetExternal::statusChanged, this));
params_.templ = ExternalTemplateManager::get().getTemplates().begin()->second;
}
@ -201,34 +200,60 @@ grfx::Params get_grfx_params(InsetExternal::Params const & eparams,
return gparams;
}
ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
{
ExternalTemplateManager & etm = ExternalTemplateManager::get();
ExternalTemplate const & templ = etm.getTemplateByName(params.templatename);
if (templ.lyxName.empty())
return 0;
return &templ;
}
string const getScreenLabel(InsetExternal::Params const & params)
{
ExternalTemplate const * const ptr = getTemplatePtr(params);
if (!ptr)
return bformat(_("External template %1$s is not installed"),
params.templatename);
return doSubstitution(params, 0, ptr->guiName);
}
} // namespace anon
void InsetExternal::setParams(Params const & p, string const & filepath)
{
// The stored params; what we would like to happen in an ideal world.
params_.filename = p.filename;
params_.templ = p.templ;
params_.templatename = p.templatename;
params_.display = p.display;
params_.lyxscale = p.lyxscale;
// A temporary set of params; whether the thing can be displayed
// within LyX depends on the availability of this template.
Params tmp = params_;
if (!getTemplatePtr(params_))
tmp.display = grfx::NoDisplay;
// Update the display using the new parameters.
if (params_.filename.empty() || !filepath.empty())
renderer_->update(get_grfx_params(params_, filepath));
string const msg = doSubstitution(params_, 0, params_.templ.guiName);
renderer_->setNoDisplayMessage(msg);
renderer_->update(get_grfx_params(tmp, filepath));
renderer_->setNoDisplayMessage(getScreenLabel(params_));
}
string const InsetExternal::editMessage() const
{
return doSubstitution(params_, 0, params_.templ.guiName);
return getScreenLabel(params_);
}
void InsetExternal::write(Buffer const *, ostream & os) const
{
os << "External\n"
<< "\ttemplate " << params_.templ.lyxName << '\n';
<< "\ttemplate " << params_.templatename << '\n';
if (!params_.filename.empty())
os << "\tfilename " << params_.filename << '\n';
@ -270,10 +295,7 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
switch (lex.lex()) {
case EX_TEMPLATE: {
lex.next();
string const name = lex.getString();
ExternalTemplateManager & etm =
ExternalTemplateManager::get();
params.templ = etm.getTemplateByName(name);
params.templatename = lex.getString();
break;
}
@ -320,20 +342,15 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
lex.popTable();
// Replace the inset's store
params_ = params;
string const path = buffer ? buffer->filePath() : string();
setParams(params, path);
lyxerr[Debug::INFO] << "InsetExternal::Read: "
<< "template: '" << params_.templ.lyxName
<< "template: '" << params_.templatename
<< "' filename: '" << params_.filename
<< "' display: '" << params_.display
<< "' scale: '" << params_.lyxscale
<< '\'' << endl;
// Update the display using the new parameters.
if (buffer)
renderer_->update(get_grfx_params(params_, buffer->filePath()));
string const msg = doSubstitution(params_, 0, params_.templ.guiName);
renderer_->setNoDisplayMessage(msg);
}
@ -341,13 +358,17 @@ int InsetExternal::write(string const & format,
Buffer const * buf, ostream & os,
bool external_in_tmpdir) const
{
ExternalTemplate const & et = params_.templ;
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return 0;
ExternalTemplate const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit =
et.formats.find(format);
if (cit == et.formats.end()) {
lyxerr << "External template format '" << format
<< "' not specified in template "
<< params_.templ.lyxName << endl;
<< params_.templatename << endl;
return 0;
}
@ -371,7 +392,11 @@ 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 & et = params_.templ;
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return 0;
ExternalTemplate const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit =
et.formats.find("PDFLaTeX");
if (cit != et.formats.end())
@ -402,7 +427,11 @@ int InsetExternal::docbook(Buffer const * buf, ostream & os, bool) const
void InsetExternal::validate(LaTeXFeatures & features) const
{
ExternalTemplate const & et = params_.templ;
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
ExternalTemplate::Formats::const_iterator cit =
et.formats.find("LaTeX");
@ -422,7 +451,11 @@ void InsetExternal::updateExternal(string const & format,
Buffer const * buf,
bool external_in_tmpdir) const
{
ExternalTemplate const & et = params_.templ;
ExternalTemplate const * const et_ptr = getTemplatePtr(params_);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
if (!et.automaticProduction)
return;
@ -535,7 +568,11 @@ void editExternal(InsetExternal::Params const & params, Buffer const * buffer)
if (!buffer)
return;
ExternalTemplate const & et = params.templ;
ExternalTemplate const * const et_ptr = getTemplatePtr(params);
if (!et_ptr)
return;
ExternalTemplate const & et = *et_ptr;
if (et.editCommand.empty())
return;

View File

@ -13,7 +13,6 @@
#define INSET_EXTERNAL_H
#include "inset.h"
#include "ExternalTemplate.h"
#include "graphics/GraphicsTypes.h"
#include "LString.h"
@ -32,10 +31,10 @@ public:
~Params();
/// the filename
string filename;
/// the current template used
string templatename;
/// The name of the tempfile used for manipulations.
string tempname;
/// the current template used
ExternalTemplate templ;
/// how the inset is displayed by LyX
grfx::DisplayType display;
/// The scale of the displayed graphic (If shown).