]> git.lyx.org Git - lyx.git/blobdiff - src/format.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / format.C
index 29ebe338c2f4edcae906f7ae502651f816c5560a..d762f297365e40e3f383fd8821f832d89b7492a3 100644 (file)
@@ -35,6 +35,7 @@ using support::absolutePath;
 using support::bformat;
 using support::compare_ascii_no_case;
 using support::contains;
+using support::FileName;
 using support::libScriptSearch;
 using support::makeDisplayPath;
 using support::onlyPath;
@@ -52,9 +53,9 @@ namespace os = support::os;
 
 namespace {
 
-string const token_from("$$i");
-string const token_path("$$p");
-string const token_socket("$$a");
+string const token_from_format("$$i");
+string const token_path_format("$$p");
+string const token_socket_format("$$a");
 
 
 class FormatNamesEqual : public std::unary_function<Format, bool> {
@@ -136,7 +137,7 @@ Format const * Formats::getFormat(string const & name) const
 }
 
 
-string Formats::getFormatFromFile(string const & filename) const
+string Formats::getFormatFromFile(FileName const & filename) const
 {
        if (filename.empty())
                return string();
@@ -146,7 +147,7 @@ string Formats::getFormatFromFile(string const & filename) const
                return format;
 
        // try to find a format from the file extension.
-       string const ext(support::getExtension(filename));
+       string const ext(support::getExtension(filename.absFilename()));
        if (!ext.empty()) {
                // this is ambigous if two formats have the same extension,
                // but better than nothing
@@ -261,14 +262,13 @@ void Formats::setViewer(string const & name, string const & command)
 }
 
 
-bool Formats::view(Buffer const & buffer, string const & filename,
+bool Formats::view(Buffer const & buffer, FileName const & filename,
                   string const & format_name) const
 {
-       BOOST_ASSERT(absolutePath(filename));
-       if (filename.empty() || !fs::exists(filename)) {
+       if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
                Alert::error(_("Cannot view file"),
                        bformat(_("File does not exist: %1$s"),
-                               from_utf8(filename)));
+                               from_utf8(filename.absFilename())));
                return false;
        }
 
@@ -286,12 +286,12 @@ bool Formats::view(Buffer const & buffer, string const & filename,
        }
        // viewer is 'auto'
        if (format->viewer() == "auto") {
-               if (os::autoOpenFile(filename, os::VIEW))
+               if (os::autoOpenFile(filename.absFilename(), os::VIEW))
                        return true;
                else {
                        Alert::error(_("Cannot view file"),
                                bformat(_("Auto-view file %1$s failed"),
-                                       from_utf8(filename)));
+                                       from_utf8(filename.absFilename())));
                        return false;
                }
        }
@@ -309,13 +309,14 @@ bool Formats::view(Buffer const & buffer, string const & filename,
                        command += 'r';
        }
 
-       if (!contains(command, token_from))
-               command += ' ' + token_from;
+       if (!contains(command, token_from_format))
+               command += ' ' + token_from_format;
 
-       command = subst(command, token_from, quoteName(filename));
-       command = subst(command, token_path, quoteName(onlyPath(filename)));
-       command = subst(command, token_socket, quoteName(theLyXServerSocket().address()));
+       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(theLyXServerSocket().address()));
        lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
+       // FIXME UNICODE utf8 can be wrong for files
        buffer.message(_("Executing command: ") + from_utf8(command));
 
        Systemcall one;
@@ -331,14 +332,13 @@ bool Formats::view(Buffer const & buffer, string const & filename,
 }
 
 
-bool Formats::edit(Buffer const & buffer, string const & filename,
+bool Formats::edit(Buffer const & buffer, FileName const & filename,
                         string const & format_name) const
 {
-       BOOST_ASSERT(absolutePath(filename));
-       if (filename.empty() || !fs::exists(filename)) {
+       if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
                Alert::error(_("Cannot edit file"),
                        bformat(_("File does not exist: %1$s"),
-                               from_utf8(filename)));
+                               from_utf8(filename.absFilename())));
                return false;
        }
 
@@ -356,25 +356,26 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
        }
        // editor is 'auto'
        if (format->editor() == "auto") {
-               if (os::autoOpenFile(filename, os::EDIT))
+               if (os::autoOpenFile(filename.absFilename(), os::EDIT))
                        return true;
                else {
                        Alert::error(_("Cannot edit file"),
                                bformat(_("Auto-edit file %1$s failed"),
-                                       from_utf8(filename)));
+                                       from_utf8(filename.absFilename())));
                        return false;
                }
        }
 
        string command = format->editor();
 
-       if (!contains(command, token_from))
-               command += ' ' + token_from;
+       if (!contains(command, token_from_format))
+               command += ' ' + token_from_format;
 
-       command = subst(command, token_from, quoteName(filename));
-       command = subst(command, token_path, quoteName(onlyPath(filename)));
-       command = subst(command, token_socket, quoteName(theLyXServerSocket().address()));
+       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(theLyXServerSocket().address()));
        lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
+       // FIXME UNICODE utf8 can be wrong for files
        buffer.message(_("Executing command: ") + from_utf8(command));
 
        Systemcall one;