Angus Leeming wrote: > On Thursday 18 April 2002 5:03 pm, Marco Morandini wrote: > > In ControlGraphics.C, are you sure you need to #include "converter.h"? >
It defines the class Format and declares the external formats variable. > > and #include "insets/insetexternal.h" ? > No, I don't need it. I've added it while I was lookig for a method to get the formats variable. > You're right about the ugliness of the "|" stuff. Really we should pass the > vector to browseRelFile and let it deal with this. For now though, you should > use: > > #include "support/lstrings.h" > > string const answer = > "*.(" + getStringFromVector(browsable_formats, " | ") +"|gz)|"; > > I think. (Don't forget the gz). > Thanks. "|" and not " | ", or it will not work. > Could you test it for me? Seems to work. Thanks again, Marco
Index: src/frontends/controllers/ControlGraphics.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlGraphics.C,v retrieving revision 1.33 diff -u -r1.33 ControlGraphics.C --- src/frontends/controllers/ControlGraphics.C 2002/04/12 15:25:11 1.33 +++ src/frontends/controllers/ControlGraphics.C 2002/04/18 16:51:35 @@ -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,14 +50,42 @@ 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)|"; +string const grfx_pattern() { + vector<string> 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<string> browsable_formats = native_formats; + + grfx::GConverter const & gconverter = grfx::GConverter::get(); + + vector<string>::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<string>::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; + } + } + } + + string const answer = + "*.(" + getStringFromVector(browsable_formats, "|") +"|gz)|"; + return answer; +}; } @@ -113,7 +143,7 @@ pair<string, string> 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, ::grfx_pattern(), dir1, dir2); } Index: src/graphics/GraphicsCache.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/graphics/GraphicsCache.C,v retrieving revision 1.23 diff -u -r1.23 GraphicsCache.C --- src/graphics/GraphicsCache.C 2002/04/11 17:40:44 1.23 +++ src/graphics/GraphicsCache.C 2002/04/18 16:51:35 @@ -185,5 +185,10 @@ return it->second->raw_height(); } + +std::vector<string> GCache::loadableFormats() const { + return GImage::loadableFormats(); +} + } // namespace grfx Index: src/graphics/GraphicsCache.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/graphics/GraphicsCache.h,v retrieving revision 1.17 diff -u -r1.17 GraphicsCache.h --- src/graphics/GraphicsCache.h 2002/04/11 17:40:44 1.17 +++ src/graphics/GraphicsCache.h 2002/04/18 16:51:35 @@ -23,6 +23,7 @@ #include "GraphicsTypes.h" #include <map> +#include <vector> #include "LString.h" #include <boost/utility.hpp> @@ -71,6 +72,8 @@ unsigned int raw_width(string const & filename) const; /// unsigned int raw_height(string const & filename) const; + /// + std::vector<string> loadableFormats() const; private: /** Make the c-tor private so we can control how many objects