diff options
author | con <qtc-committer@nokia.com> | 2009-12-21 11:08:20 +0100 |
---|---|---|
committer | con <qtc-committer@nokia.com> | 2009-12-21 11:08:52 +0100 |
commit | 1a95f6f20545b9e73351a559c903629c46be4817 (patch) | |
tree | ec6c6de9e8386b0e34536c8d5aed9b39d753b045 /src/plugins/cpptools/cppfindreferences.cpp | |
parent | f229a7618a193438e6eec61aa69d2a35cbf3f5ee (diff) | |
download | qt-creator-1a95f6f20545b9e73351a559c903629c46be4817.tar.gz |
Implement string based search & replace in multiple files.
This uses the same UI as "Rename Symbol".
Moves the actual rename implementation to a static method in
BaseFileFind and uses it for rename symbol and search & replace.
Moves the signal notification for the code model from VCSManager to
the more general FileManager.
Note that as for rename symbol, there's no undo yet.
Task-number: QTCREATORBUG-73
Diffstat (limited to 'src/plugins/cpptools/cppfindreferences.cpp')
-rw-r--r-- | src/plugins/cpptools/cppfindreferences.cpp | 61 |
1 files changed, 5 insertions, 56 deletions
diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 8758a9f4b4..bf01f13fad 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -32,6 +32,7 @@ #include "cpptoolsconstants.h" #include <texteditor/basetexteditor.h> +#include <texteditor/basefilefind.h> #include <find/searchresultwindow.h> #include <extensionsystem/pluginmanager.h> #include <utils/filesearch.h> @@ -294,63 +295,11 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text, { Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename")); - if (text.isEmpty()) - return; - - QHash<QString, QList<Find::SearchResultItem> > changes; - - foreach (const Find::SearchResultItem &item, items) - changes[item.fileName].append(item); - - Core::EditorManager *editorManager = Core::EditorManager::instance(); - - QHashIterator<QString, QList<Find::SearchResultItem> > it(changes); - while (it.hasNext()) { - it.next(); - - const QString fileName = it.key(); - const QList<Find::SearchResultItem> items = it.value(); - - const QList<Core::IEditor *> editors = editorManager->editorsForFileName(fileName); - TextEditor::BaseTextEditor *textEditor = 0; - foreach (Core::IEditor *editor, editors) { - textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget()); - if (textEditor != 0) - break; - } - - if (textEditor != 0) { - QTextCursor tc = textEditor->textCursor(); - tc.beginEditBlock(); - applyChanges(textEditor->document(), text, items); - tc.endEditBlock(); - } else { - QFile file(fileName); - - if (file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - // ### set the encoding - const QString plainText = stream.readAll(); - file.close(); - - QTextDocument doc; - doc.setPlainText(plainText); - - applyChanges(&doc, text, items); - - QFile newFile(fileName); - if (newFile.open(QFile::WriteOnly)) { - QTextStream stream(&newFile); - // ### set the encoding - stream << doc.toPlainText(); - } - } - } + const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items); + if (!fileNames.isEmpty()) { + _modelManager->updateSourceFiles(fileNames); + _resultWindow->hide(); } - - const QStringList fileNames = changes.keys(); - _modelManager->updateSourceFiles(fileNames); - _resultWindow->hide(); } void CppFindReferences::displayResults(int first, int last) |