When demote button is pressed too many times, TOC item dissapears from
the toc dialog, since it is no longer numbered. Hence, promoting back
to the original state from TOC dialog is not possible. Attached patch
is a way of correcting this behaviour. It simply prevents demoting the
item more than document default max toc depth.

What is your idea about the patch?

regards

Ugras
Index: frontends/qt4/TocWidget.cpp
===================================================================
--- frontends/qt4/TocWidget.cpp	(revision 18311)
+++ frontends/qt4/TocWidget.cpp	(working copy)
@@ -143,6 +143,7 @@
 void TocWidget::on_typeCO_currentIndexChanged(int value)
 {
 	setTocModel(value);
+	update();
 }
 
 
@@ -211,6 +212,8 @@
 	tocTV->selectionModel()->setCurrentIndex(index,
 		QItemSelectionModel::ClearAndSelect);
 	tocTV->selectionModel()->blockSignals(false);
+	moveInTB->setEnabled(form_->allowDemoteCurrentItem(typeCO->currentIndex()) &&
+			moveOutTB->isEnabled()); //means controls are enabled.
 }
 
 
@@ -223,7 +226,8 @@
 
 	moveUpTB->setEnabled(enable);
 	moveDownTB->setEnabled(enable);
-	moveInTB->setEnabled(enable);
+	moveInTB->setEnabled(enable &&
+			form_->allowDemoteCurrentItem(typeCO->currentIndex()));
 	moveOutTB->setEnabled(enable);
 
 	depthSL->setEnabled(enable);
Index: frontends/controllers/ControlToc.cpp
===================================================================
--- frontends/controllers/ControlToc.cpp	(revision 18311)
+++ frontends/controllers/ControlToc.cpp	(working copy)
@@ -142,5 +142,10 @@
 		return _(type);
 }
 
+bool const ControlToc::allowDemoteCurrentItem(size_t type) const
+{
+	return ((kernel().buffer().params().tocdepth - (*getCurrentTocItem(type)).depth() + 1)>0);
+}
+
 } // namespace frontend
 } // namespace lyx
Index: frontends/controllers/ControlToc.h
===================================================================
--- frontends/controllers/ControlToc.h	(revision 18311)
+++ frontends/controllers/ControlToc.h	(working copy)
@@ -62,6 +62,8 @@
 	bool canOutline(size_t type) const;
 	///
 	void updateBackend();
+	/// Is current item depth is equal the max allowed toc depth
+	bool const allowDemoteCurrentItem(size_t type_) const;
 
 private:
 	/// Return the guiname from a given cmdName of the TOC param

Reply via email to