Angus Leeming wrote:
> On Thursday 18 April 2002 2:17 pm, Marco Morandini wrote:
> 
>>The wish: from
>>http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg36560.html
>>some more extensions were added to the graphic file selection filter.
>>However, it would be really nice if a simple user could add
>>custom extensions without having to modify the source (.fig, for
>>example). Is this already possible?
> 
> 
> No, but the way to do so was:
>       http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg36553.html
> Patches are always welcome.
> 
> Angus
> 


A first draft. However, I'm not a very good programmer.
For example, I've used this sintax:

string answer;
answer += ")|);

where perhaps the right way is to use a stringstream.

And

     for (; b_it != b_before_end; ++b_it) {
         answer += *b_it;
         answer += "|";
     }
     answer += *b_before_end;
     answer += ")|";

is not very clear.

Let me know if I have to modify the patch.

Ciao,

Marco Morandini

P.S. Angus, I apologize I've sent this mail to your address too,I should 
have not used the "Reply" button.
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 15:45:52
@@ -26,6 +26,7 @@
 
 #include "helper_funcs.h"
 
+#include "converter.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "Dialogs.h"
@@ -34,9 +35,11 @@
 #include "lyxrc.h"
 
 #include "graphics/GraphicsCache.h"
+#include "graphics/GraphicsConverter.h"
 
 #include "insets/insetgraphics.h"
 #include "insets/insetgraphicsParams.h"
+#include "insets/insetexternal.h"
 
 #include "support/lstrings.h"
 #include "support/filetools.h"
@@ -48,14 +51,49 @@
 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 answer("*.(");
+       vector<string>::const_iterator b_it = browsable_formats.begin();
+       vector<string>::const_iterator b_end = browsable_formats.end();
+       vector<string>::const_iterator b_before_end = b_end-1;
+       for (; b_it != b_before_end; ++b_it) {
+               answer += *b_it;
+               answer += "|";
+       }
+       answer += *b_before_end;
+       answer += ")|";
+       return answer;
+};
 }
 
  
@@ -113,7 +151,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 15:45:52
@@ -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 15:45:52
@@ -23,6 +23,8 @@
 
 #include "GraphicsTypes.h"
 #include <map>
+#include <vector>
+#include <string>
 #include "LString.h"
 #include <boost/utility.hpp>
 
@@ -71,6 +73,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

Reply via email to