X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetHyperlink.cpp;h=3f1131c4ad3a86cb12a882a909026e5f89e61e52;hb=997f0621c5346bb623cf86713c4fe1be0c941104;hp=6246ff840a53ac3752fb1fbf9b59b009b09844f5;hpb=a6b07608d8e9de24383d3ebaec20b6b265ed9314;p=lyx.git diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index 6246ff840a..3f1131c4ad 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -10,29 +10,31 @@ */ #include - #include "InsetHyperlink.h" #include "Buffer.h" -#include "DispatchResult.h" -#include "Encoding.h" #include "Format.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LaTeXFeatures.h" -#include "OutputParams.h" +#include "output_docbook.h" #include "output_xhtml.h" #include "xml.h" #include "texstream.h" +#include "support/debug.h" #include "support/docstream.h" #include "support/FileName.h" #include "support/filetools.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/qstring_helpers.h" #include "frontends/alert.h" +#include +#include + using namespace std; using namespace lyx::support; @@ -106,9 +108,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 +124,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); @@ -213,21 +224,18 @@ int InsetHyperlink::plaintext(odocstringstream & os, } -int InsetHyperlink::docbook(odocstream & os, OutputParams const &) const +void InsetHyperlink::docbook(XMLStream & xs, OutputParams const &) const { - os << "" - << xml::escapeString(getParam("name")) - << ""; - return 0; + xs << xml::StartTag("link", "xlink:href=\"" + subst(getParam("target"), from_ascii("&"), from_ascii("&")) + "\""); + xs << xml::escapeString(getParam("name")); + xs << xml::EndTag("link"); } 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); @@ -275,6 +283,13 @@ void InsetHyperlink::validate(LaTeXFeatures & features) const } +pair InsetHyperlink::isWords() const +{ + docstring const label = getParam("name"); + return pair(label.size(), wordCount(label)); +} + + string InsetHyperlink::contextMenuName() const { return "context-hyperlink";