]> git.lyx.org Git - lyx.git/commitdiff
Enable the external inset to handle unknown templates gracefully.
authorAngus Leeming <leeming@lyx.org>
Wed, 11 Jun 2003 14:30:04 +0000 (14:30 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 11 Jun 2003 14:30:04 +0000 (14:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7146 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlExternal.C
src/frontends/controllers/ControlExternal.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/QExternal.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormExternal.C
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetexternal.h

index b9c6dd957e9b4fd9661e104cb4add6c73405ba54..0656c5e7b06ae2a6537d86b8372d36581e418d57 100644 (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>
 
index c985ef4fd574e5bdddc356f8acedf5fa81f8af6a..287cdaed1bf8114342f5b26f2adca44e26d9c4ef 100644 (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 += '|';
index bdef4881eb8657d616417d131cb3e403287ba083..9f7acd8cdd70c39dacbbb6e9466fa0965484f4fd 100644 (file)
@@ -20,6 +20,9 @@
 #include <boost/scoped_ptr.hpp>
 
 
+class ExternalTemplate;
+
+
 class ControlExternal : public Dialog::Controller {
 public:
        ///
index cc261b33c3479fc13f6923dec39a0fa3dd82e6b5..31f341be933affa51997fa9a72d424062b63e40f 100644 (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 ;-)
index 2196f56c920b0082c594c5f8a10fcacc5eae0b45..da958b70efb373d763798f2bf2d3b35e6018bd0d 100644 (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;
index c6214f4552afe22bb63771a725bbdc35fc0b5831..dcd3832c7c28dad66204a5f6d155b69439fb0540 100644 (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.
index 0546add807536f3e0b130077f3d02c4ef246ae99..a24b020739cfdd15848d2fbb7120d546423039ee 100644 (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);
 
index c5c7a3b6314e5e4ba370e166130af830a0d0b89f..b0f09f656d2fff6f13cab5eddaf0d6883b333c62 100644 (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.
index 0cfc8586e55cdb5bf5d43c38a604b50dff926045..ee0cbea2bce080049438023f1904924b09d052e6 100644 (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;
 
index 83285347febdb0a79c815aac75f9b8dff0384b87..4916bae6dae61476b8a3702cea3f9a48cb38cd1a 100644 (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).