2007-10-11 14:52:00 +00:00
|
|
|
/**
|
|
|
|
* \file InsetInfo.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Bo Peng
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetInfo.h"
|
2015-03-28 20:05:41 +00:00
|
|
|
#include "LyX.h"
|
2007-12-19 18:09:00 +00:00
|
|
|
#include "Buffer.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
2010-04-19 21:36:32 +00:00
|
|
|
#include "CutAndPaste.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "FuncRequest.h"
|
2008-06-05 15:08:46 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-06-05 03:41:35 +00:00
|
|
|
#include "InsetGraphics.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "InsetSpecialChar.h"
|
|
|
|
#include "KeyMap.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "LayoutFile.h"
|
2015-03-25 20:26:32 +00:00
|
|
|
#include "Length.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "LyXAction.h"
|
2007-10-11 15:23:52 +00:00
|
|
|
#include "LyXRC.h"
|
2010-02-12 01:44:04 +00:00
|
|
|
#include "LyXVC.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "Lexer.h"
|
|
|
|
#include "ParagraphParameters.h"
|
2011-02-09 17:23:20 +00:00
|
|
|
#include "version.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
2007-12-25 22:27:32 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2015-03-12 23:38:05 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2008-05-24 10:15:52 +00:00
|
|
|
#include "support/docstring_list.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2007-12-19 18:09:00 +00:00
|
|
|
#include "support/FileName.h"
|
2008-06-05 03:41:35 +00:00
|
|
|
#include "support/filetools.h"
|
2007-12-25 22:27:32 +00:00
|
|
|
#include "support/gettext.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
#include "support/lstrings.h"
|
2015-03-25 20:26:32 +00:00
|
|
|
#include "support/qstring_helpers.h"
|
2011-07-14 17:00:35 +00:00
|
|
|
#include "support/Translator.h"
|
2007-10-11 14:52:00 +00:00
|
|
|
|
2008-03-06 21:50:27 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2015-03-25 20:26:32 +00:00
|
|
|
#include <QtGui/QImage>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-10-11 14:52:00 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2008-09-30 14:11:40 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef Translator<InsetInfo::info_type, string> NameTranslator;
|
|
|
|
|
|
|
|
NameTranslator const initTranslator()
|
|
|
|
{
|
|
|
|
NameTranslator translator(InsetInfo::UNKNOWN_INFO, "unknown");
|
|
|
|
|
|
|
|
translator.addPair(InsetInfo::SHORTCUTS_INFO, "shortcuts");
|
|
|
|
translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
|
|
|
|
translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
|
|
|
|
translator.addPair(InsetInfo::PACKAGE_INFO, "package");
|
|
|
|
translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
|
|
|
|
translator.addPair(InsetInfo::MENU_INFO, "menu");
|
|
|
|
translator.addPair(InsetInfo::ICON_INFO, "icon");
|
|
|
|
translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
|
2010-04-17 13:04:41 +00:00
|
|
|
translator.addPair(InsetInfo::LYX_INFO, "lyxinfo");
|
2008-09-30 14:11:40 +00:00
|
|
|
|
|
|
|
return translator;
|
|
|
|
}
|
2007-10-11 14:52:00 +00:00
|
|
|
|
2008-09-30 14:11:40 +00:00
|
|
|
/// The translator between the information type enum and corresponding string.
|
|
|
|
NameTranslator const & nameTranslator()
|
|
|
|
{
|
|
|
|
static NameTranslator const translator = initTranslator();
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetInfo
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetInfo::InsetInfo(Buffer * buf, string const & name)
|
2008-10-26 02:25:57 +00:00
|
|
|
: InsetCollapsable(buf), type_(UNKNOWN_INFO), name_()
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
|
|
|
setAutoBreakRows(true);
|
|
|
|
setInfo(name);
|
2008-10-26 02:25:57 +00:00
|
|
|
status_ = Collapsed;
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 03:25:36 +00:00
|
|
|
Inset * InsetInfo::editXY(Cursor & cur, int x, int y)
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
2010-01-31 01:44:49 +00:00
|
|
|
// do not allow the cursor to be set in this Inset
|
|
|
|
return Inset::editXY(cur, x, y);
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 14:11:40 +00:00
|
|
|
string InsetInfo::infoType() const
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
2008-09-30 14:11:40 +00:00
|
|
|
return nameTranslator().find(type_);
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring InsetInfo::layoutName() const
|
2008-06-06 04:10:42 +00:00
|
|
|
{
|
2008-09-30 14:11:40 +00:00
|
|
|
return from_ascii("Info:" + infoType());
|
2008-06-06 04:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-04 09:57:37 +00:00
|
|
|
docstring InsetInfo::toolTip(BufferView const &, int, int) const
|
2008-06-04 07:15:43 +00:00
|
|
|
{
|
2008-11-03 17:36:28 +00:00
|
|
|
return bformat(_("Information regarding %1$s '%2$s'"),
|
|
|
|
_(infoType()), from_utf8(name_));
|
2008-06-04 07:15:43 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetInfo::read(Lexer & lex)
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
|
|
|
string token;
|
|
|
|
while (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
token = lex.getString();
|
|
|
|
if (token == "type") {
|
|
|
|
lex.next();
|
|
|
|
token = lex.getString();
|
|
|
|
type_ = nameTranslator().find(token);
|
|
|
|
} else if (token == "arg") {
|
2008-10-23 13:12:19 +00:00
|
|
|
lex.next(true);
|
2007-10-11 14:52:00 +00:00
|
|
|
name_ = lex.getString();
|
|
|
|
} else if (token == "\\end_inset")
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
lex.printError("Missing \\end_inset at this point");
|
|
|
|
throw ExceptionMessage(WarningException,
|
|
|
|
_("Missing \\end_inset at this point."),
|
|
|
|
from_utf8(token));
|
|
|
|
}
|
2008-02-27 20:43:16 +00:00
|
|
|
updateInfo();
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetInfo::write(ostream & os) const
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
2008-10-23 13:12:19 +00:00
|
|
|
os << "Info\ntype \"" << infoType()
|
|
|
|
<< "\"\narg " << Lexer::quoteString(name_);
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 11:15:05 +00:00
|
|
|
bool InsetInfo::validateModifyArgument(docstring const & arg) const
|
2008-06-06 08:01:59 +00:00
|
|
|
{
|
2008-08-03 22:14:04 +00:00
|
|
|
string type;
|
2008-09-15 14:11:57 +00:00
|
|
|
string const name = trim(split(to_utf8(arg), type, ' '));
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
switch (nameTranslator().find(type)) {
|
|
|
|
case UNKNOWN_INFO:
|
|
|
|
return false;
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
case SHORTCUT_INFO:
|
|
|
|
case SHORTCUTS_INFO:
|
|
|
|
case MENU_INFO:
|
|
|
|
case ICON_INFO: {
|
|
|
|
FuncRequest func = lyxaction.lookupFunc(name);
|
2010-04-09 19:00:42 +00:00
|
|
|
return func.action() != LFUN_UNKNOWN_ACTION;
|
2008-08-03 22:14:04 +00:00
|
|
|
}
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
case LYXRC_INFO: {
|
|
|
|
ostringstream oss;
|
|
|
|
lyxrc.write(oss, true, name);
|
|
|
|
return !oss.str().empty();
|
|
|
|
}
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
case PACKAGE_INFO:
|
|
|
|
case TEXTCLASS_INFO:
|
|
|
|
return true;
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
case BUFFER_INFO:
|
2010-04-17 13:34:13 +00:00
|
|
|
if (name == "name" || name == "path" || name == "class")
|
|
|
|
return true;
|
|
|
|
if (name == "vcs-revision" || name == "vcs-tree-revision" ||
|
|
|
|
name == "vcs-author" || name == "vcs-date" || name == "vcs-time")
|
|
|
|
return buffer().lyxvc().inUse();
|
|
|
|
return false;
|
|
|
|
|
2010-04-17 13:04:41 +00:00
|
|
|
case LYX_INFO:
|
|
|
|
return name == "version";
|
2008-08-03 22:14:04 +00:00
|
|
|
}
|
2010-04-17 13:34:13 +00:00
|
|
|
|
2008-08-03 22:14:04 +00:00
|
|
|
return false;
|
2008-06-06 08:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
bool InsetInfo::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2008-06-05 15:28:27 +00:00
|
|
|
bv->showDialog("info");
|
2008-06-05 15:08:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2010-03-06 17:47:50 +00:00
|
|
|
case LFUN_INSET_SETTINGS:
|
2008-09-30 14:11:40 +00:00
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
2010-11-29 09:47:46 +00:00
|
|
|
|
2009-04-18 05:57:02 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2010-04-19 21:36:32 +00:00
|
|
|
case LFUN_INSET_COPY_AS:
|
2009-04-18 05:57:02 +00:00
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
2010-11-29 09:47:46 +00:00
|
|
|
|
2010-03-09 23:04:35 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (validateModifyArgument(cmd.argument())) {
|
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-18 23:35:59 +00:00
|
|
|
//fall through
|
2010-11-29 09:47:46 +00:00
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-06-06 08:45:58 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2008-06-06 08:45:58 +00:00
|
|
|
setInfo(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
2010-04-19 21:36:32 +00:00
|
|
|
case LFUN_INSET_COPY_AS: {
|
|
|
|
cap::clearSelection();
|
|
|
|
Cursor copy(cur);
|
|
|
|
copy.pushBackward(*this);
|
|
|
|
copy.pit() = 0;
|
|
|
|
copy.pos() = 0;
|
|
|
|
copy.resetAnchor();
|
|
|
|
copy.pit() = copy.lastpit();
|
|
|
|
copy.pos() = copy.lastpos();
|
|
|
|
copy.setSelection();
|
|
|
|
cap::copySelection(copy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
default:
|
2010-04-18 23:47:11 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2007-10-11 14:52:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInfo::setInfo(string const & name)
|
|
|
|
{
|
|
|
|
if (name.empty())
|
|
|
|
return;
|
|
|
|
// info_type name
|
|
|
|
string type;
|
|
|
|
name_ = trim(split(name, type, ' '));
|
|
|
|
type_ = nameTranslator().find(type);
|
2008-06-06 08:45:58 +00:00
|
|
|
updateInfo();
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 09:33:24 +00:00
|
|
|
void InsetInfo::error(string const & err)
|
|
|
|
{
|
2008-11-05 16:40:18 +00:00
|
|
|
setText(bformat(_(err), from_utf8(name_)),
|
|
|
|
Font(inherit_font, buffer().params().language), false);
|
2008-06-06 09:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInfo::setText(docstring const & str)
|
|
|
|
{
|
2008-11-05 16:40:18 +00:00
|
|
|
setText(str, Font(inherit_font, buffer().params().language), false);
|
2008-06-06 09:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetInfo::updateInfo()
|
2007-10-11 14:52:00 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
BufferParams const & bp = buffer().params();
|
2007-12-19 18:09:00 +00:00
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
switch (type_) {
|
|
|
|
case UNKNOWN_INFO:
|
2008-06-06 09:33:24 +00:00
|
|
|
error("Unknown Info: %1$s");
|
2007-10-11 14:52:00 +00:00
|
|
|
break;
|
2008-06-06 09:33:24 +00:00
|
|
|
case SHORTCUT_INFO:
|
2008-06-05 03:41:35 +00:00
|
|
|
case SHORTCUTS_INFO: {
|
2010-04-09 19:00:42 +00:00
|
|
|
FuncRequest const func = lyxaction.lookupFunc(name_);
|
|
|
|
if (func.action() == LFUN_UNKNOWN_ACTION) {
|
2008-06-06 09:33:24 +00:00
|
|
|
error("Unknown action %1$s");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func);
|
|
|
|
if (bindings.empty()) {
|
2008-08-03 21:31:06 +00:00
|
|
|
// It is impropriate to use error() for undefined shortcut
|
|
|
|
setText(_("undefined"));
|
2008-06-06 09:33:24 +00:00
|
|
|
break;
|
2008-06-05 03:41:35 +00:00
|
|
|
}
|
2008-06-06 09:33:24 +00:00
|
|
|
if (type_ == SHORTCUT_INFO)
|
2008-11-05 16:40:18 +00:00
|
|
|
setText(bindings.begin()->print(KeySequence::Portable));
|
2008-06-06 09:33:24 +00:00
|
|
|
else
|
2008-11-05 16:40:18 +00:00
|
|
|
setText(theTopLevelKeymap().printBindings(func, KeySequence::Portable));
|
2008-06-05 03:41:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 15:23:52 +00:00
|
|
|
case LYXRC_INFO: {
|
|
|
|
ostringstream oss;
|
2010-04-23 11:46:24 +00:00
|
|
|
if (name_.empty()) {
|
|
|
|
setText(_("undefined"));
|
|
|
|
break;
|
|
|
|
}
|
2007-10-11 15:23:52 +00:00
|
|
|
lyxrc.write(oss, true, name_);
|
|
|
|
string result = oss.str();
|
2010-04-23 11:46:24 +00:00
|
|
|
if (result.size() < 2) {
|
|
|
|
setText(_("undefined"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string::size_type loc = result.rfind("\n", result.size() - 2);
|
|
|
|
loc = loc == string::npos ? 0 : loc + 1;
|
|
|
|
if (result.size() < loc + name_.size() + 1
|
|
|
|
|| result.substr(loc + 1, name_.size()) != name_) {
|
|
|
|
setText(_("undefined"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// remove leading comments and \\name and space
|
|
|
|
result = result.substr(loc + name_.size() + 2);
|
|
|
|
|
2007-10-11 15:23:52 +00:00
|
|
|
// remove \n and ""
|
|
|
|
result = rtrim(result, "\n");
|
|
|
|
result = trim(result, "\"");
|
2008-06-06 09:33:24 +00:00
|
|
|
setText(from_utf8(result));
|
2007-10-11 15:23:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 14:52:00 +00:00
|
|
|
case PACKAGE_INFO:
|
|
|
|
// check in packages.lst
|
2008-06-06 09:33:24 +00:00
|
|
|
setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"));
|
2007-10-11 14:52:00 +00:00
|
|
|
break;
|
2010-04-22 19:36:03 +00:00
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
case TEXTCLASS_INFO: {
|
|
|
|
// name_ is the class name
|
2010-04-22 19:36:03 +00:00
|
|
|
LayoutFileList const & list = LayoutFileList::get();
|
|
|
|
bool available = false;
|
|
|
|
if (list.haveClass(name_))
|
|
|
|
available = list[name_].isTeXClassAvailable();
|
|
|
|
setText(available ? _("yes") : _("no"));
|
2007-10-11 14:52:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 15:14:11 +00:00
|
|
|
case MENU_INFO: {
|
2008-05-24 10:15:52 +00:00
|
|
|
docstring_list names;
|
2010-04-09 19:00:42 +00:00
|
|
|
FuncRequest const func = lyxaction.lookupFunc(name_);
|
|
|
|
if (func.action() == LFUN_UNKNOWN_ACTION) {
|
2008-06-06 09:33:24 +00:00
|
|
|
error("Unknown action %1$s");
|
2007-10-11 15:14:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// iterate through the menubackend to find it
|
2011-01-06 18:40:39 +00:00
|
|
|
if (!theApp()) {
|
|
|
|
error("Can't determine menu entry for action %1$s in batch mode");
|
|
|
|
break;
|
|
|
|
}
|
2008-03-06 21:50:27 +00:00
|
|
|
if (!theApp()->searchMenu(func, names)) {
|
2008-06-06 09:33:24 +00:00
|
|
|
error("No menu entry for action %1$s");
|
2007-10-11 15:14:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-30 14:11:40 +00:00
|
|
|
// if found, return its path.
|
|
|
|
clear();
|
|
|
|
Paragraph & par = paragraphs().front();
|
2008-11-05 16:40:18 +00:00
|
|
|
Font const f(inherit_font, buffer().params().language);
|
2008-09-30 14:11:40 +00:00
|
|
|
//Font fu = f;
|
|
|
|
//fu.fontInfo().setUnderbar(FONT_ON);
|
|
|
|
docstring_list::const_iterator beg = names.begin();
|
|
|
|
docstring_list::const_iterator end = names.end();
|
|
|
|
for (docstring_list::const_iterator it = beg ;
|
|
|
|
it != end ; ++it) {
|
2007-10-11 15:14:11 +00:00
|
|
|
// do not insert > for the top level menu item
|
2008-09-30 14:11:40 +00:00
|
|
|
if (it != beg)
|
|
|
|
par.insertInset(par.size(), new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
|
2013-05-19 10:28:11 +00:00
|
|
|
f, Change(Change::UNCHANGED));
|
2008-09-30 14:11:40 +00:00
|
|
|
//FIXME: add proper underlines here. This
|
|
|
|
// involves rewriting searchMenu used above to
|
|
|
|
// return a vector of menus. If we do not do
|
|
|
|
// that, we might as well use below
|
|
|
|
// Paragraph::insert on each string (JMarc)
|
|
|
|
for (size_type i = 0; i != it->length(); ++i)
|
|
|
|
par.insertChar(par.size(), (*it)[i],
|
|
|
|
f, Change(Change::UNCHANGED));
|
2007-10-11 15:14:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-06-05 03:41:35 +00:00
|
|
|
case ICON_INFO: {
|
|
|
|
FuncRequest func = lyxaction.lookupFunc(name_);
|
2011-01-06 18:40:39 +00:00
|
|
|
docstring icon_name = frontend::Application::iconName(func, true);
|
2015-03-24 01:58:45 +00:00
|
|
|
// FIXME: We should use the icon directly instead of
|
2008-09-30 14:11:40 +00:00
|
|
|
// going through FileName. The code below won't work
|
|
|
|
// if the icon is embedded in the executable through
|
|
|
|
// the Qt resource system.
|
2011-01-06 18:40:39 +00:00
|
|
|
// This is only a negligible performance problem:
|
|
|
|
// If the installed icon differs from the resource icon the
|
|
|
|
// installed one is preferred anyway, and all icons that are
|
|
|
|
// embedded in the resources are installed as well.
|
2008-06-05 08:49:19 +00:00
|
|
|
FileName file(to_utf8(icon_name));
|
2015-03-28 11:45:20 +00:00
|
|
|
if (file.onlyFileNameWithoutExt() == "unknown") {
|
|
|
|
string dir = "images";
|
|
|
|
FileName file2(imageLibFileSearch(dir, name_, "svgz,png"));
|
|
|
|
if (!file2.empty())
|
|
|
|
file = file2;
|
|
|
|
}
|
2008-06-05 08:49:19 +00:00
|
|
|
if (!file.exists())
|
2008-06-05 03:41:35 +00:00
|
|
|
break;
|
2015-03-25 20:26:32 +00:00
|
|
|
int percent_scale = 100;
|
2015-03-28 20:05:41 +00:00
|
|
|
if (use_gui) {
|
|
|
|
int imgsize = QImage(toqstr(file.absFileName())).width();
|
|
|
|
if (imgsize > 0) {
|
|
|
|
int iconsize = Length(1, Length::EM).inPixels(1);
|
|
|
|
percent_scale = (100 * iconsize + imgsize / 2)/imgsize;
|
|
|
|
}
|
2015-03-25 20:26:32 +00:00
|
|
|
}
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetGraphics * inset = new InsetGraphics(buffer_);
|
2008-06-05 03:41:35 +00:00
|
|
|
InsetGraphicsParams igp;
|
|
|
|
igp.filename = file;
|
2015-03-25 20:26:32 +00:00
|
|
|
igp.lyxscale = percent_scale;
|
|
|
|
igp.scale = string();
|
|
|
|
igp.width = Length(1, Length::EM);
|
2008-06-05 03:41:35 +00:00
|
|
|
inset->setParams(igp);
|
2008-09-30 14:11:40 +00:00
|
|
|
clear();
|
2013-05-19 10:28:11 +00:00
|
|
|
Font const f(inherit_font, buffer().params().language);
|
|
|
|
paragraphs().front().insertInset(0, inset, f,
|
2008-09-30 14:11:40 +00:00
|
|
|
Change(Change::UNCHANGED));
|
2008-06-05 03:41:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-19 18:09:00 +00:00
|
|
|
case BUFFER_INFO: {
|
2010-04-17 13:24:32 +00:00
|
|
|
if (name_ == "name") {
|
2008-06-06 09:33:24 +00:00
|
|
|
setText(from_utf8(buffer().fileName().onlyFileName()));
|
2010-04-17 13:24:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (name_ == "path") {
|
2011-09-07 08:14:10 +00:00
|
|
|
setText(from_utf8(os::latex_path(buffer().filePath())));
|
2010-04-17 13:24:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (name_ == "class") {
|
2008-06-06 09:33:24 +00:00
|
|
|
setText(from_utf8(bp.documentClass().name()));
|
2010-04-17 13:24:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything that follows is for version control.
|
|
|
|
// nothing that isn't version control should go below this line.
|
|
|
|
if (!buffer().lyxvc().inUse()) {
|
|
|
|
setText(_("No version control"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LyXVC::RevisionInfo itype = LyXVC::Unknown;
|
|
|
|
if (name_ == "vcs-revision")
|
|
|
|
itype = LyXVC::File;
|
|
|
|
else if (name_ == "vcs-tree-revision")
|
|
|
|
itype = LyXVC::Tree;
|
|
|
|
else if (name_ == "vcs-author")
|
|
|
|
itype = LyXVC::Author;
|
|
|
|
else if (name_ == "vcs-time")
|
|
|
|
itype = LyXVC::Time;
|
|
|
|
else if (name_ == "vcs-date")
|
|
|
|
itype = LyXVC::Date;
|
|
|
|
string binfo = buffer().lyxvc().revisionInfo(itype);
|
2010-11-01 15:16:59 +00:00
|
|
|
if (binfo.empty())
|
2011-03-29 01:43:06 +00:00
|
|
|
setText(from_ascii(name_) + " unknown");
|
2010-11-01 15:16:59 +00:00
|
|
|
else
|
2010-04-17 13:24:32 +00:00
|
|
|
setText(from_utf8(binfo));
|
2007-12-19 18:09:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-04-17 13:04:41 +00:00
|
|
|
case LYX_INFO:
|
|
|
|
if (name_ == "version")
|
2011-02-09 17:23:20 +00:00
|
|
|
setText(from_ascii(lyx_version));
|
2010-04-17 13:24:49 +00:00
|
|
|
break;
|
2007-10-11 14:52:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetInfo::contextMenu(BufferView const &, int, int) const
|
2010-11-29 23:21:52 +00:00
|
|
|
{
|
|
|
|
//FIXME: We override the implementation of InsetCollapsable,
|
|
|
|
//because this inset is not a collapsable inset.
|
|
|
|
return contextMenuName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetInfo::contextMenuName() const
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-info";
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 14:11:40 +00:00
|
|
|
|
2007-10-11 14:52:00 +00:00
|
|
|
} // namespace lyx
|