On Wed, Sep 19, 2007 at 03:06:30PM +0200, Jean-Marc Lasgouttes wrote:
> Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> > The attached does this experimentally. It looks good... what we lose is
> > the possibility to get the previous word automatically into the index
> > inset. But I suspect there's a trick even for that if we go this way.
> >
> > The question is, do we?
> 
> Personally, I do not think do. An index is not just yet another
> collapsable inset. We should decide what UI we want and write the code
> necessary to get it. Not change the UI so that it fits what we have in
> store...

Actually have a look at the attached. I somewhat changed my mind since
the previous reply: what is inside an index inset is real LaTeX, so
logically it should be a real LyXText. (Yes, there are some limitations
such as no linebreaks allowed; but you get the idea.)

The attached does everything the old index inset does wrt. indexing the
selection and the previous/surrounding word. And it collapses to a
really small button, and can be opened by "Open all insets". Which the
old one did not...

- Martin

Index: src/insets/InsetCollapsable.cpp
===================================================================
--- src/insets/InsetCollapsable.cpp	(revision 20354)
+++ src/insets/InsetCollapsable.cpp	(working copy)
@@ -351,6 +351,8 @@
 void InsetCollapsable::cursorPos(BufferView const & bv,
 		CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
+	if (geometry() == ButtonOnly)
+		status_ = Open;
 	BOOST_ASSERT(geometry() != ButtonOnly);
 
 	InsetText::cursorPos(bv, sl, boundary, x, y);
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp	(revision 20348)
+++ src/Text3.cpp	(working copy)
@@ -49,6 +49,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"
@@ -211,23 +212,34 @@
 		return false;
 
 	recordUndo(cur);
-	bool gotsel = false;
-	if (cur.selection()) {
-		lyx::dispatch(FuncRequest(LFUN_CUT));
-		gotsel = true;
-	}
-	text->insertInset(cur, inset);
+	TextClass tclass = cur.buffer().params().getTextClass();
+	InsetLayout il = tclass.insetlayout(from_utf8(cmd.getArg(0)));
+	if (il.lyxtype == "indexing") {
+		docstring const ds = text->getStringToIndex(cur);
+		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;
@@ -1682,7 +1694,8 @@
 		InsetLayout il =  cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
 		if (il.lyxtype != "charstyle" &&
 		    il.lyxtype != "custom" &&
-		    il.lyxtype != "element")
+		    il.lyxtype != "element" &&
+		    il.lyxtype != "indexing")
 			enable = false;
 		break;
 		}
Index: lib/layouts/stdinsets.inc
===================================================================
--- lib/layouts/stdinsets.inc	(revision 20348)
+++ lib/layouts/stdinsets.inc	(working copy)
@@ -101,4 +101,15 @@
 	EndFont
 End
 
+InsetLayout Index
+	LyXType               indexing
+	LabelString           Idx
+	LatexType             command
+	LatexName             index
+	Decoration            minimalistic
+	LabelFont
+	  Color               Red
+	  Size                Small
+	EndFont
+End
 
Index: lib/ui/stdmenus.inc
===================================================================
--- lib/ui/stdmenus.inc	(revision 20348)
+++ lib/ui/stdmenus.inc	(working copy)
@@ -304,7 +304,7 @@
 		Item "Cross-Reference...|R" "dialog-show-new-inset ref"
 		Item "Label...|L" "label-insert"
 		Item "Caption" "caption-insert"
-		Item "Index Entry|d" "index-insert"
+		Item "Index Entry|d" "flex-insert Index"
 		Item "Nomenclature Entry...|y" "nomencl-insert"
 		Separator
 		Item "Table...|T" "tabular-insert"

Reply via email to