]> git.lyx.org Git - lyx.git/blobdiff - src/Format.cpp
cleanup and reorder initialisation code of GuiView and GuiToolbars. Move some things...
[lyx.git] / src / Format.cpp
index 8bd34ad48968d9fb6df3b53ec97eebacfeee22f3..9b3b8f8bfdab6de8d907a6957dc2bc840b43657a 100644 (file)
@@ -18,7 +18,6 @@
 #include "gettext.h"
 #include "ServerSocket.h"
 
-#include "frontends/Application.h"
 #include "frontends/alert.h" //to be removed?
 
 #include "support/filetools.h"
@@ -26,8 +25,6 @@
 #include "support/os.h"
 #include "support/Systemcall.h"
 
-#include <boost/filesystem/operations.hpp>
-
 using std::find_if;
 using std::string;
 using std::distance;
@@ -49,7 +46,6 @@ using support::Systemcall;
 using support::token;
 
 namespace Alert = frontend::Alert;
-namespace fs = boost::filesystem;
 namespace os = support::os;
 
 namespace {
@@ -143,12 +139,12 @@ string Formats::getFormatFromFile(FileName const & filename) const
        if (filename.empty())
                return string();
 
-       string const format = support::getFormatFromContents(filename);
+       string const format = filename.guessFormatFromContents();
        if (!format.empty())
                return format;
 
        // try to find a format from the file extension.
-       string const ext(support::getExtension(filename.absFilename()));
+       string const ext = support::getExtension(filename.absFilename());
        if (!ext.empty()) {
                // this is ambigous if two formats have the same extension,
                // but better than nothing
@@ -156,18 +152,16 @@ string Formats::getFormatFromFile(FileName const & filename) const
                        find_if(formatlist.begin(), formatlist.end(),
                                FormatExtensionsEqual(ext));
                if (cit != formats.end()) {
-                       LYXERR(Debug::GRAPHICS)
-                               << "\twill guess format from file extension: "
-                               << ext << " -> " << cit->name() << std::endl;
+                       LYXERR(Debug::GRAPHICS, "\twill guess format from file extension: "
+                               << ext << " -> " << cit->name());
                        return cit->name();
                }
        }
        return string();
 }
 
-namespace {
 
-string fixCommand(string const & cmd, string const & ext,
+static string fixCommand(string const & cmd, string const & ext,
                  os::auto_open_mode mode)
 {
        // configure.py says we do not want a viewer/editor
@@ -186,7 +180,6 @@ string fixCommand(string const & cmd, string const & ext,
        return cmd;
 }
 
-}
 
 void Formats::setAutoOpen()
 {
@@ -266,7 +259,7 @@ void Formats::setViewer(string const & name, string const & command)
 bool Formats::view(Buffer const & buffer, FileName const & filename,
                   string const & format_name) const
 {
-       if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
+       if (filename.empty() || !filename.exists()) {
                Alert::error(_("Cannot view file"),
                        bformat(_("File does not exist: %1$s"),
                                from_utf8(filename.absFilename())));
@@ -316,7 +309,7 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
        command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
        command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
        command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
-       LYXERR(Debug::FILES) << "Executing command: " << command << std::endl;
+       LYXERR(Debug::FILES, "Executing command: " << command);
        // FIXME UNICODE utf8 can be wrong for files
        buffer.message(_("Executing command: ") + from_utf8(command));
 
@@ -336,7 +329,7 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
 bool Formats::edit(Buffer const & buffer, FileName const & filename,
                         string const & format_name) const
 {
-       if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
+       if (filename.empty() || !filename.exists()) {
                Alert::error(_("Cannot edit file"),
                        bformat(_("File does not exist: %1$s"),
                                from_utf8(filename.absFilename())));
@@ -375,7 +368,7 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename,
        command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
        command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
        command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
-       LYXERR(Debug::FILES) << "Executing command: " << command << std::endl;
+       LYXERR(Debug::FILES, "Executing command: " << command);
        // FIXME UNICODE utf8 can be wrong for files
        buffer.message(_("Executing command: ") + from_utf8(command));