X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fformat.C;h=fa327785dadd188a85976ccb42f90777708a94f2;hb=024275f0690b41634e26dabe8758e3dc6cd31ee2;hp=fe43a0735b2d733a9a97eaa40588f0ecd23591ea;hpb=1f8fe293847e941f4737dc09064b5dc877494f21;p=lyx.git diff --git a/src/format.C b/src/format.C index fe43a0735b..fa327785da 100644 --- a/src/format.C +++ b/src/format.C @@ -28,25 +28,28 @@ #include -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::onlyPath; -using lyx::support::quoteName; -using lyx::support::subst; -using lyx::support::Systemcall; -using lyx::support::token; + +namespace lyx { + +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; +using support::quoteName; +using support::subst; +using support::Systemcall; +using support::token; using std::string; using std::distance; -namespace Alert = lyx::frontend::Alert; +namespace Alert = frontend::Alert; namespace fs = boost::filesystem; -namespace os = lyx::support::os; +namespace os = support::os; namespace { @@ -134,17 +137,17 @@ 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(); - string const format = lyx::support::getFormatFromContents(filename); + string const format = support::getFormatFromContents(filename); if (!format.empty()) return format; // try to find a format from the file extension. - string const ext(lyx::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 @@ -259,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"), - lyx::from_utf8(filename))); + from_utf8(filename.absFilename()))); return false; } @@ -284,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"), - lyx::from_utf8(filename))); + from_utf8(filename.absFilename()))); return false; } } @@ -310,11 +312,12 @@ bool Formats::view(Buffer const & buffer, string const & filename, if (!contains(command, token_from)) command += ' ' + token_from; - command = subst(command, token_from, quoteName(filename)); - command = subst(command, token_path, quoteName(onlyPath(filename))); + command = subst(command, token_from, quoteName(filename.toFilesystemEncoding())); + command = subst(command, token_path, quoteName(onlyPath(filename.toFilesystemEncoding()))); command = subst(command, token_socket, quoteName(theLyXServerSocket().address())); lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; - buffer.message(_("Executing command: ") + lyx::from_utf8(command)); + // FIXME UNICODE utf8 can be wrong for files + buffer.message(_("Executing command: ") + from_utf8(command)); Systemcall one; int const res = one.startscript(Systemcall::DontWait, command); @@ -329,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"), - lyx::from_utf8(filename))); + from_utf8(filename.absFilename()))); return false; } @@ -354,12 +356,12 @@ 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"), - lyx::from_utf8(filename))); + from_utf8(filename.absFilename()))); return false; } } @@ -369,11 +371,12 @@ bool Formats::edit(Buffer const & buffer, string const & filename, if (!contains(command, token_from)) command += ' ' + token_from; - command = subst(command, token_from, quoteName(filename)); - command = subst(command, token_path, quoteName(onlyPath(filename))); + command = subst(command, token_from, quoteName(filename.toFilesystemEncoding())); + command = subst(command, token_path, quoteName(onlyPath(filename.toFilesystemEncoding()))); command = subst(command, token_socket, quoteName(theLyXServerSocket().address())); lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; - buffer.message(_("Executing command: ") + lyx::from_utf8(command)); + // FIXME UNICODE utf8 can be wrong for files + buffer.message(_("Executing command: ") + from_utf8(command)); Systemcall one; int const res = one.startscript(Systemcall::DontWait, command); @@ -392,9 +395,9 @@ docstring const Formats::prettyName(string const & name) const { Format const * format = getFormat(name); if (format) - return lyx::from_utf8(format->prettyname()); + return from_utf8(format->prettyname()); else - return lyx::from_utf8(name); + return from_utf8(name); } @@ -413,3 +416,6 @@ string const Formats::extension(string const & name) const Formats formats; Formats system_formats; + + +} // namespace lyx