diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 7dac660c3..7a975c99c 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -208,6 +208,21 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in table:
" + toolTip);
}
+ declareSection ("search", "Search & Replace");
+ {
+ Setting *before = createSetting (Type_SpinBox, "char-before",
+ "Characters before search string");
+ before->setDefaultValue (10);
+ before->setRange (0, 1000);
+ before->setToolTip ("Maximum number of character to display in search result before the searched text");
+
+ Setting *after = createSetting (Type_SpinBox, "char-after",
+ "Characters after search string");
+ after->setDefaultValue (10);
+ after->setRange (0, 1000);
+ after->setToolTip ("Maximum number of character to display in search result after the searched text");
+ }
+
{
/******************************************************************
* There are three types of values:
diff --git a/apps/opencs/model/tools/search.cpp b/apps/opencs/model/tools/search.cpp
index e2bab3866..28d92f06a 100644
--- a/apps/opencs/model/tools/search.cpp
+++ b/apps/opencs/model/tools/search.cpp
@@ -85,11 +85,10 @@ QString CSMTools::Search::formatDescription (const QString& description, int pos
text.remove ('\r');
// split
- int padding = 10; ///< \todo make this configurable
-
QString highlight = flatten (text.mid (pos, length));
- QString before = flatten (padding<=pos ? text.mid (0, pos) : text.mid (pos-padding, padding));
- QString after = flatten (text.mid (pos+length, padding));
+ QString before = flatten (mPaddingBefore<=pos ?
+ text.mid (0, pos) : text.mid (pos-mPaddingBefore, mPaddingBefore));
+ QString after = flatten (text.mid (pos+length, mPaddingAfter));
// join
text = before + "" + highlight + "" + after;
@@ -111,24 +110,24 @@ QString CSMTools::Search::flatten (const QString& text) const
return flat;
}
-CSMTools::Search::Search() : mType (Type_None) {}
+CSMTools::Search::Search() : mType (Type_None), mPaddingBefore (10), mPaddingAfter (10) {}
CSMTools::Search::Search (Type type, const std::string& value)
-: mType (type), mText (value)
+: mType (type), mText (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_Text && type!=Type_Id)
throw std::logic_error ("Invalid search parameter (string)");
}
CSMTools::Search::Search (Type type, const QRegExp& value)
-: mType (type), mRegExp (value)
+: mType (type), mRegExp (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_TextRegEx && type!=Type_IdRegEx)
throw std::logic_error ("Invalid search parameter (RegExp)");
}
CSMTools::Search::Search (Type type, int value)
-: mType (type), mValue (value)
+: mType (type), mValue (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_RecordState)
throw std::logic_error ("invalid search parameter (int)");
@@ -230,3 +229,9 @@ void CSMTools::Search::searchRow (const CSMWorld::IdTableBase *model, int row,
}
}
}
+
+void CSMTools::Search::setPadding (int before, int after)
+{
+ mPaddingBefore = before;
+ mPaddingAfter = after;
+}
diff --git a/apps/opencs/model/tools/search.hpp b/apps/opencs/model/tools/search.hpp
index 0148beab3..452b3cad2 100644
--- a/apps/opencs/model/tools/search.hpp
+++ b/apps/opencs/model/tools/search.hpp
@@ -45,6 +45,8 @@ namespace CSMTools
std::set