(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
This commit is contained in:
Angus Leeming 2002-04-19 09:17:05 +00:00
parent 6277647f63
commit 8dfe03e027
4 changed files with 59 additions and 4 deletions

View 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);
}

View 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

View 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

View 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