]> git.lyx.org Git - lyx.git/commitdiff
(Marco Morandini): make the list of loadable graphics formats dynamic.
authorAngus Leeming <leeming@lyx.org>
Fri, 19 Apr 2002 09:17:05 +0000 (09:17 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 19 Apr 2002 09:17:05 +0000 (09:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4029 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ControlGraphics.C
src/graphics/ChangeLog
src/graphics/GraphicsCache.C
src/graphics/GraphicsCache.h

index 8dc3ba5963dbbbf5e567366d69608f00b0479da4..a834b41486726e47e76953d4b9b2d482d018f1e3 100644 (file)
@@ -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<string> const grfx_formats()
+{
+       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;
+                       }
+               }
+       }
+
+       browsable_formats.push_back("gz");
+
+       return browsable_formats;
+}
+
+
+string const xforms_pattern()
+{
+       vector<string> 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<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, ::xforms_pattern(), dir1, dir2);
 }
 
 
index 3a6188d528b8e7a35d0973379029ed4fdbe55685..7d32da96f4789bbf092b4274c3567709e44eec4f 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-19  Marco Morandini <morandini@aero.polimi.it>
+
+       * 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  <larsbj@birdstep.com>
 
        * GraphicsImageXPM.C (convertTo7chars): drop all conversions and
index 562b4d214ba526374c98111d7f2538f5c8020a65..02b589b861b9cce54396d72fcf6773202a30bcdc 100644 (file)
@@ -185,5 +185,10 @@ unsigned int GCache::raw_height(string const & filename) const
        return it->second->raw_height();
 }
 
+
+std::vector<string> GCache::loadableFormats() const {
+       return GImage::loadableFormats();
+}
+
 } // namespace grfx
 
index ed2d9bb20fc20ec6bf823e3b3fc9205783b5d045..8a57e20f2cb1745f80316aba27de3808c46e69ac 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "GraphicsTypes.h"
 #include <map>
+#include <vector>
 #include "LString.h"
 #include <boost/utility.hpp>
 
@@ -71,6 +72,8 @@ public:
        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