From b1d6406ac4da81d589c0b0aafeb99ac6de363d6e Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Sun, 29 Aug 2010 23:04:36 +0000 Subject: [PATCH] Learn URL viewing for hyperlink insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35232 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Format.cpp | 22 ++++++++++++++++++++++ src/Format.h | 2 ++ src/insets/InsetHyperlink.cpp | 16 +++++++++------- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Format.cpp b/src/Format.cpp index e6ad5962d5..74a19eaf23 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -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 diff --git a/src/Format.h b/src/Format.h index 326a68d3c8..0a63bccbf1 100644 --- a/src/Format.h +++ b/src/Format.h @@ -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; /// diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index e9c9efea91..b688b22aca 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -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); + } }