2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetUrl.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Jos<EFBFBD> Matos
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetUrl.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-05-16 07:44:00 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "outputparams.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::subst;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetUrl::InsetUrl(InsetCommandParams const & p)
|
2003-12-11 15:23:15 +00:00
|
|
|
|
: InsetCommand(p, "url")
|
2000-07-27 08:55:59 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const InsetUrl::getScreenLabel(Buffer const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const temp =
|
|
|
|
|
(getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
|
2000-07-27 08:55:59 +00:00
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
docstring url;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
if (!getParam("name").empty())
|
|
|
|
|
url += getParam("name");
|
2000-07-27 08:55:59 +00:00
|
|
|
|
else
|
2006-10-20 16:12:49 +00:00
|
|
|
|
url += getParam("target");
|
2002-08-25 01:15:01 +00:00
|
|
|
|
|
|
|
|
|
// elide if long
|
|
|
|
|
if (url.length() > 30) {
|
|
|
|
|
url = url.substr(0, 10) + "..."
|
|
|
|
|
+ url.substr(url.length() - 17, url.length());
|
|
|
|
|
}
|
2006-10-20 16:12:49 +00:00
|
|
|
|
return temp + url;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetUrl::latex(Buffer const &, odocstream & os,
|
2007-02-16 09:28:25 +00:00
|
|
|
|
OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const & name = getParam("name");
|
|
|
|
|
if (!name.empty())
|
|
|
|
|
os << name + ' ';
|
2003-05-23 09:23:03 +00:00
|
|
|
|
if (runparams.moving_arg)
|
2000-03-02 02:19:43 +00:00
|
|
|
|
os << "\\protect";
|
2006-10-19 16:51:30 +00:00
|
|
|
|
os << "\\url{" << getParam("target") << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetUrl::plaintext(Buffer const &, odocstream & os,
|
2007-02-16 09:28:25 +00:00
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2007-02-16 09:28:25 +00:00
|
|
|
|
odocstringstream oss;
|
|
|
|
|
|
|
|
|
|
oss << '[' << getParam("target");
|
2006-10-20 16:12:49 +00:00
|
|
|
|
if (getParam("name").empty())
|
2007-02-16 09:28:25 +00:00
|
|
|
|
oss << ']';
|
2000-04-24 20:58:23 +00:00
|
|
|
|
else
|
2007-02-16 09:28:25 +00:00
|
|
|
|
oss << "||" << getParam("name") << ']';
|
|
|
|
|
|
2007-02-24 14:35:38 +00:00
|
|
|
|
docstring const str = oss.str();
|
2007-02-16 09:28:25 +00:00
|
|
|
|
os << str;
|
|
|
|
|
return str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetUrl::docbook(Buffer const &, odocstream & os,
|
2007-02-16 09:28:25 +00:00
|
|
|
|
OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
|
os << "<ulink url=\""
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< subst(getParam("target"), from_ascii("&"), from_ascii("&"))
|
2006-10-20 16:12:49 +00:00
|
|
|
|
<< "\">"
|
|
|
|
|
<< getParam("name")
|
|
|
|
|
<< "</ulink>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetUrl::textString(Buffer const & buf, odocstream & os,
|
2005-11-25 14:40:34 +00:00
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-29 06:30:53 +00:00
|
|
|
|
void InsetUrl::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("url");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|