Support preserving case when replacing.

When making a case insensitive search, try to keep the string capitalization when doing
the replace:
      - All upper-case matches are replaced with the upper-case new	text.
      - All lower-case matches are replaced with the lower-case new text.
      - Capitalized matches are replace with the capitalized new text.
      - Other matches are replaced with the new text as provided.

Note: this does not work with regexp replace, only plain text.

Change-Id: I87cbc28eb64688bdf3c8c6ec173fcb22f91abcd0
Reviewed-by: Cristian Tibirna <tibirna@kde.org>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Francois Ferrand
2012-11-30 16:15:07 +01:00
committed by Eike Ziller
parent a8a33b9a3b
commit 058d2e8cb5
23 changed files with 256 additions and 32 deletions

View File

@@ -270,6 +270,11 @@ void FindPlugin::setRegularExpression(bool regExp)
setFindFlag(Find::FindRegularExpression, regExp);
}
void FindPlugin::setPreserveCase(bool preserveCase)
{
setFindFlag(Find::FindPreserveCase, preserveCase);
}
void FindPlugin::setFindFlag(Find::FindFlag flag, bool enabled)
{
bool hasFlag = hasFindFlag(flag);
@@ -296,6 +301,7 @@ void FindPlugin::writeSettings()
settings->setValue(QLatin1String("CaseSensitively"), hasFindFlag(Find::FindCaseSensitively));
settings->setValue(QLatin1String("WholeWords"), hasFindFlag(Find::FindWholeWords));
settings->setValue(QLatin1String("RegularExpression"), hasFindFlag(Find::FindRegularExpression));
settings->setValue(QLatin1String("PreserveCase"), hasFindFlag(Find::FindPreserveCase));
settings->setValue(QLatin1String("FindStrings"), d->m_findCompletions);
settings->setValue(QLatin1String("ReplaceStrings"), d->m_replaceCompletions);
settings->endGroup();
@@ -312,6 +318,7 @@ void FindPlugin::readSettings()
setCaseSensitive(settings->value(QLatin1String("CaseSensitively"), false).toBool());
setWholeWord(settings->value(QLatin1String("WholeWords"), false).toBool());
setRegularExpression(settings->value(QLatin1String("RegularExpression"), false).toBool());
setPreserveCase(settings->value(QLatin1String("PreserveCase"), false).toBool());
blockSignals(block);
d->m_findCompletions = settings->value(QLatin1String("FindStrings")).toStringList();
d->m_replaceCompletions = settings->value(QLatin1String("ReplaceStrings")).toStringList();