InsetInfo: add InsetInfo (core)

* src/insets/Inset.cpp: add InsetInfo
	* src/insets/Inset.h
	* src/insets/InsetInfo.cpp
	* src/insets/InsetInfo.h
	* src/LyXAction.cpp: add LFUN_INFO_INSERT
	* src/lfuns.h
	* src/BufferView.cpp: 
	* src/factory.cpp
	* src/Text3.cpp: insert InsetInfo with selected text
	* development/scons/scons_manifest.py: build tools update
	* src/Makefile.am


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20904 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-10-11 14:52:00 +00:00
parent a800da1bfe
commit 62c98f2ffc
11 changed files with 320 additions and 4 deletions

View File

@ -1028,6 +1028,7 @@ src_insets_header_files = Split('''
InsetHFill.h
InsetInclude.h
InsetIndex.h
InsetInfo.h
InsetLabel.h
InsetLine.h
InsetListings.h
@ -1083,6 +1084,7 @@ src_insets_files = Split('''
InsetHFill.cpp
InsetInclude.cpp
InsetIndex.cpp
InsetInfo.cpp
InsetLabel.cpp
InsetLine.cpp
InsetListings.cpp

View File

@ -867,6 +867,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
break;
case LFUN_FONT_STATE:
case LFUN_LABEL_INSERT:
case LFUN_INFO_INSERT:
case LFUN_PARAGRAPH_GOTO:
// FIXME handle non-trivially
case LFUN_OUTLINE_UP:

View File

@ -376,6 +376,7 @@ void LyXAction::init()
{ LFUN_LAYOUT_MODULES_CLEAR, "layout-modules-clear", Noop },
{ LFUN_LAYOUT_MODULE_ADD, "layout-module-add", Noop },
{ LFUN_LAYOUT_RELOAD, "layout-reload", Noop },
{ LFUN_INFO_INSERT, "info-insert", Noop },
{ LFUN_NOACTION, "", Noop }
};

View File

@ -523,6 +523,8 @@ liblyxinsets_la_SOURCES = \
insets/InsetInclude.h \
insets/InsetIndex.cpp \
insets/InsetIndex.h \
insets/InsetInfo.cpp \
insets/InsetInfo.h \
insets/InsetLabel.cpp \
insets/InsetLabel.h \
insets/InsetLine.cpp \

View File

@ -58,6 +58,7 @@
#include "insets/InsetQuotes.h"
#include "insets/InsetSpecialChar.h"
#include "insets/InsetText.h"
#include "insets/InsetInfo.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -1113,7 +1114,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
}
case LFUN_INFO_INSERT: {
if (!cur.selection())
break;
Inset * inset = createInset(&cur.bv(), cmd);
if (!inset)
break;
// use selected text as info to avoid a separate UI
docstring ds = cur.selectionAsString(false);
cutSelection(cur, true, false);
insertInset(cur, inset);
static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
cur.posRight();
break;
}
#if 0
case LFUN_LIST_INSERT:
case LFUN_THEOREM_INSERT:
@ -1706,6 +1720,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_LABEL_INSERT:
code = Inset::LABEL_CODE;
break;
case LFUN_INFO_INSERT:
code = Inset::INFO_CODE;
break;
case LFUN_OPTIONAL_INSERT:
code = Inset::OPTARG_CODE;
enable = numberOfOptArgs(cur.paragraph())

View File

@ -38,6 +38,7 @@
#include "insets/InsetHFill.h"
#include "insets/InsetInclude.h"
#include "insets/InsetIndex.h"
#include "insets/InsetInfo.h"
#include "insets/InsetNomencl.h"
#include "insets/InsetLabel.h"
#include "insets/InsetLine.h"
@ -221,6 +222,8 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
case LFUN_ENVIRONMENT_INSERT:
return new InsetEnvironment(params, cmd.argument());
case LFUN_INFO_INSERT:
return new InsetInfo(params, to_utf8(cmd.argument()));
#if 0
case LFUN_LIST_INSERT:
return new InsetList;
@ -497,6 +500,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
inset.reset(new InsetIndex(buf.params()));
} else if (tmptok == "FloatList") {
inset.reset(new InsetFloatList);
} else if (tmptok == "Info") {
inset.reset(new InsetInfo(buf.params()));
} else {
lyxerr << "unknown Inset type '" << tmptok
<< "'" << std::endl;

View File

@ -103,6 +103,7 @@ static TranslatorMap const build_translator()
InsetName("vspace", Inset::VSPACE_CODE),
InsetName("mathmacroarg", Inset::MATHMACROARG_CODE),
InsetName("listings", Inset::LISTINGS_CODE),
InsetName("info", Inset::INFO_CODE),
};
std::size_t const insetnames_size =

View File

