From 8dfe03e0274634bc42c99fe6d4c97bee78b2c174 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 19 Apr 2002 09:17:05 +0000 Subject: [PATCH] (Marco Morandini): make the list of loadable graphics formats dynamic. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4029 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlGraphics.C | 49 +++++++++++++++++++-- src/graphics/ChangeLog | 6 +++ src/graphics/GraphicsCache.C | 5 +++ src/graphics/GraphicsCache.h | 3 ++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 8dc3ba5963..a834b41486 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -26,6 +26,7 @@ #include "helper_funcs.h" +#include "converter.h" #include "buffer.h" #include "BufferView.h" #include "Dialogs.h" @@ -34,6 +35,7 @@ #include "lyxrc.h" #include "graphics/GraphicsCache.h" +#include "graphics/GraphicsConverter.h" #include "insets/insetgraphics.h" #include "insets/insetgraphicsParams.h" @@ -48,13 +50,52 @@ using std::make_pair; using std::ifstream; namespace { +using std::vector; // FIXME: currently we need the second '|' to prevent mis-interpretation! // All supported graphic formats with their file-extension and the // gzip-ext for zipped (e)ps-files. -string const grfx_pattern = - "*.(agr|bmp|eps|epsi|fits|gif|jpg|obj|pdf|pbm|pgm|png|" - "ppm|ps|tif|tiff|xbm|xpm|xwd|gz)|"; +// string const grfx_pattern = +// "*.(agr|bmp|eps|epsi|fits|gif|jpg|obj|pdf|pbm|pgm|png|" +// "ppm|ps|tif|tiff|xbm|xpm|xwd|gz)|"; +vector const grfx_formats() +{ + vector native_formats = grfx::GCache::get().loadableFormats(); + // We can load any format that can be loaded natively together with + // those that can be converted to one of these native formats. + vector browsable_formats = native_formats; + + grfx::GConverter const & gconverter = grfx::GConverter::get(); + + vector::const_iterator to_end = native_formats.end(); + + Formats::const_iterator from_it = formats.begin(); + Formats::const_iterator from_end = formats.end(); + for (; from_it != from_end; ++from_it) { + string const from = from_it->name(); + + vector::const_iterator to_it = native_formats.begin(); + for (; to_it != to_end; ++to_it) { + if (gconverter.isReachable(from, *to_it)) { + browsable_formats.push_back(from); + break; + } + } + } + + browsable_formats.push_back("gz"); + + return browsable_formats; +} + + +string const xforms_pattern() +{ + vector const browsable_formats = grfx_formats(); + string const answer = + "*.(" + getStringFromVector(browsable_formats, "|") +")|"; + return answer; +} } @@ -113,7 +154,7 @@ string const ControlGraphics::Browse(string const & in_name) pair dir2(_("Documents|#o#O"), string(lyxrc.document_path)); // Show the file browser dialog return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(), - title, ::grfx_pattern, dir1, dir2); + title, ::xforms_pattern(), dir1, dir2); } diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 3a6188d528..7d32da96f4 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,9 @@ +2002-04-19 Marco Morandini + + * GraphicsCache.[Ch] (loadableFormats): new method. A wrapper for + GImage::loadableFormats() that ensures that the signal is connected + to the derived class' method. + 2002-04-18 Lars Gullik Bjønnes * GraphicsImageXPM.C (convertTo7chars): drop all conversions and diff --git a/src/graphics/GraphicsCache.C b/src/graphics/GraphicsCache.C index 562b4d214b..02b589b861 100644 --- a/src/graphics/GraphicsCache.C +++ b/src/graphics/GraphicsCache.C @@ -185,5 +185,10 @@ unsigned int GCache::raw_height(string const & filename) const return it->second->raw_height(); } + +std::vector GCache::loadableFormats() const { + return GImage::loadableFormats(); +} + } // namespace grfx diff --git a/src/graphics/GraphicsCache.h b/src/graphics/GraphicsCache.h index ed2d9bb20f..8a57e20f2c 100644 --- a/src/graphics/GraphicsCache.h +++ b/src/graphics/GraphicsCache.h @@ -23,6 +23,7 @@ #include "GraphicsTypes.h" #include +#include #include "LString.h" #include @@ -71,6 +72,8 @@ public: unsigned int raw_width(string const & filename) const; /// unsigned int raw_height(string const & filename) const; + /// + std::vector loadableFormats() const; private: /** Make the c-tor private so we can control how many objects