Bit of cleanup around the Format view and edit code.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35914 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-10-29 17:14:00 +00:00
parent 2b067ed466
commit 455ac11cfc
3 changed files with 17 additions and 28 deletions

View File

@ -258,29 +258,28 @@ void Formats::setEditor(string const & name, string const & command)
it->setEditor(command); it->setEditor(command);
} }
bool Formats::viewURL(string const &url){
bool Formats::viewURL(docstring const & url) {
Format const * format = getFormat("html"); Format const * format = getFormat("html");
if (!format)
return false;
string command = libScriptSearch(format->viewer()); string command = libScriptSearch(format->viewer());
if (!contains(command, token_from_format)) if (!contains(command, token_from_format))
command += ' ' + token_from_format; command += ' ' + token_from_format;
command = subst(command, token_from_format, quoteName(url)); command = subst(command, token_from_format, quoteName(to_utf8(url)));
LYXERR(Debug::FILES, "Executing command: " << command); LYXERR(Debug::FILES, "Executing command: " << command);
//buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one; Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command); one.startscript(Systemcall::DontWait, command);
if (res) { // we can't report any sort of error, since we aren't waiting
Alert::error(_("Cannot view URL"),
bformat(_("An error occurred whilst running %1$s"),
makeDisplayPath(command, 50)));
return false;
}
return true; return true;
} }
bool Formats::view(Buffer const & buffer, FileName const & filename, bool Formats::view(Buffer const & buffer, FileName const & filename,
string const & format_name) const string const & format_name) const
{ {
@ -340,14 +339,9 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
buffer.message(_("Executing command: ") + from_utf8(command)); buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one; Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command); one.startscript(Systemcall::DontWait, command);
if (res) { // we can't report any sort of error, since we aren't waiting
Alert::error(_("Cannot view file"),
bformat(_("An error occurred whilst running %1$s"),
makeDisplayPath(command, 50)));
return false;
}
return true; return true;
} }
@ -412,14 +406,9 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename,
buffer.message(_("Executing command: ") + from_utf8(command)); buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one; Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command); one.startscript(Systemcall::DontWait, command);
if (res) { // we can't report any sort of error, since we aren't waiting
Alert::error(_("Cannot edit file"),
bformat(_("An error occurred whilst running %1$s"),
makeDisplayPath(command, 50)));
return false;
}
return true; return true;
} }

View File

@ -143,8 +143,8 @@ public:
void setViewer(std::string const & name, std::string const & command); void setViewer(std::string const & name, std::string const & command);
/// ///
void setEditor(std::string const & name, std::string const & command); void setEditor(std::string const & name, std::string const & command);
/// Currently used by hyperlink insets /// Currently used by hyperlink insets and GuiCitation
bool viewURL(std::string const &url); bool viewURL(docstring const & url);
/// View the given file. Buffer used for DVI's paper orientation. /// View the given file. Buffer used for DVI's paper orientation.
bool view(Buffer const & buffer, support::FileName const & filename, bool view(Buffer const & buffer, support::FileName const & filename,
std::string const & format_name) const; std::string const & format_name) const;

View File

@ -101,11 +101,11 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetHyperlink::viewTarget() const void InsetHyperlink::viewTarget() const
{ {
if (getParam("type").empty()) if (getParam("type").empty())
formats.viewURL(to_ascii(getParam("target"))); formats.viewURL(getParam("target"));
else if (getParam("type") == "file:") { else if (getParam("type") == "file:") {
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath()); FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
string format = formats.getFormatFromFile(url); string const format = formats.getFormatFromFile(url);
formats.view(buffer(), url, format); formats.view(buffer(), url, format);
} }
} }