Commit ad62b1e0 authored by Ivan Donchevskii's avatar Ivan Donchevskii

EditorManager: move all openEditor functions to one place

Remove code duplication for openEditor function that
gets search result as a parameter.

Change-Id: I3eb1c41b8a0fda3b2e8a4929cef1d5924295f1f5
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent 34a4c60d
......@@ -50,7 +50,9 @@ std::unique_ptr<SearchHandle> QtCreatorSearch::startNewSearch(const QString &sea
QObject::connect(searchResult,
&Core::SearchResult::activated,
&QtCreatorSearch::openEditor);
[](const Core::SearchResultItem& item) {
Core::EditorManager::openEditorAtSearchResult(item);
});
auto searchHandle = std::unique_ptr<SearchHandle>(new QtCreatorSearchHandle(searchResult));
......@@ -61,11 +63,4 @@ std::unique_ptr<SearchHandle> QtCreatorSearch::startNewSearch(const QString &sea
return searchHandle;
}
void QtCreatorSearch::openEditor(const Core::SearchResultItem &item)
{
Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.mainRange.begin.line,
item.mainRange.begin.column);
}
} // namespace ClangRefactoring
......@@ -41,10 +41,7 @@ public:
QtCreatorSearch(Core::SearchResultWindow &searchResultWindow);
std::unique_ptr<SearchHandle> startNewSearch(const QString &searchLabel,
const QString &searchTerm);
private:
static void openEditor(const Core::SearchResultItem &item);
const QString &searchTerm);
private:
Core::SearchResultWindow &searchResultWindow;
......
......@@ -48,6 +48,7 @@
#include <coreplugin/editortoolbar.h>
#include <coreplugin/fileutils.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/find/searchresultitem.h>
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
#include <coreplugin/infobar.h>
......@@ -2646,6 +2647,17 @@ IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int colu
fileName, line, column, editorId, flags, newEditor);
}
void EditorManager::openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags)
{
if (item.path.empty()) {
openEditor(QDir::fromNativeSeparators(item.text), Id(), flags);
return;
}
openEditorAt(QDir::fromNativeSeparators(item.path.first()), item.mainRange.begin.line,
item.mainRange.begin.column, Id(), flags);
}
EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)
{
// :10:2 GCC/Clang-style
......
......@@ -50,6 +50,7 @@ class IMode;
class IVersionControl;
class EditorToolBar;
class SearchResultItem;
enum MakeWritableResult {
OpenedWithVersionControl,
......@@ -114,6 +115,7 @@ public:
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
Id editorId = Id(), OpenEditorFlags flags = NoFlags,
bool *newEditor = 0);
static void openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags = NoFlags);
static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0,
const QByteArray &contents = QByteArray(),
const QString &uniqueId = QString(),
......
......@@ -370,7 +370,9 @@ void CppFindReferences::findAll_helper(SearchResult *search, Symbol *symbol,
return;
}
connect(search, &SearchResult::activated,
this, &CppFindReferences::openEditor);
[](const SearchResultItem& item) {
Core::EditorManager::openEditorAtSearchResult(item);
});
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
const WorkingCopy workingCopy = m_modelManager->workingCopy();
......@@ -589,18 +591,6 @@ static void searchFinished(SearchResult *search, QFutureWatcher<Usage> *watcher)
watcher->deleteLater();
}
void CppFindReferences::openEditor(const SearchResultItem &item)
{
if (item.path.size() > 0) {
EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.mainRange.begin.line,
item.mainRange.begin.column);
} else {
EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
}
}
namespace {
class FindMacroUsesInFile: public std::unary_function<QString, QList<Usage> >
......@@ -728,7 +718,9 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro &macro, const QStri
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
connect(search, &SearchResult::activated,
this, &CppFindReferences::openEditor);
[](const Core::SearchResultItem& item) {
Core::EditorManager::openEditorAtSearchResult(item);
});
const Snapshot snapshot = m_modelManager->snapshot();
const WorkingCopy workingCopy = m_modelManager->workingCopy();
......
......@@ -77,7 +77,6 @@ public:
void renameMacroUses(const CPlusPlus::Macro &macro, const QString &replacement = QString());
private:
void openEditor(const Core::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
void searchAgain();
......
......@@ -959,7 +959,9 @@ void FindReferences::displayResults(int first, int last)
this, &FindReferences::onReplaceButtonClicked);
}
connect(m_currentSearch.data(), &SearchResult::activated,
this, &FindReferences::openEditor);
[](const Core::SearchResultItem& item) {
Core::EditorManager::openEditorAtSearchResult(item);
});
connect(m_currentSearch.data(), &SearchResult::cancelled, this, &FindReferences::cancel);
connect(m_currentSearch.data(), &SearchResult::paused, this, &FindReferences::setPaused);
SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch | IOutputPane::WithFocus));
......@@ -1005,17 +1007,6 @@ void FindReferences::setPaused(bool paused)
m_watcher.setPaused(paused);
}
void FindReferences::openEditor(const SearchResultItem &item)
{
if (item.path.size() > 0) {
EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.mainRange.begin.line,
item.mainRange.begin.column);
} else {
EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
}
}
void FindReferences::onReplaceButtonClicked(const QString &text, const QList<SearchResultItem> &items, bool preserveCase)
{
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
......
......@@ -82,7 +82,6 @@ private:
void searchFinished();
void cancel();
void setPaused(bool paused);
void openEditor(const Core::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
QPointer<Core::SearchResult> m_currentSearch;
......
......@@ -448,16 +448,8 @@ void BaseFileFind::openEditor(const SearchResultItem &item)
FileFindParameters parameters = result->userData().value<FileFindParameters>();
IEditor *openedEditor =
d->m_searchEngines[parameters.searchEngineIndex]->openEditor(item, parameters);
if (!openedEditor) {
if (item.path.size() > 0) {
openedEditor = EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.mainRange.begin.line,
item.mainRange.begin.column, Id(),
EditorManager::DoNotSwitchToDesignMode);
} else {
openedEditor = EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
}
}
if (!openedEditor)
EditorManager::openEditorAtSearchResult(item, EditorManager::DoNotSwitchToDesignMode);
if (d->m_currentFindSupport)
d->m_currentFindSupport->clearHighlights();
d->m_currentFindSupport = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment