Author: jghali
Date: Wed Oct  9 03:19:13 2019
New Revision: 23240

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23240
Log:
#15841: When cloning a style, add a number instead of prepending "Clone of"

Modified:
    trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
    
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
    
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/styles/styleset.h
    trunk/Scribus/scribus/ui/smcellstyle.cpp
    trunk/Scribus/scribus/ui/smlinestyle.cpp
    trunk/Scribus/scribus/ui/smtablestyle.cpp
    trunk/Scribus/scribus/ui/smtextstyles.cpp

Modified: 
trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
==============================================================================
--- 
trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp    
    (original)
+++ 
trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp    
    Wed Oct  9 03:19:13 2019
@@ -2252,8 +2252,9 @@
        QString fColor, sColor;
        QString tmpf;
        double xf, xf2;
-       bool fou = false;
+       bool found = false;
        const StyleSet<ParagraphStyle> & 
docParagraphStyles(tempParagraphStyles? *tempParagraphStyles : 
doc->paragraphStyles());
+
        vg->setName(pg->attribute("NAME"));
        
vg->setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(pg->attribute("LINESPMode",
 "0").toInt()));
        vg->setLineSpacing(ScCLocale::toDoubleC(pg->attribute("LINESP")));
@@ -2313,7 +2314,7 @@
                        tbs.append(tb);
                }
                vg->setTabValues(tbs);
-               tmp = "";
+               tmp.clear();
        }
        else
        {
@@ -2336,49 +2337,51 @@
                                tbs.append(tb);
                        }
                        vg->setTabValues(tbs);
-                       IT=IT.nextSibling();
-               }
-       }
-       for (int xx=0; xx<docParagraphStyles.count(); ++xx)
-       {
-               if (vg->name() == docParagraphStyles[xx].name())
+                       IT = IT.nextSibling();
+               }
+       }
+       for (int i = 0; i < docParagraphStyles.count(); ++i)
+       {
+               const ParagraphStyle& paraStyle = docParagraphStyles[i];
+               if (vg->name() == paraStyle.name())
                {
                        //Compare the attributes of the pasted styles vs 
existing ones
-                       if (vg->equiv(docParagraphStyles[xx]))
+                       if (vg->equiv(paraStyle))
                        {
                                if (fl)
                                {
-                                       DoVorl[VorlC] = 
docParagraphStyles[xx].name();
+                                       DoVorl[VorlC] = paraStyle.name();
                                        VorlC++;
                                }
-                               fou = true;
+                               found = true;
                        }
                        else
                        {
-                               vg->setName("Copy of 
"+docParagraphStyles[xx].name());
-                               fou = false;
+                               
vg->setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
+                               found = false;
                        }
                        break;
                }
        }
-       if (!fou)
-       {
-               for (int xx=0; xx< docParagraphStyles.count(); ++xx)
-               {
-                       if (vg->equiv(docParagraphStyles[xx]))
+       if (!found)
+       {
+               for (int i = 0; i < docParagraphStyles.count(); ++i)
+               {
+                       const ParagraphStyle& paraStyle = docParagraphStyles[i];
+                       if (vg->equiv(paraStyle))
                        {
-                               vg->setName(docParagraphStyles[xx].name());
-                               fou = true;
+                               vg->setName(paraStyle.name());
+                               found = true;
                                if (fl)
                                {
-                                       DoVorl[VorlC] = 
docParagraphStyles[xx].name();
+                                       DoVorl[VorlC] = paraStyle.name();
                                        VorlC++;
                                }
                                break;
                        }
                }
        }
-       if (!fou)
+       if (!found)
        {
                if (tempParagraphStyles)
                        tempParagraphStyles->create(*vg);

Modified: 
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- 
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp  
    (original)
+++ 
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp  
    Wed Oct  9 03:19:13 2019
@@ -3493,13 +3493,14 @@
 void Scribus134Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& 
reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
 {
        bool  found(false);
-       const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? 
tempStyles : & doc->paragraphStyles();
+       const StyleSet<ParagraphStyle> &docParagraphStyles = tempStyles ? 
*tempStyles : doc->paragraphStyles();
        readParagraphStyle(doc, reader, style);
-       for (int xx=0; xx<docParagraphStyles->count(); ++xx)
-       {
-               if (style.name() == (*docParagraphStyles)[xx].name())
-               {
-                       if (style.equiv((*docParagraphStyles)[xx]))
+       for (int i = 0; i < docParagraphStyles.count(); ++i)
+       {
+               const ParagraphStyle& paraStyle = docParagraphStyles[i];
+               if (style.name() == paraStyle.name())
+               {
+                       if (style.equiv(paraStyle))
                        {
                                if (fl)
                                {
@@ -3510,7 +3511,7 @@
                        }
                        else
                        {
-                               style.setName("Copy of 
"+(*docParagraphStyles)[xx].name());
+                               
style.setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
                                found = false;
                        }
                        break;
@@ -3518,12 +3519,13 @@
        }
        if (!found && fl)
        {
-               for (int xx=0; xx < docParagraphStyles->count(); ++xx)
-               {
-                       if (style.equiv((*docParagraphStyles)[xx]))
-                       {
-                               parStyleMap[style.name()] = 
(*docParagraphStyles)[xx].name();
-                               style.setName((*docParagraphStyles)[xx].name());
+               for (int i = 0; i < docParagraphStyles.count(); ++i)
+               {
+                       const ParagraphStyle& paraStyle = docParagraphStyles[i];
+                       if (style.equiv(paraStyle))
+                       {
+                               parStyleMap[style.name()] = paraStyle.name();
+                               style.setName(paraStyle.name());
                                legacyStyleMap[legacyStyleCount] = style.name();
                                legacyStyleCount++;
                                found = true;

Modified: 
trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
==============================================================================
--- 
trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp    
    (original)
+++ 
trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp    
    Wed Oct  9 03:19:13 2019
@@ -2516,38 +2516,40 @@
 
 void Scribus13Format::GetStyle(QDomElement *pg, ParagraphStyle *vg, 
StyleSet<ParagraphStyle> *tempParagraphStyles, ScribusDoc* doc, bool fl)
 {
-       bool fou = false;
+       bool found = false;
        readParagraphStyle(*vg, *pg, doc);
-       const StyleSet<ParagraphStyle> & 
docParagraphStyles(tempParagraphStyles? *tempParagraphStyles : 
doc->paragraphStyles());
-       for (int xx=0; xx<docParagraphStyles.count(); ++xx)
-       {
-               if (vg->name() == docParagraphStyles[xx].name())
-               {
-                       if (vg->equiv(docParagraphStyles[xx]))
+       const StyleSet<ParagraphStyle> & docParagraphStyles(tempParagraphStyles 
? *tempParagraphStyles : doc->paragraphStyles());
+       for (int i = 0; i < docParagraphStyles.count(); ++i)
+       {
+               const ParagraphStyle& paraStyle = docParagraphStyles[i];
+               if (vg->name() == paraStyle.name())
+               {
+                       if (vg->equiv(paraStyle))
                        {
                                if (fl)
                                {
                                        DoVorl[VorlC] = vg->name();
                                        ++VorlC;
                                }
-                               fou = true;
+                               found = true;
                        }
                        else
                        {
-                               vg->setName("Copy of 
"+docParagraphStyles[xx].name());
-                               fou = false;
+                               
vg->setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
+                               found = false;
                        }
                        break;
                }
        }
-       if (!fou)
-       {
-               for (int xx=0; xx< docParagraphStyles.count(); ++xx)
-               {
-                       if (vg->equiv(docParagraphStyles[xx]))
-                       {
-                               vg->setName(docParagraphStyles[xx].name());
-                               fou = true;
+       if (!found)
+       {
+               for (int i = 0; i < docParagraphStyles.count(); ++i)
+               {
+                       const ParagraphStyle& paraStyle = docParagraphStyles[i];
+                       if (vg->equiv(paraStyle))
+                       {
+                               vg->setName(paraStyle.name());
+                               found = true;
                                if (fl)
                                {
                                        DoVorl[VorlC] = vg->name();
@@ -2557,7 +2559,7 @@
                        }
                }
        }
-       if (!fou)
+       if (!found)
        {
                if (tempParagraphStyles)
                        tempParagraphStyles->create(*vg);

Modified: 
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- 
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp  
    (original)
+++ 
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp  
    Wed Oct  9 03:19:13 2019
@@ -6599,20 +6599,20 @@
 void Scribus150Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& 
reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
 {
        bool  found(false);
-       const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? 
tempStyles : & doc->paragraphStyles();
-       //UNUSED: PrefsManager& prefsManager = PrefsManager::instance();
+       const StyleSet<ParagraphStyle> &docParagraphStyles = tempStyles ? 
*tempStyles : doc->paragraphStyles();
        readParagraphStyle(doc, reader, style);
-       for (int xx=0; xx<docParagraphStyles->count(); ++xx)
-       {
-               if (style.name() == (*docParagraphStyles)[xx].name())
-               {
-                       if (style.equiv((*docParagraphStyles)[xx]))
+       for (int xx = 0; xx < docParagraphStyles.count(); ++xx)
+       {
+               const ParagraphStyle& paraStyle = docParagraphStyles[xx];
+               if (style.name() == paraStyle.name())
+               {
+                       if (style.equiv(paraStyle))
                        {
                                found = true;
                        }
                        else
                        {
-                               style.setName("Copy of 
"+(*docParagraphStyles)[xx].name());
+                               
style.setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
                                found = false;
                        }
                        break;
@@ -6620,12 +6620,13 @@
        }
        if (!found && fl)
        {
-               for (int xx=0; xx< docParagraphStyles->count(); ++xx)
-               {
-                       if (style.equiv((*docParagraphStyles)[xx]))
-                       {
-                               parStyleMap[style.name()] = 
(*docParagraphStyles)[xx].name();
-                               style.setName((*docParagraphStyles)[xx].name());
+               for (int xx = 0; xx < docParagraphStyles.count(); ++xx)
+               {
+                       const ParagraphStyle& paraStyle = 
docParagraphStyles[xx];
+                       if (style.equiv(paraStyle))
+                       {
+                               parStyleMap[style.name()] = paraStyle.name();
+                               style.setName(paraStyle.name());
                                found = true;
                                break;
                        }

Modified: trunk/Scribus/scribus/styles/styleset.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/styles/styleset.h
==============================================================================
--- trunk/Scribus/scribus/styles/styleset.h     (original)
+++ trunk/Scribus/scribus/styles/styleset.h     Wed Oct  9 03:19:13 2019
@@ -4,6 +4,7 @@
 #define STYLESET_H
 
 #include <QList>
+#include <QRegExp>
 
 #include <assert.h>
 #include "style.h"
@@ -38,6 +39,8 @@
        inline int find(const QString& name) const;
 
        inline const BaseStyle* resolve(const QString& name) const;
+
+       QString getUniqueCopyName(const QString& originalName) const;
        
        int count() const
        {
@@ -124,7 +127,7 @@
 template<class STYLE>
 inline void StyleSet<STYLE>::remove(int index)
 {
-       assert(index>=0 && index < styles.count()); 
+       assert(index >= 0 && index < styles.count()); 
 //     QList<STYLE*> it = styles.at(index);
        if (styles.at(index) == m_default)
                return;
@@ -156,7 +159,7 @@
 {
        if (name.isEmpty())
                return m_default;
-       for (int i=0; i < styles.count(); ++i)
+       for (int i = 0; i < styles.count(); ++i)
        {
                if (styles[i]->name() == name)
                        return styles[i];
@@ -165,12 +168,49 @@
 }
 
 template<class STYLE>
+QString StyleSet<STYLE>::getUniqueCopyName(const QString& originalName) const
+{
+       if (!this->contains(originalName))
+               return originalName;
+
+       QString newName(originalName);
+
+       // Search the string for (number) at the end and capture
+       // both the number and the text leading up to it sans brackets.
+       //     Copy of fred (5)
+       //     ^^^^^^^^^^^^  ^   (where ^ means captured)
+       static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
+       int numMatches = rx.lastIndexIn(originalName);
+       // Add a (number) suffix to the end of the name. We start at the
+       // old suffix's value if there was one, or at 2 if there was not.
+       int suffixNum = 1;
+       QString prefix(newName);
+       if (numMatches != -1)
+       {
+               // Already had a suffix; use the name w/o suffix for prefix and
+               // grab the old suffix value as a starting point.
+               QStringList matches = rx.capturedTexts();
+               prefix = matches[1];
+               suffixNum = matches[2].toInt();
+       }
+       // Keep on incrementing the suffix 'till we find a free name
+       do
+       {
+               suffixNum ++;
+               newName = prefix + " (" + QString::number(suffixNum) + ")";
+       }
+       while (this->contains(newName));
+
+       return newName;
+}
+
+template<class STYLE>
 inline void StyleSet<STYLE>::redefine(const StyleSet<STYLE>& defs, bool 
removeUnused)
 {
-       for (int i=signed(styles.count())-1; i >= 0; --i) 
+       for (int i = styles.count() - 1; i >= 0; --i) 
        {
                bool found = false;
-               for (int j=0; j < defs.count(); ++j)
+               for (int j = 0; j < defs.count(); ++j)
                {
                        if (styles[i]->name() == defs[j].name()) 
                        {
@@ -189,7 +229,7 @@
                        remove(i);
                }
        }
-       for (int j=0; j < defs.count(); ++j)
+       for (int j = 0; j < defs.count(); ++j)
        {
                if (find(defs[j].name()) < 0) 
                {
@@ -204,7 +244,7 @@
 template<class STYLE>
 inline void StyleSet<STYLE>::rename(const QMap<QString,QString>& newNames)
 {
-       for (int i=0; i < styles.count(); ++i)
+       for (int i = 0; i < styles.count(); ++i)
        { 
                QMap<QString,QString>::ConstIterator it;
                

Modified: trunk/Scribus/scribus/ui/smcellstyle.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/ui/smcellstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smcellstyle.cpp    (original)
+++ trunk/Scribus/scribus/ui/smcellstyle.cpp    Wed Oct  9 03:19:13 2019
@@ -167,7 +167,7 @@
                return QString();
 
        // Copy the style with name constructed from the original name.
-       QString styleName(getUniqueName(tr("Clone of %1").arg(fromStyle)));
+       QString styleName(getUniqueName(fromStyle));
        CellStyle cellStyle(m_cachedStyles.get(fromStyleName));
        cellStyle.setDefaultStyle(false);
        cellStyle.setName(styleName);
@@ -379,29 +379,7 @@
 
 QString SMCellStyle::getUniqueName(const QString &name)
 {
-       int id = 0;
-       bool done = false;
-       QString s(name);
-
-       while (!done)
-       {
-start:
-               ++id;
-               for (int i = 0; i < m_cachedStyles.count(); ++i)
-               {
-                       if (m_cachedStyles[i].name() == s)
-                       {
-                               s = tr("%1 (%2)", "This for unique name when 
creating "
-                                               "a new character style. %1 will 
be the name "
-                                                               "of the style 
and %2 will be a number forming "
-                                                               "a style name 
like: New Style (2)").arg(name).arg(id);
-                               goto start;
-                       }
-               }
-               done = true;
-       }
-
-       return s;
+       return m_cachedStyles.getUniqueCopyName(name);
 }
 
 void SMCellStyle::languageChange()

Modified: trunk/Scribus/scribus/ui/smlinestyle.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/ui/smlinestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smlinestyle.cpp    (original)
+++ trunk/Scribus/scribus/ui/smlinestyle.cpp    Wed Oct  9 03:19:13 2019
@@ -6,6 +6,7 @@
 */
 
 #include <QEvent>
+#include <QRegExp>
 
 #include "colorcombo.h"
 #include "smlinestyle.h"
@@ -199,26 +200,46 @@
        Q_ASSERT(m_tmpLines.contains(fromStyle));
 
        multiLine ml(m_tmpLines[fromStyle]);
-       QString name = getUniqueName( tr("Clone of %1").arg(fromStyle));
+       QString name = getUniqueName(fromStyle);
        m_tmpLines[name] = ml;
        return name;
 }
 
 QString SMLineStyle::getUniqueName(const QString &name)
 {
-       int id = 0;
-       QString s = name;
-
-       while (m_tmpLines.contains(s))
-       {
-               ++id;
-               s = tr("%1 (%2)", "This for unique name when creating "
-                       "a new character style. %1 will be the name "
-                       "of the style and %2 will be a number forming "
-                       "a style name like: New Style (2)").arg(name).arg(id);
-       }
-
-       return s;
+       // Unfortunately we have to copy the logic from 
StyleSet::generateUniqueCopyName
+       if (!m_tmpLines.contains(name))
+               return name;
+
+       QString newName(name);
+
+       // Search the string for (number) at the end and capture
+       // both the number and the text leading up to it sans brackets.
+       //     Copy of fred (5)
+       //     ^^^^^^^^^^^^  ^   (where ^ means captured)
+       static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
+       int numMatches = rx.lastIndexIn(name);
+       // Add a (number) suffix to the end of the name. We start at the
+       // old suffix's value if there was one, or at 2 if there was not.
+       int suffixNum = 1;
+       QString prefix(newName);
+       if (numMatches != -1)
+       {
+               // Already had a suffix; use the name w/o suffix for prefix and
+               // grab the old suffix value as a starting point.
+               QStringList matches = rx.capturedTexts();
+               prefix = matches[1];
+               suffixNum = matches[2].toInt();
+       }
+       // Keep on incrementing the suffix 'till we find a free name
+       do
+       {
+               suffixNum ++;
+               newName = prefix + " (" + QString::number(suffixNum) + ")";
+       }
+       while (m_tmpLines.contains(newName));
+
+       return newName;
 }
 
 void SMLineStyle::apply()

Modified: trunk/Scribus/scribus/ui/smtablestyle.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/ui/smtablestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtablestyle.cpp   (original)
+++ trunk/Scribus/scribus/ui/smtablestyle.cpp   Wed Oct  9 03:19:13 2019
@@ -163,7 +163,7 @@
                return QString();
 
        // Copy the style with name constructed from the original name.
-       QString styleName(getUniqueName(tr("Clone of %1").arg(fromStyle)));
+       QString styleName(getUniqueName(fromStyle));
        TableStyle tableStyle(m_cachedStyles.get(fromStyleName));
        tableStyle.setDefaultStyle(false);
        tableStyle.setName(styleName);
@@ -375,29 +375,7 @@
 
 QString SMTableStyle::getUniqueName(const QString &name)
 {
-       int id = 0;
-       bool done = false;
-       QString s(name);
-
-       while (!done)
-       {
-start:
-               ++id;
-               for (int i = 0; i < m_cachedStyles.count(); ++i)
-               {
-                       if (m_cachedStyles[i].name() == s)
-                       {
-                               s = tr("%1 (%2)", "This for unique name when 
creating "
-                                               "a new character style. %1 will 
be the name "
-                                                               "of the style 
and %2 will be a number forming "
-                                                               "a style name 
like: New Style (2)").arg(name).arg(id);
-                               goto start;
-                       }
-               }
-               done = true;
-       }
-
-       return s;
+       return m_cachedStyles.getUniqueCopyName(name);
 }
 
 void SMTableStyle::languageChange()

Modified: trunk/Scribus/scribus/ui/smtextstyles.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23240&path=/trunk/Scribus/scribus/ui/smtextstyles.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtextstyles.cpp   (original)
+++ trunk/Scribus/scribus/ui/smtextstyles.cpp   Wed Oct  9 03:19:13 2019
@@ -249,7 +249,7 @@
                return QString();
 
        //Copy the style with the original name
-       QString s(getUniqueName( tr("Clone of %1").arg(fromStyle)));
+       QString s(getUniqueName(fromStyle));
        ParagraphStyle p(m_tmpStyles.get(copiedStyleName));
        p.setDefaultStyle(false);
        p.setName(s);
@@ -262,29 +262,7 @@
 // helper function to find a unique name to a new style or a clone
 QString SMParagraphStyle::getUniqueName(const QString &name)
 {
-       int id = 0;
-       bool done = false;
-       QString s(name);
-
-       while (!done)
-       {
-start:
-               ++id;
-               for (int i = 0; i < m_tmpStyles.count(); ++i)
-               {
-                       if (m_tmpStyles[i].name() == s)
-                       {
-                               s = tr("%1 (%2)", "This for unique name when 
creating "
-                                               "a new character style. %1 will 
be the name "
-                                                               "of the style 
and %2 will be a number forming "
-                                                               "a style name 
like: New Style (2)").arg(name).arg(id);
-                               goto start;
-                       }
-               }
-               done = true;
-       }
-
-       return s;
+       return m_tmpStyles.getUniqueCopyName(name);
 }
 
 void SMParagraphStyle::apply()
@@ -2266,7 +2244,7 @@
        if (!m_tmpStyles.resolve(copiedStyleName))
                return QString();
        //Copy the style with the original name
-       QString s(getUniqueName( tr("Clone of %1").arg(fromStyle)));
+       QString s(getUniqueName(fromStyle));
        CharStyle c(m_tmpStyles.get(copiedStyleName));
        c.setDefaultStyle(false);
        c.setName(s);
@@ -2278,29 +2256,7 @@
 
 QString SMCharacterStyle::getUniqueName(const QString &name)
 {
-       int id = 0;
-       bool done = false;
-       QString s(name);
-
-       while (!done)
-       {
-start:
-               ++id;
-               for (int i = 0; i < m_tmpStyles.count(); ++i)
-               {
-                       if (m_tmpStyles[i].name() == s)
-                       {
-                               s = tr("%1 (%2)", "This for unique name when 
creating "
-                                               "a new character style. %1 will 
be the name "
-                                                               "of the style 
and %2 will be a number forming "
-                                                               "a style name 
like: New Style (2)").arg(name).arg(id);
-                               goto start;
-                       }
-               }
-               done = true;
-       }
-
-       return s;
+       return m_tmpStyles.getUniqueCopyName(name);
 }
 
 void SMCharacterStyle::apply()


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to