Learn URL viewing for hyperlink insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35232 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Pavel Sanda 2010-08-29 23:04:36 +00:00
parent 3ee100f47d
commit b1d6406ac4
3 changed files with 33 additions and 7 deletions

View File

@ -258,6 +258,28 @@ void Formats::setEditor(string const & name, string const & command)
it->setEditor(command);
}
bool Formats::viewURL(string const &url){
Format const * format = getFormat("html");
string command = libScriptSearch(format->viewer());
if (!contains(command, token_from_format))
command += ' ' + token_from_format;
command = subst(command, token_from_format, quoteName(url));
LYXERR(Debug::FILES, "Executing command: " << command);
//buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command);
if (res) {
Alert::error(_("Cannot view URL"),
bformat(_("An error occurred whilst running %1$s"),
makeDisplayPath(command, 50)));
return false;
}
return true;
}
bool Formats::view(Buffer const & buffer, FileName const & filename,
string const & format_name) const

View File

@ -144,6 +144,8 @@ public:
///
void setEditor(std::string const & name, std::string const & command);
///
bool viewURL(std::string const &url);
///
bool view(Buffer const & buffer, support::FileName const & filename,
std::string const & format_name) const;
///

View File

@ -89,7 +89,7 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
{
switch (cmd.action()) {
case LFUN_INSET_EDIT:
flag.setEnabled(getParam("type") == "file:");
flag.setEnabled(getParam("type").empty() || getParam("type") == "file:");
return true;
default:
@ -100,12 +100,14 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetHyperlink::viewTarget() const
{
// FIXME implement viewer for web url
if (getParam("type") != "file:")
return;
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
string format = formats.getFormatFromFile(url);
formats.view(buffer(), url, format);
if (getParam("type").empty())
formats.viewURL(to_ascii(getParam("target")));
else if (getParam("type") == "file:") {
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
string format = formats.getFormatFromFile(url);
formats.view(buffer(), url, format);
}
}