]> git.lyx.org Git - lyx.git/blobdiff - src/format.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / format.C
index 3cb3926f78d1cae0fe25a8846b7952e5caeea3ea..2ce250db95d00373e27e8c2d35755cb942f5ddf0 100644 (file)
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/os.h"
-#include "support/path.h"
 #include "support/systemcall.h"
 
 #include <boost/filesystem/operations.hpp>
 
+using lyx::docstring;
+using lyx::support::absolutePath;
 using lyx::support::bformat;
 using lyx::support::compare_ascii_no_case;
 using lyx::support::contains;
 using lyx::support::libScriptSearch;
 using lyx::support::makeDisplayPath;
-using lyx::support::onlyFilename;
 using lyx::support::onlyPath;
-using lyx::support::Path;
 using lyx::support::quoteName;
 using lyx::support::subst;
 using lyx::support::Systemcall;
@@ -95,7 +94,7 @@ bool operator<(Format const & a, Format const & b)
 
 Format::Format(string const & n, string const & e, string const & p,
               string const & s, string const & v, string const & ed,
-               bool d)
+              bool d)
        : name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v),
          editor_(ed), document_(d)
 {}
@@ -164,7 +163,7 @@ string Formats::getFormatFromFile(string const & filename) const
 
 namespace {
 
-string fixCommand(string const & cmd, string const & ext, 
+string fixCommand(string const & cmd, string const & ext,
                  os::auto_open_mode mode)
 {
        // configure.py says we do not want a viewer/editor
@@ -176,7 +175,7 @@ string fixCommand(string const & cmd, string const & ext,
                return "auto";
 
        // if configure.py found nothing, clear the command
-       if (token(cmd, ' ', 0) == "none")
+       if (token(cmd, ' ', 0) == "auto")
                return string();
 
        // use the command found by configure.py
@@ -225,10 +224,10 @@ void Formats::add(string const & name, string const & extension,
        if (it == formatlist.end())
                formatlist.push_back(Format(name, extension, prettyname,
                                            shortcut, viewer, editor,
-                                           document));
+                                           document));
        else
                *it = Format(name, extension, prettyname, shortcut, viewer,
-                            editor, document);
+                            editor, document);
 }
 
 
@@ -262,10 +261,11 @@ void Formats::setViewer(string const & name, string const & command)
 bool Formats::view(Buffer const & buffer, string const & filename,
                   string const & format_name) const
 {
+       BOOST_ASSERT(absolutePath(filename));
        if (filename.empty() || !fs::exists(filename)) {
                Alert::error(_("Cannot view file"),
                        bformat(_("File does not exist: %1$s"),
-                               filename));
+                               lyx::from_utf8(filename)));
                return false;
        }
 
@@ -288,7 +288,7 @@ bool Formats::view(Buffer const & buffer, string const & filename,
                else {
                        Alert::error(_("Cannot view file"),
                                bformat(_("Auto-view file %1$s failed"),
-                                       filename));
+                                       lyx::from_utf8(filename)));
                        return false;
                }
        }
@@ -309,14 +309,12 @@ bool Formats::view(Buffer const & buffer, string const & filename,
        if (!contains(command, token_from))
                command += ' ' + token_from;
 
-       command = subst(command, token_from,
-                       quoteName(onlyFilename(filename)));
+       command = subst(command, token_from, quoteName(filename));
        command = subst(command, token_path, quoteName(onlyPath(filename)));
        command = subst(command, token_socket, quoteName(lyxsocket->address()));
        lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
-       buffer.message(_("Executing command: ") + command);
+       buffer.message(_("Executing command: ") + lyx::from_utf8(command));
 
-       Path p(onlyPath(filename));
        Systemcall one;
        int const res = one.startscript(Systemcall::DontWait, command);
 
@@ -333,10 +331,11 @@ bool Formats::view(Buffer const & buffer, string const & filename,
 bool Formats::edit(Buffer const & buffer, string const & filename,
                         string const & format_name) const
 {
+       BOOST_ASSERT(absolutePath(filename));
        if (filename.empty() || !fs::exists(filename)) {
                Alert::error(_("Cannot edit file"),
                        bformat(_("File does not exist: %1$s"),
-                               filename));
+                               lyx::from_utf8(filename)));
                return false;
        }
 
@@ -359,7 +358,7 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
                else {
                        Alert::error(_("Cannot edit file"),
                                bformat(_("Auto-edit file %1$s failed"),
-                                       filename));
+                                       lyx::from_utf8(filename)));
                        return false;
                }
        }
@@ -369,14 +368,12 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
        if (!contains(command, token_from))
                command += ' ' + token_from;
 
-       command = subst(command, token_from,
-                       quoteName(onlyFilename(filename)));
+       command = subst(command, token_from, quoteName(filename));
        command = subst(command, token_path, quoteName(onlyPath(filename)));
        command = subst(command, token_socket, quoteName(lyxsocket->address()));
        lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
-       buffer.message(_("Executing command: ") + command);
+       buffer.message(_("Executing command: ") + lyx::from_utf8(command));
 
-       Path p(onlyPath(filename));
        Systemcall one;
        int const res = one.startscript(Systemcall::DontWait, command);
 
@@ -390,13 +387,13 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
 }
 
 
-string const Formats::prettyName(string const & name) const
+docstring const Formats::prettyName(string const & name) const
 {
        Format const * format = getFormat(name);
        if (format)
-               return format->prettyname();
+               return lyx::from_utf8(format->prettyname());
        else
-               return name;
+               return lyx::from_utf8(name);
 }