dissolve Importer 'class' to LyXFunc/Converter

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21195 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-25 06:09:38 +00:00
parent 07b6198f4c
commit 93bd28f040
7 changed files with 105 additions and 189 deletions

View File

@ -701,11 +701,34 @@ bool Converters::isReachable(string const & from, string const & to)
} }
Graph::EdgePath const Graph::EdgePath Converters::getPath(string const & from, string const & to)
Converters::getPath(string const & from, string const & to)
{ {
return G_.getPath(formats.getNumber(from), return G_.getPath(formats.getNumber(from),
formats.getNumber(to)); formats.getNumber(to));
} }
vector<Format const *> Converters::importableFormats()
{
vector<string> l = loaders();
vector<Format const *> result = getReachableTo(l[0], true);
for (vector<string>::const_iterator it = l.begin() + 1;
it != l.end(); ++it) {
vector<Format const *> r = getReachableTo(*it, false);
result.insert(result.end(), r.begin(), r.end());
}
return result;
}
vector<string> Converters::loaders() const
{
vector<string> v;
v.push_back("lyx");
v.push_back("text");
v.push_back("textparagraph");
return v;
}
} // namespace lyx } // namespace lyx

View File

@ -98,10 +98,15 @@ public:
std::vector<Format const *> const std::vector<Format const *> const
getReachable(std::string const & from, bool only_viewable, getReachable(std::string const & from, bool only_viewable,
bool clear_visited); bool clear_visited);
std::vector<Format const *> importableFormats();
std::vector<std::string> loaders() const;
/// Does a conversion path from format \p from to format \p to exist? /// Does a conversion path from format \p from to format \p to exist?
bool isReachable(std::string const & from, std::string const & to); bool isReachable(std::string const & from, std::string const & to);
/// ///
Graph::EdgePath const getPath(std::string const & from, std::string const & to); Graph::EdgePath getPath(std::string const & from, std::string const & to);
/// ///
OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path); OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
/// Flags for converting files /// Flags for converting files

View File

@ -1,133 +0,0 @@
/**
* \file Importer.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author unknown
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "Importer.h"
#include "Converter.h"
#include "Format.h"
#include "frontends/LyXView.h"
#include "FuncRequest.h"
#include "support/filetools.h"
#include "frontends/alert.h"
#include "gettext.h"
#include "BufferView.h"
#include "buffer_funcs.h"
using std::find;
using std::string;
using std::vector;
namespace lyx {
using support::bformat;
using support::changeExtension;
using support::FileName;
using support::makeDisplayPath;
using frontend::LyXView;
bool Importer::Import(LyXView * lv, FileName const & filename,
string const & format, ErrorList & errorList)
{
docstring const displaypath = makeDisplayPath(filename.absFilename());
lv->message(bformat(_("Importing %1$s..."), displaypath));
FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
string loader_format;
vector<string> loaders = Loaders();
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
for (vector<string>::const_iterator it = loaders.begin();
it != loaders.end(); ++it) {
if (theConverters().isReachable(format, *it)) {
string const tofile =
changeExtension(filename.absFilename(),
formats.extension(*it));
if (!theConverters().convert(0, filename, FileName(tofile),
filename, format, *it, errorList))
return false;
loader_format = *it;
break;
}
}
if (loader_format.empty()) {
frontend::Alert::error(_("Couldn't import file"),
bformat(_("No information for importing the format %1$s."),
formats.prettyName(format)));
return false;
}
} else {
loader_format = format;
}
if (loader_format == "lyx") {
Buffer * buf = lv->loadLyXFile(lyxfile);
if (!buf) {
// we are done
lv->message(_("file not imported!"));
return false;
}
updateLabels(*buf);
lv->setBuffer(buf);
lv->showErrorList("Parse");
} else {
Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
if (b)
lv->setBuffer(b);
else
return false;
bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename.absFilename()
: changeExtension(filename.absFilename(),
formats.extension(loader_format));
lv->view()->insertPlaintextFile(filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF));
}
// we are done
lv->message(_("imported."));
return true;
}
vector<Format const *> const Importer::GetImportableFormats()
{
vector<string> loaders = Loaders();
vector<Format const *> result =
theConverters().getReachableTo(loaders[0], true);
for (vector<string>::const_iterator it = loaders.begin() + 1;
it != loaders.end(); ++it) {
vector<Format const *> r =
theConverters().getReachableTo(*it, false);
result.insert(result.end(), r.begin(), r.end());
}
return result;
}
vector<string> const Importer::Loaders()
{
vector<string> v;
v.push_back("lyx");
v.push_back("text");
v.push_back("textparagraph");
return v;
}
} // namespace lyx

View File

@ -1,47 +0,0 @@
// -*- C++ -*-
/**
* \file Importer.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author unknown
* \author Jean-Marc Lasgouttes
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*/
#ifndef IMPORTER_H
#define IMPORTER_H
#include <string>
#include <vector>
namespace lyx {
namespace support { class FileName; }
class ErrorList;
class Format;
namespace frontend {
class LyXView;
}
class Importer {
public:
///
static bool Import(frontend::LyXView * lv, support::FileName const & filename,
std::string const & format, ErrorList & errorList);
///
static std::vector<Format const *> const GetImportableFormats();
private:
///
static std::vector<std::string> const Loaders();
};
} // namespace lyx
#endif

