Helge Hafting wrote:

> Bugs when inserting an index element:
> 
> 1. Insert->index element to the right of some existing index
> element. 2. Type "Something" in the box (without quotes) and click
> ok 3. Reopen the box and find |++|Something|++| there?
> 
> This don't work with makeindex, so I have to correct it.  Every
> _new_ index entry get |++| prepended and appended.
> 
> Note that this don't happen in the common case where I
> create the index entry next to a word that becomes
> the default entry. (Iow it is copied into the index entry popup)
> 
> It happens when creating index entries next to other
> index entries.  Which is common when something needs multiple
> entries.

Thanks, Helge. Patch attached.

Lars, this 'does the right thing' and is properly tested.
Ok to apply?


> Another small one:
> Add an index entry to the rigth of two other entries:
> textexttext[first entry][second entry]<cursor is here>
> 
> Insert the third index entry.  I expect it to go after the
> other two, but it ends up like this:
> 
> textextext[first][third][second]
> 
> This don't matter for the printed document, but is somewhat
> annoying during editing.

This one is quite interesting. The cursor is moved before the 
previous inset in the course of opening the dialog.

I suspect that LyXText::getStringToIndex(BufferView *) is to blame, 
but my knowledge of cursor manipulation is zero. Guys, does the 
change below make sense to you. It seems to do the trick and doesn't 
affect the ability of the function to find the selection.

Can I submit this change too, Lars
Angus



string LyXText::getStringToIndex(BufferView * bview)
{
        string idxstring;

        // Try implicit word selection
        // If there is a change in the language the implicit
        // word selection is disabled.
        LyXCursor const reset_cursor = cursor;
        bool const implicitSelection =
                selectWordWhenUnderCursor(bview, PREVIOUS_WORD);

+       cursor = reset_cursor;
+       setCursor(bview, cursor.par(), cursor.pos());
+       selection.cursor = cursor;
+
        if (!selection.set()) {
!               // The second "inset index" call returns here
!               // but the cursor position is now >before_ the
!               // previous inset.
                bview->owner()->message(_("Nothing to index!"));
                return string();
        }
        if (selection.start.par() != selection.end.par()) {
                bview->owner()->message(_("Cannot index more than one paragraph!"));
                return string();
        }

        idxstring = selectionAsString(bview->buffer(), false);

        // Implicit selections are cleared afterwards
        // and cursor is set to the original position.
        if (implicitSelection) {
                clearSelection();
-               cursor = reset_cursor;
-               setCursor(bview, cursor.par(), cursor.pos());
-               selection.cursor = cursor;
        }
        return idxstring;
}


> Helge Hafting

-- 
Angus
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1018
diff -u -p -r1.1018 ChangeLog
--- src/ChangeLog	23 Jan 2003 16:23:36 -0000	1.1018
+++ src/ChangeLog	30 Jan 2003 15:08:51 -0000
@@ -1,3 +1,8 @@
+2003-01-30  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* factory.C (createInset): create an InsetCommandParam of type "index"
+	and use it to 'do the right thing'.
+
 2003-01-20  Michael Schmitt <[EMAIL PROTECTED]>
 
         * bufferview.C:
Index: src/factory.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v
retrieving revision 1.9
diff -u -p -r1.9 factory.C
--- src/factory.C	4 Nov 2002 00:15:54 -0000	1.9
+++ src/factory.C	30 Jan 2003 15:08:51 -0000
@@ -93,11 +93,16 @@ Inset * createInset(FuncRequest const & 
 			return 0;
 
 		case LFUN_INDEX_INSERT: {
-			string entry = cmd.argument;
-			if (entry.empty())
-				entry = bv->getLyXText()->getStringToIndex(bv);
-			if (!entry.empty())
-				return new InsetIndex(InsetCommandParams("index", entry));
+			string const entry = cmd.argument.empty() ?
+				"index" : cmd.argument;
+			InsetCommandParams icp;
+			icp.setFromString(entry);
+
+			if (icp.getContents().empty())
+				icp.setContents(bv->getLyXText()->getStringToIndex(bv));
+			if (!icp.getContents().empty())
+				return new InsetIndex(icp);
+			
 			bv->owner()->getDialogs().createIndex();
 			return 0;
 		}
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.384
diff -u -p -r1.384 ChangeLog
--- src/frontends/qt2/ChangeLog	26 Jan 2003 22:37:12 -0000	1.384
+++ src/frontends/qt2/ChangeLog	30 Jan 2003 15:09:10 -0000
@@ -1,3 +1,8 @@
+2003-01-30  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* Dialogs2.C (createIndex): enable ControlCommand to create an
+	InsetCommandParam of type "index", not null.
+
 2003-01-26  Michael Schmitt  <[EMAIL PROTECTED]>
 
 	* ui/QThesaurusDialogBase.ui: add colons to labels.
Index: src/frontends/qt2/Dialogs2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Dialogs2.C,v
retrieving revision 1.16
diff -u -p -r1.16 Dialogs2.C
--- src/frontends/qt2/Dialogs2.C	1 Dec 2002 22:59:18 -0000	1.16
+++ src/frontends/qt2/Dialogs2.C	30 Jan 2003 15:09:11 -0000
@@ -127,7 +127,7 @@ void Dialogs::showIndex(InsetCommand * i
 
 void Dialogs::createIndex()
 {
-	pimpl_->index.controller().createInset(string());
+	pimpl_->index.controller().createInset("index");
 }
 
 
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.658
diff -u -p -r1.658 ChangeLog
--- src/frontends/xforms/ChangeLog	26 Jan 2003 22:37:12 -0000	1.658
+++ src/frontends/xforms/ChangeLog	30 Jan 2003 15:09:26 -0000
@@ -1,3 +1,8 @@
+2003-01-30  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* Dialogs2.C (createIndex): enable ControlCommand to create an
+	InsetCommandParam of type "index", not null.
+
 2003-01-26  Michael Schmitt  <[EMAIL PROTECTED]>
 
 	* forms/form_thesaurus.fd: add colons to labels. Shrink dialog.
Index: src/frontends/xforms/Dialogs2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Dialogs2.C,v
retrieving revision 1.10
diff -u -p -r1.10 Dialogs2.C
--- src/frontends/xforms/Dialogs2.C	1 Dec 2002 22:59:19 -0000	1.10
+++ src/frontends/xforms/Dialogs2.C	30 Jan 2003 15:09:29 -0000
@@ -129,7 +129,7 @@ void Dialogs::showIndex(InsetCommand * i
 
 void Dialogs::createIndex()
 {
-	pimpl_->index.controller().createInset(string());
+	pimpl_->index.controller().createInset("index");
 }
 
 

Reply via email to