From: Angus Leeming Date: Thu, 25 Sep 2003 10:49:13 +0000 (+0000) Subject: Re-add the RasterImage template. X-Git-Tag: 1.6.10~16036 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9a3737148b86a17f2aa5c7016ba2cb2148d649c3;p=features.git Re-add the RasterImage template. 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 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index b160534ab5..66c04a5d28 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2003-09-25 Angus Leeming + + * external_templates: re-add the RasterImage template. + 2003-09-23 Jean-Marc Lasgouttes * CREDITS: add Hartmut Haase diff --git a/lib/external_templates b/lib/external_templates index 25aef4547a..e3d4927806 100644 --- a/lib/external_templates +++ b/lib/external_templates @@ -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 "" + 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 diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 9c8dad8913..c2a6497c31 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-09-25 Angus Leeming + + * ControlExternal.C (getTemplatePtr): simplify, due to change in + ExternalTemplateManager interface. + 2003-09-21 Lars Gullik Bjønnes * ControlDocument.C (setParams): fix new bug diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 22c62770cc..d59d13d939 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -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 diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 7cfdd74930..70522abae7 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2003-09-25 Angus Leeming + + * QExternal.C (update_contents, apply): InsetExternal::Params:: + templatename now has accessor functions. + 2003-09-22 Lars Gullik Bjønnes * QLPopupMenu.C (getLabel): fix so that bindings are added even if diff --git a/src/frontends/qt2/QExternal.C b/src/frontends/qt2/QExternal.C index a33f645b31..9d1e593d67 100644 --- a/src/frontends/qt2/QExternal.C +++ b/src/frontends/qt2/QExternal.C @@ -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; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 22067539b0..3d140cb9af 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2003-09-25 Angus Leeming + + * FormExternal.C (update, apply): InsetExternal::Params:: + templatename now has accessor functions. + 2003-09-24 Martin Vermeer * FormNote.C: generalize loop end/vector size diff --git a/src/frontends/xforms/FormExternal.C b/src/frontends/xforms/FormExternal.C index 0303447953..9c732778d5 100644 --- a/src/frontends/xforms/FormExternal.C +++ b/src/frontends/xforms/FormExternal.C @@ -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); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 970c5bd59c..baf4d93cf7 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,7 @@ +2003-09-25 Angus Leeming + + * GraphicsParams.[Ch] (asString): new member function. + 2003-09-21 Lars Gullik Bjønnes * Previews.C (Previews): fix new bug diff --git a/src/graphics/GraphicsParams.C b/src/graphics/GraphicsParams.C index 91f54a0916..bf163b26a9 100644 --- a/src/graphics/GraphicsParams.C +++ b/src/graphics/GraphicsParams.C @@ -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), diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h index 9759643ccb..6da48f8843 100644 --- a/src/graphics/GraphicsParams.h +++ b/src/graphics/GraphicsParams.h @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 4a29d233e0..7e6a81606a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,7 +1,19 @@ +2003-09-25 Angus Leeming + + * 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 + + * ExternalTemplate.[Ch] (getTemplateByName): now it's a const member + function, returning a const pointer. + 2003-09-23 Angus Leeming - * 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. diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index 7cd8442d02..49d9e3cf7f 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -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::const_iterator it = ft.preambleNames.begin(); - vector::const_iterator end = ft.preambleNames.end(); - for (; it != end; ++it) { - ost << "\t\tPreamble " << *it << '\n'; - } + vector::const_iterator it = ft.preambleNames.begin(); + vector::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; } diff --git a/src/insets/ExternalTemplate.h b/src/insets/ExternalTemplate.h index 094ab3797c..538af91ab7 100644 --- a/src/insets/ExternalTemplate.h +++ b/src/insets/ExternalTemplate.h @@ -12,15 +12,15 @@ #ifndef EXTERNALTEMPLATE_H #define EXTERNALTEMPLATE_H - -#include -#include #include "support/std_string.h" #include +#include +#include #include 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: diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 80a7fdc38b..b29d976b7f 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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 diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 7859b67a4c..51b9871aab 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -24,22 +24,46 @@ 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(); diff --git a/src/support/ChangeLog b/src/support/ChangeLog index f1abf82299..1ba1d463c5 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,12 +1,17 @@ +2003-09-25 Angus Leeming + + * translator.h (add): new member function. + 2003-09-16 Angus Leeming - * 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 - * 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 - * translator.h: add #include , so that the template is - self-contained. + * translator.h: add #include , so that the + template is self-contained. 2003-09-11 Angus Leeming diff --git a/src/support/translator.h b/src/support/translator.h index 16c54e3c86..4d4020dafa 100644 --- a/src/support/translator.h +++ b/src/support/translator.h @@ -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 {