InsetHFill.h
InsetInclude.h
InsetIndex.h
+ InsetInfo.h
InsetLabel.h
InsetLine.h
InsetListings.h
InsetHFill.cpp
InsetInclude.cpp
InsetIndex.cpp
+ InsetInfo.cpp
InsetLabel.cpp
InsetLine.cpp
InsetListings.cpp
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:
{ 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 }
};
insets/InsetInclude.h \
insets/InsetIndex.cpp \
insets/InsetIndex.h \
+ insets/InsetInfo.cpp \
+ insets/InsetInfo.h \
insets/InsetLabel.cpp \
insets/InsetLabel.h \
insets/InsetLine.cpp \
#include "insets/InsetQuotes.h"
#include "insets/InsetSpecialChar.h"
#include "insets/InsetText.h"
+#include "insets/InsetInfo.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
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:
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())
#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"
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;
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;
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 =
///
PAGEBREAK_CODE,
///
- LISTINGS_CODE
+ LISTINGS_CODE,
+ ///
+ INFO_CODE,
};
/** returns the Code corresponding to the \c name.
--- /dev/null
+/**
+ * \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
--- /dev/null
+// -*- 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
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
};