@ -367,7 +367,9 @@ public:
///
PAGEBREAK_CODE,
///
LISTINGS_CODE
LISTINGS_CODE,
///
INFO_CODE,
};
/** returns the Code corresponding to the \c name.

208
src/insets/InsetInfo.cpp Normal file
View File

@ -0,0 +1,208 @@
/**
* \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"
#include <sstream>
#include <stack>
#include "BufferParams.h"
#include "BufferView.h"
#include "debug.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "InsetSpecialChar.h"
#include "KeyMap.h"
#include "LaTeXFeatures.h"
#include "LyXAction.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "ParagraphParameters.h"
#include "TextClassList.h"
#include "support/lstrings.h"
#include "support/ExceptionMessage.h"
using std::pair;
using std::string;
using std::ostream;
using std::ostringstream;
using std::stack;
namespace lyx {
using support::prefixIs;
using support::trim;
using support::split;
using support::rtrim;
using support::ExceptionMessage;
using support::WarningException;
InsetInfo::InsetInfo(BufferParams const & bp, string const & name)
: InsetText(bp), bp_(bp), type_(UNKNOWN_INFO), name_(),
mouse_hover_(false)
{
setAutoBreakRows(true);
setDrawFrame(true);
setInfo(name);
}
Inset * InsetInfo::editXY(Cursor & cur, int x, int y)
{
return this;
}
void InsetInfo::draw(PainterInfo & pi, int x, int y) const
{
InsetText::draw(pi, x, y);
if (mouse_hover_) {
odocstringstream os;
os << _("Information regarding ")
<<_(nameTranslator().find(type_))
<< _(" ") << from_utf8(name_);
pi.base.bv->message(os.str());
}
}
namespace {
Translator<InsetInfo::info_type, string> const initTranslator()
{
Translator<InsetInfo::info_type, string> translator(InsetInfo::UNKNOWN_INFO, "unknown");
translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
translator.addPair(InsetInfo::PACKAGE_INFO, "package");
translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
return translator;
}
} // namespace anon
Translator<InsetInfo::info_type, std::string> const & InsetInfo::nameTranslator() const
{
static Translator<info_type, string> const translator =
initTranslator();
return translator;
}
void InsetInfo::read(Buffer const & buf, Lexer & lex)
{
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") {
lex.next();
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));
}
updateInfo();
}
void InsetInfo::write(Buffer const & buf, std::ostream & os) const
{
os << "Info\ntype \""
<< nameTranslator().find(type_)
<< "\"\narg \"" << name_ << '\"';
}
void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
{
// FIXME: we should allow selection, copy etc...
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
// do not dispatch to InsetText
cur.dispatched();
break;
default:
InsetText::doDispatch(cur, cmd);
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);
updateInfo();
}
void InsetInfo::updateInfo()
{
InsetText::clear();
switch (type_) {
case UNKNOWN_INFO:
setText(_("Unknown Info: ") + from_utf8(name_),
bp_.getFont(), false);
break;
case SHORTCUT_INFO: {
FuncRequest func = lyxaction.lookupFunc(name_);
if (func.action != LFUN_UNKNOWN_ACTION)
setText(theTopLevelKeymap().printbindings(func),
bp_.getFont(), false);
break;
}
case PACKAGE_INFO:
// check in packages.lst
setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"),
bp_.getFont(), false);
break;
case TEXTCLASS_INFO: {
// name_ is the class name
pair<bool, lyx::textclass_type> pp =
textclasslist.numberOfClass(name_);
setText(pp.first ? _("yes") : _("no"),
bp_.getFont(), false);
break;
}
}
// remove indent
paragraphs().begin()->params().noindent(true);
}
bool InsetInfo::setMouseHover(bool mouse_hover)
{
mouse_hover_ = mouse_hover;
return true;
}
} // namespace lyx

76
src/insets/InsetInfo.h Normal file
View File

@ -0,0 +1,76 @@
// -*- C++ -*-
/**
* \file InsetInfo.h
* 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.
*/
#ifndef INSET_INFO_H
#define INSET_INFO_H
#include "InsetText.h"
#include "RenderButton.h"
#include "gettext.h"
#include "Cursor.h"
#include "support/Translator.h"
namespace lyx {
/** Used to insert index labels
*/
class InsetInfo : public InsetText {
public:
enum info_type {
UNKNOWN_INFO, // Invalid type
SHORTCUT_INFO, // Keyboard shortcut
PACKAGE_INFO, // Availability of package
TEXTCLASS_INFO, // Availability of textclass
};
///
InsetInfo(BufferParams const & bp, std::string const & info = std::string());
///
Inset * editXY(Cursor & cur, int x, int y);
///
EDITABLE editable() const { return NOT_EDITABLE; }
///
void draw(PainterInfo & pi, int x, int y) const;
///
void read(Buffer const &, Lexer & lex);
///
void write(Buffer const & buf, std::ostream & os) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
Inset::Code lyxCode() const { return Inset::INFO_CODE; }
///
void setInfo(std::string const & info);
///
bool setMouseHover(bool mouse_hover);
private:
/// The translator between the information type enum and corresponding string.
Translator<info_type, std::string> const & nameTranslator() const;
/// update info_ and text
void updateInfo();
///
virtual Inset * clone() const { return new InsetInfo(*this); }
///
info_type type_;
///
std::string name_;
/// store the buffer parameter
BufferParams const & bp_;
///
bool mouse_hover_;
};
} // namespace lyx
#endif

View File

@ -402,8 +402,9 @@ enum kb_action {
LFUN_LAYOUT_MODULES_CLEAR, // rgh, 20070825
LFUN_LAYOUT_MODULE_ADD, // rgh, 20070825
LFUN_LAYOUT_RELOAD, // rgh, 20070903
LFUN_MASTER_BUFFER_VIEW, // Tommaso, 20070920
LFUN_MASTER_BUFFER_UPDATE, // Tommaso, 20070920
LFUN_MASTER_BUFFER_VIEW, // Tommaso, 20070920
LFUN_MASTER_BUFFER_UPDATE, // Tommaso, 20070920
LFUN_INFO_INSERT, // bpeng, 20071007
LFUN_LASTACTION // end of the table
};