Index as collapsible, preserving existing feature set

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20699 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2007-10-03 13:38:19 +00:00
parent d81e1b3a2d
commit d21a3bb445
8 changed files with 185 additions and 59 deletions

View File

@ -101,4 +101,18 @@ InsetLayout Branch
EndFont
End
InsetLayout Index
LabelString Idx
LatexType command
LatexName index
Decoration minimalistic
Font
Color Green
Size Small
EndFont
LabelFont
Color Green
Size Small
EndFont
End

View File

@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 1)),
("1_6", range(277,289), minor_versions("1.6" , 0))] #RGH, command insets
("1_6", range(277,290), minor_versions("1.6" , 0))] #MV, index collapsable
def formats_list():

View File

@ -357,13 +357,49 @@ def revert_wrapfig_options(document):
i = i + 1
def convert_latexcommand_index(document):
"Convert from LatexCommand form to collapsable form."
i = 0
while True:
i = find_token(document.body, "\\begin_inset CommandInset index", i)
if i == -1:
return
if document.body[i + 1] != "LatexCommand index": # Might also be index_print
return
fullcommand = document.body[i + 2]
document.body[i] = "\\begin_inset Index"
document.body[i + 1] = "status collapsed"
document.body[i + 2] = "\\begin_layout standard"
document.body.insert(i + 3, fullcommand[6:].strip('"'))
document.body.insert(i + 4, "\\end_layout")
i = i + 5
def revert_latexcommand_index(document):
"Revert from collapsable form toLatexCommand form."
i = 0
while True:
i = find_token(document.body, "\\begin_inset Index", i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
del document.body[j - 1]
del document.body[j - 2] # \end_layout
document.body[i] = "\\begin_inset CommandInset index"
document.body[i + 1] = "LatexCommand index"
document.body[i + 3] = "name " + '"' + document.body[i + 3] + '"'
document.body.insert(i + 4, "")
del document.body[i + 2] # \begin_layout standard
i = i + 5
##
# Conversion hub
#
supported_versions = ["1.6.0","1.6"]
convert = [
[277, [fix_wrong_tables]],
convert = [[277, [fix_wrong_tables]],
[278, [close_begin_deeper]],
[279, [long_charstyle_names]],
[280, [axe_show_label]],
@ -374,10 +410,12 @@ convert = [
[285, []], # an empty manifest is automatically added
[286, []],
[287, [convert_wrapfig_options]],
[288, [convert_inset_command]]
[288, [convert_inset_command]],
[289, [convert_latexcommand_index]]
]
revert = [
[288, [revert_latexcommand_index]],
[287, [revert_inset_command]],
[286, [revert_wrapfig_options]],
[285, [revert_pdf_options]],

View File

@ -151,7 +151,7 @@ namespace fs = boost::filesystem;
namespace {
int const LYX_FORMAT = 288; //RGH, command insets
int const LYX_FORMAT = 289; //MV, index collapsable
} // namespace anon

View File

@ -50,6 +50,7 @@
#include "frontends/Clipboard.h"
#include "frontends/Selection.h"
#include "insets/InsetCollapsable.h"
#include "insets/InsetCommand.h"
#include "insets/InsetFloatList.h"
#include "insets/InsetNewline.h"
@ -188,23 +189,32 @@ static bool doInsertInset(Cursor & cur, Text * text,
return false;
recordUndo(cur);
bool gotsel = false;
if (cur.selection()) {
lyx::dispatch(FuncRequest(LFUN_CUT));
gotsel = true;
}
text->insertInset(cur, inset);
if (cmd.action == LFUN_INDEX_INSERT) {
docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
text->insertInset(cur, inset);
if (edit)
inset->edit(cur, true);
// Now put this into inset
static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
} else {
bool gotsel = false;
if (cur.selection()) {
lyx::dispatch(FuncRequest(LFUN_CUT));
gotsel = true;
}
text->insertInset(cur, inset);
if (edit)
inset->edit(cur, true);
if (edit)
inset->edit(cur, true);
if (gotsel && pastesel) {
lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
// reset first par to default
if (cur.lastpit() != 0 || cur.lastpos() != 0) {
LayoutPtr const layout =
cur.buffer().params().getTextClass().defaultLayout();
cur.text()->paragraphs().begin()->layout(layout);
if (gotsel && pastesel) {
lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
// reset first par to default
if (cur.lastpit() != 0 || cur.lastpos() != 0) {
LayoutPtr const layout =
cur.buffer().params().getTextClass().defaultLayout();
cur.text()->paragraphs().begin()->layout(layout);
}
}
}
return true;
@ -1173,6 +1183,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
case LFUN_INDEX_INSERT:
doInsertInset(cur, this, cmd, true, true);
cur.posRight();
break;
case LFUN_NOMENCL_INSERT: {
Inset * inset = createInset(&cur.bv(), cmd);
if (!inset)

View File

@ -177,14 +177,8 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
return 0;
}
case LFUN_INDEX_INSERT: {
// Try and generate a valid index entry.
InsetCommandParams icp("index");
icp["name"] = cmd.argument().empty() ?
bv->cursor().innerText()->getStringToIndex(bv->cursor()) :
cmd.argument();
return new InsetIndex(icp);
}
case LFUN_INDEX_INSERT:
return new InsetIndex(params);
case LFUN_NOMENCL_INSERT: {
InsetCommandParams icp("nomenclature");
@ -290,10 +284,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
return new InsetInclude(iip);
} else if (name == "index") {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
icp);
return new InsetIndex(icp);
return new InsetIndex(params);
} else if (name == "nomenclature") {
InsetCommandParams icp(name);
@ -412,7 +403,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
} else if (insetType == "bibtex") {
inset.reset(new InsetBibtex(inscmd));
} else if (insetType == "index") {
inset.reset(new InsetIndex(inscmd));
inset.reset(new InsetIndex(buf.params()));
} else if (insetType == "nomenclature") {
inset.reset(new InsetNomencl(inscmd));
} else if (insetType == "include") {
@ -502,6 +493,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
#endif
} else if (tmptok == "Caption") {
inset.reset(new InsetCaption(buf.params()));
} else if (tmptok == "Index") {
inset.reset(new InsetIndex(buf.params()));
} else if (tmptok == "FloatList") {
inset.reset(new InsetFloatList);
} else {

View File

@ -13,6 +13,7 @@
#include "DispatchResult.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "MetricsInfo.h"
@ -27,31 +28,25 @@ using std::string;
using std::ostream;
InsetIndex::InsetIndex(InsetCommandParams const & p)
: InsetCommand(p, "index")
{}
docstring const InsetIndex::getScreenLabel(Buffer const &) const
InsetIndex::InsetIndex(BufferParams const & bp)
: InsetCollapsable(bp)
{
size_t const maxLabelChars = 25;
docstring label = _("Idx: ") + getParam("name");
if (label.size() > maxLabelChars) {
label.erase(maxLabelChars - 3);
label += "...";
}
return label;
setLayout(bp);
}
int InsetIndex::docbook(Buffer const &, odocstream & os,
OutputParams const &) const
InsetIndex::InsetIndex(InsetIndex const & in)
: InsetCollapsable(in)
{}
int InsetIndex::docbook(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const
{
os << "<indexterm><primary>"
<< sgml::escapeString(getParam("name"))
<< "</primary></indexterm>";
return 0;
os << "<indexterm><primary>";
int const i = InsetText::docbook(buf, os, runparams);
os << "</primary></indexterm>";
return i;
}
@ -61,6 +56,63 @@ Inset::Code InsetIndex::lyxCode() const
}
Inset * InsetIndex::clone() const
{
return new InsetIndex(*this);
}
void InsetIndex::write(Buffer const & buf, std::ostream & os) const
{
os << to_utf8(name()) << "\n";
InsetCollapsable::write(buf, os);
}
void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
{
Font tmpfont = mi.base.font;
getDrawFont(mi.base.font);
mi.base.font.realize(tmpfont);
InsetCollapsable::metrics(mi, dim);
mi.base.font = tmpfont;
}
void InsetIndex::draw(PainterInfo & pi, int x, int y) const
{
Font tmpfont = pi.base.font;
getDrawFont(pi.base.font);
pi.base.font.realize(tmpfont);
InsetCollapsable::draw(pi, x, y);
pi.base.font = tmpfont;
}
void InsetIndex::getDrawFont(Font & font) const
{
font = Font(Font::ALL_INHERIT);
font.realize(layout_.font);
}
bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action) {
// paragraph breaks not allowed
case LFUN_BREAK_PARAGRAPH:
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
case LFUN_BREAK_PARAGRAPH_SKIP:
status.enabled(false);
return true;
default:
return InsetCollapsable::getStatus(cur, cmd, status);
}
}
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
: InsetCommand(p, string())

View File

@ -13,6 +13,7 @@
#define INSET_INDEX_H
#include "InsetCollapsable.h"
#include "InsetCommand.h"
@ -22,23 +23,38 @@ class LaTeXFeatures;
/** Used to insert index labels
*/
class InsetIndex : public InsetCommand {
class InsetIndex : public InsetCollapsable {
public:
///
InsetIndex(InsetCommandParams const &);
InsetIndex(BufferParams const &);
///
docstring const getScreenLabel(Buffer const &) const;
InsetIndex(InsetIndex const &);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset::Code lyxCode() const;
///
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo &, int, int) const;
///
docstring name() const { return from_ascii("Index"); }
///
void getDrawFont(Font &) const;
///
void write(Buffer const & buf, std::ostream & os) const;
///
int docbook(Buffer const &, odocstream &,
OutputParams const &) const;
/// should paragraph indendation be omitted in any case?
bool neverIndent(Buffer const &) const { return true; }
private:
virtual Inset * clone() const {
return new InsetIndex(params());
}
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
///
virtual Inset * clone() const;
};