diff --git a/apps/opencs/view/tools/searchbox.cpp b/apps/opencs/view/tools/searchbox.cpp index 1e92acb75..ca5520787 100644 --- a/apps/opencs/view/tools/searchbox.cpp +++ b/apps/opencs/view/tools/searchbox.cpp @@ -36,7 +36,7 @@ void CSVTools::SearchBox::updateSearchButton() } CSVTools::SearchBox::SearchBox (QWidget *parent) -: QWidget (parent), mSearch ("Search"), mSearchEnabled (false) +: QWidget (parent), mSearch ("Search"), mSearchEnabled (false), mReplace ("Replace All") { mLayout = new QGridLayout (this); @@ -78,12 +78,16 @@ CSVTools::SearchBox::SearchBox (QWidget *parent) mReplaceInput.insertWidget (1, &mReplacePlaceholder); mLayout->addWidget (&mReplaceInput, 1, 1); + + mLayout->addWidget (&mReplace, 1, 3); // layout adjustments mLayout->setColumnMinimumWidth (2, 50); mLayout->setColumnStretch (1, 1); mLayout->setContentsMargins (0, 0, 0, 0); + + connect (&mReplace, (SIGNAL (clicked (bool))), this, SLOT (replaceAll (bool))); // update modeSelected (0); @@ -144,6 +148,11 @@ std::string CSVTools::SearchBox::getReplaceText() const } } +void CSVTools::SearchBox::setEditLock (bool locked) +{ + mReplace.setEnabled (!locked); +} + void CSVTools::SearchBox::modeSelected (int index) { switch (index) @@ -176,3 +185,8 @@ void CSVTools::SearchBox::startSearch (bool checked) if (mSearch.isEnabled()) emit startSearch (getSearch()); } + +void CSVTools::SearchBox::replaceAll (bool checked) +{ + emit replaceAll(); +} diff --git a/apps/opencs/view/tools/searchbox.hpp b/apps/opencs/view/tools/searchbox.hpp index 594788e6c..433c09693 100644 --- a/apps/opencs/view/tools/searchbox.hpp +++ b/apps/opencs/view/tools/searchbox.hpp @@ -31,6 +31,7 @@ namespace CSVTools QStackedWidget mReplaceInput; QLineEdit mReplaceText; QLabel mReplacePlaceholder; + QPushButton mReplace; private: @@ -46,6 +47,8 @@ namespace CSVTools std::string getReplaceText() const; + void setEditLock (bool locked); + private slots: void modeSelected (int index); @@ -54,9 +57,13 @@ namespace CSVTools void startSearch (bool checked = true); + void replaceAll (bool checked); + signals: void startSearch (const CSMTools::Search& search); + + void replaceAll(); }; } diff --git a/apps/opencs/view/tools/searchsubview.cpp b/apps/opencs/view/tools/searchsubview.cpp index 0bdb9d658..5743ad761 100644 --- a/apps/opencs/view/tools/searchsubview.cpp +++ b/apps/opencs/view/tools/searchsubview.cpp @@ -11,6 +11,36 @@ #include "reporttable.hpp" #include "searchbox.hpp" +void CSVTools::SearchSubView::replace (bool selection) +{ + if (mLocked) + return; + + std::vector indices = mTable->getReplaceIndices (selection); + + std::string replace = mSearchBox.getReplaceText(); + + const CSMTools::ReportModel& model = + dynamic_cast (*mTable->model()); + + // We are running through the indices in reverse order to avoid messing up multiple results + // in a single string. + for (std::vector::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter) + { + CSMWorld::UniversalId id = model.getUniversalId (*iter); + + CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::getParentType (id.getType()); + + CSMWorld::IdTableBase *table = &dynamic_cast ( + *mDocument.getData().getTableModel (type)); + + std::string hint = model.getHint (*iter); + + mSearch.replace (mDocument, table, id, hint, replace); + mTable->flagAsReplaced (*iter); + } +} + CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) : CSVDoc::SubView (id), mDocument (document), mPaddingBefore (10), mPaddingAfter (10), mLocked (false) @@ -41,11 +71,14 @@ CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc: connect (&mSearchBox, SIGNAL (startSearch (const CSMTools::Search&)), this, SLOT (startSearch (const CSMTools::Search&))); + + connect (&mSearchBox, SIGNAL (replaceAll()), this, SLOT (replaceAllRequest())); } void CSVTools::SearchSubView::setEditLock (bool locked) { - mLocked = false; + mLocked = locked; + mSearchBox.setEditLock (locked); } void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list) @@ -77,30 +110,10 @@ void CSVTools::SearchSubView::startSearch (const CSMTools::Search& search) void CSVTools::SearchSubView::replaceRequest() { - if (mLocked) - return; - - std::vector indices = mTable->getReplaceIndices (true); - - std::string replace = mSearchBox.getReplaceText(); - - const CSMTools::ReportModel& model = - dynamic_cast (*mTable->model()); - - // We are running through the indices in reverse order to avoid messing up multiple results - // in a single string. - for (std::vector::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter) - { - CSMWorld::UniversalId id = model.getUniversalId (*iter); - - CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::getParentType (id.getType()); + replace (true); +} - CSMWorld::IdTableBase *table = &dynamic_cast ( - *mDocument.getData().getTableModel (type)); - - std::string hint = model.getHint (*iter); - - mSearch.replace (mDocument, table, id, hint, replace); - mTable->flagAsReplaced (*iter); - } +void CSVTools::SearchSubView::replaceAllRequest() +{ + replace (false); } diff --git a/apps/opencs/view/tools/searchsubview.hpp b/apps/opencs/view/tools/searchsubview.hpp index 59fbfe66e..eeefa9afb 100644 --- a/apps/opencs/view/tools/searchsubview.hpp +++ b/apps/opencs/view/tools/searchsubview.hpp @@ -31,6 +31,10 @@ namespace CSVTools CSMTools::Search mSearch; bool mLocked; + private: + + void replace (bool selection); + public: SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document); @@ -46,6 +50,8 @@ namespace CSVTools void startSearch (const CSMTools::Search& search); void replaceRequest(); + + void replaceAllRequest(); }; }