]> git.lyx.org Git - features.git/commitdiff
Re-add the RasterImage template.
authorAngus Leeming <leeming@lyx.org>
Thu, 25 Sep 2003 10:49:13 +0000 (10:49 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 25 Sep 2003 10:49:13 +0000 (10:49 +0000)
Several small clean-ups of the InsetExternal code.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7823 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
lib/ChangeLog
lib/external_templates
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlExternal.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QExternal.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormExternal.C
src/graphics/ChangeLog
src/graphics/GraphicsParams.C
src/graphics/GraphicsParams.h
src/insets/ChangeLog
src/insets/ExternalTemplate.C
src/insets/ExternalTemplate.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/support/ChangeLog
src/support/translator.h

index b160534ab5c51f36307e23680114d8d8dd0d7770..66c04a5d28b0bf81e85b1a44a68c8d1454331aff 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * external_templates: re-add the RasterImage template.
+
 2003-09-23  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * CREDITS: add Hartmut Haase
index 25aef4547aa2a12b1587a242f5ba2272a78c296c..e3d4927806072a37f5c0b8b94c66e7bf5f097e9a 100644 (file)
@@ -33,6 +33,53 @@ PreambleDef InputOrWarn
                \IfFileExists{#1}{\input{#1}}{\warnNotFound{#1}}}
 PreambleDefEnd
 
+
+Template RasterImage
+       GuiName "Bitmap: $$Basename"
+       HelpText
+               A bitmap file.
+               In the parameters box, you can provide optional
+               parameters for the ImageMagick convert program.
+               E.g., use `-border 10x10 -bordercolor black'
+               to surround the picture with a black border 
+               when you export to LaTeX.
+               When you export to Ascii, you can provide a
+               number describing how many columns the picture
+               should expand to.
+               This template uses Gimp for editing.
+       HelpTextEnd
+       InputFormat "*"
+       FileFilter "*.(gif|png|jpg|bmp|pbm|ppm|tga|tif|xpm|xbm)"
+       EditCommand "gimp $$FName"
+       AutomaticProduction true
+       Format LaTeX
+               Product "\\includegraphics{$$Basename}"
+               UpdateFormat eps
+               UpdateResult "$$Basename.eps"
+               Requirement "graphicx"
+       FormatEnd
+       Format PDFLaTeX
+               Product "\\includegraphics{$$Basename}"
+               UpdateFormat png
+               UpdateResult "$$Basename.png"
+               Requirement "graphicx"  
+       FormatEnd
+       Format Ascii
+               Product "$$Contents(\"$$Basename.asc\")"
+               UpdateFormat asciiimage
+               UpdateResult "$$Basename.asc"
+       FormatEnd
+       Format DocBook
+               Product "<graphic fileref=\"$$Basename.eps\"></graphic>"
+               UpdateFormat eps
+               UpdateResult "$$Basename.eps"
+       FormatEnd
+       Format LinuxDoc
+               Product "[Bitmap: $$FName]"
+       FormatEnd
+TemplateEnd
+
+
 Template XFig
        GuiName "XFig: $$Basename"
        HelpText
@@ -74,6 +121,7 @@ Template XFig
        FormatEnd
 TemplateEnd
 
+
 Template ChessDiagram
        GuiName "Chess: $$Basename"
        HelpText
@@ -116,6 +164,7 @@ Template ChessDiagram
        FormatEnd
 TemplateEnd
 
+
 Template Date
        GuiName "Date"
        HelpText
index 9c8dad891338c0bc57db76cdc0f6c6828d908fef..c2a6497c312d729b823b4de485e1a25bdb1839e5 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * ControlExternal.C (getTemplatePtr): simplify, due to change in
+       ExternalTemplateManager interface.
+
 2003-09-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * ControlDocument.C (setParams): fix new bug
index 22c62770cc718eccf9a2e6c0d8adda5c4a3f2de4..d59d13d939d7aed64e8767260a1c1a07f38698c7 100644 (file)
@@ -121,11 +121,8 @@ 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;
+       ExternalTemplateManager const & etm = ExternalTemplateManager::get();
+       return etm.getTemplateByName(params.templatename());
 }
 
 } // namespace anon
index 7cfdd749308eb7c0893a351d9014cfba09916c7b..70522abae7193c7a5558ead40e663361a506660f 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * QExternal.C (update_contents, apply): InsetExternal::Params::
+       templatename now has accessor functions.
+
 2003-09-22  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * QLPopupMenu.C (getLabel): fix so that bindings are added even if
index a33f645b31f4a99847c6097698c6ffb80d9af739..9d1e593d6720cc88fa09c3120ff42fc5578f6e79 100644 (file)
@@ -68,7 +68,8 @@ void QExternal::update_contents()
                params.filename.outputFilename(kernel().bufferFilepath());
        dialog_->fileED->setText(toqstr(name));
 
-       dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templatename));
+       dialog_->externalCO->setCurrentItem(controller()
+                                           .getTemplateNumber(params.templatename()));
        dialog_->externalTV->setText(toqstr(helpText()));
 
        int item = 0;
@@ -106,8 +107,8 @@ void QExternal::apply()
        params.filename.set(fromqstr(dialog_->fileED->text()),
                            kernel().bufferFilepath());
 
-       params.templatename =
-               controller().getTemplate(dialog_->externalCO->currentItem()).lyxName;
+       params.settemplate(
+               controller().getTemplate(dialog_->externalCO->currentItem()).lyxName);
 
        switch (dialog_->showCB->currentItem()) {
                case 0: params.display = lyx::graphics::DefaultDisplay; break;
index 22067539b0f1c0d76afb94fe56f3d1e56bffd944..3d140cb9af1a3c894ba03a8a9982c93465e77c9c 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * FormExternal.C (update, apply): InsetExternal::Params::
+       templatename now has accessor functions.
+
 2003-09-24  Martin Vermeer  <martin.vermeer@hut.fi>
 
        * FormNote.C: generalize loop end/vector size
index 03034479530287814abaaf3e182e877911f95dd3..9c732778d5a6f1edadb4085fc96fd058cd34d23a 100644 (file)
@@ -47,7 +47,7 @@ void FormExternal::apply()
        params.filename.set(getString(dialog_->input_filename), buffer_path);
 
        int const choice = fl_get_choice(dialog_->choice_template) - 1;
-       params.templatename = controller().getTemplate(choice).lyxName;
+       params.settemplate(controller().getTemplate(choice).lyxName);
 
        params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
        if (params.lyxscale == 0)
@@ -127,7 +127,7 @@ void FormExternal::update()
        string const name = params.filename.outputFilename(buffer_path);
        fl_set_input(dialog_->input_filename, name.c_str());
 
-       int ID = controller().getTemplateNumber(params.templatename);
+       int ID = controller().getTemplateNumber(params.templatename());
        if (ID < 0) ID = 0;
        fl_set_choice(dialog_->choice_template, ID+1);
 
index 970c5bd59cb0bca93427fe19374bab5ad14b739a..baf4d93cf730e8a8f69d0eda0107a2ccbca0a785 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * GraphicsParams.[Ch] (asString): new member function.
+
 2003-09-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * Previews.C (Previews): fix new bug
index 91f54a0916afb3f42a14fe8ad0357451b11b16c8..bf163b26a9d7d85c2535e6b56e6c7a08ea6430f0 100644 (file)
@@ -22,6 +22,14 @@ using std::abs;
 namespace lyx {
 namespace graphics {
 
+string const BoundingBox::asString() const
+{
+       std::ostringstream os;
+       os << xl << ' ' << yb << ' ' << xr << ' ' << yt;
+       return os.str();
+}
+
+
 Params::Params()
        : display(ColorDisplay),
          scale(100),
index 9759643ccbaaa09003859d01f7a90d0f291bcf13..6da48f884389d8342a29fdcd0f482c6414ff3674 100644 (file)
@@ -33,6 +33,9 @@ struct BoundingBox {
        /// 0 0 0 0 is empty!
        bool empty() const;
 
+       /// The bounding box as "xl yb xr yr"
+       string const asString() const;
+
        unsigned int xl;
        unsigned int yb;
        unsigned int xr;
index 4a29d233e01458f9cdf324faccbbb1f027ae5c17..7e6a81606ab55e2bdf84ad940f8bc885fbdb567d 100644 (file)
@@ -1,7 +1,19 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.[Ch] (TempName): new (private) nested struct with
+       fake copy semantics. Enables us to use the generated copy c-tor
+       in the Params struct.
+       (Params::templatename, Params::tempname): use accessor functions.
+
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * ExternalTemplate.[Ch] (getTemplateByName): now it's a const member
+       function, returning a const pointer.
+
 2003-09-23  Angus Leeming  <leeming@lyx.org>
 
-       * ExternalTemplate.[Ch]: can have multiple preamble snippets if we store them
-       in a vector, preambleNames.
+       * ExternalTemplate.[Ch]: can have multiple preamble snippets if we
+       store them in a vector, preambleNames.
 
        * insetexternal.C (validate): loop over all preambleNames and call
        LaTeXFeatures::addExternalPreamble with each.
index 7cd8442d02f5960038f324d156a9a9754b2d9436..49d9e3cf7f88a8234e46bc9e624232bc04e114b7 100644 (file)
@@ -46,7 +46,6 @@ ExternalTemplate::FormatTemplate::FormatTemplate()
 
 ExternalTemplateManager::ExternalTemplateManager()
 {
-       // gimp gnuchess gnuplot ical netscape tetris xpaint
        readTemplates(support::user_lyxdir());
        if (lyxerr.debugging(Debug::EXTERNAL)) {
                dumpPreambleDefs(lyxerr);
@@ -114,12 +113,10 @@ public:
                    << "\t\tUpdateResult " << ft.updateResult << '\n'
                    << "\t\tRequirement " << ft.requirement << '\n';
 
-               if (!ft.preambleNames.empty()) {
-                       vector<string>::const_iterator it  = ft.preambleNames.begin();
-                       vector<string>::const_iterator end = ft.preambleNames.end();
-                       for (; it != end; ++it) {
-                               ost << "\t\tPreamble " << *it << '\n';
-                       }
+               vector<string>::const_iterator it  = ft.preambleNames.begin();
+               vector<string>::const_iterator end = ft.preambleNames.end();
+               for (; it != end; ++it) {
+                       ost << "\t\tPreamble " << *it << '\n';
                }
 
                ost << "\tFormatEnd\n";
@@ -168,9 +165,11 @@ ExternalTemplateManager::getTemplates() const
 }
 
 
-ExternalTemplate const & ExternalTemplateManager::getTemplateByName(string const & name)
+ExternalTemplate const *
+ExternalTemplateManager::getTemplateByName(string const & name) const
 {
-       return templates[name];
+       Templates::const_iterator it = templates.find(name);
+       return (it == templates.end()) ? 0 : &it->second;
 }
 
 
index 094ab3797c0538041bb9f65e640a3bdae32b8873..538af91ab766180d649209a5788e8444e9a0a079 100644 (file)
 #ifndef EXTERNALTEMPLATE_H
 #define EXTERNALTEMPLATE_H
 
-
-#include <iosfwd>
-#include <map>
 #include "support/std_string.h"
 #include <boost/utility.hpp>
+#include <iosfwd>
+#include <map>
 #include <vector>
 
 class LyXLex;
 
+
 ///
 struct ExternalTemplate {
        /// What is the name of this template in the LyX format?
@@ -85,7 +85,13 @@ public:
        static ExternalTemplateManager & get();
        Templates & getTemplates();
        Templates const & getTemplates() const;
-       /// return the template by LyX name
+       /** return the template by LyX name.
+        *  If it isn't found, return 0.
+        */
+       ExternalTemplate const * getTemplateByName(string const & name) const;
+       /** return the preamble definition by LyX name.
+        *  If it isn't found, return an empty string.
+        */
        ExternalTemplate const & getTemplateByName(string const & name);
        string const getPreambleDefByName(string const & name) const;
 private:
index 80a7fdc38b841ff0c650e45d88b09a49959988e8..b29d976b7f5ed5ce8f98e536a964c5226768d14b 100644 (file)
@@ -71,23 +71,62 @@ string const doSubstitution(InsetExternal::Params const & params,
 /// Invoke the external editor.
 void editExternal(InsetExternal::Params const & params, Buffer const & buffer);
 
+
+ExternalTemplate const * getTemplatePtr(string const & name)
+{
+       ExternalTemplateManager const & etm = ExternalTemplateManager::get();
+       return etm.getTemplateByName(name);
+}
+
+
+ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
+{
+       ExternalTemplateManager const & etm = ExternalTemplateManager::get();
+       return etm.getTemplateByName(params.templatename());
+}
+
 } // namespace anon
 
 
-InsetExternal::Params::Params()
-       : display(defaultDisplayType),
-         lyxscale(defaultLyxScale)
+InsetExternal::TempName::TempName()
 {
-       tempname = support::tempName(string(), "lyxext");
-       support::unlink(tempname);
+       tempname_ = support::tempName(string(), "lyxext");
+       support::unlink(tempname_);
        // must have an extension for the converter code to work correctly.
-       tempname += ".tmp";
+       tempname_ += ".tmp";
 }
 
 
-InsetExternal::Params::~Params()
+InsetExternal::TempName::TempName(InsetExternal::TempName const &)
 {
-       support::unlink(tempname);
+       tempname_ = TempName()();
+}
+
+
+InsetExternal::TempName::~TempName()
+{
+       support::unlink(tempname_);
+}
+
+
+InsetExternal::TempName &
+InsetExternal::TempName::operator=(InsetExternal::TempName const & other)
+{
+       if (this != &other)
+               tempname_ = TempName()();
+       return *this;
+}
+
+
+InsetExternal::Params::Params()
+       : display(defaultDisplayType),
+         lyxscale(defaultLyxScale)
+{}
+
+
+void InsetExternal::Params::settemplate(string const & name)
+{
+       templatename_ = name;
 }
 
 
@@ -203,23 +242,13 @@ lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams)
 }
 
 
-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,
                            Buffer const & buffer)
 {
        ExternalTemplate const * const ptr = getTemplatePtr(params);
        if (!ptr)
                return support::bformat(_("External template %1$s is not installed"),
-                                       params.templatename);
+                                       params.templatename());
        return doSubstitution(params, buffer, ptr->guiName);
 }
 
@@ -235,10 +264,7 @@ InsetExternal::Params const & InsetExternal::params() const
 void InsetExternal::setParams(Params const & p, Buffer const & buffer)
 {
        // The stored params; what we would like to happen in an ideal world.
-       params_.filename = p.filename;
-       params_.templatename = p.templatename;
-       params_.display = p.display;
-       params_.lyxscale = p.lyxscale;
+       params_ = p;
 
        // We display the inset as a button by default.
        bool display_button = (!getTemplatePtr(params_) ||
@@ -273,7 +299,7 @@ void InsetExternal::setParams(Params const & p, Buffer const & buffer)
 void InsetExternal::write(Buffer const & buffer, ostream & os) const
 {
        os << "External\n"
-          << "\ttemplate " << params_.templatename << '\n';
+          << "\ttemplate " << params_.templatename() << '\n';
 
        if (!params_.filename.empty())
                os << "\tfilename "
@@ -317,7 +343,7 @@ void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
                switch (lex.lex()) {
                case EX_TEMPLATE: {
                        lex.next();
-                       params.templatename = lex.getString();
+                       params.settemplate(lex.getString());
                        break;
                }
 
@@ -366,7 +392,7 @@ void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
 
        lyxerr[Debug::EXTERNAL]
                << "InsetExternal::Read: "
-               << "template: '" << params_.templatename
+               << "template: '" << params_.templatename()
                << "' filename: '" << params_.filename.absFilename()
                << "' display: '" << params_.display
                << "' scale: '" << params_.lyxscale
@@ -389,7 +415,7 @@ int InsetExternal::write(string const & format,
                lyxerr[Debug::EXTERNAL]
                        << "External template format '" << format
                        << "' not specified in template "
-                       << params_.templatename << endl;
+                       << params_.templatename() << endl;
                return 0;
        }
 
@@ -568,7 +594,7 @@ string const doSubstitution(InsetExternal::Params const & params,
        result = support::subst(s, "$$FName", filename);
        result = support::subst(result, "$$Basename", basename);
        result = support::subst(result, "$$FPath", filepath);
-       result = support::subst(result, "$$Tempname", params.tempname);
+       result = support::subst(result, "$$Tempname", params.tempname());
        result = support::subst(result, "$$Sysdir", support::system_lyxdir());
 
        // Handle the $$Contents(filename) syntax
index 7859b67a4c284a0cd0d558f2a477de43e853bd21..51b9871aabe0ec4fe13353b642db95c45481f81a 100644 (file)
 class RenderInset;
 
 ///
-class InsetExternal : public InsetOld, public boost::signals::trackable {
+class InsetExternal : public InsetOld, public boost::signals::trackable
+{
+       /** No two Params variables can have the same temporary file.
+        *  This struct has copy-semantics but the copy constructor
+        *  and assignment operator simply call the default constructor.
+        *  Use of this struct enables us to use the compiler-generated
+        *  copy constructor and assignment operator for the Params struct.
+        */
+       struct TempName {
+               TempName();
+               TempName(TempName const &);
+               ~TempName();
+               TempName & operator=(TempName const &);
+               string const & operator()() const { return tempname_; }
+       private:
+               string tempname_;
+       };
+
 public:
        /// hold parameters settable from the GUI
        struct Params {
                Params();
-               ~Params();
+
+               /// The name of the tempfile used for manipulations.
+               string const & tempname() const { return tempname_(); }
+
+               /// the current template used
+               void settemplate(string const &);
+               string const & templatename() const { return templatename_; }
+
                /// the filename
                lyx::support::FileName filename;
-               /// the current template used
-               string templatename;
-               /// The name of the tempfile used for manipulations.
-               string tempname;
                /// how the inset is displayed by LyX
                lyx::graphics::DisplayType display;
                /// The scale of the displayed graphic (If shown).
                unsigned int lyxscale;
+
+       private:
+               TempName tempname_;
+               string templatename_;
        };
 
        InsetExternal();
index f1abf8229932858ce613119aa37c75bbc03d4afc..1ba1d463c53589b6155f6535f5165c6e32c1c248 100644 (file)
@@ -1,12 +1,17 @@
+2003-09-25  Angus Leeming  <leeming@lyx.org>
+
+       * translator.h (add): new member function.
+
 2003-09-16  Angus Leeming  <leeming@lyx.org>
 
-       * textutils.h: remove #include "paragraph.h". Remove functions IsInsetChar
-       and IsWordChar.
+       * textutils.h: remove #include "paragraph.h". Remove functions
+       IsInsetChar and IsWordChar.
 
 2003-09-15  Angus Leeming  <leeming@lyx.org>
 
-       * copied_ptr.h: re-jig to something that resembles Herb Sutter's HolderPtr ---
-       see http://www.gotw.ca/gotw/062.htm. Also known in his book as ValuePtr.
+       * copied_ptr.h: re-jig to something that resembles Herb Sutter's
+       HolderPtr --- see http://www.gotw.ca/gotw/062.htm. Also known in
+       his book as ValuePtr.
        Use a memory_traits template parameter to create/destroy memory in a
        flexible manner.
 
@@ -27,8 +32,8 @@
 
 2003-09-15  Angus Leeming  <leeming@lyx.org>
 
-       * translator.h: add #include <boost/assert.hpp>, so that the template is
-       self-contained.
+       * translator.h: add #include <boost/assert.hpp>, so that the
+       template is self-contained.
 
 2003-09-11  Angus Leeming  <leeming@lyx.org>
 
index 16c54e3c86112b6c069e31bd260c4cc054b156ca..4d4020dafa8c4a1977d1ec9ee6d275fcfafda374 100644 (file)
@@ -48,6 +48,12 @@ public:
        void addPair(T1 const & first, T2 const & second) {
                map.push_back(MapPair(first, second));
        }
+       // Add the contents of \c other
+       void add(Translator const & other) {
+               if (other.map.empty())
+                       return;
+               map.insert(map.end(), other.map.begin(), other.map.end());
+       }
 
        /// Find the mapping for the first argument
        T2 const & find(T1 const & first) const {