View File

@ -30,6 +30,7 @@
#include "BufferView.h" #include "BufferView.h"
#include "CmdDef.h" #include "CmdDef.h"
#include "Color.h" #include "Color.h"
#include "Converter.h"
#include "Cursor.h" #include "Cursor.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
@ -40,7 +41,6 @@
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h" #include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "Importer.h"
#include "InsetIterator.h" #include "InsetIterator.h"
#include "Intl.h" #include "Intl.h"
#include "KeyMap.h" #include "KeyMap.h"
@ -107,6 +107,8 @@ using std::pair;
using std::string; using std::string;
using std::istringstream; using std::istringstream;
using std::ostringstream; using std::ostringstream;
using std::find;
using std::vector;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -136,12 +138,80 @@ using support::token;
using support::trim; using support::trim;
using support::prefixIs; using support::prefixIs;
namespace Alert = frontend::Alert; namespace Alert = frontend::Alert;
extern bool quitting; extern bool quitting;
namespace { namespace {
bool import(LyXView * lv, FileName const & filename,
string const & format, ErrorList & errorList)
{
docstring const displaypath = makeDisplayPath(filename.absFilename());
lv->message(bformat(_("Importing %1$s..."), displaypath));
FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
string loader_format;
vector<string> loaders = theConverters().loaders();
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
for (vector<string>::const_iterator it = loaders.begin();
it != loaders.end(); ++it) {
if (theConverters().isReachable(format, *it)) {
string const tofile =
changeExtension(filename.absFilename(),
formats.extension(*it));
if (!theConverters().convert(0, filename, FileName(tofile),
filename, format, *it, errorList))
return false;
loader_format = *it;
break;
}
}
if (loader_format.empty()) {
frontend::Alert::error(_("Couldn't import file"),
bformat(_("No information for importing the format %1$s."),
formats.prettyName(format)));
return false;
}
} else {
loader_format = format;
}
if (loader_format == "lyx") {
Buffer * buf = lv->loadLyXFile(lyxfile);
if (!buf) {
// we are done
lv->message(_("file not imported!"));
return false;
}
updateLabels(*buf);
lv->setBuffer(buf);
lv->showErrorList("Parse");
} else {
Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
if (b)
lv->setBuffer(b);
else
return false;
bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename.absFilename()
: changeExtension(filename.absFilename(),
formats.extension(loader_format));
lv->view()->insertPlaintextFile(filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF));
}
// we are done
lv->message(_("imported."));
return true;
}
// This function runs "configure" and then rereads lyx.defaults to // This function runs "configure" and then rereads lyx.defaults to
// reconfigure the automatic settings. // reconfigure the automatic settings.
void reconfigure(LyXView & lv, string const & option) void reconfigure(LyXView & lv, string const & option)
@ -2295,7 +2365,7 @@ void LyXFunc::doImport(string const & argument)
} }
ErrorList errorList; ErrorList errorList;
Importer::Import(lyx_view_, fullname, format, errorList); import(lyx_view_, fullname, format, errorList);
// FIXME (Abdel 12/08/06): Is there a need to display the error list here? // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
} }

View File

@ -156,8 +156,6 @@ liblyxcore_la_SOURCES = \
gettext.h \ gettext.h \
Graph.cpp \ Graph.cpp \
Graph.h \ Graph.h \
Importer.cpp \
Importer.h \
InsetIterator.cpp \ InsetIterator.cpp \
InsetIterator.h \ InsetIterator.h \
InsetList.cpp \ InsetList.cpp \

View File

@ -21,13 +21,13 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferList.h" #include "BufferList.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "Converter.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "Floating.h" #include "Floating.h"
#include "FloatList.h" #include "FloatList.h"
#include "Format.h" #include "Format.h"
#include "gettext.h" #include "gettext.h"
#include "Importer.h"
#include "KeyMap.h" #include "KeyMap.h"
#include "Session.h" #include "Session.h"
#include "LyXAction.h" #include "LyXAction.h"
@ -544,7 +544,7 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf)
switch (kind) { switch (kind) {
case MenuItem::ImportFormats: case MenuItem::ImportFormats:
formats = Importer::GetImportableFormats(); formats = theConverters().importableFormats();
action = LFUN_BUFFER_IMPORT; action = LFUN_BUFFER_IMPORT;
break; break;
case MenuItem::ViewFormats: case MenuItem::ViewFormats: