View Issue Details

IDProjectCategoryView StatusLast Update
0009883ScribusStylespublic2026-10-05 11:18
Reporteralexandre Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status newResolutionopen 
Summary0009883: "Style of next paragraph" option
DescriptionA user wants to be able to say what style should be used for the next paragraph. E.g. formatting a header as Header2 will automatically make the next paragraph e.g . BodyText.
Tags#please_test
PatchNo

Relationships

has duplicate 0011131 closedale circonda immagine con testo 
has duplicate 0014079 closedjghali Follow-up-style for paragraph styles 

Activities

jirib

2011-03-28 08:48

reporter   ~0025964

Yes, it would be nice for example in this scenario.

1st paragraph has inicials defined, then logically next paragraph should be without inicials ;)

cezaryece

2011-03-28 09:54

updater   ~0025965

Do you know that it is only usable while you typing new text? I think it maybe nice to have such feature, but... there are more important thing to do.
Maybe some day when dev team will be very bored...

Nathan

2025-07-16 20:23

reporter   ~0052903

Just wanted to add some more context to this one. I regularly create event programs, where things such as boards of directors, menus, and event itineraries are common. Often, each line will require its own paragraph style, for instance:

Board Title
Board Member Name
Board Member Position
Board Member Company,

or:

Itinerary Item Time
Itinerary Item Name
Itinerary Item Description

or:

Menu Section Title
Menu Subsection Title
Menu Item Title
Menu Item Description
Menu Item Diet Suitability

An event program might easily have dozens of similar items, so right now, it is a major pain point to use the story editor to manually apply paragraph styles to each line. Not only does this have to be done initially, but styles frequently need to be updated when receiving new or changed copy from colleagues (which, unfortunately, happens all the time), resulting in hundreds of clicks that aren't necessary in other desktop publishing programs.

A "Next Style" feature would also make the Scribus feature to export and import text from the Story Editor much more useful. For instance, rather than editing all of the text in place, I could have a plaintext file available to my colleague via a shared folder where they can input menu items. When they were done, I could simply import the file again, apply the first paragraph style, and the rest would take care of itself. As of now, the export / import feature is of limited utility, because it means manually applying every single paragraph style all over again.

I can understand why this feature might appear like a bit of a luxury if you don't regularly make such documents, but for me, the lack of this feature significantly decreases my productivity as compared to using proprietary software that does have a "Next Style" feature. This feature would result in a tremendous productivity increase for me and others working on similar projects, it would vastly increase the utility of Scribus' paragraph styles, and it would make the import/export text feature especially useful when working with others, resulting in further productivity gains.

I hope that the devs will consider building this feature; I am sure that it would ease a significant pain-point for many others also.

ale

2025-07-17 05:54

manager   ~0052904

There is one problem I see here: often you will be importing the text from an external source.
In that case, the "Next style" won't help you.

Some time ago, a question from a user inspired me to write a script that repeats an existing style pattern:

https://github.com/aoloe/scribus-script-repository/tree/master/style-repeater

You can start the script from the the "Action search" or (hopefully) in the (near) future, you will be able to add it to a customizable toolbar.

If your text is in one single frame, it might speedup your workflow.

If you have multiple frames, we can talk about how a Script might help there.
I suggest that you ask a question about it in the forums or in the Element chat / IRC channel.

Also, the "Style search" just landed in 1.7 and it will allow you to apply styles by typing a few of the letters in the style name.
No more wild clicking in the Story editor : - )

All this having been said, it's still a good idea to allow the user to define a "Next style" (only applies to Paragraph styles...), but in most cases I think that the lack of this feature should not be a significant pain-point anymore...

Nathan

2025-07-17 15:01

reporter   ~0052906

> often you will be importing the text from an external source. In that case, the "Next style" won't help you.

The idea is that a user could import from an external source into the story editor, apply the top style, and the rest would apply themselves automatically. No idea how that would work technically, but lord would it be a time saver. I think that's how it works in InDesign?

> Some time ago, a question from a user inspired me to write a script that repeats an existing style pattern:

That script looks very useful; I'll give it a try! For me, things like menus are often in one frame, but a list of directors will often be many frames due to the inclusion of a photo for each.

> suggest that you ask a question about it in the forums or in the Element chat / IRC channel.

Does Scribus have a Matrix room? If so, what is the address?

> Also, the "Style search" just landed in 1.7 and it will allow you to apply styles by typing a few of the letters in the style name.

This also sounds like a useful feature. Unfortunately, it'll still be pretty slow when applying a large number of styles, but little quality of life improvements like that really go a long way towards making a program feel easier to use.

> All this having been said, it's still a good idea to allow the user to define a "Next style" (only applies to Paragraph styles...), but in most cases I think that the lack of this feature should not be a significant pain-point anymore...

Unfortunately, for my workflow, it remains a large impediment to my productivity, so I am hoping that someone with the skills will be interested in implementing the feature.

ale

2025-07-17 16:27

manager   ~0052907

Here is the matrix channel

https://matrix.to/#/#scribus-general-chat:matrix.org

And for applying the next style to existing text, I think that (at least at first) I would implement it as a script.
And, at the end, the easiest way to create such a script might be to add a "Next style" in the style definition....

buttar

2026-10-05 11:11

reporter   ~0054510

I see this is a very useful feature. And it should be a native feature, not added by a script. I took a shot at it. Here is a 3-patch series based on r27875/79.

## ns1-next-style-foundation-v1.03.patch

- Adds a Next Style relationship to paragraph styles with None, Same Style and named-style targets.
- Keeps Next Style separate from inherited paragraph formatting.
- Adds save/load and generic style serialisation support.
- Handles rename, delete/replacement, cloning, equivalence and named-resource remapping.
- Adds two-pass import remapping for forward references, cycles and renamed conflicts.
- Adds the Paragraph Style editor control beside Based on.

## ns2-apply-next-styles-v1.02.patch

- Adds Apply “X” + Next Styles to the Paragraph Style context menu (in SM, for now).
- Walks the configured style chain across the selected paragraphs only.
- Supports Same Style, cycles and stopping at None without changing the remaining selected paragraphs.
- Keeps the whole chained application as one Undo/Redo transaction.
- Preserves normal single-style Apply behaviour.
- Fixes Style Manager right-click context handling and keeps Apply availability consistent with pending style edits.

## ns3-next-style-on-enter-v1.00.patch

- Makes interactive Enter follow the current paragraph style’s Next Style.
- Supports named targets, Same Style and existing Scribus behaviour for None.
- Works in both canvas text editing and Story Editor.
- Handles paragraph splits in the middle of existing text.
- Stores the resolved target in the existing paragraph-insert undo state so Redo restores the correct style transition.
- Leaves generic paragraph insertion, paste/import and Shift+Enter unchanged.

Please test @Nathan, @ale
ns1-next-style-foundation-v1.03.patch (26,702 bytes)   
Index: scribus/plugins/fileloader/scribus171format/scribus171format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format.cpp	(revision 27875)
+++ scribus/plugins/fileloader/scribus171format/scribus171format.cpp	(working copy)
@@ -3573,6 +3573,16 @@
 			newStyle.setParent(CommonStrings::DefaultParagraphStyle);
 	}
 
+	newStyle.clearNextStyle();
+	if (attrs.hasAttribute("NextStyleMode"))
+	{
+		const auto nextStyleMode = static_cast<ParagraphStyle::NextStyleMode>(attrs.valueAsInt("NextStyleMode"));
+		if (nextStyleMode == ParagraphStyle::SameStyle)
+			newStyle.setNextStyleMode(ParagraphStyle::SameStyle);
+		else if (nextStyleMode == ParagraphStyle::NamedNextStyle && attrs.hasAttribute("NextStyle"))
+			newStyle.setNextStyle(attrs.valueAsString("NextStyle"));
+	}
+
 	//Remove uppercase in 1.8 format
 	if (attrs.hasAttribute("LINESPMode"))
 		newStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt("LINESPMode")));
Index: scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp	(revision 27875)
+++ scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp	(working copy)
@@ -821,6 +821,12 @@
 		docu.writeAttribute("Name", style.name());
 	if (!style.parent().isEmpty())
 		docu.writeAttribute("Parent", style.parent());
+	if (style.nextStyleMode() != ParagraphStyle::NoNextStyle)
+	{
+		docu.writeAttribute("NextStyleMode", static_cast<int>(style.nextStyleMode()));
+		if (style.nextStyleMode() == ParagraphStyle::NamedNextStyle)
+			docu.writeAttribute("NextStyle", style.nextStyle());
+	}
 	if ( style.isDefaultStyle())
 		docu.writeAttribute("DefaultStyle", style.isDefaultStyle());
 
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 27875)
+++ scribus/scribusdoc.cpp	(working copy)
@@ -1753,6 +1753,10 @@
 				if ((*wrkStyles)[i] != parDefault)
 					namesMap[(*wrkStyles)[i].name()] = (*wrkStyles)[i].name();
 			}
+			ResourceCollection renamedStyles;
+			renamedStyles.mapStyles(namesMap);
+			for (int i(0); i < wrkStyles->count(); ++i)
+				(*wrkStyles)[i].replaceNamedResources(renamedStyles);
 			wrkStyles->rename(namesMap);
 		}
 	}
Index: scribus/styles/paragraphstyle.cpp
===================================================================
--- scribus/styles/paragraphstyle.cpp	(revision 27875)
+++ scribus/styles/paragraphstyle.cpp	(working copy)
@@ -43,9 +43,11 @@
 
 
 ParagraphStyle::ParagraphStyle(const ParagraphStyle& other)
-	          : BaseStyle(other), 
+	          : BaseStyle(other),
 	            m_cstyleContextIsInh(other.m_cstyleContextIsInh),
-	            m_cstyle(other.charStyle())
+	            m_cstyle(other.charStyle()),
+	            m_nextStyleMode(other.m_nextStyleMode),
+	            m_nextStyleName(other.m_nextStyleName)
 {
 	if (m_cstyleContextIsInh)
 		m_cstyle.setContext(nullptr);
@@ -62,6 +64,50 @@
 #undef ATTRDEF
 }
 
+QString ParagraphStyle::nextStyle() const
+{
+	switch (m_nextStyleMode)
+	{
+		case SameStyle:
+			return name();
+		case NamedNextStyle:
+			return m_nextStyleName;
+		case NoNextStyle:
+		default:
+			return QString();
+	}
+}
+
+void ParagraphStyle::setNextStyleMode(NextStyleMode mode)
+{
+	if (mode != SameStyle && mode != NamedNextStyle)
+		mode = NoNextStyle;
+	if (mode == NamedNextStyle && m_nextStyleName.isEmpty())
+		mode = NoNextStyle;
+
+	m_nextStyleMode = mode;
+	if (mode != NamedNextStyle)
+		m_nextStyleName.clear();
+}
+
+void ParagraphStyle::setNextStyle(QString styleName)
+{
+	if (styleName.isEmpty())
+	{
+		clearNextStyle();
+		return;
+	}
+
+	if (hasName() && styleName == name())
+	{
+		setNextStyleMode(SameStyle);
+		return;
+	}
+
+	m_nextStyleMode = NamedNextStyle;
+	m_nextStyleName = styleName;
+}
+
 QString ParagraphStyle::displayName() const
 {
 	if (isDefaultStyle())
@@ -80,6 +126,8 @@
 	const auto* oth = reinterpret_cast<const ParagraphStyle*> ( & other );
 	return  oth &&
 		parent() == oth->parent() && m_cstyle.equiv(oth->charStyle())
+		&& m_nextStyleMode == oth->m_nextStyleMode
+		&& (m_nextStyleMode != NamedNextStyle || m_nextStyleName == oth->m_nextStyleName)
 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
 		&& (inh_##attr_NAME == oth->inh_##attr_NAME) \
 		&& (inh_##attr_NAME || isequiv(m_##attr_NAME, oth->m_##attr_NAME))
@@ -94,6 +142,8 @@
 
 	other.validate();
 	m_cstyle = other.charStyle();
+	m_nextStyleMode = other.m_nextStyleMode;
+	m_nextStyleName = other.m_nextStyleName;
 
 	// we dont want cstyleContext to point to other's charstyle...
 	m_cstyleContext.setDefaultStyle( &m_cstyle );
@@ -212,7 +262,16 @@
 void ParagraphStyle::getNamedResources(ResourceCollection& lists) const
 {
 	for (const BaseStyle *sty = parentStyle(); sty != nullptr; sty = sty->parentStyle())
+	{
+		const bool alreadyCollected = lists.styles().contains(sty->name());
 		lists.collectStyle(sty->name());
+		if (!alreadyCollected)
+		{
+			const auto* paragraphStyle = dynamic_cast<const ParagraphStyle*>(sty);
+			if (paragraphStyle)
+				paragraphStyle->getNamedResources(lists);
+		}
+	}
 	charStyle().getNamedResources(lists);
 
 	const QString& backgroundColorName = backgroundColor();
@@ -231,6 +290,18 @@
 			peCharStyle->getNamedResources(lists);
 		lists.collectCharStyle(parEffectStyle);
 	}
+
+	if (m_nextStyleMode == NamedNextStyle && !m_nextStyleName.isEmpty())
+	{
+		const bool alreadyCollected = lists.styles().contains(m_nextStyleName);
+		lists.collectStyle(m_nextStyleName);
+		if (!alreadyCollected && context())
+		{
+			const auto* next = dynamic_cast<const ParagraphStyle*>(context()->resolve(m_nextStyleName));
+			if (next)
+				next->getNamedResources(lists);
+		}
+	}
 }
 
 
@@ -252,6 +323,10 @@
 
 	if ((it = (newNames.charStyles().find(peCharStyleName()))) != newNames.charStyles().end())
 		setPeCharStyleName(it.value());
+
+	if (m_nextStyleMode == NamedNextStyle && (it = newNames.styles().find(m_nextStyleName)) != newNames.styles().end())
+		setNextStyle(it.value());
+
 	m_cstyle.replaceNamedResources(newNames);
 }
 
@@ -266,6 +341,11 @@
 	return QString::number(static_cast<int>(val));
 }
 
+static QString toXMLString(ParagraphStyle::NextStyleMode val)
+{
+	return QString::number(static_cast<int>(val));
+}
+
 static QString toXMLString(const QList<ParagraphStyle::TabRecord> & )
 {
 	return "dummy";
@@ -280,6 +360,12 @@
 		att.insert(# attr_NAME, toXMLString(m_##attr_NAME)); 
 #include "paragraphstyle.attrdefs.cxx"
 #undef ATTRDEF
+	if (m_nextStyleMode != NoNextStyle)
+	{
+		att["NextStyleMode"] = toXMLString(m_nextStyleMode);
+		if (m_nextStyleMode == NamedNextStyle && !m_nextStyleName.isEmpty())
+			att["NextStyle"] = m_nextStyleName;
+	}
 	if (!name().isEmpty())
 		att["id"] = mkXMLName(elemtag + name());
 	handler.begin(elemtag, att);
@@ -356,6 +442,12 @@
 	return parseEnum<ParagraphStyle::LineSpacingMode>(str);
 }
 
+template<>
+ParagraphStyle::NextStyleMode parse<ParagraphStyle::NextStyleMode>(const Xml_string& str)
+{
+	return parseEnum<ParagraphStyle::NextStyleMode>(str);
+}
+
 
 using Tablist = QList<ParagraphStyle::TabRecord>;
 
@@ -377,6 +469,8 @@
 	ruleset.addRule(stylePrefix, Factory<ParagraphStyle>());
 	ruleset.addRule(stylePrefix, IdRef<ParagraphStyle>());
 	BaseStyle::desaxeRules<ParagraphStyle>(prefixPattern, ruleset, elemtag);
+	ruleset.addRule(stylePrefix, SetAttributeWithConversion<ParagraphStyle, ParagraphStyle::NextStyleMode> (&ParagraphStyle::setNextStyleMode, "NextStyleMode", &parse<ParagraphStyle::NextStyleMode>));
+	ruleset.addRule(stylePrefix, SetAttributeWithConversion<ParagraphStyle, QString> (&ParagraphStyle::setNextStyle, "NextStyle", &parse<QString>));
 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
 	if ( strcmp(# attr_NAME, "TabValues") != 0) \
 		ruleset.addRule(stylePrefix, SetAttributeWithConversion<ParagraphStyle, attr_TYPE> ( & ParagraphStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> ));
Index: scribus/styles/paragraphstyle.h
===================================================================
--- scribus/styles/paragraphstyle.h	(revision 27875)
+++ scribus/styles/paragraphstyle.h	(working copy)
@@ -67,6 +67,13 @@
 		AutomaticHyphenation = 2
 	};
 
+	enum NextStyleMode
+	{
+		NoNextStyle    = 0,
+		SameStyle      = 1,
+		NamedNextStyle = 2
+	};
+
 	enum TabType
 	{
 		LeftTab = 0,
@@ -108,6 +115,12 @@
 	void update(const StyleContext*) override;
 	
 	bool equiv(const BaseStyle& other) const override;
+
+	NextStyleMode nextStyleMode() const { return m_nextStyleMode; }
+	QString nextStyle() const;
+	void setNextStyleMode(NextStyleMode mode);
+	void setNextStyle(QString styleName);
+	void clearNextStyle() { setNextStyleMode(NoNextStyle); }
 	
 	void applyStyle(const ParagraphStyle& other);
 	void eraseStyle(const ParagraphStyle& other);
@@ -175,6 +188,8 @@
 	StyleContextProxy m_cstyleContext { nullptr };
 	bool m_cstyleContextIsInh { true };
 	CharStyle m_cstyle;
+	NextStyleMode m_nextStyleMode { NoNextStyle };
+	QString m_nextStyleName;
 	
 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
 		attr_TYPE m_##attr_NAME; \
Index: scribus/ui/smpstylewidget.cpp
===================================================================
--- scribus/ui/smpstylewidget.cpp	(revision 27875)
+++ scribus/ui/smpstylewidget.cpp	(working copy)
@@ -6,6 +6,10 @@
 */
 
 #include <QEvent>
+#include <QSignalBlocker>
+
+#include <algorithm>
+#include <utility>
 
 
 #include "iconmanager.h"
@@ -446,6 +450,7 @@
 		parentCombo->setCurrentIndex(index);
 	}
 
+	showNextStyle(pstyle, pstyles);
 }
 
 void SMPStyleWidget::show(QList<ParagraphStyle*> &pstyles, QList<ParagraphStyle> &pstylesAll, QList<CharStyle> &cstyles, int unitIndex, const QString &defLang)
@@ -470,6 +475,7 @@
 		showTabs(pstyles, unitIndex);
 		showCStyle(pstyles, cstyles, defLang, unitIndex);
 		showParent(pstyles);
+		showNextStyle(pstyles, pstylesAll);
 		//checkParEffectState();
 		setParagraphEffect(0);
 		showColors(pstyles);
@@ -870,6 +876,110 @@
 }
 
 
+namespace
+{
+void populateNextStyleCombo(QComboBox* combo, const QList<ParagraphStyle>& styles, const QString& currentStyle, bool includeCurrent, const QString& noneText, const QString& sameStyleText)
+{
+	combo->clear();
+	combo->addItem(noneText);
+	combo->setItemData(combo->count() - 1, static_cast<int>(ParagraphStyle::NoNextStyle), Qt::UserRole);
+	combo->addItem(sameStyleText);
+	combo->setItemData(combo->count() - 1, static_cast<int>(ParagraphStyle::SameStyle), Qt::UserRole);
+	combo->insertSeparator(combo->count());
+
+	QList<const ParagraphStyle*> sortedStyles;
+	for (const ParagraphStyle& style : styles)
+	{
+		if (!style.hasName())
+			continue;
+		if (!includeCurrent && style.name() == currentStyle)
+			continue;
+		sortedStyles.append(&style);
+	}
+	std::sort(sortedStyles.begin(), sortedStyles.end(), [](const ParagraphStyle* lhs, const ParagraphStyle* rhs) {
+		return lhs->displayName().compare(rhs->displayName(), Qt::CaseSensitive) < 0;
+	});
+
+	for (const ParagraphStyle* style : std::as_const(sortedStyles))
+	{
+		combo->addItem(style->displayName());
+		const int index = combo->count() - 1;
+		combo->setItemData(index, static_cast<int>(ParagraphStyle::NamedNextStyle), Qt::UserRole);
+		combo->setItemData(index, style->name(), Qt::UserRole + 1);
+	}
+}
+
+int findNextStyleItem(const QComboBox* combo, ParagraphStyle::NextStyleMode mode, const QString& styleName = QString())
+{
+	for (int i = 0; i < combo->count(); ++i)
+	{
+		if (combo->itemData(i, Qt::UserRole).toInt() != static_cast<int>(mode))
+			continue;
+		if (mode != ParagraphStyle::NamedNextStyle || combo->itemData(i, Qt::UserRole + 1).toString() == styleName)
+			return i;
+	}
+	return -1;
+}
+}
+
+void SMPStyleWidget::showNextStyle(ParagraphStyle* pstyle, const QList<ParagraphStyle>& pstyles)
+{
+	const QSignalBlocker blocker(nextStyleCombo);
+	populateNextStyleCombo(nextStyleCombo, pstyles, pstyle->name(), false, tr("None"), tr("Same Style"));
+
+	int index = findNextStyleItem(nextStyleCombo, pstyle->nextStyleMode(), pstyle->nextStyle());
+	if (index < 0 && pstyle->nextStyleMode() == ParagraphStyle::NamedNextStyle)
+	{
+		nextStyleCombo->addItem(pstyle->nextStyle());
+		index = nextStyleCombo->count() - 1;
+		nextStyleCombo->setItemData(index, static_cast<int>(ParagraphStyle::NamedNextStyle), Qt::UserRole);
+		nextStyleCombo->setItemData(index, pstyle->nextStyle(), Qt::UserRole + 1);
+	}
+	if (index < 0)
+		index = findNextStyleItem(nextStyleCombo, ParagraphStyle::NoNextStyle);
+	nextStyleCombo->setCurrentIndex(index);
+	nextStyleCombo->setEnabled(true);
+}
+
+void SMPStyleWidget::showNextStyle(const QList<ParagraphStyle*>& pstyles, const QList<ParagraphStyle>& pstylesAll)
+{
+	const QSignalBlocker blocker(nextStyleCombo);
+	nextStyleCombo->setEnabled(true);
+	populateNextStyleCombo(nextStyleCombo, pstylesAll, QString(), true, tr("None"), tr("Same Style"));
+
+	ParagraphStyle::NextStyleMode mode = pstyles.first()->nextStyleMode();
+	QString styleName = pstyles.first()->nextStyle();
+	bool mixed = false;
+	for (int i = 1; i < pstyles.count(); ++i)
+	{
+		if (pstyles[i]->nextStyleMode() != mode || (mode == ParagraphStyle::NamedNextStyle && pstyles[i]->nextStyle() != styleName))
+		{
+			mixed = true;
+			break;
+		}
+	}
+
+	if (mixed)
+	{
+		nextStyleCombo->insertItem(0, tr("Mixed"));
+		nextStyleCombo->setItemData(0, -1, Qt::UserRole);
+		nextStyleCombo->setCurrentIndex(0);
+		return;
+	}
+
+	int index = findNextStyleItem(nextStyleCombo, mode, styleName);
+	if (index < 0 && mode == ParagraphStyle::NamedNextStyle)
+	{
+		nextStyleCombo->addItem(styleName);
+		index = nextStyleCombo->count() - 1;
+		nextStyleCombo->setItemData(index, static_cast<int>(ParagraphStyle::NamedNextStyle), Qt::UserRole);
+		nextStyleCombo->setItemData(index, styleName, Qt::UserRole + 1);
+	}
+	if (index < 0)
+		index = findNextStyleItem(nextStyleCombo, ParagraphStyle::NoNextStyle);
+	nextStyleCombo->setCurrentIndex(index);
+}
+
 void SMPStyleWidget::clearAll()
 {
 
Index: scribus/ui/smpstylewidget.h
===================================================================
--- scribus/ui/smpstylewidget.h	(revision 27875)
+++ scribus/ui/smpstylewidget.h	(working copy)
@@ -69,6 +69,8 @@
 	void showTabs(const QList<ParagraphStyle*> &pstyles, int unitIndex);
 	void showCStyle(const QList<ParagraphStyle*> &pstyles, const QList<CharStyle> &cstyles, const QString &defLang, int unitIndex);
 	void showParent(const QList<ParagraphStyle*> &pstyles);
+	void showNextStyle(ParagraphStyle* pstyle, const QList<ParagraphStyle>& pstyles);
+	void showNextStyle(const QList<ParagraphStyle*>& pstyles, const QList<ParagraphStyle>& pstylesAll);
 
 	void openEnhanced();
 	void closeEnhanced(bool show = false);
Index: scribus/ui/smpstylewidget.ui
===================================================================
--- scribus/ui/smpstylewidget.ui	(revision 27875)
+++ scribus/ui/smpstylewidget.ui	(working copy)
@@ -54,27 +54,58 @@
        <item>
         <layout class="QHBoxLayout">
          <property name="spacing">
-          <number>4</number>
+          <number>12</number>
          </property>
          <item>
-          <widget class="QLabel" name="parentLabel">
-           <property name="text">
-            <string>Based On:</string>
-           </property>
-           <property name="wordWrap">
-            <bool>false</bool>
+          <layout class="QHBoxLayout">
+           <property name="spacing">
+            <number>4</number>
            </property>
-          </widget>
+           <item>
+            <widget class="QLabel" name="parentLabel">
+             <property name="text">
+              <string>Based on:</string>
+             </property>
+             <property name="wordWrap">
+              <bool>false</bool>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QComboBox" name="parentCombo">
+             <property name="toolTip">
+              <string>Parent Style</string>
+             </property>
+             <property name="sizeAdjustPolicy">
+              <enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
+             </property>
+            </widget>
+           </item>
+          </layout>
          </item>
          <item>
-          <widget class="QComboBox" name="parentCombo">
-           <property name="toolTip">
-            <string>Parent Style</string>
-           </property>
-           <property name="sizeAdjustPolicy">
-            <enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
+          <layout class="QHBoxLayout">
+           <property name="spacing">
+            <number>4</number>
            </property>
-          </widget>
+           <item>
+            <widget class="QLabel" name="nextStyleLabel">
+             <property name="text">
+              <string>Next style:</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QComboBox" name="nextStyleCombo">
+             <property name="toolTip">
+              <string>Paragraph style used for the following paragraph</string>
+             </property>
+             <property name="sizeAdjustPolicy">
+              <enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
+             </property>
+            </widget>
+           </item>
+          </layout>
          </item>
          <item>
           <spacer name="horizontalSpacer_10">
@@ -1775,6 +1806,7 @@
  <tabstops>
   <tabstop>tabWidget</tabstop>
   <tabstop>parentCombo</tabstop>
+  <tabstop>nextStyleCombo</tabstop>
   <tabstop>lineSpacingMode</tabstop>
   <tabstop>lineSpacing</tabstop>
   <tabstop>spaceAbove</tabstop>
Index: scribus/ui/smtextstyles.cpp
===================================================================
--- scribus/ui/smtextstyles.cpp	(revision 27875)
+++ scribus/ui/smtextstyles.cpp	(working copy)
@@ -9,6 +9,8 @@
 #include <QMessageBox>
 #include <QTabWidget>
 
+#include <utility>
+
 #include "alignselect.h"
 #include "colorcombo.h"
 #include "commonstrings.h"
@@ -376,34 +378,59 @@
 		m_deleted.append(removeList[i]);
 	}
 
-	// Check other paragraph styles and replace inherited styles if necessary
+	// Repair references from the remaining paragraph styles.
 	for (int i = 0; i < m_tmpStyles.count(); ++i)
 	{
 		ParagraphStyle& parStyle = m_tmpStyles[i];
-		QString parentName = parStyle.parent();
-		if (parentName.isEmpty())
+
+		const QString parentName = parStyle.parent();
+		if (!parentName.isEmpty())
+		{
+			QString replacementName = parentName;
+			for (const RemoveItem& removeItem : removeList)
+			{
+				if (removeItem.first == parentName)
+				{
+					replacementName = removeItem.second;
+					break;
+				}
+			}
+
+			if (replacementName != parentName)
+			{
+				if (replacementName == CommonStrings::trDefaultParagraphStyle)
+					replacementName = CommonStrings::DefaultParagraphStyle;
+				if (!parStyle.canInherit(replacementName))
+					replacementName.clear();
+				if (!replacementName.isEmpty() && m_tmpStyles.find(replacementName) < 0)
+					replacementName.clear();
+				parStyle.setParent(replacementName);
+			}
+		}
+
+		if (parStyle.nextStyleMode() != ParagraphStyle::NamedNextStyle)
 			continue;
 
-		QString replacementName = parentName;
-		for (int j = 0; j < removeList.count(); ++j)
+		const QString nextName = parStyle.nextStyle();
+		QString replacementName = nextName;
+		for (const RemoveItem& removeItem : removeList)
 		{
-			if (removeList.at(j).first == parentName)
+			if (removeItem.first == nextName)
 			{
-				replacementName = removeList.at(j).second;
+				replacementName = removeItem.second;
 				break;
 			}
 		}
 
-		if (replacementName == parentName)
+		if (replacementName == nextName)
 			continue;
 		if (replacementName == CommonStrings::trDefaultParagraphStyle)
 			replacementName = CommonStrings::DefaultParagraphStyle;
-		if (!parStyle.canInherit(replacementName))
-			replacementName = QString();
-		if (!replacementName.isEmpty() && (m_tmpStyles.find(replacementName) < 0))
-			replacementName = QString();
-		parStyle.setParent(replacementName);
+		if (!replacementName.isEmpty() && m_tmpStyles.find(replacementName) < 0)
+			replacementName.clear();
+		parStyle.setNextStyle(replacementName);
 	}
+
 }
 
 void SMParagraphStyle::nameChanged(const QString &newName)
@@ -427,11 +454,13 @@
 		}
 	}
 
-	//When a parent style is renamed, also set the parent style name of the children
+	// When a referenced style is renamed, keep paragraph-style relationships intact.
 	for (int j = 0; j < m_tmpStyles.count(); ++j)
 	{
 		if (m_tmpStyles[j].parent() == oldName)
 			m_tmpStyles[j].setParent(newName);
+		if (m_tmpStyles[j].nextStyleMode() == ParagraphStyle::NamedNextStyle && m_tmpStyles[j].nextStyle() == oldName)
+			m_tmpStyles[j].setNextStyle(newName);
 	}
 
 	for (auto it = m_deleted.begin(); it != m_deleted.end(); ++it)
@@ -538,6 +567,7 @@
 	connect(m_pwidget->tabList->firstLineSpin, SIGNAL(valueChanged(double)), this, SLOT(slotFirstLine()));
 
 	connect(m_pwidget->parentCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(slotParentChanged(QString)));
+	connect(m_pwidget->nextStyleCombo, SIGNAL(activated(int)), this, SLOT(slotNextStyleChanged(int)));
 	connect(m_pwidget->backgroundColor->colorButton, SIGNAL(colorChanged()), this, SLOT(slotBackPColor()));
 	connect(m_pwidget->backgroundColor->parentButton, SIGNAL(clicked()), this, SLOT(slotBackPColor()));
 
@@ -622,6 +652,7 @@
 	disconnect(m_pwidget->numNewLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSelectionDirty()));
 	
 	disconnect(m_pwidget->parentCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(slotParentChanged(QString)));
+	disconnect(m_pwidget->nextStyleCombo, SIGNAL(activated(int)), this, SLOT(slotNextStyleChanged(int)));
 
 	disconnect(m_pwidget->keepLinesStart, SIGNAL(valueChanged(int)), this, SLOT(handleKeepLinesStart()));
 	disconnect(m_pwidget->keepLinesEnd, SIGNAL(valueChanged(int)), this, SLOT(handleKeepLinesEnd()));
@@ -1768,6 +1799,36 @@
 
 	slotSelectionDirty();
 }
+
+void SMParagraphStyle::slotNextStyleChanged(int index)
+{
+	if (index < 0 || m_selection.isEmpty())
+		return;
+
+	const int modeValue = m_pwidget->nextStyleCombo->itemData(index, Qt::UserRole).toInt();
+	if (modeValue < static_cast<int>(ParagraphStyle::NoNextStyle) || modeValue > static_cast<int>(ParagraphStyle::NamedNextStyle))
+		return;
+
+	const auto mode = static_cast<ParagraphStyle::NextStyleMode>(modeValue);
+	const QString styleName = m_pwidget->nextStyleCombo->itemData(index, Qt::UserRole + 1).toString();
+	for (ParagraphStyle* style : std::as_const(m_selection))
+	{
+		switch (mode)
+		{
+			case ParagraphStyle::NoNextStyle:
+				style->clearNextStyle();
+				break;
+			case ParagraphStyle::SameStyle:
+				style->setNextStyleMode(ParagraphStyle::SameStyle);
+				break;
+			case ParagraphStyle::NamedNextStyle:
+				style->setNextStyle(styleName);
+				break;
+		}
+	}
+
+	slotSelectionDirty();
+}
 
 void SMParagraphStyle::slotCharParentChanged(const QString &parent)
 {
Index: scribus/ui/smtextstyles.h
===================================================================
--- scribus/ui/smtextstyles.h	(revision 27875)
+++ scribus/ui/smtextstyles.h	(working copy)
@@ -127,6 +127,7 @@
 	void slotBaselineOffset();
 	void slotFont(const QString& s);
 	void slotParentChanged(const QString &parent);
+	void slotNextStyleChanged(int index);
 	void slotCharParentChanged(const QString &parent);
 	void slotFontFeatures();
 	void slotCharStylesDeleted(const QList<RemoveItem> &removeList);
Index: scribus/ui/stylemanager.cpp
===================================================================
--- scribus/ui/stylemanager.cpp	(revision 27875)
+++ scribus/ui/stylemanager.cpp	(working copy)
@@ -710,21 +710,26 @@
 		QStringList neededOpticalMarginSets;
 		neededOpticalMarginSets.clear();
 
+		QMap<QString, QString> importedParagraphStyleNames;
 		foreach (const QString& aStyle, dia2->paragraphStyles())
 		{
-			ParagraphStyle& sty(tmpParaStyles[tmpParaStyles.find(aStyle)]);
+			const int sourceIndex = tmpParaStyles.find(aStyle);
+			if (sourceIndex < 0)
+				continue;
+
+			ParagraphStyle sty(tmpParaStyles[sourceIndex]);
+			const QString sourceName = sty.name();
+			QString destinationName = sourceName;
 			if (dia2->clashRename())
-			{
-				sty.setName(pstyle->getUniqueName(sty.name()));
-				pstyle->tmpStyles().create(sty);
-			}
+				destinationName = pstyle->getUniqueName(sourceName);
+
+			sty.setName(destinationName);
+			if (!dia2->clashRename() && pstyle->tmpStyles().find(destinationName) >= 0)
+				pstyle->tmpStyles()[pstyle->tmpStyles().find(destinationName)] = sty;
 			else
-			{
-				if (pstyle->tmpStyles().find(sty.name()) >= 0)
-					(pstyle->tmpStyles())[pstyle->tmpStyles().find(/*it.data()*/aStyle)] = sty;
-				else
-					pstyle->tmpStyles().create(sty);
-			}
+				pstyle->tmpStyles().create(sty);
+			importedParagraphStyleNames.insert(sourceName, destinationName);
+
 //#7315 				selected << QPair<QString, QString>(pstyle->typeName(), sty.name());
 			if ((!m_doc->PageColors.contains(sty.charStyle().strokeColor())) && (!neededColors.contains(sty.charStyle().strokeColor())))
 				neededColors.append(sty.charStyle().strokeColor());
@@ -735,6 +740,26 @@
 				neededOpticalMarginSets.append(sty.opticalMarginSetId());
 		}
 
+		// Next Style may point forward or form a cycle, so remap it only after
+		// every selected paragraph style has received its final destination name.
+		for (auto it = importedParagraphStyleNames.cbegin(); it != importedParagraphStyleNames.cend(); ++it)
+		{
+			const int styleIndex = pstyle->tmpStyles().find(it.value());
+			if (styleIndex < 0)
+				continue;
+
+			ParagraphStyle& importedStyle = pstyle->tmpStyles()[styleIndex];
+			if (importedStyle.nextStyleMode() != ParagraphStyle::NamedNextStyle)
+				continue;
+
+			const QString sourceTarget = importedStyle.nextStyle();
+			const auto mappedTarget = importedParagraphStyleNames.constFind(sourceTarget);
+			if (mappedTarget != importedParagraphStyleNames.cend())
+				importedStyle.setNextStyle(mappedTarget.value());
+			else if (pstyle->tmpStyles().find(sourceTarget) < 0)
+				importedStyle.clearNextStyle();
+		}
+
 		foreach (const QString& aStyle, dia2->characterStyles())
 		{
 			CharStyle& sty(tmpCharStyles[tmpCharStyles.find(/*it.data()*/aStyle)]);
ns2-apply-next-styles-v1.02.patch (13,188 bytes)   
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp
+++ scribus/scribusdoc.cpp
@@ -8218,6 +8218,135 @@
 	itemSelection_ApplyParagraphStyle(newStyle, customSelection, false);
 }
 
+bool ScribusDoc::itemSelection_HasMultiParagraphTextSelection(Selection* customSelection) const
+{
+	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+	if (!itemSelection || itemSelection->count() != 1)
+		return false;
+	if (appMode != modeEdit && appMode != modeEditTable)
+		return false;
+
+	PageItem* currItem = itemSelection->itemAt(0);
+	if (currItem->isTable() && appMode == modeEditTable)
+		currItem = currItem->asTable()->activeCell().textFrame();
+
+	const StoryText& story = currItem->itemText;
+	if (!story.hasSelection())
+		return false;
+
+	const int start = story.startOfSelection();
+	const int stop = story.endOfSelection();
+	for (int pos = start; pos < stop; ++pos)
+	{
+		if (story.text(pos) == SpecialChars::PARSEP)
+			return true;
+	}
+	return false;
+}
+
+void ScribusDoc::itemSelection_SetNamedParagraphStyleWithNextStyles(const QString& name, Selection* customSelection)
+{
+	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+	if (!itemSelection_HasMultiParagraphTextSelection(itemSelection))
+		return;
+
+	PageItem* currItem = itemSelection->itemAt(0);
+	if (currItem->isTable() && appMode == modeEditTable)
+		currItem = currItem->asTable()->activeCell().textFrame();
+
+	StoryText& story = currItem->itemText;
+	const int start = story.startOfSelection();
+	const int stop = story.endOfSelection();
+
+	QList<int> paragraphPositions;
+	for (int pos = start; pos < stop; ++pos)
+	{
+		if (story.text(pos) == SpecialChars::PARSEP)
+			paragraphPositions.append(pos);
+	}
+	paragraphPositions.append(stop);
+
+	QString currentStyleName = name;
+	if (currentStyleName.isEmpty() && m_docParagraphStyles.getDefault())
+		currentStyleName = m_docParagraphStyles.getDefault()->name();
+
+	int styleIndex = m_docParagraphStyles.find(currentStyleName);
+	if (styleIndex < 0)
+		return;
+
+	UndoTransaction activeTransaction;
+	if (UndoManager::undoEnabled())
+	{
+		const ParagraphStyle& firstStyle = m_docParagraphStyles[styleIndex];
+		activeTransaction = m_undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(), Um::ApplyTextStyle, firstStyle.displayName(), Um::IFont);
+	}
+
+	for (int paragraphPos : std::as_const(paragraphPositions))
+	{
+		styleIndex = m_docParagraphStyles.find(currentStyleName);
+		if (styleIndex < 0)
+			break;
+
+		const ParagraphStyle& styleDefinition = m_docParagraphStyles[styleIndex];
+		ParagraphStyle newStyle;
+		newStyle.setParent(currentStyleName);
+
+		// A numbered or bulleted paragraph caches its generated marker string.
+		// Clear only the paragraph that is actually being changed; a chain that
+		// stops at None must leave the rest of the selection untouched.
+		const uint paragraphIndex = story.nrOfParagraph(paragraphPos);
+		const int paragraphStart = story.startOfParagraph(paragraphIndex);
+		const int paragraphEnd = story.endOfParagraph(paragraphIndex);
+		for (int pos = paragraphStart; pos < paragraphEnd; ++pos)
+		{
+			if (!story.hasMark(pos))
+				continue;
+			Mark* mark = story.mark(pos);
+			if (!mark->isType(MARKBullNumType))
+				continue;
+			if (UndoManager::undoEnabled())
+			{
+				auto *is = new ScItemState<QPair<int, QString>>(Um::SetStyle);
+				is->set("CLEARMARKSTRING");
+				is->setItem(qMakePair(pos, mark->getString()));
+				m_undoManager->action(currItem, is);
+			}
+			mark->setString(QString());
+		}
+
+		if (UndoManager::undoEnabled())
+		{
+			auto *is = new ScOldNewState<ParagraphStyle>(Um::SetStyle);
+			is->set("APPLY_PARASTYLE");
+			is->set("POS", paragraphPos);
+			is->setStates(story.paragraphStyle(paragraphPos), newStyle);
+			m_undoManager->action(currItem, is);
+		}
+		story.applyStyle(paragraphPos, newStyle, false);
+
+		const QString nextStyleName = styleDefinition.nextStyle();
+		if (nextStyleName.isEmpty() || m_docParagraphStyles.find(nextStyleName) < 0)
+			break;
+		currentStyleName = nextStyleName;
+	}
+
+	flag_Renumber = true;
+	currItem->invalid = true;
+	if (currItem->isPathText())
+		currItem->updatePolyClip();
+	if (currItem->isNoteFrame())
+		currItem->asNoteFrame()->updateNotesText();
+	else if (currItem->isTextFrame() && currItem->asTextFrame()->hasNoteFrame(nullptr, true))
+		setNotesChanged(true);
+	currItem->invalidateLayout();
+
+	if (activeTransaction)
+		activeTransaction.commit();
+	changed();
+	regionsChanged()->update(QRectF());
+	changedPagePreview();
+}
+
 void ScribusDoc::itemSelection_SetNamedLineStyle(const QString &name, Selection* customSelection)
 {
 	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h
+++ scribus/scribusdoc.h
@@ -1179,6 +1179,8 @@
 		void itemSelection_EraseParagraphStyle(Selection* customSelection = nullptr);
 		void itemSelection_EraseCharStyle(Selection* customSelection = nullptr);
 		void itemSelection_SetNamedParagraphStyle(const QString & name, Selection* customSelection = nullptr);
+		bool itemSelection_HasMultiParagraphTextSelection(Selection* customSelection = nullptr) const;
+		void itemSelection_SetNamedParagraphStyleWithNextStyles(const QString& name, Selection* customSelection = nullptr);
 		void itemSelection_SetNamedCharStyle(const QString & name, Selection* customSelection = nullptr);
 		void itemSelection_SetNamedLineStyle(const QString & name, Selection* customSelection = nullptr);
 		void itemSelection_SetNamedCellStyle(const QString & name, Selection* customSelection = nullptr);
Index: scribus/ui/smtextstyles.cpp
===================================================================
--- scribus/ui/smtextstyles.cpp
+++ scribus/ui/smtextstyles.cpp
@@ -209,18 +209,35 @@
 	if (!m_doc)
 		return; // nowhere to apply or no doc
 
-	QString realName = styleName;
-	int styleIndex = m_tmpStyles.find(styleName);
-	if (styleIndex < 0 && (styleName == CommonStrings::trDefaultParagraphStyle))
-	{
-		styleIndex = m_tmpStyles.find(CommonStrings::DefaultParagraphStyle);
-		if (styleIndex >= 0)
-			realName = CommonStrings::DefaultParagraphStyle;
-	}
-	if (styleIndex >= 0)
-	{
+	const QString realName = resolveStyleName(styleName);
+	if (!realName.isNull())
 		m_doc->itemSelection_SetNamedParagraphStyle(realName);
-	}
+}
+
+bool SMParagraphStyle::canApplyNextStyles() const
+{
+	return m_doc && m_doc->itemSelection_HasMultiParagraphTextSelection();
+}
+
+void SMParagraphStyle::toSelectionWithNextStyles(const QString& styleName) const
+{
+	if (!m_doc)
+		return;
+
+	const QString realName = resolveStyleName(styleName);
+	if (!realName.isNull())
+		m_doc->itemSelection_SetNamedParagraphStyleWithNextStyles(realName);
+}
+
+QString SMParagraphStyle::resolveStyleName(const QString& styleName) const
+{
+	if (m_tmpStyles.find(styleName) >= 0)
+		return styleName;
+
+	if (styleName == CommonStrings::trDefaultParagraphStyle && m_tmpStyles.find(CommonStrings::DefaultParagraphStyle) >= 0)
+		return CommonStrings::DefaultParagraphStyle;
+
+	return QString();
 }
 
 QString SMParagraphStyle::newStyle()
Index: scribus/ui/smtextstyles.h
===================================================================
--- scribus/ui/smtextstyles.h
+++ scribus/ui/smtextstyles.h
@@ -34,6 +34,8 @@
 	void selected(const QStringList &styleNames) override;
 	QString fromSelection() const override;
 	void toSelection(const QString &styleName) const override;
+	bool canApplyNextStyles() const;
+	void toSelectionWithNextStyles(const QString& styleName) const;
 	QString newStyle() override;
 	QString newStyle(const QString &fromStyle) override;
 	void apply() override;
@@ -68,6 +70,7 @@
 	void updateStyleList();
 	void reloadTmpStyles();
 	QList<CharStyle> getCharStyles() const;
+	QString resolveStyleName(const QString& styleName) const;
 
 private slots:
 	// pstyle
Index: scribus/ui/stylemanager.cpp
===================================================================
--- scribus/ui/stylemanager.cpp
+++ scribus/ui/stylemanager.cpp
@@ -8,6 +8,7 @@
 #include <QDebug>
 #include <QEvent>
 #include <QHash>
+#include <QAction>
 #include <QSet>
 #include <QMenu>
 #include <QToolTip>
@@ -49,6 +50,8 @@
 	m_layout = new QGridLayout(mainFrame);
 	m_newPopup = new QMenu(newButton);
 	m_rightClickPopup = new QMenu(styleView);
+	m_applyNextStylesAction = new QAction(this);
+	connect(m_applyNextStylesAction, &QAction::triggered, this, &StyleManager::slotApplyNextStyles);
 	newButton->setMenu(m_newPopup);
 	QString pname(name);
 	if (pname.isEmpty())
@@ -1073,6 +1076,7 @@
 	StyleViewItem *item = static_cast<StyleViewItem*>(styleView->currentItem());
 	m_rcStyle.clear();
 	m_rcType.clear();
+	m_rightClickPopup->removeAction(m_applyNextStylesAction);
 
 	if (m_isEditMode && item) // make item the only selection if in edit mode
 	{                        // default behaviour for right clicking is not to select the item
@@ -1113,6 +1117,26 @@
 
 		// Added last so that it ends up above the apply entry.
 		setNewMenuEntry(tr("New %1").arg(m_styleClassesPS[item->rootName()]));
+
+		if (styleView->selectedItems().count() == 1 && m_selectedStyleAction)
+		{
+			const bool hasPendingStyleEdits = m_isEditMode && resetButton->isEnabled();
+			m_selectedStyleAction->setEnabled(!hasPendingStyleEdits);
+
+			auto *paragraphItem = qobject_cast<SMParagraphStyle*>(m_item);
+			if (paragraphItem)
+			{
+				QString styleLabel = m_rcStyle;
+				styleLabel.replace(QStringLiteral("&"), QStringLiteral("&&"));
+				m_applyNextStylesAction->setText(tr("Apply \"%1\" + Next Styles").arg(styleLabel));
+				m_applyNextStylesAction->setEnabled(!hasPendingStyleEdits && paragraphItem->canApplyNextStyles());
+
+				const QList<QAction*> actions = m_rightClickPopup->actions();
+				const int applyIndex = actions.indexOf(m_selectedStyleAction);
+				QAction* before = (applyIndex >= 0 && applyIndex + 1 < actions.count()) ? actions.at(applyIndex + 1) : nullptr;
+				m_rightClickPopup->insertAction(before, m_applyNextStylesAction);
+			}
+		}
 	}
 	else if (item && item->isRoot())
 	{
@@ -1146,6 +1170,18 @@
 	}
 
 	m_rightClickPopup->exec(styleView->mapToGlobal(point));
+
+	// m_selectedStyleAction is shared with shortcut handling, so any temporary
+	// context-menu disablement must not survive after the popup closes. The
+	// execution slot itself still rejects application while the editor is dirty.
+	if (m_selectedStyleAction)
+		m_selectedStyleAction->setEnabled(true);
+
+	// Right-click target state is only valid while the popup is active. Leaving
+	// it set after dismissing the menu makes later edit-widget selection resolve
+	// to the old context-menu target instead of the actual tree selection.
+	m_rcStyle.clear();
+	m_rcType.clear();
 }
 
 void StyleManager::slotDoubleClick(QTreeWidgetItem *item, /*const QPoint &point, */int col)
@@ -1676,7 +1712,11 @@
 
 void StyleManager::slotApplyStyle(const QString& keyString)
 {
-	if (m_isEditMode)
+	// In edit mode the temporary style set can contain unapplied definitions.
+	// Applying a style against the document's older definition would be
+	// surprising, but a clean editor is safe: the temporary and document style
+	// definitions are identical.
+	if (m_isEditMode && resetButton->isEnabled())
 		return;
 
 	QStringList slist = keyString.split(SEPARATOR, Qt::SkipEmptyParts);
@@ -1687,6 +1727,28 @@
 	slotDocSelectionChanged();
 
 	m_rcStyle.clear();
+	m_rcType.clear();
+}
+
+void StyleManager::slotApplyNextStyles()
+{
+	if (m_rcStyle.isEmpty())
+		return;
+
+	// In edit mode the temporary style set may contain unapplied definitions.
+	// Applying a chain against the document's older definitions would be
+	// surprising, so allow the action only while the editor is clean.
+	if (m_isEditMode && resetButton->isEnabled())
+		return;
+
+	auto *paragraphItem = qobject_cast<SMParagraphStyle*>(m_item);
+	if (!paragraphItem || !paragraphItem->canApplyNextStyles())
+		return;
+
+	paragraphItem->toSelectionWithNextStyles(m_rcStyle);
+	slotDocSelectionChanged();
+
+	m_rcStyle.clear();
 	m_rcType.clear();
 }
 
Index: scribus/ui/stylemanager.h
===================================================================
--- scribus/ui/stylemanager.h
+++ scribus/ui/stylemanager.h
@@ -12,6 +12,7 @@
 #include <QPointer>
 #include <QSet>
 
+class QAction;
 class QEvent;
 
 #include "styleitem.h"
@@ -78,6 +79,7 @@
 	QString             m_currentType;
 	QMenu              *m_newPopup { nullptr };
 	QMenu              *m_rightClickPopup { nullptr };
+	QAction            *m_applyNextStylesAction { nullptr };
 
 	QAction            *m_rcpNewId { nullptr };
 	QAction            *m_rcpDeleteId { nullptr };
@@ -213,6 +215,7 @@
 	void slotApplyStyle(QTreeWidgetItem *item);
 	void slotApplyStyle(QTreeWidgetItem *newitem, QTreeWidgetItem *olditem);
 	void slotApplyStyle(QTreeWidgetItem *item, int column);
+	void slotApplyNextStyles();
 
 	void slotDocSelectionChanged();
 	void slotDocStylesChanged();
ns3-next-style-on-enter-v1.00.patch (6,412 bytes)   
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp	(revision 27875)
+++ scribus/pageitem.cpp	(working copy)
@@ -7193,6 +7193,12 @@
 	else
 	{
 		itemText.insertChars(start, SpecialChars::PARSEP);
+		if (ss->contains("NEXT_PARASTYLE"))
+		{
+			ParagraphStyle nextStyle;
+			nextStyle.setParent(ss->get("NEXT_PARASTYLE"));
+			itemText.applyStyle(start + 1, nextStyle, false);
+		}
 		itemText.setCursorPosition(start + 1);
 		invalid = true;
 		invalidateLayout();
Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 27875)
+++ scribus/pageitem_textframe.cpp	(working copy)
@@ -4585,18 +4585,24 @@
 		}
 		else if ((as > 31) || (as == 13) || (as == 30))
 		{
+			const int cursorPos = itemText.cursorPosition();
+			QString nextStyleName;
+			if (uc[0] == SpecialChars::PARSEP)
+				nextStyleName = m_Doc->nextParagraphStyleName(itemText.paragraphStyle(cursorPos));
+
 			if (UndoManager::undoEnabled())
 			{
 				ScItemState<ParagraphStyle> *ip = nullptr;
 				SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
 				UndoObject *undoTarget = this;
-				int cursorPos = itemText.cursorPosition();
 				if (uc[0] == SpecialChars::PARSEP)
 				{
 					ip = new ScItemState<ParagraphStyle>(Um::InsertText, "", Um::ICreate);
 					ip->set("INSERT_FRAMEPARA");
 					ip->set("ETEA", QString("insert_framepara"));
 					ip->set("START", cursorPos);
+					if (!nextStyleName.isEmpty())
+						ip->set("NEXT_PARASTYLE", nextStyleName);
 					ip->setItem(itemText.paragraphStyle(cursorPos));
 					if (isNoteFrame())
 					{
@@ -4623,6 +4629,13 @@
 				}
 			}
 			itemText.insertChars(uc, true);
+			if (!nextStyleName.isEmpty())
+			{
+				ParagraphStyle nextStyle;
+				nextStyle.setParent(nextStyleName);
+				itemText.applyStyle(cursorPos + 1, nextStyle, false);
+				m_Doc->scMW()->setTBvals(this);
+			}
 			if ((m_Doc->docHyphenator->autoCheck()) && (itemText.cursorPosition() > 1))
 			{
 				Twort = "";
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 27875)
+++ scribus/scribusdoc.cpp	(working copy)
@@ -8218,6 +8218,23 @@
 	itemSelection_ApplyParagraphStyle(newStyle, customSelection, false);
 }
 
+QString ScribusDoc::nextParagraphStyleName(const ParagraphStyle& currentStyle) const
+{
+	QString currentStyleName = currentStyle.parent();
+	if (currentStyleName.isEmpty() || currentStyleName == BaseStyle::INHERIT_PARENT)
+		currentStyleName = CommonStrings::DefaultParagraphStyle;
+
+	const int styleIndex = m_docParagraphStyles.find(currentStyleName);
+	if (styleIndex < 0)
+		return QString();
+
+	const QString nextStyleName = m_docParagraphStyles[styleIndex].nextStyle();
+	if (nextStyleName.isEmpty() || m_docParagraphStyles.find(nextStyleName) < 0)
+		return QString();
+
+	return nextStyleName;
+}
+
 bool ScribusDoc::itemSelection_HasMultiParagraphTextSelection(Selection* customSelection) const
 {
 	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 27875)
+++ scribus/scribusdoc.h	(working copy)
@@ -1179,6 +1179,7 @@
 		void itemSelection_EraseParagraphStyle(Selection* customSelection = nullptr);
 		void itemSelection_EraseCharStyle(Selection* customSelection = nullptr);
 		void itemSelection_SetNamedParagraphStyle(const QString & name, Selection* customSelection = nullptr);
+		QString nextParagraphStyleName(const ParagraphStyle& currentStyle) const;
 		bool itemSelection_HasMultiParagraphTextSelection(Selection* customSelection = nullptr) const;
 		void itemSelection_SetNamedParagraphStyleWithNextStyles(const QString& name, Selection* customSelection = nullptr);
 		void itemSelection_SetNamedCharStyle(const QString & name, Selection* customSelection = nullptr);
Index: scribus/ui/storyeditor.cpp
===================================================================
--- scribus/ui/storyeditor.cpp	(revision 27875)
+++ scribus/ui/storyeditor.cpp	(working copy)
@@ -74,6 +74,7 @@
 #include "scraction.h"
 #include "scribusapp.h"
 #include "scribuscore.h"
+#include "scribusdoc.h"
 #include "scribusview.h"
 #include "scrspinbox.h"
 #include "search.h"
@@ -422,7 +423,7 @@
 				if (k->modifiers() == Qt::ShiftModifier)
 					insertChars(SpecialChars::LINEBREAK, k->text());
 				else
-					insertChars(SpecialChars::PARSEP, k->text());
+					insertParagraph(k->text());
 				emit SideBarUp(true);
 				emit SideBarUpdate();
 				return;
@@ -528,6 +529,36 @@
 	--blockContentsChangeHook;
 }
 
+void SEditor::insertParagraph(const QString& editText)
+{
+	QTextCursor cursor = textCursor();
+	if (cursor.hasSelection())
+	{
+		cursor.removeSelectedText();
+		setTextCursor(cursor);
+	}
+
+	const int pos = qMin(textCursor().position(), StyledText.length());
+	const QString nextStyleName = doc ? doc->nextParagraphStyleName(StyledText.paragraphStyle(pos)) : QString();
+
+	insertChars(SpecialChars::PARSEP, editText);
+	if (nextStyleName.isEmpty())
+		return;
+
+	ParagraphStyle nextStyle;
+	nextStyle.setParent(nextStyleName);
+	StyledText.applyStyle(pos + 1, nextStyle, false);
+
+	// Keep the Story Editor's QTextDocument block presentation in step with
+	// its authoritative StyledText paragraph style, including an empty new paragraph.
+	QTextCursor paragraphCursor = textCursor();
+	paragraphCursor.setPosition(qMin(pos + 1, StyledText.length()));
+	const ParagraphStyle& appliedStyle = StyledText.paragraphStyle(pos + 1);
+	setAlign(paragraphCursor, appliedStyle.alignment());
+	setDirection(paragraphCursor, appliedStyle.direction());
+	setTextCursor(paragraphCursor);
+}
+
 void SEditor::insertChars(const QString& styledText, const QString& editText)
 {
 	if ((styledText.length() == editText.length()) && !styledText.isEmpty())
Index: scribus/ui/storyeditor.h
===================================================================
--- scribus/ui/storyeditor.h	(revision 27875)
+++ scribus/ui/storyeditor.h	(working copy)
@@ -109,6 +109,7 @@
 
 	void insertChars(const QString& text);
 	void insertChars(const QString& styledText, const QString& editText);
+	void insertParagraph(const QString& editText);
 
 	StoryText StyledText;
 

buttar

2026-10-05 11:16

reporter   ~0054511

For the demo, I chose the loop but it can do more:

- Set Next Style to None, Same Style, or another paragraph style.
- Press Enter to automatically apply the configured next style.
- Apply a whole style chain across selected paragraphs with Apply “X” + Next Styles.
- Use self-loops for repeated styles such as Body → Body.
- Use cycles such as Question → Answer → Question.
- Stop a bulk chain when the next style is set to `None`, leaving later selected paragraphs unchanged.
- Undo/redo chained application as one action.
- Works in canvas editing and Story Editor.
- Handles mid-paragraph Enter correctly.
- Preserves chains through save/load, rename, clone, delete/replacement and style import.
- Keeps normal Apply, Shift+Enter, paste and generic paragraph insertion unchanged.

Issue History

Date Modified Username Field Change
2011-03-27 05:33 alexandre New Issue
2011-03-28 08:48 jirib Note Added: 0025964
2011-03-28 09:54 cezaryece Note Added: 0025965
2012-10-27 12:08 ale Relationship added has duplicate 0011131
2016-04-25 11:58 Kunda Patch => No
2016-04-25 11:58 Kunda Severity minor => feature
2016-04-25 12:06 Kunda Category General => Styles
2016-05-18 14:00 jghali Relationship added has duplicate 0014079
2025-07-16 20:23 Nathan Note Added: 0052903
2025-07-17 05:54 ale Note Added: 0052904
2025-07-17 15:01 Nathan Note Added: 0052906
2025-07-17 16:27 ale Note Added: 0052907
2026-10-05 11:11 buttar Note Added: 0054510
2026-10-05 11:11 buttar File Added: ns1-next-style-foundation-v1.03.patch
2026-10-05 11:11 buttar File Added: ns2-apply-next-styles-v1.02.patch
2026-10-05 11:11 buttar File Added: ns3-next-style-on-enter-v1.00.patch
2026-10-05 11:11 buttar File Added: next-style-loop-demo.mp4
2026-10-05 11:16 buttar Note Added: 0054511
2026-10-05 11:18 buttar Tag Attached: #please_test