]> git.lyx.org Git - features.git/commitdiff
dissolve Importer 'class' to LyXFunc/Converter
authorAndré Pönitz <poenitz@gmx.net>
Thu, 25 Oct 2007 06:09:38 +0000 (06:09 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 25 Oct 2007 06:09:38 +0000 (06:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21195 a592a061-630c-0410-9148-cb99ea01b6c8

src/Converter.cpp
src/Converter.h
src/Importer.cpp [deleted file]
src/Importer.h [deleted file]
src/LyXFunc.cpp
src/Makefile.am
src/MenuBackend.cpp

index 481d706ed1fd8dae24d8b28e07e79369f3c52e72..b168cd1a240c4a715a9b647952a86f4a86ccabd4 100644 (file)
@@ -701,11 +701,34 @@ bool Converters::isReachable(string const & from, string const & to)
 }
 
 
-Graph::EdgePath const
-Converters::getPath(string const & from, string const & to)
+Graph::EdgePath Converters::getPath(string const & from, string const & to)
 {
        return G_.getPath(formats.getNumber(from),
                          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
index 77b5e363b5a9d8b09c68e8afcc960a1c891e22cb..942f33acd14939a4c2a13d981df647e39025d927 100644 (file)
@@ -98,10 +98,15 @@ public:
        std::vector<Format const *> const
        getReachable(std::string const & from, bool only_viewable,
                     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?
        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);
        /// Flags for converting files
diff --git a/src/Importer.cpp b/src/Importer.cpp
deleted file mode 100644 (file)
index 902df65..0000000
+++ /dev/null
@@ -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
diff --git a/src/Importer.h b/src/Importer.h
deleted file mode 100644 (file)
index 4483d78..0000000
+++ /dev/null
@@ -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
index 541113b58994271af250c703381a4ee51650f900..87e6b031e4502249fe40b7094e979763d37b9a15 100644 (file)
@@ -30,6 +30,7 @@
 #include "BufferView.h"
 #include "CmdDef.h"
 #include "Color.h"
+#include "Converter.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
 #include "debug.h"
@@ -40,7 +41,6 @@
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "gettext.h"
-#include "Importer.h"
 #include "InsetIterator.h"
 #include "Intl.h"
 #include "KeyMap.h"
@@ -107,6 +107,8 @@ using std::pair;
 using std::string;
 using std::istringstream;
 using std::ostringstream;
+using std::find;
+using std::vector;
 
 namespace fs = boost::filesystem;
 
@@ -136,12 +138,80 @@ using support::token;
 using support::trim;
 using support::prefixIs;
 
+
 namespace Alert = frontend::Alert;
 
 extern bool quitting;
 
 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
 // reconfigure the automatic settings.
 void reconfigure(LyXView & lv, string const & option)
@@ -2295,7 +2365,7 @@ void LyXFunc::doImport(string const & argument)
        }
 
        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?
 }
 
index 318fd20ce88daa87e74e3133de705661ea100c6c..ec58f7268a2595179abf484db75cae88d551db72 100644 (file)
@@ -156,8 +156,6 @@ liblyxcore_la_SOURCES = \
        gettext.h \
        Graph.cpp \
        Graph.h \
-       Importer.cpp \
-       Importer.h \
        InsetIterator.cpp \
        InsetIterator.h \
        InsetList.cpp \
index b35a78375d2b7c6776216f04f3d2f0785b142e6e..2dd4efb7313bc6921760af649f07bbc01f5f0d3f 100644 (file)
 #include "Buffer.h"
 #include "BufferList.h"
 #include "BufferParams.h"
+#include "Converter.h"
 #include "CutAndPaste.h"
 #include "debug.h"
 #include "Floating.h"
 #include "FloatList.h"
 #include "Format.h"
 #include "gettext.h"
-#include "Importer.h"
 #include "KeyMap.h"
 #include "Session.h"
 #include "LyXAction.h"
@@ -544,7 +544,7 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf)
 
        switch (kind) {
        case MenuItem::ImportFormats:
-               formats = Importer::GetImportableFormats();
+               formats = theConverters().importableFormats();
                action = LFUN_BUFFER_IMPORT;
                break;
        case MenuItem::ViewFormats: