Try 2, with patch this time ...

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.
> 
> 
> 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.
> 
> 
> Helge Hafting

Helge, 

The attched patch should fix both problems. I''ve tested it quite thoroughly 
but it won't be applied until you confirm that it does the trick. Don't 
forget to check the latex and that the saved LyX file is reloaded correctly

$ diff -u before.lyx after.lyx 

will help you there, as well as a visual test that all is well.

Regards,
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 16:14:04 -0000
@@ -1,3 +1,11 @@
+2003-01-30  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* factory.C (createInset): create an InsetCommandParam of type "index"
+	and use it to 'do the right thing'.
+
+	* text2.C (getStringToIndex): ensure that cursor position is always
+	reset to the reset_cursor position.
+
 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 16:14:04 -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/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.269
diff -u -p -r1.269 text2.C
--- src/text2.C	18 Dec 2002 14:36:28 -0000	1.269
+++ src/text2.C	30 Jan 2003 16:14:10 -0000
@@ -1039,33 +1039,30 @@ void LyXText::toggleFree(BufferView * bv
 
 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);
 
-	if (!selection.set()) {
+	string idxstring;
+	if (!selection.set())
 		bview->owner()->message(_("Nothing to index!"));
-		return string();
-	}
-	if (selection.start.par() != selection.end.par()) {
+	else if (selection.start.par() != selection.end.par())
 		bview->owner()->message(_("Cannot index more than one paragraph!"));
-		return string();
+	else
+		idxstring = selectionAsString(bview->buffer(), false);
 	}
 
-	idxstring = selectionAsString(bview->buffer(), false);
+	// Reset cursors to their original position.
+	cursor = reset_cursor;
+	setCursor(bview, cursor.par(), cursor.pos());
+	selection.cursor = cursor;
 
 	// Implicit selections are cleared afterwards
-	//and cursor is set to the original position.
-	if (implicitSelection) {
+	if (implicitSelection)
 		clearSelection();
-		cursor = reset_cursor;
-		setCursor(bview, cursor.par(), cursor.pos());
-		selection.cursor = cursor;
-	}
+
 	return idxstring;
 }
 
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 16:14:18 -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 16:14:19 -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 16:14:44 -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 16:14:45 -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