X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetHyperlink.cpp;h=bfa478d2f17b82edf3f0bacbc693a76b798d1f54;hb=48b1e8a0aca2f3f3faa8f1f800568e47792ba9a0;hp=0f039e34d81deb9372452bcbd939ad622b80cc7a;hpb=11a57ce6c68e712cab9818c92a0442e96f6d58d7;p=lyx.git diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index 0f039e34d8..bfa478d2f1 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -12,6 +12,9 @@ #include #include "InsetHyperlink.h" +#include +#include + #include "Buffer.h" #include "DispatchResult.h" #include "Encoding.h" @@ -30,6 +33,7 @@ #include "support/filetools.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/qstring_helpers.h" #include "frontends/alert.h" @@ -106,9 +110,13 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action()) { - case LFUN_INSET_EDIT: - flag.setEnabled(getParam("type").empty() || getParam("type") == "file:"); + case LFUN_INSET_EDIT: { + QUrl url(toqstr(getParam("target")),QUrl::StrictMode); + bool url_valid = getParam("type").empty() && url.isValid(); + + flag.setEnabled(url_valid || getParam("type") == "file:"); return true; + } default: return InsetCommand::getStatus(cur, cmd, flag); @@ -118,7 +126,12 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetHyperlink::viewTarget() const { - if (getParam("type") == "file:") { + if (getParam("type").empty()) { //==Web + QUrl url(toqstr(getParam("target")),QUrl::StrictMode); + if (!QDesktopServices::openUrl(url)) + LYXERR0("Unable to open URL!"); + + } else if (getParam("type") == "file:") { FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath()); string const format = theFormats().getFormatFromFile(url); theFormats().view(buffer(), url, format); @@ -224,7 +237,7 @@ void InsetHyperlink::docbook(XMLStream & xs, OutputParams const &) const docstring InsetHyperlink::xhtml(XMLStream & xs, OutputParams const &) const { docstring const & target = - xml::xmlize(getParam("target"), XMLStream::ESCAPE_AND); + xml::escapeString(getParam("target"), XMLStream::ESCAPE_AND); docstring const & name = getParam("name"); xs << xml::StartTag("a", to_utf8("href=\"" + target + "\"")); xs << (name.empty() ? target : name);